[5.9][Parse/Sema/SIL] Implement init accessors
feature
#66372
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Cherry-pick of #66283
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
andaccesses
;Example of init accessor that initializes a stored property:
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 getinit(a: Int) { self.a = a }
.Adds a new SIL instruction -
assign_or_init
; Similar toassign_by_wrapper
the "mode" is set by DI based on each use site.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.