Commit Graph

341 Commits

Author SHA1 Message Date
Janat Baig
798c0f51a4 Merge branch 'main' into temp-branch 2025-08-23 11:11:04 -04:00
JanBaig
836e20a253 [SILGen] Refactor InitializationPtr usage 2025-08-17 14:05:02 -04:00
JanBaig
b793db7bfa [SILGen] Inline InitializationPtr setup for init accessor @out buffer 2025-08-12 11:21:11 -04:00
JanBaig
b939bdc31a [SIL] Initial Implemention of thunk support for local contexts 2025-08-09 19:39:29 -04:00
JanBaig
ff894c4d01 [Format] Apply clang-format to recent changes 2025-08-09 12:46:18 -04:00
JanBaig
544aa3b06a [SILGen] SILGen body emission for the new SILDeclRef works for nominal types 2025-08-08 19:05:27 -04:00
Erik Eckstein
c1258f5a90 SILGen: use builtin prepareInitialization instead of zeroInitializer when generating a value constructor for an empty non-copyable type
`zeroInitializer` is blocking optimizations. It is not needed because the constructor will initialize the memory anyway.
We only need to tell mandatory passes that this memory should be treated as initialized.
2025-08-03 11:06:14 +02:00
John McCall
bee053f1f0 Switch InitializationPtr to use PossiblyUniquePtr so that we can just
forward existing initializations around when necessary.
2025-08-02 02:13:25 -04:00
Michael Gottesman
3871d22257 [concurrency] Emit nonisolated(nonsending) async throw initializers correctly.
Specifically, we were not inserting the implicit isolated parameter and were not
setting up the actor prologue. To keep this specific to nonisolated(nonsending)
code, I only setup the actor prologue if we know that we have something that is
nonisolated(nonsending).

I also ported some async initializer tests to run with/without
nonisolated(nonsending) just to increase code coverage.

rdar://156919493
2025-07-29 19:15:08 -07:00
John McCall
2eee30dfbe [NFC] Encapsulate the parameter index of an ActorIsolation 2025-06-27 19:48:12 -04:00
Nate Chandler
96eb85cc93 [SILGen] Make eagerMove class init's self lexical.
Change the representation for eagerMove classes so that the body of
their deinit runs after the body of their init.

rdar://149782365
2025-04-23 17:16:05 -07:00
John McCall
3fe70968cc Remove the substitution map from zeroInitializer builtin in SIL.
This is a value operation that can work just fine on lowered types,
so there's no need to carry along a formal type. Make the value/address
duality clearer, and enforce it in the verifier.
2025-03-26 00:34:15 -04:00
Joe Groff
da813458a6 SILGen: Emit an addressable representation for immutable bindings on demand.
To ensure that dependent values have a persistent-enough memory representation
to point into, when an immutable binding is referenced as an addressable
argument to a call, have SILGen retroactively emit a stack allocation and
materialization that covers the binding's scope.
2025-03-12 18:35:42 -07:00
Michael Gottesman
f6349aaf1e Revert "SILGen: Emit an addressable representation for immutable bindings on demand."
This reverts commit 19a99ea42b.

rdar://146864906
2025-03-12 13:24:33 -07:00
Joe Groff
19a99ea42b SILGen: Emit an addressable representation for immutable bindings on demand.
To ensure that dependent values have a persistent-enough memory representation
to point into, when an immutable binding is referenced as an addressable
argument to a call, have SILGen retroactively emit a stack allocation and
materialization that covers the binding's scope.
2025-03-11 15:15:48 -07:00
Michael Gottesman
7e350bb4ce Revert "[concurrency] Add Concurrent/ConcurrentUnsafe and use it instead of ActorIsolation::Nonisolated."
This reverts commit 0cb64638d0.
2025-02-06 14:05:06 -08:00
Michael Gottesman
f05f08c2c0 Revert "[concurrency] Make ActorIsolation::Nonisolated -> CallerIsolationInheriting and delete CallerIsolationInheriting."
This reverts commit 543b1e6ca3.
2025-02-06 14:04:30 -08:00
Michael Gottesman
543b1e6ca3 [concurrency] Make ActorIsolation::Nonisolated -> CallerIsolationInheriting and delete CallerIsolationInheriting. 2025-02-03 10:56:08 -08:00
Michael Gottesman
0cb64638d0 [concurrency] Add Concurrent/ConcurrentUnsafe and use it instead of ActorIsolation::Nonisolated.
This is just the first part of a larger transition.
2025-02-03 10:56:06 -08:00
Anthony Latsis
a84dfc8387 [Gardening] Fix some set but not used variables 2025-01-30 21:34:38 +00:00
Andrew Trick
fe075dcb29 Fix SILGenFunction::emitValueConstructor for library evolution.
Always call createMarkUnresolvedNonCopyableValueInst for a constructor
with move-only 'self'. Handle 'self' that is either returned by value
or as an indirect result

