Commit Graph

6851 Commits

Author SHA1 Message Date
stzn
aa4db79e45 [SILGen]Check if baseType is DynamicSelfType 2025-04-18 07:09:04 +09:00
Pavel Yaskevich
f0bdecde34 Merge pull request #80872 from xedin/rdar-149107104
[TypeChecker] Allow closures to assume `nonisolated(nonsending)`
2025-04-17 13:08:58 -07:00
Pavel Yaskevich
bb62e961b8 [SILGen] Concurrency: Fix caller isolated closures to hop to the right actor
Closures that are caller isolated used to still hop to the generic
executor, which is incorrect.
2025-04-16 18:21:44 -07: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
Doug Gregor
fed5b2628a Merge pull request #80702 from DougGregor/enable-se-0470
[SE-0470] Enable isolated conformances by default
2025-04-14 15:09:18 -07:00
Doug Gregor
53707a121c Collapse two implementations into ExistentialLayout::containsNonMarkerProtocols 2025-04-14 08:42:32 -07:00
Alastair Houghton
352907fc3e Merge pull request #80758 from al45tair/eng/PR-149058236
[Concurrency] Remove -executor-factory option and replace with magic type.
2025-04-14 09:21:25 +01:00
Doug Gregor
8626404de3 [SE-0470] Treat metatype of archetype/existential type with no protocol requirements as Sendable
A metatype for an archetype or existential with no (non-marker)
protocol requirements cannot, by definition, carry any (isolated)
protocol conformances with it, so it's safe to treat such metatypes as
Sendable.
2025-04-13 15:42:02 -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
Alastair Houghton
94b054479b [Concurrency] Remove -executor-factory option and replace with magic type.
We decided that using a magic typealias to set the executor factory was better
than using a compiler option. Remove the `-executor-factory` option, and replace
by looking up the `DefaultExecutorFactory` type, first in the main module, and
then if that fails in Concurrency.

rdar://149058236
2025-04-11 13:55:38 +01:00
nate-chandler
2e1494df9f Merge pull request #80701 from nate-chandler/rdar148941214
[CoroutineAccessors] Use yield_once_2 on Darwin and Linux.
2025-04-10 14:46:05 -07:00
Nate Chandler
b76a76bdf1 [CoroutineAccessors] Unwind based on feature.
Now that coroutine kind (and consequently ABI) for the accessors is
keyed off a SIL option, it's no longer possible to read whether a given
SILFunction arose from a read/modify coroutine just by checking its
coroutine kind.  Regardless of ABI, read/modify coroutines may only
unwind (i.e. are only permitted not to "run to completion") if the
relevant experimental (soon to be deleted) feature is enabled.
2025-04-10 07:41:37 -07:00
Michael Gottesman
f63be76a90 Merge pull request #80622 from gottesmm/pr-9c92d645ac34f929bbaf39f2f26aa2e3e3acf5cb
[concurrency] Implement protocol witness thunking in SILGen for @execution(caller)/@execution(concurrent).
2025-04-08 21:46:23 -07:00
Michael Gottesman
04b845cc97 [concurrency] Implement protocol witness thunking in SILGen for @execution(caller)/@execution(concurrent).
This involved cleaning up and generalizing the work from
f245389bb3. I followed the same approach: hide the
implicit parameter while we run things through translateArgument and friends and
then put it back in manually.

As an additional benefit, I think I found a good place to put FunctionIsolation
onto lowered AnyFunctionTypes that will not cause cycles in the evaluator since
it is done in TypeLowering.

