Commit Graph

3433 Commits

Author SHA1 Message Date
Holly Borla
97f1e617fd [Concurrency] Replace ClosureActorIsolation with ActorIsolation throughout
the isolation query APIs.
2023-09-16 12:21:36 -07:00
Holly Borla
54f5fef20e [Concurrency] Store ActorIsolation in AbstractClosureExpr instead of
ClosureActorIsolation.
2023-09-16 12:20:53 -07:00
Holly Borla
4b23564711 [Concurrency] Rename AbstractClosureExpr::getActorIsolation to
getClosureActorIsolation.

This is preparation for changing AbstractClosureExpr to store
ActorIsolation instead of ClosureActorIsolation, and convert to
ClosureActorIsolation when needed to allow incrementally updating
callers. This change is NFC.
2023-09-16 12:20:53 -07:00
Alex Hoppen
44a4d6998c Merge pull request #67111 from AnthonyLatsis/astgen-decls
ASTGen: An assortment of strides and improvements
2023-09-16 08:08:05 -07:00
Alexis Laferrière
1c0ccf6c5d Merge pull request #68479 from xymus/access-level-fix-private
Sema: Improve diagnostics logic for references to imported decl behind a restrictive import
2023-09-14 08:59:26 -07:00
Alexis Laferrière
fca9a91bc9 [Sema] Extend access scope services to apply import restrictions
Apply import restriction in central access scope services allows us to
simplify the access-level on import enforcement as it's better
integrated with the existing logic.
2023-09-13 15:40:24 -07:00
Alexis Laferrière
48893ea391 [Sema] Introduce utility service ValueDecl::getImportAccessFrom 2023-09-12 11:12:56 -07:00
Anthony Latsis
b6be6da277 ASTGen: Translate associated type declarations
Plus tweak `DefaultDefinitionTypeRequest` caching to support querying the
cached type when dumping. This fixes a crash where type computation is
triggered in the dumper before import resolution in `-dump-parse` mode.
2023-09-12 20:37:50 +03:00
Anthony Latsis
6293332cba ASTGen: Translate default arguments 2023-09-12 20:37:50 +03:00
Allan Shortlidge
9b641f9ba3 ModuleInterface: Typecheck PatternBindingDecls lazily before printing.
Previously, fully qualified types would be missing for global vars and
properties in `.swiftinterface` files that were emitted lazily.

Adding the test case also revealed that PatternBindingDecls needed to be
typechecked before lazy module serialization as well.
2023-09-12 09:08:10 -07:00
Holly Borla
e23e4c32f5 Merge pull request #68414 from hborla/nonisolated-init-hole
[Concurrency] Don't allow nonisolated initializers to introduce data races via superclass property observers.
2023-09-09 09:55:24 -07:00
Holly Borla
a6d078b820 [Concurrency] Use the 'nonisolated' terminology instead of 'independent'.
This commit is NFC; it's mostly renames.
2023-09-08 13:28:55 -07:00
Doug Gregor
f8f8d24608 Merge pull request #67758 from DougGregor/member-macro-conformances 2023-09-07 11:25:10 -07:00
Slava Pestov
973a5065e2 Merge pull request #68282 from slavapestov/sema-tuple-conformances
(More) Declaration checker support for tuple conformances
2023-09-07 11:57:05 -04:00
Doug Gregor
596da3121d [SE-0407] Provide member macros with information about "missing" conformances
Provide member macros with similar information about conformances to
what extension macros receive, allowing member macros to document
which conformances they care about (e.g., Decodable) and then
receiving the list of conformances that aren't already available for
the type in question. For example, a macro such as

    @attached(member, conformances: Decodable, Encodable, names:
named(init(from:), encode(to:)))
    macro Codable() = ...

Expanded on a type that is not already Decodable/Encodable would be
provided with Decodable and Encodable (via the new
`missingConformancesTo:` argument to the macro implementation) when
the type itself does not conform to those types.

Member macros still cannot produce conformances, so this is likely to
be used in conjunction with extension macros most of the time. The
extension macro declares the conformance, and can also declare any
members that shouldn't be part of the primary type definition---such
as initializers that shouldn't suppress the memberwise initializer. On
the other hand, the member macro will need to define any members that
must be in the primary definition, such as required initializers,
members that must be overridable by subclasses, and stored properties.

Codable synthesis is an example that benefits from member macros with
conformances, because for classes it wants to introduce a required
initializer for decoding and an overridable encode operation, and
these must be members of the nominal type itself. Specifically, the
`Codable` macro above is likely to have two attached member roles:

    @attached(member, conformances: Decodable, Encodable, names:
named(init(from:), encode(to:)))
    @attached(extension, conformances: Decodable, Encodable, names:
named(init(from:), encode(to:)))
    macro Codable() = ...

