Commit Graph

6754 Commits

Author SHA1 Message Date
swift-ci
e88cda751e Merge remote-tracking branch 'origin/main' into rebranch 2023-09-29 16:17:35 -07:00
Allan Shortlidge
5ef85ff7e3 SILGen: Don't call _diagnoseUnavailableCodeReached() from already unreachable functions.
We must avoid emitting applies of `_diagnoseUnavailableCodeReached()` in
function bodies that are already marked unreachable since there isn't a valid
insertion point once an `unreachable` instruction has been emitted. A function
body may be marked unreachable if, for example, the parameters of the function
are uninhabited.

Resolves rdar://116246677
2023-09-29 11:47:19 -07:00
Pavel Yaskevich
ab54ea71fa [SILGen] InitAccessors: Prevent setter closure from escaping
The closure with applied base is not escaping and gets applied
only once (when self is fully initialized). Let's make sure that
the partial application results in on-stack closure that borrows
"self" instead of copying it.
2023-09-29 11:44:02 -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
swift-ci
309d089075 Merge remote-tracking branch 'origin/main' into rebranch 2023-09-29 10:13:55 -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
swift-ci
719d22840a Merge remote-tracking branch 'origin/main' into rebranch 2023-09-22 17:41:39 -07:00
Hamish Knight
696075687d [SILGen] Remove mark_uninitialized for if/switch expr branches
We always immediately emit an expression into the
initialization, so this isn't providing much value.
2023-09-22 18:44:45 +01:00
Hamish Knight
41dc6e2e04 [SILGen] Emit unreachable for uninhabited if/switch expr branches
If we have an uninhabited branch, emit it as an
ignored expr followed by an unreachable.
Previously we would omit the unreachable and rely
on the SILOptimizer to infer it, but we ought to
just emit it here. Also check `isUninhabited()`
instead of `isStructurallyUninhabited` since this
better matches what we allow in Sema. For tuples
of uninhabited values, we can do a regular
initialization without issue.
2023-09-22 18:44:43 +01:00
swift-ci
bc73f15add Merge remote-tracking branch 'origin/main' into rebranch 2023-09-21 15:22:08 -07:00
Kuba (Brecka) Mracek
a559d24cdb Merge pull request #68649 from kubamracek/embedded-throw-as-trap
[embedded] Add a temporary flag that turns throws into traps so that programs that use throwing can at least be compiled for now
2023-09-21 14:52:29 -07:00
swift-ci
6637cc5a27 Merge remote-tracking branch 'origin/main' into rebranch 2023-09-21 12:13:50 -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
Kuba Mracek
a3ee08fbc9 [embedded] Use cond_fail in throw-as-traps mode 2023-09-21 07:17:19 -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
swift-ci
1b6470ca9c Merge remote-tracking branch 'origin/main' into rebranch 2023-09-20 15:07:15 -07:00
Yuta Saito
c5314bd3af Centralize KeyPath accessor calling convention logic to IRGen
KeyPath's getter/setter/hash/equals functions have their own calling
convention, which receives generic arguments and embedded indices from a
given KeyPath argument buffer.
The convention was previously implemented by:
1. Accepting an argument buffer as an UnsafeRawPointer and casting it to
   indices tuple pointer in SIL.
2. Bind generic arguments info from the given argument buffer while emitting
   prologue in IRGen by creating a new forwarding thunk.

This 2-phase lowering approach was not ideal, as it blocked KeyPath
projection optimization [^1], and also required having a target arch
specific signature lowering logic in SIL-level [^2].

This patch centralizes the KeyPath accessor calling convention logic to
IRGen, by introducing `@convention(keypath_accessor_XXX)` convention in
SIL and lowering it in IRGen. This change unblocks the KeyPath projection
optimization while capturing subscript indices, and also makes it easier
to support WebAssembly target.

[^1]: https://github.com/apple/swift/pull/28799
[^2]: https://forums.swift.org/t/wasm-support/16087/21
2023-09-20 11:25:39 -07:00
Kuba Mracek
a31c3388e4 [embedded] Add a temporary flag that turns throws into traps so that programs that use throwing can at least be compiled for now 2023-09-19 22:00:51 -07:00
swift-ci
d2b176c047 Merge remote-tracking branch 'origin/main' into rebranch 2023-09-19 09:55:18 -07:00
Kavon Farvardin
54e5205194 Merge pull request #68600 from kavon/optional-try-coercion-bug-v2
[SILGen] fix SR-14882: Assertion failed: (!concreteBuffer && "concrete buffer already formed?!")
2023-09-19 09:42:04 -07:00
Kavon Farvardin
583f127de7 fix [SR-14882]: Assertion failed: (!concreteBuffer && "concrete buffer already formed?!")
The problem was that in the by-address emission, we were calling
 `getAddressForInPlaceInitialization` twice, triggering the assert.