rdar://148785846
2025-04-08 12:43:28 -07:00
Joe Groff
cc5fa6931e Merge pull request #80619 from jckarter/move-only-exclusivity-markers
SILGen: Use [unsafe] access markers for move-only storage when exclusivity enforcement is disabled.
2025-04-08 12:16:58 -07:00
Slava Pestov
ec82f6bf4d SIL: Remove SILWitnessTable::AssociatedConformanceWitness::SubstType 2025-04-07 21:36:06 -04:00
Slava Pestov
b94a0448f2 SIL: Remove SILWitnessTable::ConditionalConformance 2025-04-07 21:36:05 -04:00
Joe Groff
3b7093c7ce SILGen: Use [unsafe] access markers for move-only storage when exclusivity enforcement is disabled.
The move-only checker relies on access markers to understand access scopes, so eliding them
entirely leads to miscompiles. We can emit `begin_access [unsafe]` to semantically delimit
exclusivity scopes while still doing no runtime checking. Fixes rdar://147546262.
2025-04-07 17:08:42 -07:00
Joe Groff
e75ee3f4cf Merge pull request #80507 from jckarter/builtin-emplace-double-free
SILGen: Correct ownership forwarding of `Builtin.emplace`.
2025-04-04 09:25:35 -07:00
Slava Pestov
e475b08011 AST: Remove AssociatedType 2025-04-03 17:35:35 -04:00
Slava Pestov
44b73b92b1 SILGen: Remove a usage of ProtocolConformanceRef::getAssociatedType() 2025-04-03 17:35:34 -04:00
Slava Pestov
ea05708716 AST: Eliminate GenericEnvironment::mapConformanceRefIntoContext() 2025-04-03 17:35:34 -04:00
Slava Pestov
ec0dfc8716 AST: Add new form of SubstitutionMap::getProtocolSubstitutions() 2025-04-03 17:35:33 -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
Joe Groff
66780eef4b SILGen: Correct ownership forwarding of Builtin.emplace.
Forward the owning cleanup for the temporary buffer (if needed) instead of
creating a new cleanup, to avoid a double-free when both the initialization
cleanup and the value cleanup execute. Fixes rdar://147961840.
2025-04-03 13:18:57 -07:00
Joe Groff
562d7dc832 Merge pull request #80438 from jckarter/substitute-away-escapable-lifetime-deps
Type substitution eliminates dependencies with Escapable targets.
2025-04-02 16:56:54 -07:00
Joe Groff
6b605f41cb Type substitution eliminates dependencies with Escapable targets.
When a generic function has potentially Escapable outputs, those outputs
declare lifetime dependencies, which have no effect when substitution
leads to those types becoming `Escapable` in a concrete context.
This means that type substitution should canonically eliminate lifetime
dependencies targeting Escapable parameters or returns, and that
type checking should allow a function value with potentially-Escapable
lifetime dependencies to bind to a function type without those dependencies
when the target of the dependencies is Escapable.

Fixes rdar://147533059.
2025-04-02 08:54:45 -07:00
Allan Shortlidge
cce02961f9 AST/SILGen: Make availability ranges stored by PoundAvailableInfo optional.
Rather than representing a missing availability range on `PoundAvailableInfo`
with a default-constructed `AvailabilityRange` (empty), store the ranges as
optionals instead. This allows an empty range to represent an availability
condition which is known to be false at compile time, which will be necessary
when generating SIL for `if #available` queries that check custom availability
domains.
2025-04-01 07:46:46 -07:00
Michael Gottesman
918756f854 Merge pull request #80374 from gottesmm/pr-ee297e6b432cd07483ec86444ffd6a8b5334c203
[concurrency] Fix a few issues with @execution(caller)/@execution(concurrent).
2025-03-31 09:20:01 -07:00
Alastair Houghton
b1c345f1be Merge pull request #80266 from al45tair/custom-executors-take2
[Concurrency] Provide a Swift interface for custom main and global executors.
2025-03-31 09:53:48 +01: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
Doug Gregor
c08bd5668e Prohibit isolated conformances for checked casts to potentially-SendableMetatype types
This removes the IsolatedConformances feature gate from SILGen for
dynamic casts, such that all dynamic casts that will not work with
isolated conformances are marked as such. Isolated conformances can
still only come into a program when part of it enables the feature
flag.
2025-03-28 16:55:36 -07:00
Michael Gottesman
25c0aa3da4 [silgen] Add dump/print methods to IndirectSlot and ParamInfo.
This just makes it easier to work with these types in the debugger. Just slicing
off commits from a larger patch.
2025-03-28 11:21:43 -07:00
Alastair Houghton
6e28716319 [Concurrency] Address some review comments.
Tweaked diagnostic to use a string instead of a type.  Renamed the
feature in `FeatureAvailability.def` (and added the `TaskExecutor`
feature to 6.2).  Also fixed the `swift_getActiveExecutor()`
function to return the main executor only when on the main thread.

