Commit Graph

647 Commits

Author SHA1 Message Date
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
Evan Wilde
f3ff561c6f [NFC] add llvm namespace to Optional and None
This is phase-1 of switching from llvm::Optional to std::optional in the
next rebranch. llvm::Optional was removed from upstream LLVM, so we need
to migrate off rather soon. On Darwin, std::optional, and llvm::Optional
have the same layout, so we don't need to be as concerned about ABI
beyond the name mangling. `llvm::Optional` is only returned from one
function in
```
getStandardTypeSubst(StringRef TypeName,
                     bool allowConcurrencyManglings);
```
It's the return value, so it should not impact the mangling of the
function, and the layout is the same as `std::optional`, so it should be
mostly okay. This function doesn't appear to have users, and the ABI was
already broken 2 years ago for concurrency and no one seemed to notice
so this should be "okay".

I'm doing the migration incrementally so that folks working on main can
cherry-pick back to the release/5.9 branch. Once 5.9 is done and locked
away, then we can go through and finish the replacement. Since `None`
and `Optional` show up in contexts where they are not `llvm::None` and
`llvm::Optional`, I'm preparing the work now by going through and
removing the namespace unwrapping and making the `llvm` namespace
explicit. This should make it fairly mechanical to go through and
replace llvm::Optional with std::optional, and llvm::None with
std::nullopt. It's also a change that can be brought onto the
release/5.9 with minimal impact. This should be an NFC change.
2023-06-27 09:03:52 -07:00
Doug Gregor
a1464cfc2e Correctly remove properties subsumed by init accessors from memberwise inits
The code to remove these subsumed properties was part of creating the
memberwise initializer declaration, which could lead to
inconsistencies with the newly-introduced request for gathering the
memberwise-initialized properties. Move the code into the computation
of the list of memberwise-initialized properties.

Also update a few more places that were effectively recomputing the
set of memberwise-initialized properties themselves over to the
request.
2023-06-23 11:34:54 -07:00
Doug Gregor
e89fdd3084 Requestify the computation of the list of memberwise initialized properties.
Fixes rdar://110776763, a case where initialized stored properties
introduced by peer macros weren't working alongside declared stored
properties.
2023-06-23 11:34:52 -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
2b8a39724c Merge pull request #66513 from xedin/init-accessor-diagnostics
[Sema/SIL] Improve diagnostics related to init accessors
2023-06-14 09:57:08 -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
4f59538eba [Sema] InitAccessors: Diagnose situations when memberwise init cannot 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.
2023-06-13 10:58:50 -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
Holly Borla
cd752cca22 [NameLookup] Plumb source location arguments through all name lookup APIs.
This source location will be used to determine whether to add a name lookup
option to exclude macro expansions when the name lookup request is constructed.
Currently, the source location argument is unused.
2023-06-11 23:09:47 -07:00
Pavel Yaskevich
8c54d3d560 [Sema] InitAccessors: Don't synthesize default memberwise arg for init accessor initializations
Default arguments for `init accessors` are not fully supported
at the moment, so we shouldn't attempt to synthesize them in
Sema just to crash during linking.
2023-06-08 12:13:55 -07:00
Pavel Yaskevich
ad95e911a8 [Sema/SIL] InitAccessors: Incorporate init accessors into memberwise initializers
Properties with init accessors are used in place of properties they
are supposed to initialize in order of stored properties.
2023-06-06 18:59:46 -07:00
Allan Shortlidge
aef5e42457 Sema: Inherit SPI groups when synthesizing modify accessor.
Resolves rdar://108069565
2023-05-01 15:34:08 -07:00
Becca Royal-Gordon
e8c43bb168 Fix @objcImpl subclass init visibility computation
When writing an @objc subclass of an @objcImplementation class, implicit initializers in the subclass were treated as overriding the *implementation decl*, not the *interface decl*, of the initializer in the superclass. This caused Swift to incorrectly compute the visibility of the superclass initializer and omit an `override` keyword from the module interface when one would definitely be necessary.

Correct this oversight by looking up the interface decl matching the superclass implementation in `collectNonOveriddenSuperclassInits()`.
2023-03-25 14:53:29 -07:00
Becca Royal-Gordon
7d93b7543d Merge pull request #63534 from beccadax/default-is-not-init-stars
Make objcImpl classes derive inherited inits
2023-02-09 12:02:44 -08:00
Becca Royal-Gordon
31d8cadcd7 Make objcImpl classes derive inherited inits
A class that uses @objcImplementation but does not explicitly declare any designated initializers previously did not override the superclass initializers, so its stored properties would not be initialized. Opt these classes into that logic and adjust it to add the initializers to the @objcImplementation extension instead of the ClassDecl itself.

