Skip to content

[Sema/SIL] Improve diagnostics related to init accessors #66513

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

Merged
merged 10 commits into from
Jun 14, 2023

Conversation

xedin
Copy link
Contributor

@xedin xedin commented Jun 9, 2023

  • Diagnose standalone self within init accessors
  • Diagnose references to members not listed in initializes or accesses attributes within init accessors
  • Enforce that @out parameters are fully initialized before every terminator
  • Detect and don't synthesize memberwise initializer with intersecting init accessor calls
  • Diagnose situations when memberwise init cannot be synthesized due to use of not-yet-initialized properties

@xedin xedin requested review from hborla and slavapestov as code owners June 9, 2023 21:20
@xedin xedin changed the title [Sema/SILGen] Improve diagnostics related to init accessors [Sema/SIL] Improve diagnostics related to init accessors Jun 9, 2023
@xedin
Copy link
Contributor Author

xedin commented Jun 10, 2023

@swift-ci please test

xedin added 10 commits June 13, 2023 10:58
'self' within init accessor could only be used to refer to
properties listed in `initializes` and `accesses` attributes.
…s within init accessors

Only properties that are listed in 'initializes' and 'accesses'
attributes could be referenced within init accessor. Detect any
and all invalid member references in the solver.
…d before every terminator

This closes a hole where an early return could leave some
properties from `initializes(...)` list uninitialized.

For example:

```swift
init(initialValue) initializes(_a, _b) {
  _a = initialValue.0
  if _a > 0 {
    return
  }

  _b = initialValue.1
}
```

Here `_b` is not initialized when `_a > 0`.
… memberwise init

If init accessor initialize the same properties, let's emit them
in sequence and emit `destroy_addr` in-between to make sure that
there is no double initialization.
… be synthesized

If some of the properties with init accessors have out of order
accesses diagnose that while checking whether memberwise init
could be synthesized.
…tializes` intersect

If some property is initializable by one than one init accessor
let's not sythesize a memberwise initializer in that case because
it's ambiguous what is the best init accessor to use.
…ors should follow field order

Skip stored properties that are initialized via init accessors and
emit parameters/initializations in field order which allows us to
cover more use-cases.
@xedin xedin force-pushed the init-accessor-diagnostics branch from 9ce73f5 to 34c8cf6 Compare June 13, 2023 20:57
@xedin
Copy link
Contributor Author

xedin commented Jun 13, 2023

@swift-ci please test

1 similar comment
@xedin
Copy link
Contributor Author

xedin commented Jun 14, 2023

@swift-ci please test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants