Commit Graph

3433 Commits

Author SHA1 Message Date
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
Alexis Laferrière
322ada60c8 [Sema] Intro flag to default imports to internal, the Swift 6 mode
The feature InternalImportsByDefault makes imports default to internal instead
of public. Applying the Swift 6 behavior of SE-0409 in Swift 5.

Let's use only that flag to track the Swift 6 behavior as well instead
of separately checking for the language version.
2023-10-10 09:09:21 -07:00
Holly Borla
1f07cbae2a [Macros] Diagnose attached and freestanding declaration macros that produce
something other than a declaration.

The validation code already diagnosed all sorts of invalid declarations, but
it was ignoring AST nodes that aren't declarations at all.
2023-10-09 22:50:12 -07:00
Doug Gregor
7d7c726efe [Typed throws] Teach associated type inference to infer from thrown errors
When comparing a requirement that uses typed throws and uses an
associated type for the thrown error type against a potential witness,
infer the associated type from the thrown error of the
witness---whether explicitly specified, untyped throws (`any Error`),
or non-throwing (`Never`).
2023-10-09 21:21:21 -07:00
Erik Eckstein
a86b7ccfe4 AST: fix missing header files
`ForeignAsyncConvention.h` and `ForeignErrorConvention.h` must be included in `Decl.h`, because those types are used in an `llvm::Optional` in `Decl.h`.
2023-10-09 09:22:55 +02:00
Slava Pestov
f321dd3321 Merge pull request #66247 from karwa/nested-protocols
Allow protocols to be nested in non-generic contexts
2023-10-08 12:00:46 -04:00
Holly Borla
5a81c00b3e [Concurrency] Rename IsolatedDefaultArguments to IsolatedDefaultValues. 2023-10-06 16:59:41 -07:00
Karl Wagner
ab4f80ed95 [SE-0404] Allow protocols to be nested in non-generic contexts 2023-10-06 21:04:03 +02:00
Holly Borla
67e3326048 [Concurrency] Remove swift::computeRequiredIsolation and change all callers to go
through the DefaultInitializerIsolation request.
2023-10-04 15:14:06 -07:00
Holly Borla
3cb9bb89bc [Concurrency] Serialize default argument isolation. 2023-10-04 13:12:11 -07:00
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