Fixes rdar://142690658 (In ~Copyable public struct,
an init with COW type param causes compiler error)
2025-01-10 18:05:05 -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
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
John McCall
af8115ffa3 Hop to the current isolation properly in delegating async actor initializers.
This requires two major changes.

The first is that we need to teach SILGen that the isolation of an initializer
is essentially dynamic (as far as SILGen is concerned) --- that it needs to emit
code in order to get the isolation reference.  To make this work, I needed to
refactor how we store the expected executor of a function so that it's not
always a constant value; instead, we'll need to emit code that DI will lower
properly.  Fortunately, I can largely build on top of the work that Doug previously
did to support #isolation in these functions.  The SIL we emit here around delegating
initializer calls is not ideal --- the breadcrumb hop ends up jumping to the
generic executor, and then DI actually emits the hop to the actor.  This is a little
silly, but it's hard to eliminate without special-casing the self-rebinding, which
honestly we should consider rather than the weirdly global handling of that in
SILGen today.  The optimizer should eliminate this hop pretty reliably, at least.

The second is that we need to teach DI to handle the pattern of code we get in
delegating initializers, where the builtin actually has to be passed the self var
rather than a class reference.  This is because we don't *have* a class reference
that's consistently correct in these cases.  This ended up being a fairly
straightforward generalization.

I also taught the hop_to_executor optimizer to skip over the initialization of
the default-actor header; there are a lot of simple cases where we still do emit
the prologue generic-executor hop, but at least the most trivial case is handled.
To do this better, we'd need to teach this bit of the optimizer that the properties
of self can be stored to in an initializer prior to the object having escaped, and
we don't have that information easily at hand, I think.

