Commit Graph

21 Commits

Author SHA1 Message Date
Slava Pestov
1a06313ac9 SIL: Fix DynamicSelfType references from inside init accessor
We need the self metatype parameter to correctly lower
DynamicSelfType in IRGen, so plumb this through to all
calls of init accessors, and inside the prolog of an
init accessor definition.

This does not break the public ABI, because init
accessors are never public. Also for value types, the
metatype is thin, so it should not change generated
code.

For classes we need the metatype in the general case
because of `Self`, but hopefully in most cases the
init accessor can be inlined away and the value_metatype
instruction subject to dead code elimination.

Fixes rdar://problem/119822466.
2024-01-09 10:52:54 -05:00
Pavel Yaskevich
3414609586 [Tests] NFC: Expand init accessor with nonmutating set coverage 2023-09-29 13:21:17 -07:00
Pavel Yaskevich
10947decec [SILGen] InitAccessors: Make sure that assign_or_init always directly references self
`nonmutating set` gets a copy of "self" in `GetterSetterComponent`
which is expected for partial application of the setter but doesn't
work for "self" reference that `assign_or_init` instruction needs
to emit references to stored properties during lowering. We need to
make sure that "self" is always a reference to rootself of the
constructor before passing it to `assign_or_init`.

Resolves: https://github.com/apple/swift/issues/67827
Resolves: rdar://114433261
2023-08-25 15:32:50 -07:00
Pavel Yaskevich
416bbaec8d [TypeChecker] InitAccessors: Fix handling of defaultable init accessor properties during default init synthesis
Default initializable init properties shouldn't prevent default
init synthesis and such properties without anything to initialize
should be considered by it.
2023-08-21 09:05:26 -07:00
Pavel Yaskevich
11f1b08ada [DI] Properties with init accessors without "initializes" act as stored
Adjust DI to treat init accessor properties that have only 'accesses'
or no restrictions as if they are stored properties, this means that
if such property doesn't have a default initializer users would have
to reference it explicitly in their custom initializers.

We also need to suppress default init synthesis for such cases which
would be done in a followup commit.

Resolves: rdar://113401979
2023-08-04 21:05:07 -07:00
Pavel Yaskevich
2a0651e8b0 [Frontend/NFC] SE-0400: Enable InitAccessors feature by default 2023-07-31 13:18:59 -07:00
Alex Hoppen
563a6805dc [test] Use @storageRestriction instead of initializes and access effects in test/Interpreter/init_accessors.swift 2023-07-27 14:54:19 -07:00
Pavel Yaskevich
52ac782184 [DI] InitAccessors: Use of SILModule::getFieldIndex is incompatible 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.
2023-07-18 17:19:42 -07:00
Pavel Yaskevich
2bfbb43af5 [CodeSynthesis] Teach AreAllStoredPropertiesDefaultInitableRequest 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.
2023-07-18 17:19:42 -07:00
Pavel Yaskevich
fd2a7d5ad3 [Sema] InitAccessors: Make sure that init accessor default subsumes initialization of stored properties
Default expression associated with an init accessor property
should always subsume that of any property listed in "initializes".
2023-07-18 17:19:42 -07:00
Pavel Yaskevich
aa52e42b3e [SILGen] InitAccessors: Start emitting init property initialization expressions
Similar to regular stored properties emit initialization expressions
for properties with init accessors at constructor's prolog.
2023-07-18 17:19:42 -07:00
Pavel Yaskevich
06216fc0f1 [Sema] InitAccessors: Synthesize memberwise inits only with init accessor properties 2023-07-07 13:56:02 -07:00
Pavel Yaskevich
e84cd810d1 [AST] InitAccessors: fallback to init accessor effects if @storageRestrictions is not used 2023-07-07 11:21:37 -07:00
Pavel Yaskevich
fe17491982 [AST] InitAccessors: Switch from init accessor effects (initializes/accesses) to @storageRestrictions 2023-07-07 10:00:36 -07:00
Pavel Yaskevich
8a1107ea45 [Tests] InitAccessors: Test use of init accessor properties without setters 2023-07-04 00:05:25 -07:00
Doug Gregor
fe2dec5ee5 [SE-0400] All properties with init accessors become part of the memberwise init
Per the clarification during the review thread, all properties with
init accessors (including those that do not initialize any underlying
storage) are part of the memberwise initializer.
2023-06-27 17:28:53 -07:00
Pavel Yaskevich
f58d4077c4 [Sema/SILGen] Consider init exprs associated with init accessor properties for memberwise init 2023-06-15 13:12:16 -07:00
Pavel Yaskevich
34c8cf60f1 [Sema/SILGen] InitAccessors: Memberwise initializers with init accessors 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.
2023-06-13 13:56:33 -07:00
Pavel Yaskevich
cffc3fd73d [Sema/SILGen] InitAccessors: Don't synthesize memberwise init if initializes 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.
2023-06-13 12:40:41 -07:00
Pavel Yaskevich
ddcfe01ba5 [Sema/SILGen] InitAccessors: Emit intersecting init accessor calls in 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.
2023-06-13 10:58:50 -07:00
Pavel Yaskevich
aaa72612bf [Tests] InitAccessors/NFC: add interpreter tests for different configurations of init accessors 2023-06-06 18:59:46 -07:00