Commit Graph

3461 Commits

Author SHA1 Message Date
Holly Borla
e9750bc4e5 [Concurrency] Diagnose default values whose isolation differs from the corresponding
stored property.
2023-11-16 23:56:08 -05:00
Allan Shortlidge
84098f9fb1 Sema: Always mark initializers of lazy vars as subsumed.
Previously, the initializer expressions of lazy vars would only be marked as
subsumed when the getter body for the var was synthesized. This didn't work
with `-experimental-lazy-typechecking` since accessor synthesis was not
guaranteed to happen. Consequently, SILGen would emit the initializer even
though it was already subsumed and then assert/crash since the init had also
not been checked and contextualized. Now lazy var inits are marked subsumed in
the request creating storage.

Resolves rdar://118421753
2023-11-16 18:01:54 -08:00
Allan Shortlidge
8d7cf970a5 AST: Refactor pattern binding initializer expression state representation.
As a follow up to https://github.com/apple/swift/pull/69841, clarify the
possible states that initializer expression of a pattern can be in. The
possible states are not checked, checked, and "checked and contextualized"
(which is the new state that was introduced and requestified in the previous
PR). This refactoring encodes the states more explicitly and renames a few
compiler APIs to better align with the new naming. NFC.
2023-11-16 10:06:47 -08:00
Kavon Farvardin
2cd298926f [NCGenerics] fix existential conformances
I was not expanding default requirements in
AbstractGenericSignatureRequest or ExistentialLayout.

Also fixes printing of composition types.
2023-11-15 15:43:11 -08:00
Allan Shortlidge
111eea7f5d AST/SILGen: Requestify var initializer expression typechecking.
Allow initializer expressions to be emitted during SILGen when
`-experimental-lazy-typecheck` is specified by introducing a new request that
fully typechecks the init expressions of pattern binding declarations
on-demand.

There are still a few rough edges, like missing support for wrapped properties
and incomplete handling of subsumed initializers. Fixing these issues is not an
immediate priority because in the short term `-experimental-lazy-typecheck`
will always be accompanied by `-enable-library-evolution` and
`-experimental-skip-non-exportable-decls`. This means that only the
initializers of properties on `@frozen` types will need to be emitted and
property wrappers are not yet fully supported on properties belonging to
`@frozen` types.

Resolves rdar://117448868
2023-11-14 11:54:01 -08:00
Doug Gregor
b53026d8d4 [Macros] Macro-metaprogram macro roles
Introduce X-macros for the various macro roles, and use them to
macro-metaprogram a lot of boilerplate involved with introducing new
macro roles.
2023-11-13 22:37:54 -08:00
Allan Shortlidge
7e77241634 AST: Requestify unique underlying type substitutions.
Introduce a request that computes the unique underlying type substitution of an
opaque type declaration. This ensures that the type substitution is available
on-demand when generating SIL in lazy typechecking mode.

Resolves rdar://117439760
2023-11-10 13:27:33 -08:00
Robert Widmann
f93c66dbb7 Merge pull request #69709 from CodaFi/vulf-pack
Fix the Effective Access Level of package Declarations
2023-11-09 18:05:43 -07:00
Meghana Gupta
5658deae27 Add initial support for _resultDependsOnSelf
This is used to establish lifetime dependence between self and the result.

Add under NonEscapableTypes experimental feature
2023-11-08 01:48:59 -08:00
Konrad `ktoso` Malawski
d147898160 Merge pull request #69688 from ktoso/wip-distributed-overloads-2
[follow-up][Distributed]Adjust overload detection for distributed funcs
2023-11-08 13:34:38 +09:00
Robert Widmann
bdd4503709 Fix the Effective Access Level of package Declarations
swiftc mis-compiles package declarations today because it reports the effective access level of package declarations as less than public. There are a bunch of places in the optimizer that are checking the effective access level against an upper bound of public, so a lot of code winds up internalized or optimized as though it were internal when it definitely is not.

Fixes rdar://118081829
2023-11-07 15:55:22 -07:00
Konrad `ktoso` Malawski
c0b105722a Adjust overload detection for distributed funcs 2023-11-07 15:04:53 +09:00
Kavon Farvardin
f8d688ce12 [Sema] overhaul NoncopyableAnnotationRequest
We need to know whether the noncopyable annotation is inferred from its
generic parameters. This allows us to synthesize the conditional
conformance.
2023-11-06 15:41:46 -08:00
Kavon Farvardin
a9c64baaa3 [Sema] refactor TypeDecl::isNoncopyable
In preparation for reporting whether the inverse marking on a TypeDecl
was inferred instead of explicit.
2023-11-06 15:40:12 -08:00
swift-ci
62a24b51e1 Merge pull request #69595 from ktoso/wip-distributed-overloads
[Distributed] Allow overloads with different types; mangling can handle it
2023-11-06 03:31:44 -08:00
Konrad `ktoso` Malawski
8fde809a2c Remove ad-hoc ambiguity detection code; use conflicting() 2023-11-06 12:59:30 +09:00
Allan Shortlidge
4eb8ed7182 AST: Trigger HasStorageRequest when retrieving semantic attributes.
When retrieving the full list of semantic attributes for printing, trigger the
HasStorage request to add an implicit `@_hasStorage` attribute if necessary.

