Commit Graph

6754 Commits

Author SHA1 Message Date
Joe Groff
a25edb2185 Make Builtin.addressForBorrow work with addressable parameters. 2025-01-02 21:33:55 -08:00
Joe Groff
5c4406b5e8 Add an @_addressableForDependencies type attribute.
This attribute makes it so that a parameter of the annotated type, as well as
any type structurally containing that type as a field, becomes passed as
if `@_addressable` if the return value of the function has a dependency on
the parameter. This allows nonescapable values to take interior pointers into
such types.
2025-01-02 21:33:51 -08:00
Michael Gottesman
56f38c4172 [concurrency] Add support in SILGen/SIL for emitting and calling implicit leading parameters for CallerInheritingIsolation isolation.
This does not change region isolation yet to recognize these as effectively
nonisolated.
2025-01-02 13:18:54 -08:00
Michael Gottesman
5d4239af57 [concurrency] Add new isolation kind CallerIsolationInheriting.
Right now it is basically a version of nonisolated beyond a few simple cases
like constructors/destructors where we are pretty sure we want to not support
this.

This is part of my bringup strategy for changing nonisolated/unspecified to be
caller isolation inheriting.
2025-01-02 13:18:30 -08:00
Michael Gottesman
a15f52009e [gardening] Use a higher level method that describes what a piece of code is doing instead of source inlining it. 2025-01-02 13:18:30 -08:00
Michael Gottesman
b2a4f7e3cc [sil] Add to SIL and SILGen the ability to emit/represent implicit parameters.
I need this today to add the implicit isolated parameter... but I can imagine us
adding more implicit parameters in the future, so it makes sense to formalize it
so it is easier to do in the future.
2025-01-02 13:18:11 -08:00
Pavel Yaskevich
636525ebd9 Merge pull request #78171 from xedin/rdar-140300022
[TypeChecker/SILGen] Allow `any Sendable` to match `Any` while matching generic arguments
2024-12-17 20:24:34 -08:00
Andrew Trick
b56a787c74 SILGen: emit mark_dependence for unsafeAddress
Fixes a correctness issue with unsafe addressors: `unsafeAddress` and
`unsafeMutableAddress`. Previously, the resulting `Unsafe[Mutable]Pointer` did
not depend on `self`, meaning that the compiler is allowed to destroy `self`
before any uses of the pointer. This happens to be valid for
`UnsafePointer.pointee` because, in that case, `self` does not have a lifetime
anyway; the correctness burden was on the programmer to use
`withExtendedLifetime` around all uses of `self`.

Now, unsafe addressors can be used for arbitrary `Self` types.

This also enables lifetime dependence diagnostics when the addressor points to a
`~Escapable` type.

Addressors can now be used as an implementation of borrowed properties.
2024-12-17 09:53:02 -08:00
Konrad `ktoso` Malawski
daf06c7f05 diagnose and dont crash when unable to find swift_task_deinitOnExecutor 2024-12-12 16:41:03 +09:00
Konrad `ktoso` Malawski
8ff2babfde Report fatal error when missing swift_task_deinitOnExecutor 2024-12-12 16:41:03 +09:00
Pavel Yaskevich
c4e4d4d6da [SIGen] UnsafeCastExpr: Use forwarding cast instead of bitcast
Forwarding cast handles ownership correctly and doesn't disable
optimizations unlike bitcast.
2024-12-11 17:19:20 -08:00
Pavel Yaskevich
cc13060f8c [SILGenBuilder] NFC: Add createUncheckedForwardingCast that works with ManagedValue 2024-12-11 17:19:20 -08:00
Pavel Yaskevich
5e08f7e257 [CSApply/SILGen] Implement any Sendable to Any erasure for generic arguments
In non-strict concurrency mode when `@preconcurrency` declarations
are involved `any Sendable` should be treated as `Any` in generic
argument positions to support passing types that (partially) adopted
concurrency annotations to types that haven't yet done so.
2024-12-11 17:19:14 -08:00
Joe Groff
3c0b08dbcb Prototype an @_addressable attribute that puts an argument at a stable address.
Many APIs using nonescapable types would like to vend interior pointers to their
parameter bindings, but this isn't normally always possible because of representation
changes the caller may do around the call, such as moving the value in or out of memory,
bridging or reabstracting it, etc. `@_addressable` forces the corresponding parameter
to be passed indirectly in memory, in its maximally-abstracted representation.
[TODO] If return values have a lifetime dependency on this parameter, the caller must
keep this in-memory representation alive for the duration of the dependent value's
lifetime.
2024-12-03 20:39:23 -08:00
Kuba Mracek
6f4ae28520 [ASTMangler] Pass ASTContext to all instantiations of ASTMangler 2024-12-02 15:01:04 -08:00
Michael Gottesman
e6b4e0f9f1 Merge pull request #77709 from gottesmm/pr-6feaf0c91a7d95d75b36d32cc91a32150d992162
[region-isolation] Some initial NFCI refactoring commits before adding experimental support for inheriting isolation to nonisolated functions
2024-11-19 22:22:50 -08:00
Nate Chandler
38a9ef71cb [NFC] Fixed function name spelling. 2024-11-19 15:52:24 -08:00
Michael Gottesman
d541190a5a [silgen] Refactor out how we compute the actor isolation for a SILFunction so we can reuse it in other contexts.
I also want to extend it and did not want to have to copy/paste this code into
multiple places.

