Commit Graph

1624 Commits

Author SHA1 Message Date
John McCall
8301d5383b Fix the evaluation of #isolation in non-AFD contexts, most importantly
closures.

The fixes for initializers are just setting the stage for doing this
properly: we should be able to just change the isolation computation
in Sema and fix up the tests.
2025-09-09 14:26:57 -04:00
John McCall
5fb314b475 At the SIL level, allow synchronous functions to be nonisolated(nonsending). 2025-09-09 14:26:57 -04:00
Kavon Farvardin
511971fb1d Merge pull request #83959 from kavon/rdar159079818-subscript-read-nc
silgen: allow borrow of subscript for noncopyables
2025-08-29 20:52:23 -07:00
Kavon Farvardin
4964a66277 silgen: inherit eval scope for OpenExistentialExpr
We were not able to use an existential as the base
of an access that strictly borrows the existential,
because SILGen's RValue emission would establish
a fresh evaluation scope just for the existential's
opening, and then copy the opened value out.

This is problematic for noncopyable existentials.

So this patch moves & adds FormalEvaluationScope's
around so they're broad enough to enable a
borrow of an existential. The idea behind this
refactoring is to establish top-level
FormalEvaluationScopes when initially creating
RValue's for Expr's in SILGen. Any more-tightly
scoped operations will already establish their own
nested scope, so this is mostly adding safe-guards.

I've limited the existentials fix to noncopyables
for now.

part of rdar://159079818
2025-08-29 13:30:42 -07:00
Kavon Farvardin
906a4cbcdb silgen: allow borrow of subscript for noncopyables
If a subscript uses a read accessor to yield a noncopyable value,
we'd emit an `end_apply` that's too tightly scoped to allow for
a subsequent borrowing access on the yielded value.

resolves rdar://159079818
2025-08-29 13:30:31 -07:00
Slava Pestov
11f727e143 SIL: Add no-arg overload of SILFunction::getLoweredFunctionTypeInContext() 2025-08-25 16:45:45 -04:00
John McCall
6c3fd0eaec Fix projecting a tuple element out of a tuple with packs.
At the same time, make sure we propagate contextual initializations.

I'm actually not sure this is meant to be supported, but it's fine,
we should implement it.

Fixes #80937
2025-08-02 02:13:25 -04: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
Anthony Latsis
bbd84429a0 Merge pull request #83400 from swiftlang/jepa-main
Address `llvm::PointerUnion::{is,get}` deprecations
2025-07-30 17:19:58 +01:00
Anthony Latsis
fec049e5e4 Address llvm::PointerUnion::{is,get} deprecations
These were deprecated in
https://github.com/llvm/llvm-project/pull/122623.
2025-07-29 18:37:48 +01:00
John McCall
92b9857e6a Rewrite the type of nonisolated(nonsending) closures.
The constraint solver does not reliably give closures a function type
that includes `nonisolated(noncaller)`, even when the immediate context
requires a conversion to such a type. We were trying to work around this
in SILGen, but the peephole only kicked in if the types matched exactly,
so a contextual conversion that e.g. added `throws` was still emitting
the closure as `@concurrent`, which is of course the wrong semantics.
It's relatively easy to avoid all this by just rewriting the closure's
type to include `nonisolated(nonsending)` at a point where we can reliably
decide that, and then SILGen doesn't have to peephole anything for
correctness.

Fixes rdar://155313349
2025-07-28 22:20:38 -04:00
Pavel Yaskevich
785e7b1571 Merge pull request #82858 from gottesmm/rdar154969621
[concurrency] Perform some fixes so that transfernonsendable_closureliterals_isolationinference.swift now passes.
2025-07-08 00:04:14 -07:00
Michael Gottesman
648bb8fe30 [concurrency] Perform some fixes so that transfernonsendable_closureliterals_isolationinference.swift now passes.
The reason why this failed is that concurrently to @xedin landing
79af04ccc4, I enabled
NonisolatedNonsendingByDefault on a bunch of other tests. That change broke the
test and so we needed to fix it.

This commit fixes a few issues that were exposed:

1. We do not propagate nonisolated(nonsending) into a closure if its inferred
context isolation is global actor isolated or if the closure captures an
isolated parameter. We previously just always inferred
nonisolated(nonsending). Unfortunately since we do not yet have capture
information in CSApply, this required us to put the isolation change into
TypeCheckConcurrency.cpp and basically have function conversions of the form:

