Commit Graph

123 Commits

Author SHA1 Message Date
Doug Gregor
7789a0ce64 [SE-0371] Back-deploy support for main-actor-isolated deinit
When targeting a platform that predates the introduction of isolated
deinit, make a narrow exception that allows main-actor-isolated deinit
to work through a special, inlineable entrypoint that is
back-deployed. This implementation

  1. Calls into the real implementation when available, otherwise
  2. Checks if we're on the main thread, destroying immediately when
we are, otherwise
  3. Creates a new task on the main actor to handle destruction.

This implementation is less efficient than the implementation in the
runtime, but allows us to back-deploy this functionality as far back
as concurrency goes.

Fixes rdar://151029118.
2025-06-30 17:38:08 -07:00
Anthony Latsis
a84dfc8387 [Gardening] Fix some set but not used variables 2025-01-30 21:34:38 +00: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
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
Konrad `ktoso` Malawski
7d1ce789ad Revert "Revert "Isolated synchronous deinit"" 2024-09-17 17:35:38 +09:00
Alex Hoppen
c5aa49ba64 Revert "Isolated synchronous deinit" 2024-09-03 18:11:26 -07:00
Mykola Pokhylets
50b1313175 Merge branch 'main' into mpokhylets/isolated-deinit
# Conflicts:
#	lib/SILGen/SILGenDistributed.cpp
#	lib/Sema/TypeCheckConcurrency.cpp
2024-08-15 16:58:43 +02:00
Mykola Pokhylets
816d62c972 Merge remote-tracking branch 'upstream/main' into mpokhylets/isolated-deinit
# Conflicts:
#	include/swift/Basic/Features.def
#	lib/SILGen/SILGenDestructor.cpp
#	test/Concurrency/flow_isolation.swift
#	test/abi/macOS/arm64/concurrency.swift
#	test/abi/macOS/x86_64/concurrency.swift
2024-07-11 13:11:59 +02:00
Mykola Pokhylets
6b0ce0bcd7 Added emitting precondition check in the isolated deinit 2024-07-11 13:09:08 +02:00
Mykola Pokhylets
ab4d338f6a Added flags to be able to control task-locals behaviour in the future 2024-07-11 13:09:08 +02:00
Mykola Pokhylets
35f0334eb6 Rename performOnExecutor into deinitOnExecutor.
It cannot be used for executing general-purpose work, because such function would need to have a different signature to pass isolated actor instance.

And being explicit about using this method only for deinit allows to use object pointer for comparison with executor identity.
2024-07-11 13:09:07 +02:00
Mykola Pokhylets
5437b31cf3 Expanded test for SIL for distributed actor deinit, added isolated cases 2024-07-11 13:09:07 +02:00
Mykola Pokhylets
c28df0dc05 Don't isolate deinit of remote actor proxies 2024-07-11 13:09:07 +02:00
Mykola Pokhylets
f04f1de75e Fixed some typos 2024-07-11 13:09:07 +02:00
Mykola Pokhylets
485965a759 Reviewed code comments. Fixed typos and addressed some TODOs 2024-07-11 13:09:06 +02:00
Mykola Pokhylets
28a06feaad Added isolated deallocator to TBDGen 2024-07-11 13:09:06 +02:00
Mykola Pokhylets
62dbc6c966 Fixed some tests. Using extract_executor SIL instruction instead of custom code. 2024-07-11 13:09:06 +02:00
Mykola Pokhylets
95079aff06 Don't generate isolating destructor if dealloc was explicitly isolated in ObjC 2024-07-11 13:09:06 +02:00
Mykola Pokhylets
d4e449b62d SILGen for isolated deinit 2024-07-11 13:09:05 +02: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
Slava Pestov
322ce5a1ab SIL: Consistently drop substitution map when forming apply instructions
Fixes rdar://129298104.
2024-06-11 10:36:15 -04: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
Nate Chandler
23e7c36c5f [NoncopyablePartialConsumption] Ungate feature.
Remove all checks for the feature flag.  It's on all the time.
2024-04-19 12:37:34 -07:00
Nate Chandler
6100a1b495 Allow partial consumption of self in deinit.
Basic support for partial consumption in deinit without full support for
all future uses of drop_deinit.
2024-02-28 15:57:09 -08: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
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
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
581776b997 SILGen: Emit indirect error result argument 2023-10-27 17:37:43 -04: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
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
Michael Gottesman
543063ef0e [silgen] Make ManagedValue::forUnmanaged private and change users to use other more specific APIs.
I have been doing this over the past couple of days in preparation for changing
ManagedValue to specify the type of scope its cleanup is connected to.
2023-08-19 14:11:44 -07:00
Allan Shortlidge
cb7982d8d5 Merge pull request #67761 from tshortli/ast-unavailable-decl-queries
NFC: Hoist queries for unavailable decl optimizations into the AST library
2023-08-06 10:01:27 -07:00
Allan Shortlidge
ca8bf981a4 NFC: Hoist queries for unavailable decl optimizations into the AST library.
Moving the query implementation up to the AST library from SIL will allow
conveniences to be written on specific AST element classes. For instance, this
will allow `EnumDecl` to expose a convenience that enumerates element decls
that are available during lowering.