Fixes rdar://105008242.
2023-02-08 15:58:17 -08:00
Pavel Yaskevich
e2b22d9f62 [AST/Sema] Remove TypeWrapper feature functionality 2023-02-08 00:16:00 -08:00
Pavel Yaskevich
0987eff828 [Sema] TypeWrappers: Availability of init(storageWrapper:) should match that of $Storage 2023-01-04 16:04:28 -08:00
Pavel Yaskevich
ed2e07e0a1 [Sema] TypeWrappers: If type wrapper comes from .swiftinterface use synthesized decls
Swift interfaces have both attribute and all publicly accessible
synthesized members, which means that the synthesis needs to be
taught to lookup existing synthesized declarations for `$storage`,
`$Storage`, and `init(storageWrapper:)` if request comes for
declaration that belongs to a Swift interface file.
2023-01-04 16:04:28 -08:00
Pavel Yaskevich
2ce48e0b7d [AST/Sema] TypeWrappers: Augment GetTypeWrapper request to produce more info
The request is updated to return attribute, wrapper declaration,
the declaration its attached to and whether or not it has been
inferred (opposite to being declared directly).
2022-12-14 17:50:22 -08:00
Allan Shortlidge
abdc4d9112 SILGen: Use has_symbol instruction in SILGen. 2022-11-16 16:07:29 -08:00
Pavel Yaskevich
e762d20568 Merge pull request #61982 from xedin/type-wrappers-on-protocols
[Sema] TypeWrappers: Allow type wrappers on protocols and inference from them
2022-11-14 12:46:48 -08:00
Allan Shortlidge
7782f862c0 Sema: Avoid adding nonisolated twice to synthesized Hashable methods.
https://github.com/apple/swift/pull/42041 introduced a centralized mechanism for adding the `nonisolated` attribute to synthesized decls but did not clean up the existing code that was already doing so for `Hashable` conformances.

Resolves rdar://102106591
2022-11-08 18:35:27 -08:00
Pavel Yaskevich
db4b6a5c0f [AST/Sema] TypeWrappers: Implement type wrappers on protocols
Adding a type wrapper attribute on a protocol does two things:

- Synthesizes `associatedtype $Storage` declaration with `internal` access
- Synthesizes `var $storage: <#Wrapper#><Self, Self.$Storage>` value requirement
2022-11-07 14:55:05 -08:00
Becca Royal-Gordon
4fa774d839 Allow ObjC superclass to disable init inheritance
ObjC classes which have only factory and convenience initializers cannot allow their convenience inits to be inherited. To provide these classes with a reliable opt-out, tweak support for @_hasMissingDesignatedInitializers so that it affects ObjC classes even if they’re in the same module as one another.

Fixes rdar://48511013.
2022-11-02 17:12:53 -07:00
Pavel Yaskevich
5eafcf66d7 [AST/Sema] TypeWrapper: Implement synthesis of init(storageWrapper:) initializer 2022-10-21 20:04:01 +01:00
Pavel Yaskevich
2ae0cb802a [AST/Sema] TypeWrappers: Add a request skeleton to synthesize init(storageWrapper: <Wrapper>)
If there are no type wrapper ignored stored properties, the
compiler would synthesize a special public initializer that
allows to initialize a wrapped type by providing a fully
initialized wrapper instance.
2022-10-21 20:04:01 +01:00
Pavel Yaskevich
b800b0b81b [CodeSynthesis] TypeWrappers: Add "memberwise" to implicit constructor kind 2022-10-21 20:04:01 +01:00
Pavel Yaskevich
4d5cf77fcd [Sema] TypeWrappers: Synthesize body of a memberwise initializer lazily
Make sure that memberwise initializer body doesn't force
other synthesis by emitting it lazily.

Resolves: rdar://99884355
2022-10-21 20:04:01 +01:00
Pavel Yaskevich
70b0cd523a [AST/Sema] TypeWrappers/NFC: Rename type wrapper storage property to $storage 2022-10-21 20:04:00 +01:00
Pavel Yaskevich
5c8c008c8e Merge pull request #61479 from xedin/type-wrappers-init-values-in-user-defined-inits
[SILGen] TypeWrappers:  Support default values in user-defined initializers
2022-10-21 08:48:35 +01:00
Hamish Knight
b645e63ce5 [AST] NFC: Refactor GenericTypeParamDecl construction
Add distinct overloads for the parser,
deserialization and code synthesis.
2022-10-14 15:40:12 +01:00
Allan Shortlidge
182cc8de37 SILGen: Implement if #_hasSymbol() conditions.
Emit a call to a helper function that determines whether the symbols associated with the declaration referenced in the `#_hasSymbol(...)` condition are non-null at runtime. An upcoming change will emit a definition for this function during IRGen.