```
(function_conversion_expr type="nonisolated(nonsending) () async -> Void"
   (closure_expr type="() async -> ()" isolated_to_caller_isolation))
```

Notice how we have a function conversion to nonisolated(nonsending) from a
closure expr that has an isolation that is isolated_to_caller.

2. With this in hand, we found that this pattern caused us to first thunk a
nonisolated(nonsending) function to an @concurrent function and then thunk that
back to nonisolated(nonsending), causing the final function to always be
concurrent. I put into SILGen a peephole that recognizes this pattern and emits
the correct code.

3. With that in hand, we found that we were emitting nonisolated(nonsending)
parameters for inheritActorContext functions. This was then fixed by @xedin in

With all this in hand, closure literal isolation and all of the other RBI tests
with nonisolated(nonsending) enabled pass.

rdar://154969621
2025-07-07 17:21:41 -07:00
Konrad 'ktoso' Malawski
b1ca06d79d [Concurrency] #isolation+nonsending nonisolated - review followup and SIL test 2025-07-07 11:37:16 +09:00
Konrad 'ktoso' Malawski
b0d2ca9be6 [Concurrency] Fix nonisolated(nonsending) interaction with #isolation 2025-07-04 10:20:08 +09:00
Joe Groff
761faaa169 SILGen: Handle struct fields and addressors as addressable storage.
When accessing stored properties out of an addressable variable or parameter
binding, the stored property's address inside the addressable storage of the
aggregate is itself addressable. Also, if a computed property is implemented
using an addressor, treat that as a sign that the returned address should be
used as addressable storage as well. rdar://152280207
2025-06-16 20:23:47 -07:00
Slava Pestov
28af54a778 Merge pull request #80913 from stzn/fix-crash-self-keypath-root
[SILGen]Check if baseType is DynamicSelfType
2025-06-06 22:35:47 -04:00
Kavon Farvardin
32f1ebcfab SILGen: avoid double copies with 'copy' expr 2025-05-29 19:47:26 -07:00
Erik Eckstein
d28384dbd7 SILGen: use vector_base_addr in InlineArray literals 2025-05-12 19:25:12 +02:00
Alejandro Alonso
02d9779ba3 Merge pull request #81184 from Azoy/no-more-is-array-type
[AST] Rename isArrayType and split the InlineArray portion
2025-05-08 20:52:51 -07:00
Slava Pestov
6ffa8fd489 AST: Change signature of LookupConformanceFn
Instead of passing in the substituted type, we pass in the
InFlightSubstitution. This allows the substituted type to be
recovered if needed, but we can now skip computing it for
the common case of LookUpConformanceInSubstitutionMap.
2025-04-30 13:42:20 -04:00
Alejandro Alonso
e68b398d41 Rename isArrayType and split the InlineArray portion 2025-04-29 15:57:10 -07:00
Slava Pestov
cf1572c65b AST: Add ASTContext::TheSelfType for convenience 2025-04-28 11:49:50 -04:00
stzn
3a8483e515 Prevent calling getClassOrBoundGenericClass twice 2025-04-25 20:25:51 +09:00
stzn
aa4db79e45 [SILGen]Check if baseType is DynamicSelfType 2025-04-18 07:09:04 +09:00
Nate Chandler
7697a49ee9 [CoroutineAccessors] Only reference when available
Don't bind references to storage to use (new ABI) coroutine accessors
unless they're guaranteed to be available.  For example, when building
against a resilient module that has coroutine accessors, they can only
be used if the deployment target is >= the version of Swift that
includes the feature.

