Commit Graph

1035 Commits

Author SHA1 Message Date
Doug Gregor
731f58443c Address review feedback on AbstractConformance in ProtocolConformanceRef 2025-03-23 20:54:39 -07:00
Doug Gregor
2a7de1b559 Store the conforming type within an abstract ProtocolConformanceRef
An "abstract" ProtocolConformanceRef is a conformance of a type
parameter or archetype to a given protocol. Previously, we would only
store the protocol requirement itself---but not track the actual
conforming type, requiring clients of ProtocolConformanceRef to keep
track of this information separately.

Record the conforming type as part of an abstract ProtocolConformanceRef,
so that clients will be able to recover it later. This is handled by a uniqued
AbstractConformance structure, so that ProtocolConformanceRef itself stays one
pointer.

There remain a small number of places where we create an abstract
ProtocolConformanceRef with a null type. We'll want to chip away at
those and establish some stronger invariants on the abstract conformance
in the future.
2025-03-23 20:53:48 -07:00
Jeff
0b28116264 Fix non-asserting build. 2025-03-20 14:00:24 -07:00
Slava Pestov
8bcd09aaa4 SIL: Preliminary refactoring of SILWitnessTable::AssociatedConformanceWitness
The Protocol field isn't really necessary, because the conformance
stores the protocol. But we do need the substituted subject type
of the requirement, just temporarily, until an abstract conformance
stores its own subject type too.
2025-03-18 19:38:42 -04:00
Slava Pestov
a00157ec43 IRGen: Refactor LocalTypeData a bit
The "abstract conformance is just a ProtocolDecl" assumption is pretty
fundamental here, so we have to fudge a bit at the API boundary for now.