rdar://141348916
2025-03-28 10:15:14 +00:00
Alastair Houghton
47fa71787f Revert "Merge pull request #80224 from glessard/revert-79789-custom-executors"
This reverts commit 06f6358067, reversing
changes made to 033f6679e8.
2025-03-28 10:15:07 +00:00
Doug Gregor
a61c40054d Merge pull request #80337 from DougGregor/cast-prohibits-isolated-conformances
[SE-0470] Prohibit isolated conformances in dynamic casts that can't safely use them
2025-03-27 14:17:45 -07:00
Slava Pestov
09a4e16ac0 Merge pull request #80301 from slavapestov/subst-generic-function-type
Clean up GenericFunctionType substitution
2025-03-27 08:20:59 -04:00
Doug Gregor
e0b52cd20e [SIL] Extend checked-cast instructions with "prohibit isolated conformances" flag
When performing a dynamic cast to an existential type that satisfies
(Metatype)Sendable, it is unsafe to allow isolated conformances of any
kind to satisfy protocol requirements for the existential. Identify
these cases and mark the corresponding cast instructions with a new flag,
`[prohibit_isolated_conformances]` that will be used to indicate to the
runtime that isolated conformances need to be rejected.
2025-03-26 22:31:47 -07:00
Michael Gottesman
783118ec69 Merge pull request #80310 from gottesmm/pr-595edb2e0a8eecd7a5133d8932ed1c67b8e7c76c
[silgen] If SILVerifyAll is enabled verify the body of thunks in buildThunkBody
2025-03-26 18:06:18 -07:00
Michael Gottesman
de7a62e13e Merge pull request #80312 from gottesmm/pr-126bc735b2d01c0f2f35f27268ff26d404b2fb16
[sil] Make SILFunctionTypeInfo a struct enum.
2025-03-26 18:05:57 -07:00
Slava Pestov
5a684c3a29 SILGen: Replace calls to subst() on a GenericFunctionType with substGenericArgs() 2025-03-26 20:06:07 -04:00
Becca Royal-Gordon
5bb6245a5a [NFC] Check that SILGen doesn’t use ABI-only decls
Adds assertions in various places where properties that can vary between ABI-only decls and their counterparts—particularly function and parameter attributes—are handled in SILGen, ensuring that we don’t accidentally end up processing ABI-only decls there.
2025-03-26 10:47:13 -07:00
Michael Gottesman
8cfb029b5c [sil] Make SILFunctionTypeInfo a struct enum.
I am doing this in preparation for adding the ability to represent in the SIL
type system that a function is global actor isolated. Since we have isolated
parameters in SIL, we do not need to represent parameter, nonisolated, or
nonisolated caller in the type system. So this should be sufficient for our
purposes.

I am adding this since I need to ensure that we mangle into thunks that convert
execution(caller) functions to `global actor` functions what the global actor
is. Otherwise, we cannot tell the difference in between such a thunk and a thunk
that converts execution(caller) to execution(concurrent).
2025-03-26 10:23:44 -07:00
Michael Gottesman
67730c1969 [silgen] If SILVerifyAll is enabled verify the body of thunks in buildThunkBody.
This just ensures that all thunks are verified right when they are created. This
is necessary since some thunks do not go through function post processing.
2025-03-26 10:20:27 -07:00
John McCall
4da795fd61 Merge pull request #80297 from rjmccall/zero-objc-async-result-on-error-path
Pass a zero normal result to ObjC async completion handlers on the error path
2025-03-26 12:42:38 -04:00
Joe Groff
98d6480ddb Merge pull request #80275 from jckarter/classify-address-projections
SILGen: Properly classify LValue component projections in more cases.
2025-03-26 09:16:09 -07:00
John McCall
e9ebc7c848 Pass a zero normal result to ObjC async completion handlers on the error path.
Fixes #65199
2025-03-26 00:58:27 -04:00