Resolves rdar://100130015
2022-10-13 21:00:24 -07:00
Holly Borla
c4b946195e [AST] Replace the "type sequence" terminology with "parameter pack". 2022-10-10 16:28:13 -07:00
Pavel Yaskevich
24b2bcae09 [Sema] TypeWrappers: Subsume property init before injecting it into $Storage
It was done in `maybeAddTypeWrapperDefaultArg` before because
user-defined initializers weren't supported but now property
initializers need to be subsumed earlier to make sure that
SILGen doesn't try to emit them into user-defined initializers.
2022-10-07 17:35:47 -07:00
Pavel Yaskevich
92fbb3ebf3 [AST/Sema] TypeWrappers: Rename wrapped type memberwise initializer entry point 2022-09-29 20:50:37 -07:00
Pavel Yaskevich
53bcf9ff67 [Sema] TypeWrappers: Implement @typeWrapperIgnored checking 2022-09-09 23:52:40 -07:00
Pavel Yaskevich
6d2edc2789 [Sema] TypeWrappers: Disable memberwise synthesis if type has designated init
If type has any user-defined designated initializers, let's not
synthesize a special memberwise initializer.
2022-09-02 17:58:48 -07:00
Pavel Yaskevich
f7b366c669 [Sema] TypeWrappers: Don't try to manage compiler synthesized properties
Properties like `unownedExecutor` that are implicitly injected into
a type should not be managed by a type wrapper.
2022-08-30 16:47:10 -07:00
Pavel Yaskevich
347e85ddc4 [Sema] TypeWrappers: Add unamanged stored properties to the synthesized memberwise init
If a stored property would be in a default memberwise initializer
it would be added to the `init` synthesized for a type wrapped type
as well i.e. a `let` property without a default.
2022-08-26 12:25:22 -07:00
Pavel Yaskevich
5a73b48599 [Sema] CodeSynthesis: Extract logic to synthesize a parameter for memberwise init 2022-08-26 12:25:22 -07:00
Pavel Yaskevich
0500f35537 [Sema] TypeWrappers: Synthesize init parameters for property wrapped members
Since properties with property wrappers are not supported, default
init synthesis needs to handle them as well by using correct interface
type depending on outer wrapper capabilities and setting correct
default expression.
2022-08-26 12:25:22 -07:00
Pavel Yaskevich
20a52d2f97 [Sema] TypeWrappers/NFC: Move initializer synthesis into a request 2022-08-26 12:25:22 -07:00
Pavel Yaskevich
39b1566240 [Sema] TypeWrappers: convert variable init expr into initializer default
All of the stored properties are wrapped which means that their
initializers are subsummed and moved to the synthesized `init`
as default arguments.
2022-08-26 12:25:22 -07:00
Pavel Yaskevich
39f5b69bce [TypeChecker] Synthesize initializer for a type wrapped declaration
Synthesize an `init` declaration which is going to initialize
type wrapper instance property `$_storage` via user provided
values for all stored properties.
2022-08-26 12:25:22 -07:00
Pavel Yaskevich
0711d774b7 [Sema] Don't attempt init synthesis for type wrapped types
Compiler cannot synthesize regular memberwise or default
initializers for type wrapped types because stored properties
of such a type cannot be accessed directly.

A special initializer would be synthesized instead, it is going
to initialize `$_storage` variable and handle default initialization
of stored properties.
2022-08-26 12:25:22 -07:00
Evan Wilde
2373421043 [Windows]: explicitly set closure captures
MSVC isn't seeing that `CheckDefaultInitializer` is declared and being
implicitly captured by reference by the closure going into the
`forEachVariable`.
Capturing `HasStorage` and `CheckDefaultInitializer` explicitly.
2022-08-19 09:23:19 -07:00
Hamish Knight
6b9bcf3935 [AST] Change DotSyntaxCallExpr to take an Argument base
This allows us to more easily propagate inout
information to it, which will become a necessity
once InOutExpr is removed.
2022-08-08 15:11:00 +01:00
Slava Pestov
fcf79485d6 Sema: Tighten up invariants for createDesignatedInitOverride() 2022-07-29 12:01:26 -04:00