Commit Graph

659 Commits

Author SHA1 Message Date
Holly Borla
cbdb892fe5 Merge pull request #69391 from hborla/isolated-default-value-revision
[Concurrency] Allow isolated default arguments to be used from across isolation boundaries.
2023-10-26 09:33:25 -07:00
Holly Borla
49d6399a88 [Concurrency] Allow isolated default arguments to be used from across isolation
boundaries.
2023-10-24 22:54:22 -07:00
Doug Gregor
5ad39c84e0 [Typed throws] Record thrown error types and conversions in the AST
For any operation that can throw an error, such as calls, property
accesses, and non-exhaustive do..catch statements, record the thrown
error type along with the conversion from that thrown error to the
error type expected in context, as appropriate. This will prevent
later stages from having to re-compute the conversion sequences.
2023-10-24 12:40:22 -07:00
Doug Gregor
ef642098f2 [Typed throws] Parsing and AST representation for typed errors
Parse typed throw specifiers as `throws(X)` in every place where there
are effects specified, and record the resulting thrown error type in
the AST except the type system. This includes:
* `FunctionTypeRepr`, for the parsed representation of types
* `AbstractFunctionDecl`, for various function-like declarations
* `ClosureExpr`, for closures
* `ArrowExpr`, for parsing of types within expression context

This also introduces some serialization logic for the thrown error
type of function-like declarations, along with an API to extract the
thrown interface type from one of those declarations, although right
now it will either be `Error` or empty.
2023-09-29 10:51:51 -07:00
Pavel Yaskevich
a0573e0219 [CodeSynthesis] Make sure that init synthesis expands macros
Previously both `AreAllStoredPropertiesDefaultInitableRequest`
and `HasMemberwiseInitRequest` checked only "current" properties
of the type but macro expansions can add new stored and/or
init accessor properties that affect this logic so we need to
make sure that macro expansions happen and new properties are
accounted for.

Note that the original idea was to use `getStoredProperties()`
but that runs into multiple circularity issues related to lazy
properties.

Resolves: rdar://112153201
2023-08-21 18:03:01 -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
Slava Pestov
9ebb5f2e03 AST: Rename VarDecl::getType() to VarDecl::getTypeInContext()
This is a futile attempt to discourage future use of getType() by
giving it a "scary" name.

We want people to use getInterfaceType() like with the other decl kinds.
2023-08-04 14:19:25 -04:00
Pavel Yaskevich
e2bac24023 [TypeChecker] Make sure that distributed actors always get "default" init
Default initialization of stored properties doesn't play a role
in default init synthesis for distributed actors.
2023-08-02 10:30:44 -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
06216fc0f1 [Sema] InitAccessors: Synthesize memberwise inits only with init accessor properties 2023-07-07 13:56:02 -07:00
Pavel Yaskevich
28a39d6df1 [AST] NFC: Add a way to request initialized/accesses properties from init accessor 2023-07-07 10:00:36 -07:00
Slava Pestov
fdb42fe031 Sema: Fix weird logic in TypeChecker::addImplicitConstructors() 2023-06-30 12:40:13 -04: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
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