Resolves rdar://117768816
2023-11-02 10:18:00 -07:00
Allan Shortlidge
b74e4a2e20 Merge pull request #69599 from tshortli/rename-orig-attrs-to-parsed-attrs 2023-11-02 09:49:18 -07:00
Allan Shortlidge
e879c07542 AST: Rename getOrigAttrs() to getParsedAttrs().
To match terminology used elsewhere in the compiler (e.g. "parsed accessor")
rename "original attributes" to "parsed atributes". Additionally, make sure the
attributes returned by `getParsedAttrs()` really are just the parsed ones by
skipping implicit attributes in addition to the ones expanded from macros.
2023-11-01 22:50:09 -07:00
Alexis Laferrière
f2d1627656 [Serialization] Fix deserializing opaque types for computed properties and subscripts
A client shouldn't know about the underlying type of an opaque type
unless it can see the body of the naming decl. Attempting to read it can
lead to accessing a hidden dependency and a compiler crash.

This was protected by a check specific to function decls but var decls
and subscripts were not handled. To support them we have to move this
logic to the writer side where we have access to the full
AbstractStorageDecl and write in the swifmodule whether the underlying
type should be visible outside of the module.

rdar://117607906
2023-11-01 16:04:10 -07:00
Allan Shortlidge
b4c5cfd536 AST: Enumerate expanded attributes in TypeCheckAttr.
We need to avoid triggering semantic attribute requests in TypeCheckAttr
because it happens too early in type checking to trigger some semantic
attribute requests, and we only want to diagnose attributes that were written
in source anyways.
2023-11-01 10:44:28 -07:00
Allan Shortlidge
6d985e34a2 AST: Introduce Decl::getSemanticCustomAttrs().
In order to avoid triggering request cycles as `SemanticDeclAttrsRequest` grows
to cover a larger range of implicit attributes, we need a lighter-weight
accessor for just the CustomAttrs that have been expanded from macros.
Introduce `getSemanticCustomAttrs()` and adopt it where `getSemanticAttrs()`
had been previously used to enumerate macro expanded custom attributes.
2023-10-31 17:02:39 -07:00
Allan Shortlidge
a64f7052e2 AST: Introduce SemanticDeclAttrsRequest.
This request will populate a decl's attrs list with any semantic attributes
that were not written in source.
2023-10-31 16:52:46 -07:00
Ellie Shin
57e11b894f Delete skipAccessCheckIfInterface as no longer used 2023-10-30 14:00:03 -07:00
Ellie Shin
d570d41d99 s/ModuleInterfaceOptionIgnorablePrivate/ModuleInterfaceOption and formatting 2023-10-30 13:58:13 -07:00
Ellie Shin
7c80976081 Package name is only printed in private swiftinterface. This causes
ambiguity during lookup when there are multiple public or inlinalbe
package decls in public interfaces. This PR adds a package name to
public swiftinterface and lets typecheck look up the package name
to narrow down the scope of access to package decls from an external
module.

Resolves rdar://117699160
2023-10-30 13:38:17 -07:00
Allan Shortlidge
33edb6642d Serialization: Resolve type of CustomAttr before serializing.
This fixing a crash during serialization when lazy typechecking is enabled.

Resolves rdar://117442955
2023-10-26 22:46:58 -07:00
Sophia Poirier
77e7dc2c19 Merge pull request #69280 from sophiapoirier/globals_strict_concurrency_opt_out_nonisolated_unsafe
nonisolated(unsafe) to opt out of strict concurrency static checking for global variables
2023-10-26 22:34:22 -07:00
Ellie Shin
994ff25e14 Merge pull request #69360 from apple/es-bypass
Tests package types for non-resiliency
2023-10-26 17:36:40 -07:00
Sophia Poirier
4c9a726183 nonisolated(unsafe) to opt out of strict concurrency static checking for global variables 2023-10-26 16:22:28 -07:00
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
Becca Royal-Gordon
81b5d59363 Diagnose root classes with @objcImpl
@objcImpl, like @objc, cannot be used to implement root classes. Diagnose an attempt to do so.