The small test tweak occurs since I changed the initializer SILGen emission code
to set the declref field of SILFunctions to the actual decl ref which we did not
before. So we got a more specific diagnostic.
2024-11-19 12:47:45 -08:00
Slava Pestov
47156e006b AST: Introduce ProtocolConformanceRef::forAbstract() 2024-11-16 16:16:06 -05:00
Slava Pestov
35b78c950b SILGen: Remove usage of weird ProtocolConformanceRef() constructor 2024-11-16 16:16:06 -05:00
Doug Gregor
c5de02f60e Merge pull request #77628 from DougGregor/clang-importer-parse-request
[Clang importer] Use ParseSourceFileRequest for parsing swift_attr attributes
2024-11-16 01:12:27 -08:00
Michael Gottesman
ebcab8f2ee [silgen] Change ArgEmitter to use an OptionSet before I add another option.
NFCI.
2024-11-15 15:14:32 -08:00
Slava Pestov
7c21789c88 SILGen: Unwrap inherited conformance when emitting witness thunk
I'm about to fix RequirementEnvironment to correctly use
inherited conformances.
2024-11-15 17:26:35 -05:00
Slava Pestov
53e52abce1 SILGen: Fix invalid substitution map formation in coroutine witness thunk emission
If the conformance generic signature fixes all generic parameters,
F.getForwardingSubstitutionMap() is empty. Instead, map the
replacement types of the substitution map into the generic
environment earlier, before we strip off a fully-concrete generic
signature.
2024-11-15 17:26:34 -05:00
Slava Pestov
4e17871537 SIL: Fix formatting 2024-11-15 17:26:34 -05:00
Slava Pestov
59b1f1125a SILGen: Fix a spot where we passed in the wrong conformances
The conforming type didn't match the conformances, which is going to
be flagged by SubstitutionMap::verify().
2024-11-15 17:26:34 -05:00
Pavel Yaskevich
7bbb63a4f6 Merge pull request #77631 from xedin/rdar-134442168
[SILGen] ResultPlan: Make sure that checked continuations are destroye…
2024-11-15 09:03:44 -08:00
Doug Gregor
24a12ebc34 Renable GeneratedSourceInfo::Attribute to GeneratedSourceInfo::AttributeFromClang 2024-11-15 09:02:49 -08:00
Pavel Yaskevich
6fef6f5c92 [SILGen] ResultPlan: Make sure that checked continuations are destroyed after use
Currently nothing destroys the injected checked continuations which
means that their "canaries" leak.

Resolves: rdar://134442168
2024-11-14 20:17:19 -08:00
Doug Gregor
989c73d014 Ensure that buffers containing Clang swift_attr attributes are parsed as attributes
Previously, they were being parsed as top-level code, which would cause
errors because there are no definitions. Introduce a new
GeneratedSourceInfo kind to mark the purpose of these buffers so the
parser can handle them appropriately.
2024-11-13 21:19:37 -08:00
John McCall
e99ec88ce3 Use common code paths for constructor concurrency prologs if we're not in
the async self-isolated actor initializer case.

Fixes rdar://138394497, a bug where we didn't set up isolation correctly for
an async parameter-isolated initializer, but also probably a non-trivial number
of other latent differences between initializers and normal functions.
2024-11-13 17:10:32 -05:00
Nate Chandler
da71271d8f [CoroutineAccessors] Synthesize default req impls.
When a protocol which has a read (or modify) requirement is built with
the CoroutineAccessors feature, it gains a read2 (or modify2,
respectively) requirement.  For this to be compatible with binaries
built without the feature, a default implementation for these new
requirements must be provided.  Cause these new accessor requirements to
have default implementations by returning `true` from
`doesAccessorHaveBody` when the context is a `ProtocolDecl` and the
relevant availability check passes.
2024-11-07 16:47:09 -08:00
Nate Chandler
f6e145e995 [NFC] Remove dead branch.
The variable `storage` was defined as `nullptr` a couple lines above and
then is check for null, a spurious check.  Eliminate that
nullcheck--it's always true.
2024-11-06 20:52:21 -08:00
Nate Chandler
f1f0ccdeff [NFC] Improved predicate names. 2024-11-06 20:52:21 -08:00
Michael Gottesman
1046a03fb4 [concurrency] When calling an imported async objc function using continuations, use merge_isolation_region to tie the block storage and the resume buffer into one region.
This ensures that if the block has an @out return value that the return value is
considered to be affected by the actual call of the block. Before b/c we
smuggled the value through a Sendable continuation, we would lose the connection
in between the block and that result.