The first time in `emitExprInto` for the normal result case.

The second time to obtain the address again when generating the
catch block to inject a `.none` into that same address.

This patch does a light refactoring to more closely mirror
`visitOptionalEvaluationExpr`, which avoids calling the asserting method.

fixes rdar://80277465
2023-09-18 15:41:43 -07:00
swift-ci
48d37e45f5 Merge remote-tracking branch 'origin/main' into rebranch 2023-09-17 13:14:20 -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
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
swift-ci
4441b37ec8 Merge remote-tracking branch 'origin/main' into rebranch 2023-09-11 15:34:47 -07:00
Alejandro Alonso
93c332bcdd Merge pull request #66768 from Azoy/pack-count-builtin
[AST] Add Builtin.packLength
2023-09-11 15:23:37 -07:00
swift-ci
e72811e31e Merge remote-tracking branch 'origin/main' into rebranch 2023-09-09 10:13:45 -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
swift-ci
af7aa91358 Merge remote-tracking branch 'origin/main' into rebranch 2023-09-08 19:13:48 -07:00
Slava Pestov
80e43fba14 Merge pull request #68399 from slavapestov/fix-rdar114823719
SILGen: Use the right abstraction pattern when loading 'async let' result
2023-09-08 21:58:40 -04:00
swift-ci
e77b2ee5b0 Merge remote-tracking branch 'origin/main' into rebranch 2023-09-08 18:56:08 -07:00
Pavel Yaskevich
c75aea3654 Merge pull request #68390 from xedin/checked-continuations-for-foreign-callbacks
Provide ability to use CheckedContinuation when suspending for an async ObjC call
2023-09-08 18:52:04 -07:00
Slava Pestov
583c51ae87 SILGen: Use the right abstraction pattern when loading 'async let' result
The payload is stored maximally-abstracted, so make sure we respect
that to avoid a crash when the 'async let' binding has a function type.

Fixes rdar://114823719.
2023-09-08 17:41:42 -04: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
Pavel Yaskevich
ce651ca67d [SILGen] ResultPlan: Address a FIXME about resume with foreign error 2023-09-08 10:52:41 -07:00
swift-ci
734d18ac13 Merge remote-tracking branch 'origin/main' into rebranch 2023-09-08 07:14:28 -07:00
nate-chandler
e7783563ce Merge pull request #68285 from nate-chandler/effects-diagnostic
[Diagnostics] Require explicit releasenone.
2023-09-08 07:04:31 -07:00
Pavel Yaskevich
6ecbb088b9 [SILGen] ResultPlan: Add a FIXME about foreign error bridging in checking continuations mode 2023-09-07 17:52:22 -07:00
Pavel Yaskevich
4b22620d11 [SILGen] Implement async completion bridging via checked continuations
Because `CheckedContinuation` is not a @frozen struct we have
to use `Any` to store it in @block_storage indirectly. If the
flag is enabled, we'd emit a block storage with `Any` and
initialize the existential with stack allocated `CheckedContinuation`
formed from `UnsafeContinuation`. Inside of the completion handler
`Any` is going to be projected and cast back to `CheckedContinuation`.
2023-09-07 17:35:38 -07:00
Pavel Yaskevich
6e48d449e8 [SILGen] NFC: Introduce intrinsics for construction and resumption of CheckedContinuation 2023-09-07 17:35:38 -07:00
Pavel Yaskevich
a6025310a3 [SILGen] Pass storage block type and callee info to async completion handler generator
Instead of relying on `continuationType` for information, let's
take it from the source.
2023-09-07 17:35:07 -07:00
Alejandro Alonso
ff6bd36aa8 Add Builtin.packLength
Simplify packCount IRGen

Emit pack_length instruction

Add space
2023-09-07 15:36:14 -07:00
Nate Chandler
63bdb4ab1f [Gardening] Fixed variable name.
In SILGen, it's an SGM not an IGM.
2023-09-05 08:18:02 -07:00
swift-ci
225162a30f Merge remote-tracking branch 'origin/main' into rebranch 2023-09-01 14:36:50 -07:00
Hamish Knight
8dc55b8269 Merge pull request #67454 from hamishknight/then 2023-09-01 22:32:46 +01:00
swift-ci
dbe6df083f Merge remote-tracking branch 'origin/main' into rebranch 2023-09-01 09:13:39 -07:00
Hamish Knight
6ee44f09b4 Introduce then statements
These allow multi-statement `if`/`switch` expression
branches that can produce a value at the end by
saying `then <expr>`. This is gated behind
`-enable-experimental-feature ThenStatements`
pending evolution discussion.
2023-09-01 14:32:14 +01:00