Fixes rdar://109130979.
2023-10-25 16:20:16 -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
Becca Royal-Gordon
231de1a666 Add ObjCReason for @objcImpl
Besides improving diagnostics, this also allows us to track whether there were any @objc failures using the invalid bit on the @_objcImplementation attribute.
2023-10-24 10:21:37 -07:00
Becca Royal-Gordon
76f25e53d9 Allow @nonobjc inits in objcImpl extensions
Initializers can’t be made final, but they *can* be made @nonobjc. (This isn’t always enough to ensure they’re actually valid, but I’ll get to that in a follow-up commit.)
2023-10-24 10:21:37 -07:00
Ellie Shin
63746dd939 Package types are non-public and should already be treated as non-resilient
although they can be accessed indirectly. Added tests to cover various use cases
incl. enum switch exhaustive stmts and addition of resilient members resulting in
indirect access in silgen.

Resolves rdar://104617177
2023-10-24 02:05:59 -07:00
Harlan Haskins
4ac34a40ea @retroactive conformance syntax and checking (#36068) 2023-10-20 14:27:03 -07:00
Kavon Farvardin
f76360c5b1 [Sema] "Noncopyable" means no Copyable conformance 2023-10-18 13:52:14 -07:00
Kavon Farvardin
71a5935ceb [Sema] factor out the StorageVisitor pattern
This visitor is generally useful for other kinds of marker protocols
like `Copyable` that require structural checking over the storage of the
struct or enum.
2023-10-18 13:45:50 -07:00
Kavon Farvardin
d5f2d54ca7 [Sema] initial overhaul of isNoncopyable
This implementation has the function execute a request to scan the
inheritance clause of non-protocol nominals for a `~Copyable`. For
protocols, we look in the requirement signature.

This isn't our final state, as the GenericEnvironment needs to be
queried in general to determine of a Type is noncopyable. So for now
checking for a `~Copyable` only makes sense for Decls.
2023-10-18 13:45:50 -07:00
Kavon Farvardin
578db55c4c [nfc] factor out logic to remove inherited entry 2023-10-18 13:45:50 -07:00
Kavon Farvardin
148897ac1a [nfc] refactor ValueDecl::isMoveOnly
I've renamed the method to `TypeDecl::isNoncopyable`, because the query
doesn't make sense for many other kinds of `ValueDecl`'s beyond the
`TypeDecl`'s. In fact, it looks like no one was relying on that anyway.

Thus, we now have a distinction where in Sema, you ask whether
a `Type` or `TypeDecl` is "Noncopyable". But within SIL, we still
preserve the notion of "move-only" since there is additionally the
move-only type wrapper for types that otherwise support copying.
2023-10-18 13:45:50 -07:00
Andrew Trick
fca92e4ec6 Add a temporary @_nonEscapable attribute
For testing compiler support until we have the ~Escapable syntax.
2023-10-17 12:44:24 -07:00
Doug Gregor
9ffed75bc2 [Typed throws] Avoid dependency cycle between SimpleDidSetRequest and interface types
The implementation of `SimpleDidSetRequest` currently depends on a
type-checked body for `didSet`, which in turn depends on the interface
type (for the thrown error type). Break that dependency in a silly way
for now.
2023-10-16 10:30:56 -07:00
Doug Gregor
7b9c079a52 Be more careful when getting the effective thrown error type 2023-10-16 01:12:04 -07:00
Doug Gregor
3dd4df2351 [Typed throws] Location based lookup for the thrown error type
Introduce a new API to find the AST node that catches or rethrows an
error thrown from the given source location. Use it to determine the
thrown error type to use for type checking a `throw` statement, which
begins as `any Error` within a `do..catch` and is later refined.
2023-10-15 22:59:48 -07:00
Allan Shortlidge
a7daf13bf6 AST: Introduce and adopt Decl::isExposedToClients().
This method is a more ergonomic utility wrapping DeclExportabilityVisitor.
2023-10-11 22:41:31 -07:00
Alexis Laferrière
9ba500d4e4 Merge pull request #68967 from xymus/feature-0409
Sema: Lift flag requirement for access levels on imports now that SE-0409 has been accepted
2023-10-11 22:23:52 -07:00
Doug Gregor
a14f280104 Merge pull request #69087 from DougGregor/typed-throws-conformances 2023-10-10 21:16:44 -07:00
Holly Borla
fad02e3737 Merge pull request #69089 from hborla/diagnose-invalid-declaration-macros
[Macros] Diagnose attached and freestanding declaration macros that produce something other than a declaration.
2023-10-10 15:44:00 -07:00