rdar://148783895
2025-04-15 21:13:57 -07:00
Joe Groff
7ce06dde2c Merge pull request #80773 from jckarter/trivial-copy-operator
SILGen: Emit `copy x` on a trivial value as a trivial copy.
2025-04-15 09:47:13 -07:00
Joe Groff
8dac2b1566 SILGen: Emit copy x on a trivial value as a trivial copy.
Avoids an assertion failure emitting an `explicit_copy_value` on the trivial
value, which is unsupported. This allows `copy x` to compile, albeit with
no effect (which is not ideal, but also not a regression, since no-implicit-copy
controls still don't fully work on trivial values). Fixes #80573 and rdar://148712387.
2025-04-11 17:51:43 -07:00
Pavel Yaskevich
9da457d129 [Sema/SILGen] NFC: Remove all mentions of @execution from comments 2025-04-11 15:59:25 -07:00
Slava Pestov
ea05708716 AST: Eliminate GenericEnvironment::mapConformanceRefIntoContext() 2025-04-03 17:35:34 -04:00
Slava Pestov
a209ff8869 AST: Remove origType parameter from ProtocolConformanceRef::subst() 2025-04-03 17:35:33 -04:00
Slava Pestov
8b1514cfd7 AST: Remove origType parameter from ProtocolConformanceRef::getAssociatedConformance() 2025-04-03 17:35:32 -04:00
Michael Gottesman
f245389bb3 [concurrency] Fix a few issues with @execution(caller)/@execution(concurrent).
Specifically:

1. I made it so that thunks from caller -> concurrent properly ignore the
isolated parameter of the thunk when calling the concurrent function.

rdar://148112362

2. I made it so that thunks from concurrent -> caller properly create a
Optional<any Actor>.none and pass that into the caller function.

rdar://148112384

3. I made it so that in cases where we are assigning an @Sendable caller to a
non-sendable caller variable, we allow for the conversion as long as the
parameters/results are sendable as well.

rdar://148112532

4. I made it so that when we generate a thunk from @execution(caller) ->
@GlobalActor, we mangle in @GlobalActor into the thunk.

rdar://148112569

5. I discovered that due to the way we handle function conversion expr/decl ref
expr, we were emitted two thunks when we assigned a global @caller function to a
local @caller variable. The result is that we would first cast from @caller ->
@concurrent and then back to @caller. The result of this would be that the
@caller function would always be called on the global queue.

rdar://148112646

I also added a bunch of basic tests as well that showed that this behavior was
broken.
2025-03-30 20:00:05 -07:00
Slava Pestov
5a684c3a29 SILGen: Replace calls to subst() on a GenericFunctionType with substGenericArgs() 2025-03-26 20:06:07 -04:00
Alejandro Alonso
241ffafe7f Merge pull request #80245 from Azoy/ia-literal-closure
[SILGen] Use the opaque element type for address in InlineArray literal
2025-03-24 23:21:06 -07:00
Alejandro Alonso
bc6c88bfb1 Use the opaque element type for address in InlineArray literal 2025-03-24 10:35:14 -07:00
Doug Gregor
731f58443c Address review feedback on AbstractConformance in ProtocolConformanceRef 2025-03-23 20:54:39 -07:00
Amritpan Kaur
3c30d68d2e Merge pull request #78823 from amritpan/method-keypaths
[Sema/SILGen/IRGen] Implement method & initializer keypaths.
2025-03-19 18:59:17 -07:00
Amritpan Kaur
807c323159 [SILGenExpr] Lower initializers. 2025-03-19 10:54:09 -07:00
Amritpan Kaur
45a7b45ad9 [SILGen] Lower unapplied methods. 2025-03-19 10:54:09 -07:00
Amritpan Kaur
4479996d7b [NFC] Refactor method thunk handling for reuse. 2025-03-19 10:54:09 -07:00
Amritpan Kaur
60e03a85d9 [SILGen] Lower applied keypath methods. 2025-03-19 10:54:09 -07:00
Amritpan Kaur
ae86b0e96d [NFC] Refactor getter/setter logic for reuse. 2025-03-19 10:54:09 -07:00
Amritpan Kaur
e7e354d989 [NFC] Generalize subscript code for methods. 2025-03-19 10:54:09 -07:00
Amritpan Kaur
2583da94b2 [NFC] Generalize subscript index handling. 2025-03-19 08:53:18 -07:00
Amritpan Kaur
811d54901b [NFC] Rename unresolvedProperty to unresolvedMember
to generalize for both properties and method members.
2025-03-19 08:53:18 -07:00
Amritpan Kaur
8f71f5c780 [NFC] Rename property to member to generalize
for both properties and method members.
2025-03-19 08:53:18 -07:00
Alejandro Alonso
8b3499d90e Fix empty inline array literals 2025-03-13 09:53:28 -07:00
Erik Eckstein
d225c47d25 AST: rename OpenArchetypeType -> ExistentialArchetypeType
NFC
2025-03-11 20:21:46 +01:00
Slava Pestov
541757a491 AST: Remove TypeBase::isOpenedExistential()
At one point, OpenedArchetypeType did not exist as a separate subclass
of ArchetypeType, so this method did something. Now, it's just
equivalent to calling is<> or isa<>.

I also removed a couple of asserts that were obvious no-ops as a result.
2025-02-27 09:55:36 -05:00