rdar://131422332
2024-11-01 12:11:44 -07:00
Michael Gottesman
dddfdc891f [region-isolation] Codegen unsafe continuation result using calls to foreign APIs in the same manner as with checked continuation.
The reason why I am doing this is that the unlike the codegen for checked
continuation, the codegen for unchecked continuation uses a sendable value
instead of Any as the block storage which prevents me from being able to create
a dependency from a non-Sendable @out parameter to the block.

By changing to use Any consistently, we are able to take advantage of Any not
being sendable to properly propagate this information.
2024-11-01 11:25:17 -07:00
Akira Hatanaka
f73c2e51bd Revert "[SILGen] Fix the type of closure thunks that are passed const reference structs (#76903)" (#77309)
This reverts commit 9c44b79189.

The commit caused swift's deserialization code to crash.

rdar://138726860
2024-10-31 15:16:00 -07:00
John McCall
56ec62570f Merge pull request #77308 from rjmccall/optional-isolation-check
Fix a crash when emitting isolation checks in a function with optional isolation
2024-10-31 10:50:27 -07:00
John McCall
b603c3c4e4 Emit a null check before asserting isolation in a function with optional isolation.
Fixes rdar://132478429
2024-10-30 14:41:50 -07:00
Nate Chandler
a3d607965b [CoroutineAccessors] Fix begin_apply for protos.
When the CoroutineAccessors feature is enabled, `begin_apply`
instructions produce an additional result representing the allocation
done by the callee.  Fix a couple of cases where this additional result
was not being handled.
2024-10-29 14:24:35 -07:00
Joe Groff
1772f021b1 Merge pull request #75193 from jckarter/reabstract-before-abi-safe-lvalue-conversion
SILGen: Reabstract subexpr lvalue before ABISafeConversion.
2024-10-28 12:00:26 -07:00
Joe Groff
8242110bbe Merge pull request #76831 from jckarter/builtin-vector
Builtin.FixedArray
2024-10-23 05:20:21 -10:00
Joe Groff
a184782a38 Introduce a Builtin.FixedArray type.
`Builtin.FixedArray<let N: Int, T: ~Copyable & ~Escapable>` has the layout of `N` elements of type `T` laid out
sequentially in memory (with the tail padding of every element occupied by the array). This provides a primitive
on which the standard library `Vector` type can be built.
2024-10-22 16:21:45 -07:00
Michael Gottesman
0e0665bfbd [concurrency] Add support for HopToMainActorIfNeededThunk.
It is behind the experimental flag GenerateForceToMainActorThunks.
2024-10-17 13:31:39 -07:00
Allan Shortlidge
7819dd7833 AST/Sema: Remove unnecessary ASTContext parameters from availability APIs.
Many of the methods on `AvailabilityInference` take both a `Decl` and an
`ASTContext`, which is redundant.
2024-10-14 17:46:53 -07:00
Hamish Knight
7c3f965578 Merge pull request #76979 from hamishknight/regex-request
Requestify regex pattern parsing
2024-10-12 19:19:09 +01:00
Hamish Knight
6a435960b7 Requestify regex pattern parsing
Instead of doing the pattern parsing in both the
C++ parser and ASTGen, factor out the parsing into
a request that returns the pattern to emit, regex
type, and version. This can then be lazily run
during type-checking.
2024-10-11 19:25:58 +01:00
Nate Chandler
71239d6357 [CoroutineAccessors] SIL represents callee alloc.
When its operand has coroutine kind `yield_once_2`, a `begin_apply`
instruction produces an additional value representing the storage
allocated by the callee.  This storage must be deallocated by a
`dealloc_stack` on every path out of the function.  Like any other stack
allocation, it must obey stack discipline.
2024-10-11 08:25:03 -07:00
Nate Chandler
11b5d27594 [CoroutineAccessors] Add flag to observe errors.
Temporarily allow the legacy behavior of allowing caller coroutine
accessors to observe errors (i.e. by executing no code after the yield
if the caller threw an error) behind the
CoroutineAccessorsUnwindOnCallerError flag.
2024-10-11 08:25:02 -07:00
Nate Chandler
8972d6214c [CoroutineAccessors] Don't observe caller errors.
Experience with `_modify`/`_read` has shown that it is never desireable
to cleanup differently based on whether the caller has thrown.  Emit an
`end_apply` in either case.
2024-10-11 08:25:02 -07:00