Commit Graph

6681 Commits

Author SHA1 Message Date
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
John McCall
3fe70968cc Remove the substitution map from zeroInitializer builtin in SIL.
This is a value operation that can work just fine on lowered types,
so there's no need to carry along a formal type. Make the value/address
duality clearer, and enforce it in the verifier.
2025-03-26 00:34:15 -04:00
Joe Groff
f990413d39 SILGen: Properly classify LValue component projections in more cases.
PR #79084 adjusted the projection logic for addressor accessors to avoid
a temporary materialization in cases where the base value is already in
memory; however, many LValue physical components were still unconditionally
using `ManagedValue::forLValue` and causing unnecessary materializations
from already-read-accessed memory locations. Fixes rdar://147705667.
2025-03-25 09:55:31 -07:00
Nate Chandler
1c3073b804 [DefaultOverrides] SILGen.
Emit tables for open members of open classes.
2025-03-25 07:22:43 -07:00
Nate Chandler
cc4c4584bf [NFC] SILGen: Extract base class.
Add new SILGenVTableBase class as a parent of SILGenVTable in
preparation to add another subclass.
2025-03-25 07:22:43 -07:00
Nate Chandler
71412d3566 [NFC] SILGen: Name operation.
And prepare to reuse it.
2025-03-25 07:22:43 -07:00
Nate Chandler
ea0387ad9d [NFC] SILGen: Extract typealias. 2025-03-25 07:22:43 -07: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
Alastair Houghton
8b15b05c63 Revert "[Concurrency] Provide a Swift interface for custom main and global executors." 2025-03-22 02:38:11 -07:00
Alastair Houghton
8443b5f76c Merge pull request #79789 from al45tair/custom-executors
[Concurrency] Provide a Swift interface for custom main and global executors.
2025-03-21 09:05:03 +00:00
Joe Groff
b467d842c5 Merge pull request #80133 from jckarter/synchronize-vtable-layout-and-entry-emission-visibility
SILGen: Fix inconsistency between vtable layout and vtable entry emission.
2025-03-20 13:06:33 -07:00
Tony Allevato
8c43428acd Merge pull request #80118 from allevato/uninitialized-capture
[NFC] Fix a use of an uninitialized captured value.
2025-03-20 11:32:20 -04: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
Joe Groff
9e5e240704 SILGen: Fix inconsistency between vtable layout and vtable entry emission.
As part of the criteria to determine whether a method override requires a new
vtable entry in addition to overriding the base class's vtable entry for the
method, we compare the visibility of the base class to that of the derived
class, since if further subclasses of the derived class cannot see the original
base class's method descriptor, they would not be able to directly override its
vtable entry.

However, there was a subtle inconsistency in our checks in two different
places: `NeedsNewVTableEntryRequest::evaluate` compared the visibility of the
derived method to its immediate override method, whereas
`SILGenModule::emitVTableMethod` compared visibility with the ultimate base
method that originated the vtable entry in question. Internal imports create
a situation where this leads to inconsistent answers, causing us to emit
a vtable thunk but without a corresponding new vtable entry, causing the thunk
to become self-recursive (rdar://147360093). If the base class is in a separate
module:

```
// Module1
open class Base {
    public required init() {}
}
```

and an intermediate class inherits that base class, it must `public import`
the module in the file defining the class to do so:

```
// Module2

public import Module1

open class MidDerived: Base { }
```

However, another file in the same module can further inherit that class, but
with only an `internal import` of the base module:

```
// Also Module2

import Module1

open class MostDerived: MidDerived { }
```

The implicit `init()` is `public` in each class, but from the perspective of
`MostDerived.init`, `Base.init` is `internal` because of the import. However,
the fact that its immediate parent is `public` should be sufficient evidence
that its original definition had visibility to `Base`, so no thunk should
be necessary.
2025-03-19 15:34:50 -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
e5362c761d [NFC] Refactor subscript argument evaluation for reuse. 2025-03-19 10:54:09 -07:00