Commit Graph

106 Commits

Author SHA1 Message Date
Michael Gottesman
6cf9ee5ebf Merge pull request #81014 from gottesmm/pr-af452b4f8348d8c3dc39d9a1682b01910a7c3194
[silgen] When emitting a foreign async completion handler for a method, use merge isolation region to tie self and the block storage into the same region.
2025-04-24 10:17:36 -07:00
Michael Gottesman
227ab376cf [silgen] When emitting a foreign async completion handler for a method, use merge isolation region to tie self and the block storage into the same region.
This is an extension of a similar problem that I had fixed earlier where due to
the usage of intermediate Sendable types we do not propagate regions correctly.

The previous issue I fixed was that we were not properly tieing the result of a
foreign async completion handler to the block storage since we used an
intervening UnsafeContinuation (which is Sendable) to propagate the result into
the block storage. I fixed this by changing SILGen to insert a
merge_isolation_region that explicitly ties the result to the block storage.

This new issue is that the block that we create and then pass as the completion
handler is an @Sendable block. Thus when we call the actual objc_method, the
block storage and self are not viewed as being in the same region. In this PR, I
change it so that we add a merge_isolation_region from self onto the block
storage.

The end result of this is that we have that self, the result of the call, and
the block storage are all in the same region meaning that we properly diagnose
that returning an NSObject from the imported Objective-C function is task
isolated and thus we cannot return it as a sending result.

rdar://131422332
2025-04-23 10:01:24 -07:00
Michael Gottesman
132eb93d44 [silgen] Fix a small typo bug I found on inspection.
We are performing a cast instead of a dyn_cast in an if statement. This will
assert on failure rather than fall through. It seems to be an obvious typo. I
checked in the actual commit in question that introduced it and the intention
was to be a dyn_cast.

rdar://149698148
2025-04-21 10:40:07 -07:00
Tony Allevato
8b483a6a52 [NFC] Fix a use of an uninitialized captured value.
On a very recent tip-of-tree build of Clang, this was producing
the following error:

`variable 'eltMV' is uninitialized when used within its own initialization [-Werror,-Wuninitialized]`
2025-03-19 10:55:19 -04:00
Erik Eckstein
d225c47d25 AST: rename OpenArchetypeType -> ExistentialArchetypeType
NFC
2025-03-11 20:21:46 +01: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
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
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
Slava Pestov
e79763b590 AST: Factor out mapLocalArchetypesOutOfContext() utility function 2024-08-30 15:24:00 -04:00
Slava Pestov
b23a340740 SILGen: Simplify mapTypeOutOfOpenedExistentialContext() 2024-08-21 14:23:38 -04:00
Slava Pestov
39b4bda1dc AST: Introduce SubstFlags::SubstituteLocalArchetypes 2024-08-21 14:23:37 -04:00
Slava Pestov
0c2f28fd3d AST: Remove GenericSignature parameter from OpenedArchetypeType::get() 2024-08-20 12:15:27 -04:00
Slava Pestov
375363a473 AST: Move global conformance lookup entry points to ConformanceLookup.h 2024-08-08 23:35:58 -04:00
Slava Pestov
fae01d9776 AST: Remove ModuleDecl parameter from more places 2024-07-06 12:05:46 -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
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
Nate Chandler
9f6c30919b [NFC] SIL: Typed begin_borrow's isLexical. 2024-03-08 22:27:50 -08:00
Nate Chandler
dfa5c9814b [NFC] SIL: Typed alloc_stack's hasDynamicLifetime. 2024-03-08 21:24:39 -08:00
Ben Barham
f292ec9784 Use the new template deduction guides rather than makeArrayRef
LLVM has removed `make*ArrayRef`, migrate all references to their
constructor equivalent.
2024-02-23 20:04:51 -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
Slava Pestov
af50d7e6b8 AST: Add allowInverses flag to AbstractGenericSignatureRequest 2024-02-05 18:43:06 -05:00
Slava Pestov
af3ab14986 SILGen: Clean up substitution map construction to deal with Copyable 2024-01-31 21:55:52 -05:00
John McCall
444e770175 [NFC] Generalize createOpenedElementValueEnvironment to also be able
to map formal types into the new environment.
2024-01-03 16:25:16 -05:00
Slava Pestov
5dd8307e60 AST: Pass SubstOptions to DependentMemberType::substBaseType() 2023-12-07 18:00:50 -05:00
Pavel Yaskevich
ce651ca67d [SILGen] ResultPlan: Address a FIXME about resume with foreign error 2023-09-08 10:52:41 -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
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
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
Michael Gottesman
5095bd31b0 [silgen] Convert a few instances of ManagedValue::forUnmanaged(*).copy() -> ManagedValue::forCopyOwnedObjectRValue.
Just removing more ManagedValue::forUnmanaged.
2023-08-08 11:15:06 -07:00
Michael Gottesman
2208caac32 [silgen] Convert a bunch of forUnmanaged -> forObjectRValueWithoutOwnership.
NFCI.
2023-08-07 13:36:02 -07:00
John McCall
e14f2bc0c7 [NFC] Add a method to just ask if a tuple AP vanishes under substitution 2023-06-29 19:39:51 -04:00
Erik Eckstein
6b1697eb06 use new llvm::Optional APIs to fix deprecation warnings 2023-06-28 14:28:38 +02:00
Evan Wilde
250082df25 [NFC] Reformat all the LLVMs
Reformatting everything now that we have `llvm` namespaces. I've
separated this from the main commit to help manage merge-conflicts and
for making it a bit easier to read the mega-patch.
2023-06-27 09:03:52 -07: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
John McCall
e87fbc8a04 Handle vanishing tuples when emitting a result plan into an initalization
Fixes rdar://107972801
2023-04-19 15:34:03 -04:00
Adrian Prantl
829491b230 Merge pull request #64551 from adrian-prantl/88274783
Rebase SILScope generation on top of ASTScope
2023-04-05 08:30:13 -07:00
Adrian Prantl
158772c2ab Rebase SILScope generation on top of ASTScope.
This patch replaces the stateful generation of SILScope information in
SILGenFunction with data derived from the ASTScope hierarchy, which should be
100% in sync with the scopes needed for local variables. The goal is to
eliminate the surprising effects that the stack of cleanup operations can have
on the current state of SILBuilder leading to a fully deterministic (in the
sense of: predictible by a human) association of SILDebugScopes with
SILInstructions. The patch also eliminates the need to many workarounds. There
are still some accomodations for several Sema transformation passes such as
ResultBuilders, which don't correctly update the source locations when moving
around nodes. If these were implemented as macros, this problem would disappear.

This necessary rewrite of the macro scope handling included in this patch also
adds proper support nested macro expansions.

This fixes

rdar://88274783

and either fixes or at least partially addresses the following:

rdar://89252827
rdar://105186946
rdar://105757810
rdar://105997826
rdar://105102288
2023-04-04 15:20:11 -07:00
John McCall
3ffaae7948 Handle vanishing tuples correctly in result planning. 2023-04-03 23:16:38 -04:00
John McCall
74420994d4 Teach ResultPlan to handle packs correctly when we're not emitting
into an Initialization.

rdar://107161241
2023-03-28 14:34:06 -04:00
John McCall
debc8d9ebd [NFC] Move forEachTupleElement to use a generator 2023-03-22 22:04:36 -04:00
John McCall
9ab4dc494c [NFC] Add better APIs for parallel destructuring of orig+subst types
As I've been iterating on this work, I've been gradually mulling these
over, and I think this is the way to go for now.  These should make it
a lot less cumbersome to write these kinds of traversals correctly.

The intent is to the sunset the existing expanded-components stuff
after I do a similar pass for function parameters.
2023-03-16 00:19:30 -04:00
John McCall
239777aacb Fix parameter binding for tuples containing pack expansions
More missing infrastructure.  In this case, it's really *existing*
missing infrastructure, though; we should have been imploding tuples
this way all along, given that we're doing it in the first place.

I don't like that we're doing all these extra tuple copies.  I'm not
sure yet if they're just coming out of SILGen and eliminated immediately
after in practice; maybe so.  Still, it should be obvious that they're
unnecessary.
2023-03-09 02:28:29 -05:00
John McCall
81f11c19ab Implement the caller side of return types containing variadic packs
This is all relatively nicely abstracted, which is not to say that
it didn't take an awful lot of plumbing to get it to work.  The basic
problem here is inherent: we need to do component-specific setup and
teardown, and unfortunately in the current representation we have to
do that with separate loops and without any dominance relationships.
(This is the same thing preventing us from doing borrows in the
general case.)  The result is that the general case of result emission
is to emit every element of the expansion into a temporary tuple
(requiring a pack loop before the call to initialize the pack), then
process those elements in the body of a second pack loop after the
call.  And that's terrible enough that we really have to do the work
to try to avoid it, which makes all the APIs more complicated.

Anyway, most of the way through the basic plumbing for variadic
generics now.  Next is reabstraction, I think, which I hope will
mostly mean fixing bugs in the infrastructure I've already written.
2023-03-07 03:15:31 -05:00
Erik Eckstein
ab1b343dad use new llvm::Optional API
`getValue` -> `value`
`getValueOr` -> `value_or`
`hasValue` -> `has_value`
`map` -> `transform`

The old API will be deprecated in the rebranch.
To avoid merge conflicts, use the new API already in the main branch.

rdar://102362022
2022-11-21 19:44:24 +01:00
Nate Chandler
424174cd24 [OpaqueValues] Return generic tuples directly.
Only create alloc_stacks for address-only tuple returns when using
lowered addresses.
2022-11-02 16:01:58 -07:00
Holly Borla
c4b946195e [AST] Replace the "type sequence" terminology with "parameter pack". 2022-10-10 16:28:13 -07:00
Nate Chandler
3c78a0bb90 [SILGen] Only lexical types get lexical lifetimes.
Only emit `begin_borrow [lexical]` and only mark `alloc_stack`s
`[lexical]` when the variable in question's lifetime is lexical, not
eager move.
2022-08-22 15:28:00 -07:00
Slava Pestov
9d96ed940f AST: Rename 'canonical wrt. generic signature' to 'reduced'
We had two notions of canonical types, one is the structural property
where it doesn't contain sugared types, the other one where it does
not contain reducible type parameters with respect to a generic
signature.

Rename the second one to a 'reduced type'.
2022-08-09 12:46:31 -04:00