Eventually, LocalTypeDataKind should just contain a ProtocolConformanceRef
instead of duplicating the representation, however this would require
fixing various calls to LocalTypeDataKind::forAbstractProtocolWitnessTable()
which pass in a ProtocolDecl to pass in a ProtocolConformanceRef instead.
2025-03-18 19:38:37 -04:00
Slava Pestov
3617a2934c Merge pull request #80061 from slavapestov/fix-rdar146123129
IRGen: Fix crash when normal conformance fixes generic parameter to concrete type
2025-03-17 21:27:04 -04:00
Konrad `ktoso` Malawski
85fcd69833 [Concurrency] Implement detecting isIsolatingCurrentContext user impls (#79946)
* [Concurrency] Detect non-default impls of isIsolatingCurrentContext

* [Concurrency] No need for trailing info about isIsolating... in conformance

* Apply changes from review
2025-03-18 09:39:11 +09:00
Slava Pestov
eb3f3a19ce IRGen: Fix crash when normal conformance fixes generic parameter to concrete type
This can probably be handled better elsewhere, but this is
reasonable enough for now.

Fixes rdar://146123129.
2025-03-17 15:16:43 -04:00
Doug Gregor
c58e22fccc Simplify APIs for accessing conformance isolation
The NormalProtocolConformance APIs for checking for an explicitly-written
isolation on a conformance were easy to get to, and the real semantic
API was buried in the type checker, leading to some unprincipled
checking. Instead, create a central ProtocolConformance::getIsolation()
to get the (semantic) actor isolation, and let that be the only place
that will access the explicitly-written global actor isolation for a
conformance. Update all call sites appropriately.
2025-03-12 23:18:32 -07:00
Doug Gregor
0e873e723c [Isolated conformances] Change syntax to @<global actor type> P
Instead of using the `isolated P` syntax, switch to specifying the
global actor type directly, e.g.,

   class MyClass: @MainActor MyProto { ... }

No functionality change at this point
2025-03-12 23:18:10 -07:00
Erik Eckstein
5fbaf0fad3 Revert "IRGen: convert two asserts to ASSERT to check the conditions also in a release-built compiler"
This fails in TBD generation in embedded swift.
A temporary workaround until we disable TBD generation in embedded swift.
rdar://146864959
2025-03-12 19:53:22 +01:00
Erik Eckstein
23b4c6fc34 embedded: fix specialization of associated conformance entries in witness tables
When creating a specialized witness table, we need to get the right specialized conformance.
In IRGen don't emit associated conformance witness table entries if the protocol is not a class protocol.
In this case the associated type can never be used to create an existential. Therefore such a witness table entry is never used at runtime in embedded swift.

Fixes a compiler crash

rdar://146448091
2025-03-11 11:33:10 +01:00
Erik Eckstein
ecfa808425 IRGen: convert two asserts to ASSERT to check the conditions also in a release-built compiler 2025-03-11 11:20:16 +01:00
Doug Gregor
951b535608 Metadata and runtime support for checking isolated conformances at runtime
Extend the metadata representation of protocol conformance descriptors
to include information about the global actor to which the conformance is
isolated (when there is one), as well as the conformance of that type to
the GlobalActor protocol. Emit this metadata whenever a conformance is
isolated.

When performing a conforms-to-protocol check at runtime, check whether
the conformance that was found is isolated. If so, extract the serial
executor for the global actor and check whether we are running on that
executor. If not, the conformance fails.
2025-03-07 23:51:25 -08:00
Nate Chandler
6581fec9e1 [CoroutineAccessors] PtrAuth. 2025-03-07 11:46:51 -08:00
Nate Chandler
35d06c325d [CoroutineAccessors] Witness and vtable dispatch.
And thunking.
2025-03-07 11:46:50 -08:00
Kuba Mracek
6f4ae28520 [ASTMangler] Pass ASTContext to all instantiations of ASTMangler 2024-12-02 15:01:04 -08:00
Joe Groff
b5e79d5590 IRGen: Capture NecessaryBindings in fixed boxes that may invoke deinits.
Noncopyable types may have user-defined code in their `deinit`s that requires
passing the type's generic parameters, so a box for a captured noncopyable type
needs to capture the generic environment even when the captured type is fixed-
layout. Fixes rdar://138958210.
2024-11-20 11:19:10 -08:00
swift-ci
ffb7eef5ab Merge remote-tracking branch 'origin/main' into rebranch 2024-10-17 05:15:25 -07:00
Arnold Schwaighofer
8ebb3ec473 IRGen: Add the ability to mark certain generic entry points in back traces
Mark generic function calls with concrete parameters, generic v-table calls and
generic witness table calls where self is generic.
2024-10-14 14:06:10 -07:00
swift-ci
8d3265a328 Merge remote-tracking branch 'origin/main' into rebranch 2024-10-07 11:34:54 -07:00
Erik Eckstein
a3e6e86383 Embedded: support existentials with inherited conformances
That means: derived classes where the base conforms to a protocol
2024-10-07 12:25:18 +02:00
Erik Eckstein
abbc63316c IRGen: support associated-type and associated-conformance witness table entries
Associated-type entries are simply skipped.
Associated-conformance entries point to the specialized conformance witness tables.
2024-10-07 09:00:31 +02:00
Erik Eckstein
a67d9c5bed embedded: Support class existentials with inherited protocols
For example:
```
protocol Base: AnyObject {}
protocol Derived: Base {}

class C: Derived {}

let e: Derived = C()
```
2024-10-07 08:49:56 +02:00
Erik Eckstein
db4c28a5a3 IRGen: allow specialized witness tables also in regular swift 2024-10-07 08:49:56 +02:00
swift-ci
7cc6111f96 Merge remote-tracking branch 'origin/main' into rebranch 2024-10-02 01:53:55 -07:00
Erik Eckstein
5502373018 SIL: rename AssociatedTypeProtocolWitness -> AssociatedConformanceWitness in SILWitnessTable
To be consistent with the naming convention in the AST
2024-10-02 07:10:30 +02:00
Ben Barham
c15bc19946 Merge remote-tracking branch 'origin/main' into main-to-rebranch
Conflicts:
  - `lib/Serialization/ModuleFileSharedCore.cpp` new headers on main
2024-09-26 16:01:56 -07:00
eeckstein
8c5d7ee452 Merge pull request #76669 from eeckstein/class-existentials
embedded: support class existentials with generic classes
2024-09-26 07:37:35 +02:00
Doug Gregor
624570db57 Improve naming of the isResilientConformance flag that disables optimizations
Thank you, Arnold, for talking through this with me.
2024-09-25 13:05:22 -07:00
Doug Gregor
21b2f099de Use "resilient conformance" logic for deciding protocol dependencies involving Sendable
When compiling with library evolution and a pre-Swift 6.0 deployment
target, a mismatch between the notion of resilience used for determining
whether a protocol that inherits Sendable might need to be treated as
"dependent" differed from how other parts of IR generation decided
whether to conformance should be considered as resilient. The
difference came when both the protocol and its conforming type are in
the same module as the user.

Switch over to the "is this conformance resilient?" query that takes
into account such conformances.

Fixes rdar://136586922.
2024-09-25 12:09:40 -07:00
Erik Eckstein
401a602b23 IRGen: support emitting specialized witness tables 2024-09-25 19:32:14 +02:00
Erik Eckstein
2950e4521e SIL: representation for specialized witness tables
The main change here is to associate a witness table with a `ProtocolConformance` instead of a `RootProtocolConformance`.
A `ProtocolConformance` is the base class and can be a `RootProtocolConformance` or a `SpecializedProtocolConformance`.
2024-09-25 19:32:08 +02:00
swift-ci
658a00ce26 Merge remote-tracking branch 'origin/main' into rebranch 2024-09-20 14:14:24 -07:00
Kuba (Brecka) Mracek
4a51cfaf27 Merge pull request #76572 from kubamracek/embedded-class-bound-existentials
[embedded] Introduce class-bound existentials into Embedded Swift
2024-09-20 13:58:06 -07:00
Kuba Mracek
6b9a3051e3 [embedded] Introduce class-bound existentials into Embedded Swift
Motivated by need for protocol-based dynamic dispatch, which hasn't been possible in Embedded Swift due to a full ban on existentials. This lifts that restriction but only for class-bound existentials: Class-bound existentials are already (even in desktop Swift) much more lightweight than full existentials, as they don't need type metadata, their containers are typically 2 words only (reference + wtable pointer), don't incur copies (only retains+releases).

Included in this PR:
[x] Non-generic class-bound existentials, executable tests for those.
[x] Extension methods on protocols and using those from a class-bound existential.
[x] RuntimeEffects now differentiate between Existential and ExistentialClassBound.
[x] PerformanceDiagnostics don't flag ExistentialClassBound in Embedded Swift.
[x] WTables are generated in IRGen when needed.

Left for follow-up PRs:
[ ] Generic classes support
2024-09-19 07:49:50 -07:00
Ben Barham
a7b50f357f Merge remote-tracking branch 'origin/main' into manual-main-merge
Conflicts:
  - `lib/Driver/ToolChains.cpp` conflicting with the `addAllArgs` rename
    for multiple options
2024-09-16 13:53:18 -07:00
Slava Pestov
c86ce649ff IRGen: Small cleanup 2024-09-16 12:30:50 -04:00
Slava Pestov
a62ab6907d IRGen: Workaround for type substitution limitation
If a constrained extension has fewer conformance requirements
than the nominal type declaration, because some of the type
parameters of the nominal type are fixed to concrete types by
the extension, we would run into trouble because interface
type substitution does not correctly handle this case.

Applying an identity substitution map to an interface type
does not look up concrete types in the output generic
signature, so we get back a type parameter that is not valid.

getReducedType() has a hack to deal with this. I'd like to
get rid of the hack and fix interface type substitution to
do this correctly, but until then, this will do.

Fixes https://github.com/swiftlang/swift/issues/76479
2024-09-16 12:30:49 -04:00
Doug Gregor
cd52e2d4e5 Fix ABI mismatch involving Sendable-refining protocols and deployment targets
A change to the way we determined whether a protocol conformance is
"dependent" for marker protocols caused an ABI break for
Sendable-refining protocols built with pre-6.0 Swift compilers. The
fix for this issue (https://github.com/swiftlang/swift/pull/75769)
gated the change on deployment target.

The deployment target change fixed the original problem, then caused a
related issue when a project mixes deployment targets (pre-6.0 and
6.0+) with non-resilient protocols. Exempt non-resilient protocols from
this change so we get consistent behavior.

Fixes rdar://134953989.
2024-09-10 11:40:50 -07:00
swift-ci
da55e84c74 Merge remote-tracking branch 'origin/main' into rebranch 2024-09-05 15:35:33 -07:00
Alejandro Alonso
f4f60f4344 Remove Value requirement Add GenericTypeParamKind 2024-09-04 15:13:43 -07:00
Alejandro Alonso
7c85261a77 Add runtime support 2024-09-04 15:13:27 -07:00
Alejandro Alonso
75c2cbf593 Implement value generics
Some requirement machine work

Rename requirement to Value

Rename more things to Value

Fix integer checking for requirement

some docs and parser changes

Minor fixes
2024-09-04 15:13:25 -07:00
swift-ci
b08f7a1307 Merge remote-tracking branch 'origin/main' into rebranch 2024-08-20 13:58:19 -07:00
Slava Pestov
0c2f28fd3d AST: Remove GenericSignature parameter from OpenedArchetypeType::get() 2024-08-20 12:15:27 -04:00
swift-ci
3b35248991 Merge remote-tracking branch 'origin/main' into rebranch 2024-08-19 05:33:56 -07:00
Slava Pestov
3c5298f1b5 IRGen: Remove pointless usage of ArchetypeType::getRoot() 2024-08-18 18:34:35 -04:00
swift-ci
a6a019a823 Merge remote-tracking branch 'origin/main' into rebranch 2024-08-08 10:55:29 -07:00
Doug Gregor
b81f23e367 Narrow this *even further* to Sendable, because it's the only pre-6.0 marker protocol 2024-08-07 22:17:29 -07:00