You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Adds a new kind of accessor - init accessor - which could be used
to initialize one or more stored properties of the type.
- Just like getter and setter accessors, init accessor could be used
on any computed property.
- Init accessors can specify a set of properties they initialize and
accesses (property that should be initialized already) via declaration
attributes - `initializes` and `accesses`;
- Example of init accessor that initializes a stored property:
```swift
public struct Test {
private var _a: Int
public var a: Int {
init(initialValue) initializes(_a) {
_a = initialValue
}
get { _a }
set { _a = newValue }
}
}
```
- Modifies memberwise initializers to take advantage of this new
mechanism by replacing one or more stored property parameters with
corresponding init accessor(s).
- `struct Test` from previous example would get `init(a: Int) { self.a = a }`.
- Adds a new SIL instruction - `assign_or_init`; Similar to `assign_by_wrapper`
the "mode" is set by DI based on each use site.
- New intruction also tracks "assignments" - fields that have been
previously initialized and would re-assigned by invocation of init
accessor, it enables as to call init accessors multiple times even
before all fields have been initializes.
- When used in an initializer body, init accessor (i.e. `self.a = a`)
call becomes either an initialization (if all of the fields haven't
been initialized yet), or a call to setter.
0 commit comments