where the "extension" role is responsible for defining the conformance
(always), and the "member" creates the appropriate members for classes
(`init` vs. `required init`).

Tracked by rdar://112532829.
2023-09-07 08:20:46 -07:00
Allan Shortlidge
01ecd81950 AST: Introduce conveniences for inheritance clause source locations.
Replace the `front()` and `back()` accessors on `InheritedTypes` with dedicated
functions for accessing the start and end source locations of the inheritance
clause. NFC.
2023-09-06 10:41:57 -07:00
Allan Shortlidge
c884632312 AST: Consolidate inherited type resolution.
Move evaulation of `InheritedTypeRequest` into the `InheritedTypes` wrapper.
NFC.
2023-09-06 10:41:57 -07:00
Allan Shortlidge
0dd8f4c492 AST: Introduce abstraction for extension/type decl inheritance clauses.
Wrap the `InheritedEntry` array available on both `ExtensionDecl` and
`TypeDecl` in a new `InheritedTypes` class. This class will provide shared
conveniences for working with inherited type clauses. NFC.
2023-09-06 10:41:57 -07:00
Slava Pestov
b2d3184d4c Sema: Requirement inference from generic typealias in tuple extension 2023-09-05 23:21:27 -04:00
Slava Pestov
d5cdfb2cf2 AST: Clone generic parameter list of tuple extension from extended typealias 2023-09-05 23:21:27 -04:00
Slava Pestov
8269bde825 AST: Simplify DeclContext::getSelfTypeInContext() 2023-08-30 15:15:08 -04:00
Slava Pestov
361d49a843 AST: Remove DeclContext::getSelfProtocolType() 2023-08-30 15:15:08 -04:00
Luciano Almeida
c48836cb62 Merge pull request #68073 from apple/remove-diags
Removing code for 'initializes' and 'accesses' attributes old syntax
2023-08-23 08:50:49 -03:00
Luciano Almeida
76becb4cd0 [AST] Remove initializes and accesses attr reference 2023-08-22 20:54:37 -03:00
Doug Gregor
323561b157 [Macros] Use outermost source file for establishing (file)private access scope
Fixes rdar://114048069.
2023-08-21 22:01:19 -07:00
Joe Groff
ad6423f465 Merge pull request #67979 from jckarter/narrow-nominal-type-decl-is-resilient-originally-defined-in-check
Narrow `@_originallyDefinedIn` check in NominalTypeDecl::isResilient to protocols.
2023-08-17 08:43:57 -07:00
Joe Groff
448bb42225 Narrow @_originallyDefinedIn check in NominalTypeDecl::isResilient to protocols.
And add a comment explaining why this check is only relevant to protocols, and shouldn't
be copied to other similar-looking isResilient methods on other types.
According to 25376025ae, which introduced the original
`@_originallyDefinedIn` check, this check was necessary to maintain ABI compatibility
when protocol declarations are moved, but in all other cases, we should treat declarations
as resilient when they are defined in other library-evolution-enabled modules, even when
the declaration was originally defined in the current module.
2023-08-16 20:23:48 -07:00
Joe Groff
d948213c72 Merge pull request #67972 from jckarter/revert-abstractstoragedecl-originally-defined-in-check
Revert "AST: Spot fix for AbstractStorageDecl::isResilient()"
2023-08-16 20:19:56 -07:00
Pavel Yaskevich
c38b9b1e08 Merge pull request #67945 from xedin/remove-runtimeMetadata
[Frontend] NFC: Remove code and tests related to rejected @runtimeMetadata feature
2023-08-16 17:16:46 -07:00
Joe Groff
e2db4d221c Revert "AST: Spot fix for AbstractStorageDecl::isResilient()"
This reverts commit d5b354fd5f. It causes miscompiles when
accessing properties declared with `@_originallyDefinedIn` that are now defined in modules
with library evolution enabled from the module that the property was originally defined in.
Just because the property used to be declared in the current module doesn't mean it can
bypass the stable ABI of the module that the property now belongs to.

It looks like the logic that this PR replaced is also faulty, since `@_originallyDefinedIn`
really oughtn't factor into the resilience computation at any level, but let's unwind one
level of brokenness at a time.

