Skip to content

[5.9][Sema/SIL] InitAccessors: Support default initialization of init accessor properties #67437

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

xedin
Copy link
Contributor

@xedin xedin commented Jul 20, 2023

Cherry-pick of #67294


  • Explanation:

    Implements revision of the init accessor proposal where init accessor properties take over initialization of all properties in their initialization scope.

    • Emit default initialization of init accessor properties in user-defined initializers
    • Make sure that init accessor properties take over default initialization of all stored properties listed in "initializes"
    • Teach default class initializer emission (init()) about init accessors (even if a stored property doesn't have an initializer expression, the compiler needs to check whether init accessor property that handles it does).
    • Fix a bug in DI which used incorrect field indexes for subclasses.
  • Scope: Init accessors with default values

  • Main Branch PRs: [Sema/SIL] InitAccessors: Support default initialization of init accessor properties #67294

  • Resolves: rdar://112417250

  • Risk: Low

  • Reviewed By: @hborla @jckarter

  • Testing: Added test-cases to the suite.

Resolves: rdar://112417250

xedin added 10 commits July 20, 2023 10:57
…SILGenFunction

This is a preliminary step towards enabling default initialization of
init accessor properties in user-defined initializers because this logic
would have to be shared by multiple places during SILGen.

(cherry picked from commit 75ac138)
Instead of taking a setter type, let's switch over to a more general
`AccessorKind` which allows us to cover init accessors and simplify
`emitApplySetterToBase`.

(cherry picked from commit 5fd502b)
…eparate method

New method is going to be used to emit default value initializations
for user-defined constructors.

(cherry picked from commit 1f87ee8)
…xpressions

Similar to regular stored properties emit initialization expressions
for properties with init accessors at constructor's prolog.

(cherry picked from commit aa52e42)
…nitialization of stored properties

Default expression associated with an init accessor property
should always subsume that of any property listed in "initializes".

(cherry picked from commit fd2a7d5)
…about init accessors

If stored property is covered by one or more init accessor property,
it's default initializable when at least one of the init accessor
properties has default value.

(cherry picked from commit 2bfbb43)
…inBorrowOperation returns back original value

Calling `emitBeginBorrowOperation` on something which is `load_borrow`
for example with guaranteed ownership doesn't produce `begin_borrow`
instruction, so we need to be careful not to emit mismatched `end_borrow`
in such cases.

(cherry picked from commit 65cfb1c)
… with DI data structures

DI cares only about stored fields of the current type but `SILModule::getFieldIndex`
goes through all of the supertypes as well.

(cherry picked from commit 52ac782)
…ass properties

`super.init()` should fully initialize "super" which means that
such properties are mutated via a setter.

(cherry picked from commit c87daab)
@xedin xedin added 🍒 release cherry pick Flag: Release branch cherry picks swift 5.9 labels Jul 20, 2023
@xedin xedin requested a review from hborla July 20, 2023 18:00
@xedin xedin requested a review from a team as a code owner July 20, 2023 18:00
@xedin
Copy link
Contributor Author

xedin commented Jul 20, 2023

@swift-ci please test

@hborla hborla merged commit 6ba52b7 into swiftlang:release/5.9 Jul 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🍒 release cherry pick Flag: Release branch cherry picks swift 5.9
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants