Commit Graph

555 Commits

Author SHA1 Message Date
Kuba Mracek
6f4ae28520 [ASTMangler] Pass ASTContext to all instantiations of ASTMangler 2024-12-02 15:01:04 -08: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
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
Nate Chandler
df1c4f6b25 [CoroutineAccessors] Add new SILFnTy CoroKind.
For `modify` and `read` coroutines, produce SILFunctionType's whose
coroutineKind is ::YieldOnce2.
2024-10-11 08:25:02 -07:00
Slava Pestov
ff308e9510 AST: Remove TypeBase::openAnyExistentialType() 2024-08-20 12:15:27 -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
86d567f95a AST: ModuleDecl::lookupConformance() is a static method 2024-07-06 12:05:47 -04:00
Slava Pestov
fae01d9776 AST: Remove ModuleDecl parameter from more places 2024-07-06 12:05:46 -04:00
Akira Hatanaka
42bc49d3fe Add a new parameter convention @in_cxx for non-trivial C++ classes that are passed indirectly and destructed by the caller (#73019)
This corresponds to the parameter-passing convention of the Itanium C++
ABI, in which the argument is passed indirectly and possibly modified,
but not destroyed, by the callee.

@in_cxx is handled the same way as @in in callers and @in_guaranteed in
callees. OwnershipModelEliminator emits the call to destroy_addr that is
needed to destroy the argument in the caller.

rdar://122707697
2024-06-27 09:44:04 -07:00
Michael Gottesman
f781ad366d [sending] Compensate in SILGen for a typechecker bug where we do not properly mark actor isolated async closures passed to an inheritActorContext argument as being Sendable.
The reason why I am fixing this is that otherwise, we get a warning when one
creates an actor isolated closure and pass it into a task, e.x.:

```swift
@MainActor func test() {
  // We would get a warning on the closure below saying that we are sending
  // a closure that is MainActor isolated.
  Task {
    ...
  }
}
```
2024-06-21 02:24:03 -07: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
Anton Korobeynikov
0f4dacd47b [AutoDiff] Fix custom derivative thunk for Optional (#74378)
Enable the nil coalescing operator (aka `??`) for Optional type.

Fixes #55882

Co-authored-by: Andrew Savonichev <andrew.savonichev@gmail.com>
2024-06-13 10:53:18 -07:00
Max Desiatov
12f402f715 Revert "[AutoDiff] Fix custom derivative thunk for Optional (#71721)" (#74268)
This reverts commit aa5dddb952.

Fixes `preset=buildbot,tools=RA,stdlib=DA` CI job, which without this revert fails on `AutoDiff/SILGen/nil_coalescing.swift` test.
2024-06-11 09:24:19 +01:00
nate-chandler
033fc2354f Merge pull request #74157 from nate-chandler/rdar128710064
[SILGen] Store_borrow into in_guaranteed.
2024-06-07 06:47:16 -07:00
Nate Chandler
c35b86a30d [SILGen] Borrow into in_guaranteed.
Don't create a copy in order to pass a value `@in_guaranteed`.  Just
`store_borrow` the value.

rdar://128710064
2024-06-06 15:45:22 -07:00
Andrew Savonichev
aa5dddb952 [AutoDiff] Fix custom derivative thunk for Optional (#71721)
Enable the nil coalescing operator (aka `??`) for Optional type.

Fixes #55882

Co-authored-by: Anton Korobeynikov <anton@korobeynikov.info>
2024-06-05 23:41:48 -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
Ellie Shin
5ccc4cd394 SIL function can be serialized with different kinds: [serialized] or
[serialized_for_package] if Package CMO is enabled. The latter kind
allows a function to be serialized even if it contains loadable types,
if Package CMO is enabled. Renamed IsSerialized_t as SerializedKind_t.

The tri-state serialization kind requires validating inlinability
depending on the serialization kinds of callee vs caller; e.g. if the
callee is [serialized_for_package], the caller must be _not_ [serialized].
Renamed `hasValidLinkageForFragileInline` as `canBeInlinedIntoCaller`
that takes in its caller's SerializedKind as an argument. Another argument
`assumeFragileCaller` is also added to ensure that the calle sites of
this function know the caller is serialized unless it's called for SIL
inlining optimization passes.

The [serialized_for_package] attribute is allowed for SIL function, global var,
v-table, and witness-table.

Resolves rdar://128406520
2024-05-23 15:53:02 -07:00
Pavel Yaskevich
72eb8abadb [Sema/SILGen] Don't emit dynamic actor isolation checks when -disable-dynamic-actor-isolation flag is used 2024-04-15 09:19:22 -07:00
Pavel Yaskevich
8e93ae9775 [SILGen] Don't emit executor references when '_checkExpectedExecutor' is unavailable
Avoid emitting an unused executor reference for dynamic actor
isolation checking.
2024-03-08 13:04:48 -08:00
John McCall
7b3415aa23 Properly erase closure isolation to @isolated(any).
We do this by pushing the conversion down to the emission of the
closure expression, then teaching closure emission to apply the isolation
to the closure.  Ideally, we combine the isolation along with the rest of
the conversion peephole, but if necessary, we make sure we emit the
isolation.
2024-02-26 22:50:58 -05: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
John McCall
868fc6ad46 Basic SILGen for @isolated(any).
The main piece that's still missing here is support for closures;
they actually mostly work, but they infer the wrong isolation for
actor-isolated closures (it's not expressed in the type, so obviously
they're non-isolated), so it's not really functional.  We also have
a significant problem where reabstraction thunks collide incorrectly
because we don't mangle (or represent!) formal isolation into
SILFunctionType; that's another follow-up.  Otherwise, I think SILGen
is working.
2024-02-19 21:21:03 -05:00
Allan Shortlidge
2990c65457 NFC: Address some unused variable warnings. 2024-02-12 12:23:42 -08:00
Slava Pestov
6027bf46a6 AST: Simplify collectExistentialConformances() 2024-02-10 09:36:37 -05:00
Kavon Farvardin
74a3839cf3 Merge pull request #71515 from kavon/ncgenerics-test-fixes-kavon-v7
Ncgenerics test fixes kavon v7
2024-02-09 19:39:18 -08:00
Kavon Farvardin
73e176cfdb NCGenerics: fix createInitExistentialAddr call 2024-02-09 11:14:06 -08:00
Andrew Trick
da3f583492 Add mark_dependence [unresolved]
In preparation for inserting mark_dependence instructions for lifetime
dependencies early, immediately after SILGen. That will simplify the
implementation of borrowed arguments.

Marking them unresolved is needed to make OSSA verification
conservative until lifetime dependence diagnostics runs.
2024-02-08 22:53:16 -08:00
Pavel Yaskevich
2e9fffb524 [SILGen] Implement actor isolation erasure thunk
The thunk is a reabstraction thunk with a custom prolog that
has a runtime precondition check that makes sure that concurrent
environment where the thunk is run matches that of a global
actor associated with the thunked type.
2024-02-01 13:28:25 -08:00
Slava Pestov
af3ab14986 SILGen: Clean up substitution map construction to deal with Copyable 2024-01-31 21:55:52 -05:00
Pavel Yaskevich
65b07e91b7 [SILGen] Emit expected executor preconditions for synchronous isolated @preconcurrency witness thunks
For `@preconcurrency` conformance witness thunks replace hop to
executor with a precondition to make sure that the thunk is always
called in the expected context.
2024-01-16 11:51:49 -08:00
Kavon Farvardin
4eccbe136e [NFC] combine collectExistentialConformances
There are a bunch of static `collectExistentialConformances` copied
around Sema and SILGen that are almost the same, save for whether they
want to permit missing conformances and/or check conditional
conformances.

This commit requestifies and combines all but one of these functions
into a `ModuleDecl::collectExistentialConformances`. The motivation for
this clean-up is another place that will need this procedure.
2024-01-10 19:39:07 -08:00
Andrew Trick
264cbaea42 Add mark_dependence [nonescaping] flag.
The dependent 'value' may be marked 'nonescaping', which guarantees that the
lifetime dependence is statically enforceable. In this case, the compiler
must be able to follow all values forwarded from the dependent 'value', and
recognize all final (non-forwarded, non-escaping) use points. This implies
that `findPointerEscape` is false. A diagnostic pass checks that the
incoming SIL to verify that these use points are all initially within the
'base' lifetime. Regular 'mark_dependence' semantics ensure that
optimizations cannot violate the lifetime dependence after diagnostics.
2024-01-04 14:47:35 -08:00
John McCall
c66ccbcaa8 Handle variadic generic tuples (both concretely and in abstraction
patterns) in argument positions in reabstraction thunks.

Most of the difficulty in this work continues to center around
(1) trying to reuse as much code as possible between the parameter
and result paths and (2) propagating ownership information as
necessary throughout the code.  I did my best to assert the preconditions
and postconditions here, but undoubtedly I'm missing cases.  Some
simplicity here is still eluding me here.

This patch necessarily changes quite a bit of the code used in
non-variadic paths.  I tried to avoid doing things that I knew would
be risky, like optimizing copies.  I did fail in a few places: e.g.
we should now generate significantly better code when erasing to
Optional<Any>, just because the code was oddly poorly-factored before.
You can see the effect on the function_conversion test case.
2024-01-03 19:25:26 -05:00
John McCall
611776e108 [NFC] Extract the parts of TupleElementAddressGenerator that just deal
with walking the tuple so that they can be used without an address.
2024-01-03 16:30:36 -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
John McCall
b11af8854a [NFC] Abstract over the inner slot type 2024-01-03 16:09:22 -05:00
Doug Gregor
504329545f [SILGen] Handle indirect error results in allocating class initializers 2023-11-12 03:20:39 -08:00
Doug Gregor
76a89500d6 [SILGen] Handle indirect errors in other thunk kinds 2023-11-10 15:30:17 -08:00
Doug Gregor
fc19b8e1f4 [Typed throws] Handle error conversions in witness thunks 2023-11-10 15:30:17 -08:00
Doug Gregor
0ba605a4b9 [Typed throws] Implement reabstraction thunks that change the error
Introduce SILGen support for reabstractions thunks that change the
error, between indirect and direct errors as well as conversions
amongst error types (e.g., from concrete to `any Error`).
2023-11-07 11:39:56 -08:00
Slava Pestov
d2f1dedd35 Merge pull request #68220 from slavapestov/remove-get-protocol-self-type
Remove DeclContext::getSelfProtocolType()
2023-08-31 11:39:17 -04:00
Slava Pestov
361d49a843 AST: Remove DeclContext::getSelfProtocolType() 2023-08-30 15:15:08 -04:00
John McCall
acece4c35f [NFC] Push cleanup management through a few reabstraction utilities 2023-08-29 18:11:08 -04:00
John McCall
60d2a93209 [NFC] result -> inner, for consistency 2023-08-28 12:27:36 -04:00
John McCall
c1f110c8e8 Generalize the handling of pack cleanups in reabstraction thunks
The result-reabstraction code doesn't need to handle cleanups properly
during the planning phase because of course we don't have any values
yet.  That is not true of argument reabstraction, so we need to make
sure that the recursive emitters can produce values with cleanups
so that we can collect and forward those cleanups correctly when
emitting the call.

As part of this, I've changed the code so that it should forward
outer addresses to inner address more consistently; it wouldn't
have done this before if we were breaking apart or assembling
a pack.  I'm not sure I can directly test this without figuring
out a way to get SILGen to reabstract both sides of a function,
though.

I'm not sure this is really doing borrowed vs owned arguments
correctly, if e.g. we need to rebstract one component of a tuple
that's otherwise borrowed.
2023-08-28 12:27:36 -04:00