Also, improve naming and documentation for these queries.
2023-08-04 17:39:26 -07:00
Slava Pestov
9ebb5f2e03 AST: Rename VarDecl::getType() to VarDecl::getTypeInContext()
This is a futile attempt to discourage future use of getType() by
giving it a "scary" name.

We want people to use getInterfaceType() like with the other decl kinds.
2023-08-04 14:19:25 -04:00
Evan Wilde
f3ff561c6f [NFC] add llvm namespace to Optional and None
This is phase-1 of switching from llvm::Optional to std::optional in the
next rebranch. llvm::Optional was removed from upstream LLVM, so we need
to migrate off rather soon. On Darwin, std::optional, and llvm::Optional
have the same layout, so we don't need to be as concerned about ABI
beyond the name mangling. `llvm::Optional` is only returned from one
function in
```
getStandardTypeSubst(StringRef TypeName,
                     bool allowConcurrencyManglings);
```
It's the return value, so it should not impact the mangling of the
function, and the layout is the same as `std::optional`, so it should be
mostly okay. This function doesn't appear to have users, and the ABI was
already broken 2 years ago for concurrency and no one seemed to notice
so this should be "okay".

I'm doing the migration incrementally so that folks working on main can
cherry-pick back to the release/5.9 branch. Once 5.9 is done and locked
away, then we can go through and finish the replacement. Since `None`
and `Optional` show up in contexts where they are not `llvm::None` and
`llvm::Optional`, I'm preparing the work now by going through and
removing the namespace unwrapping and making the `llvm` namespace
explicit. This should make it fairly mechanical to go through and
replace llvm::Optional with std::optional, and llvm::None with
std::nullopt. It's also a change that can be brought onto the
release/5.9 with minimal impact. This should be an NFC change.
2023-06-27 09:03:52 -07:00
Andrew Trick
2f200a6caa [move-only] Fix drop_deinit OSSA lowering
drop_deinit ultimately only affects the semantics of its
destroy_value. Avoid generating releases for destroys in which the
deinit has been dropped. Instead, individually release the members.
2023-06-06 09:17:53 -07:00
Andrew Trick
6b53365cd0 [move-only] Comment emitMoveOnlyMemberDestruction drop_deinit 2023-06-06 09:17:53 -07:00
Allan Shortlidge
b1d20697fa SILGen: Stub unavailable @objc interop functions and thunks.
Part of rdar://107388493
2023-05-03 15:19:32 -07:00
Allan Shortlidge
8bc1112029 SILGen: Stub unavailable constructors and destructors.
Part of rdar://107388493
2023-05-03 15:19:31 -07:00
Erik Eckstein
dfa46c6129 SILGen: emit drop_deinit in move-only destructors 2023-04-11 10:25:49 +02:00
Konrad `ktoso` Malawski
41f99fc2ae [Executors][Distributed] custom executors for distributed actor (#64237)
* [Executors][Distributed] custom executors for distributed actor

* harden ordering guarantees of synthesised fields

* the issue was that a non-default actor must implement the is remote check differently

* NonDefaultDistributedActor to complete support and remote flag handling

* invoke nonDefaultDistributedActorInitialize when necessary in SILGen

* refactor inline assertion into method

* cleanup

* [Executors][Distributed] Update module version for NonDefaultDistributedActor

* Minor docs cleanup

* we solved those fixme's

* add mangling test for non-def-dist-actor
2023-03-15 23:42:55 +09:00
Michael Gottesman
f9f111841e [move-only] When emitting a deinit for a move only struct with only trivial fields, use an end_lifetime instead of a destructure_struct.
rdar://104875010
2023-02-22 13:36:50 -08:00
Michael Gottesman
6f7961b63c [move-only] Mark self of move only struct/enum types in deinits as being move-only.
This ensures that if we try to escape self or assign it to a variable, we
error since at the end of the deinit we always consume self and clean up its
variables.

I did not handle unique classes since it would have required a bit more surgery
around how deinits are handled and we do not need unique classes for our MVP.

rdar://102339259
2022-11-14 14:47:37 -08:00
swift-ci
fd6fd76dae Merge pull request #42513 from jsoref/spelling-silgen
Spelling silgen
2022-11-09 23:28:43 -08:00
Josh Soref
9a6bf46c0f Spelling silgen
* actually
* arbitrary
* cargo-culted
* clazz
* constrained
* continuation
* coordinator
* coroutine
* derivative
* destroyer
* given
* have
* imported
* initialization
* items
* necessarily
* occurring
* omitting
* overridden
* parameter
* possible
* predecessor
* preparation
* resilience
* should
* struct
* that
* the
* throwing
* unexpectedly
* uniqueness
* using
* value
* villain

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>
2022-11-09 21:44:17 -05:00
Becca Royal-Gordon
ad359fa753 Give @_objcImpl classes implicit deinits 2022-10-18 17:21:56 -07:00
Michael Gottesman
09c7a4e8a8 [move-only] Also add support for enums as well. 2022-09-20 15:19:31 -07:00
Michael Gottesman
c54acc83e2 [move-only] Add the ability to specify a deinit at the SIL level for a move only type.
Specifically, we get an additional table like thing called sil_moveonlydeinit. It looks as follows:

sil_moveonlydeinit TYPE {
  @FUNC_NAME
}

It always has a single entry.
2022-09-20 15:19:31 -07:00