Fixes rdar://87485045.
2024-10-04 22:23:00 -04:00
Slava Pestov
fae01d9776 AST: Remove ModuleDecl parameter from more places 2024-07-06 12:05:46 -04:00
Tim Kientzle
1098054291 Merge branch 'main' into tbkka-assertions2 2024-06-18 17:52:00 -07:00
Akira Hatanaka
d92f181ace Create two versions (for caller and callee) of the functions that answer questions about parameter convention (#74124)
Create two versions of the following functions:

isConsumedParameter
isGuaranteedParameter
SILParameterInfo::isConsumed
SILParameterInfo::isGuaranteed
SILArgumentConvention::isOwnedConvention
SILArgumentConvention::isGuaranteedConvention

These changes will be needed when we add a new convention for
non-trivial C++ types as the functions will return different answers
depending on whether they are called for the caller or the callee. This
commit doesn't change any functionality.
2024-06-18 09:06:09 -07:00
Tim Kientzle
1d961ba22d Add #include "swift/Basic/Assertions.h" to a lot of source files
Although I don't plan to bring over new assertions wholesale
into the current qualification branch, it's entirely possible
that various minor changes in main will use the new assertions;
having this basic support in the release branch will simplify that.
(This is why I'm adding the includes as a separate pass from
rewriting the individual assertions)
2024-06-05 19:37:30 -07:00
Emil Pedersen
0bc6ece9db [DebugInfo] [SILGen] Always use emitDebugDescription (NFCI) 2024-05-23 14:05:13 -07:00
Doug Gregor
39f4e38027 Diagnose inout uses of 'lets' in constructors in the type checker.
Stored `let` properties of a struct, class, or actor permit
'inout' modification within the constructor body after they have been
initialized. Tentatively remove this rule, only allowing such `let`
properties to be initialized (assigned to) and not treated as `inout`.

Fixes rdar://127258363.
2024-05-14 15:59:50 -07:00
John McCall
40d9ea598e Merge pull request #72514 from rjmccall/isolated-any-optional-conversion
Correctly apply `@isolated(any)` even when converting to an optional type
2024-03-23 05:04:18 -04:00
Joe Groff
f5128d57b9 Merge pull request #72464 from jckarter/init-conditionally-copyable-empty-type
SILGen: Emit empty type initialization for conditionally-copyable type inits.
2024-03-21 15:08:41 -07:00
John McCall
c7d3e8f559 [NFC] Generalize how Conversion works with reabstraction conversions and
force callers to specify the input lowered type as well.
2024-03-21 12:47:56 -04:00
Joe Groff
d9bd92e226 SILGen: Emit empty type initialization for conditionally-copyable type inits.
Fix the check here to go by `isMoveOnly` on the lowered type rather than
`canBeCopyable` on the declaration so that we correctly emit the
semantic initialization for types that are `~Copyable` in their most
generic form. Fixes rdar://125101955.
2024-03-20 14:14:25 -07:00
Meghana Gupta
c0847e33ac Remove diagnostic error when 'return self' is missing in an initializer with explicit lifetime dependence
Also, handle it similar to other initializers in SILGen and ASTVerifier
2024-03-13 10:34:37 -07:00
Ben Barham
ef8825bfe6 Migrate llvm::Optional to std::optional
LLVM has removed llvm::Optional, move over to std::optional. Also
clang-format to fix up all the renamed #includes.
2024-02-21 11:20:06 -08:00
John McCall
c9dac8d0b3 [NFC] Extract executor-handling stuff into SILGenConcurrency.cpp 2024-02-15 20:02:53 -05:00
John McCall
2d71c604ed Emit enum element arguments directly into the enum payload.
This generates significantly better code directly out of SILGen, at
the cost of having to reimplement a little bit of the argument-emission
logic to handle default arguments.  But it also neatly sidesteps the
problems we have with splitting tuple RValues when the tuple contains
a pack expansion, which will require some significant surgery to RValue
to fix.  That, in turn, fixes rdar://121489308.
2024-02-15 01:09:12 -05:00
John McCall
2f8a33cf0a Experimental type-checking support for @isolated(any) function types. 2024-02-06 22:54:27 -05:00
Meghana Gupta
c8ece100ba Handle explicit lifetime dependence specifiers in initializers 2024-02-02 11:50:10 -08:00
Slava Pestov
af3ab14986 SILGen: Clean up substitution map construction to deal with Copyable 2024-01-31 21:55:52 -05:00
Kavon Farvardin
b4985f7fde [NFC] replace canBeNoncopyable
First, "can have an absence of Copyable" is a rather confusing notion,
so the query is flipped to "can be Copyable". Next, it's more robust to
ask if a conformance exists for the TypeDecl to answer that question,
rather than trying to replicate what happens within that conformance
lookup.

Also renames `TypeDecl::isEscapable` to match.
2024-01-23 22:42:38 -08:00
Holly Borla
47afd21d85 [Concurrency] Remove ActorIsolation::GlobalActorUnsafe. 2024-01-21 21:05:33 -08:00
Holly Borla
20829faa43 [Concurrency] Handle cases where a property initializer is subsumed by another
property for IsolatedDefaultValues.

For property wrappers and init accesors, skip property initializers that are
subsumed, e.g. by an init accessor or a backing property wrapper initializer,
and always consider the subsuming initializer to determine whether compiler
synthesized initializers should have `nonisolated` applied.

This change also lessens the source break of SE-0411 by still emitting
member initializers in implicit constructors when the initializer violates
actor isolation to preserve the behavior of existing code when concurrency
diagnostics are downgraded to warnings in Swift 5 mode.
2024-01-19 18:12:25 -08:00
Slava Pestov
1a06313ac9 SIL: Fix DynamicSelfType references from inside init accessor
We need the self metatype parameter to correctly lower
DynamicSelfType in IRGen, so plumb this through to all
calls of init accessors, and inside the prolog of an
init accessor definition.

This does not break the public ABI, because init
accessors are never public. Also for value types, the
metatype is thin, so it should not change generated
code.

For classes we need the metatype in the general case
because of `Self`, but hopefully in most cases the
init accessor can be inlined away and the value_metatype
instruction subject to dead code elimination.

Fixes rdar://problem/119822466.
2024-01-09 10:52:54 -05:00
Doug Gregor
504329545f [SILGen] Handle indirect error results in allocating class initializers 2023-11-12 03:20:39 -08:00
Kavon Farvardin
a9c64baaa3 [Sema] refactor TypeDecl::isNoncopyable
In preparation for reporting whether the inverse marking on a TypeDecl
was inferred instead of explicit.
2023-11-06 15:40:12 -08:00
Slava Pestov
ad5697778e Merge pull request #69430 from slavapestov/silgen-typed-throws-wip
Preliminary SILGen support for address-only typed throws
2023-10-27 21:00:51 -04:00
Slava Pestov
581776b997 SILGen: Emit indirect error result argument 2023-10-27 17:37:43 -04: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