Skip to content

Commit 55b95e1

Browse files
authored
Merge pull request #24466 from eeckstein/fix-irgen-mangler-5.1
IRGen: mangle conformance access paths with opaque result type as a root
2 parents 06b2f95 + 62c4c15 commit 55b95e1

File tree

3 files changed

+59
-0
lines changed

3 files changed

+59
-0
lines changed

docs/ABI/Mangling.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,7 @@ Property behaviors are implemented using private protocol conformances.
694694
dependent-associated-conformance 'HA' DEPENDENT-CONFORMANCE-INDEX
695695

696696
dependent-associated-conformance ::= type protocol
697+
dependent-protocol-conformance ::= dependent-protocol-conformance opaque-type 'HO'
697698

698699
A compact representation used to represent mangled protocol conformance witness
699700
arguments at runtime. The ``module`` is only specified for conformances that

lib/AST/ASTMangler.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2613,6 +2613,20 @@ void ASTMangler::appendConcreteProtocolConformance(
26132613
auto conformanceAccessPath =
26142614
CurGenericSignature->getConformanceAccessPath(type, proto);
26152615
appendDependentProtocolConformance(conformanceAccessPath);
2616+
} else if (auto opaqueType = canType->getAs<OpaqueTypeArchetypeType>()) {
2617+
GenericSignature *opaqueSignature = opaqueType->getBoundSignature();
2618+
GenericTypeParamType *opaqueTypeParam = opaqueSignature->getGenericParams().back();
2619+
ConformanceAccessPath conformanceAccessPath =
2620+
opaqueSignature->getConformanceAccessPath(opaqueTypeParam, proto);
2621+
2622+
// Append the conformance access path with the signature of the opaque type.
2623+
CanGenericSignature savedSignature = CurGenericSignature;
2624+
CurGenericSignature = opaqueSignature->getCanonicalSignature();
2625+
appendDependentProtocolConformance(conformanceAccessPath);
2626+
CurGenericSignature = savedSignature;
2627+
2628+
appendType(canType);
2629+
appendOperator("HO");
26162630
} else {
26172631
auto conditionalConf = module->lookupConformance(canType, proto);
26182632
appendConcreteProtocolConformance(conditionalConf->getConcrete());
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-build-swift -module-name=test %s -o %t/a.out
3+
// RUN: %target-run %t/a.out | %FileCheck %s
4+
// REQUIRES: executable_test
5+
// REQUIRES: CPU=arm64 || CPU=x86_64
6+
7+
// Check that the IRGenMangler does not crashq when mangling a conformance
8+
// access path with an opaque result type as root.
9+
// As a bonus, also do a runtime test to check that there is no miscompile.
10+
11+
protocol P {
12+
func get() -> Int
13+
}
14+
15+
extension Int : P {
16+
func get() -> Int {
17+
return self
18+
}
19+
}
20+
21+
struct X<T> {
22+
let tt: T
23+
init(_ t: T) {
24+
tt = t
25+
}
26+
}
27+
28+
extension X : P where T : P {
29+
func get() -> Int {
30+
return tt.get()
31+
}
32+
}
33+
34+
func bar() -> some P {
35+
return 27
36+
}
37+
38+
func foo() -> some P {
39+
return X(bar())
40+
}
41+
42+
// CHECK: 27
43+
print(foo().get())
44+

0 commit comments

Comments
 (0)