Commit Graph

3502 Commits

Author SHA1 Message Date
Holly Borla
7f119474ac [Concurrency] Allow default initializer expressions for stored instance
properties to require actor isolation.

Member initializer expressions are only used in a constructor with
matching actor isolation. If the isolation prohibits the member
initializer from being evaluated synchronously (or propagating required
isolation through closure bodies), then the default value cannot be used
and the member must be explicitly initialized in the constructor.

Member initializer expressions are also used as default arguments for the
memberwise initializer, and the same rules for default argument isolation
apply.
2023-10-04 13:12:11 -07:00
Holly Borla
95a7107872 [Concurrency] Allow default arguments to require actor isolation.
Type checking a default argument expression will compute the required
actor isolation for evaluating that argument value synchronously. Actor
isolation checking is deferred to the caller; it is an error to use a
default argument from across isolation domains.

Currently gated behind -enable-experimental-feature IsolatedDefaultArguments.
2023-10-04 13:12:11 -07:00
Ellie Shin
48f3704eea Merge pull request #68811 from apple/es-add-pkg
Lift restrictions of access check for inlinalbe package symbols referenced in interfaces.
2023-10-04 12:49:49 -07:00
Ellie Shin
e41f3147fe cr feedback 2023-10-03 16:49:21 -07:00
Ellie Shin
67842e3751 Grant access to inlinalbe package symbols referenced in interfaces.
Package decls are only printed in interface files if they are inlinable
(@usableFromInline, @inlinable, @_alwaysEmitIntoClient). They could be
referenced by a module outside of its defining module that belong to the same
package determined by the `package-name` flag. However, the flag is only in
.swiftmodule and .private.swiftinterface, thus type checking references of
inlinable package symbols in public interfaces fails due to the missing flag.
Instead of adding the package-name flag to the public interfaces, which
could raise a security concern, this PR grants access to such cases.

Resolves rdar://116142791
2023-10-03 16:14:15 -07:00
Doug Gregor
581b9d8a95 Merge pull request #68629 from DougGregor/typed-throws
Typed throws
2023-09-30 11:18:41 -07:00
Alexis Laferrière
e820854784 Merge pull request #68831 from xymus/report-superfluously-public-imports
Sema: warn on imports that are too public and remark source of entities in API
2023-09-29 20:15:56 -07:00
Doug Gregor
b6b999abd4 [Typed throws] Basic SIL lowering and SIL generation for typed throws
Lower the thrown error type into the SIL function type. This requires
very little code because the thrown error type was already modeled as
a SILResultInfo, which carries type information. Note that this
lowering does not yet account for error types that need to passed
indirectly, but we will need to do so for (e.g.) using resilient error
types.

Teach a few places in SIL generation not to assume that thrown types
are always the existential error type, which primarily comes down to
ensuring that rethrow epilogues have the thrown type of the
corresponding function or closure.

Teach throw emission to implicitly box concrete thrown errors in the
error existential when needed to satisfy the throw destination. This
is a temporary solution that helps translate typed throws into untyped
throws, but it should be replaced by a better modeling within the AST
of the points at which thrown errors are converted.
2023-09-29 10:51:55 -07:00
Doug Gregor
51eed19d4b [Typed throws] Type system support for typed throws.
Add the thrown type into the AST representation of function types,
mapping from function type representations and declarations into the
appropriate thrown type. Add tests for serialization, printing, and
basic equivalence of function types that have thrown errors.
2023-09-29 10:51:53 -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
Allan Shortlidge
1d8fc104c3 AST/SILGen: Requestify function body skipping.
Function bodies are skipped during typechecking when one of the
-experimental-skip-*-function-bodies flags is passed to the frontend. This was
implemented by setting the "body kind" of an `AbstractFunctionDecl` during decl
checking in `TypeCheckDeclPrimary`. This approach had a couple of issues:

- It is incompatible with skipping function bodies during lazy typechecking,
  since the skipping is only evaluated during a phase of eager typechecking.
- It prevents skipped function bodies from being parsed on-demand ("skipped" is
  a state that is distinct from "parsed", when they ought to be orthogonal).
  This needlessly prevented complete module interfaces from being emitted with
  -experimental-skip-all-function-bodies.

Storing the skipped status of a function separately from body kind and
requestifying the determination of whether to skip a function solves these
problems.

Resolves rdar://116020403
2023-09-28 19:18:35 -07:00
Alexis Laferrière
23d9defa8c [AST] Set import access level to internal when invalid 2023-09-27 22:29:13 -07:00
Alexis Laferrière
1bf368609e Merge pull request #68776 from xymus/access-level-import-indirect-checks
Sema: report conformances and typealias underlying types behind non-public imports
2023-09-27 12:54:35 -07:00
Alexis Laferrière
0a248445be [Sema] Move getImportAccessFrom to Decl 2023-09-26 14:22:27 -07:00
Allan Shortlidge
51a4ff98a0 NFC: Address a -Wunused-result warning in Decl.cpp. 2023-09-22 18:05:20 -07:00
Kavon Farvardin
a69bcf8a61 Merge pull request #67930 from kavon/copyable-requirement
Copyable as a Requirement Against the Machine
2023-09-21 11:49:23 -07:00
Kavon Farvardin
f1142d5da4 [nfc] rename or eliminate isPureMoveOnly APIs
I think from SIL's perspective, it should only worry about whether the
type is move-only. That includes MoveOnlyWrapped SILTypes and regular
types that cannot be copied.

Most of the code querying `SILType::isPureMoveOnly` is in SILGen, where
it's very likely that the original AST type is sitting around already.
In such cases, I think it's fine to ask the AST type if it is
noncopyable. The clarity of only asking the ASTType if it's noncopyable
is beneficial, I think.
2023-09-20 15:23:17 -07:00
Alexis Laferrière
1a4a47fee3 [Sema] Merge diagnostics about package modifier outside of a package
Show the same error for both decls and imports when using the package
access level and no package name is set. Also brings up this check to
run once on decls and avoid repeated diagnostics.
2023-09-19 15:01:16 -07:00
Holly Borla
549b45250f [Concurrency] Remove ClosureActorIsolation. 2023-09-16 12:22:38 -07:00
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