Fixes rdar://113935401.
2023-08-16 14:59:43 -07:00
Allan Shortlidge
9eda39c85f NFC: Clean up code duplication in Decl.cpp. 2023-08-15 17:19:03 -07:00
Allan Shortlidge
29374cb802 SILOptimizer: Skip unreachable cases optimization when elements are available.
Cache a bit on `EnumDecl` indicating whether there are any elements that are
unavailable during lowering and then use that bit to decided whether to attempt
optimization for `switch_enum`/`switch_enum_addr` instructions.
2023-08-15 17:13:10 -07:00
Pavel Yaskevich
b21e8426a0 [AST] NFC: Remove @runtimeMetadata related code 2023-08-15 12:16:40 -07:00
Allan Shortlidge
d438bac68d AST: Fix EnumDecl's hasPotentiallyUnavailableCaseValue() cache.
The cached values for `hasOnlyCasesWithoutAssociatedValues()` and
`hasPotentiallyUnavailableCaseValue()` are computed in a single pass over the
elements of an `EnumDecl`. However, the pass would return early after finding
an element with an associated value, without checking whether any of the rest
of the elements were potentially unavailable. This made `Comparable` synthesis
succeed for any enum with potentially unavailable elements so long as the first
element in the enum has an associated value.
2023-08-10 21:59:55 -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
Doug Gregor
50ca096cd8 Make VarDecl::isLayoutExposedToClients check property wrappers more lazily
The check for "has property wrappers" as part of determining whether the
layout of a variable is exposed to clients can trigger reference
cycles. Push this check later, which eliminates these cycles for types
that aren't frozen/fixed-layout.

This is a hack, not a real fix, but it eliminates the cyclic
references observed in rdar://112079160.
2023-08-02 15:07:08 -07:00
Holly Borla
178604e8bc [Features] Remove the experimental ExtensionMacros feature identifier. 2023-07-19 08:17:28 -07:00
Doug Gregor
535b45c392 Stop treating macro declaring init identifier as producing initializers
Unwind a temporary workaround we put into the compiler that treated
the escaped identifier "init" as an initializer in the set of names
introduced by a macro. We've addressed the underlying issues.

Fixes rdar://108589649.
2023-07-17 22:44:43 -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
28a39d6df1 [AST] NFC: Add a way to request initialized/accesses properties from init accessor 2023-07-07 10:00:36 -07:00
Pavel Yaskevich
00729ad958 Merge pull request #67107 from xedin/setterless-init-accessor-properties
[SILGen/DI] Add support for init accessor properties without setters
2023-07-07 00:16:07 -07:00
Doug Gregor
f5427eaea2 Merge pull request #67148 from DougGregor/accessor-macros-finishing-touches 2023-07-05 22:56:46 -07:00
Doug Gregor
16bfd783f4 [Macros] When a macro defines a getter or setter, remove didSet/willSet
As with the initial value of a property that is converted from a stored
property to a computed property by an accessor macro, remove
didSet/willSet. It is the macro's responsibility to incorporate their
code or diagnose them.

Fixes rdar://111101833.
2023-07-05 19:37:21 -07:00
Doug Gregor
22158be449 [Macros] Diagnose when an accessor macro produces an accessor that already exists
We used to crash; now we diagnose and... don't crash.

Fixes rdar://111588129.
2023-07-05 16:27:25 -07:00
Doug Gregor
8df508c453 Merge pull request #67105 from DougGregor/freestanding-macro-global-scope-in-scripts 2023-07-04 12:17:47 -07:00
Pavel Yaskevich
1e6c9199bc [AST] InitAccessors: init accessor properties without setters use special write strategy
Such properties could be mutated only within initializer context
so they can employ a special "init accessor" strategy.
2023-07-03 22:06:54 -07:00
Doug Gregor
939376b61e [Macros] Enable freestanding macros at module scope in script mode
Eliminate the error message

    error: global freestanding macros not yet supported in script mode

by implementing name lookup, type checking, and code emission for
freestanding macros. The key problem here is that, in script mode,
it is ambiguous whether a use of a freestanding macro is an expression
or a declaration. We parse as an expression (as we do within a
function body), which then gets wrapped in a top-level code
declaration.

Teach various parts of the compiler to look through a top-level code
declaration wrapping a macro expansion expression that is for a
declaration or code-item macro, e.g., by recording these for global
name lookup and treating their expansions as "auxiliary" declarations.

Fixes rdar://109699501.
2023-07-03 21:00:51 -07:00
Holly Borla
680c0b2a2f [Macros] Add a request to get the resolved constraint types in the 'conformances:'
list of an attached extension macro attribute.
2023-06-30 22:27:16 -07:00
Holly Borla
0bd898eb12 [Macros] Allow extension macros to suppress conformances that are already
stated in the original source.

If an extension macro can introduce protocol conformances, macro expansion
will check which of those protocols already have a stated conformance in the
original source. The protocols that don't will be passed as arguments to
extension macro expansion, indicating to the macro that it should only add
conformances to those protocols.
2023-06-30 16:01:15 -07:00