Skip to content

Commit b636a07

Browse files
committed
IRGen: Use mangled names to access opaque type associated types in Swift >=5.2.
1 parent e506e4a commit b636a07

File tree

2 files changed

+32
-10
lines changed

2 files changed

+32
-10
lines changed

lib/IRGen/MetadataRequest.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2213,17 +2213,19 @@ static bool shouldAccessByMangledName(IRGenModule &IGM, CanType type) {
22132213
}
22142214

22152215
// The Swift 5.1 runtime fails to demangle associated types of opaque types.
2216-
auto hasNestedOpaqueArchetype = type.findIf([](CanType sub) -> bool {
2217-
if (auto archetype = dyn_cast<NestedArchetypeType>(sub)) {
2218-
if (isa<OpaqueTypeArchetypeType>(archetype->getRoot())) {
2219-
return true;
2216+
if (!IGM.getAvailabilityContext().isContainedIn(IGM.Context.getSwift52Availability())) {
2217+
auto hasNestedOpaqueArchetype = type.findIf([](CanType sub) -> bool {
2218+
if (auto archetype = dyn_cast<NestedArchetypeType>(sub)) {
2219+
if (isa<OpaqueTypeArchetypeType>(archetype->getRoot())) {
2220+
return true;
2221+
}
22202222
}
2221-
}
2222-
return false;
2223-
});
2224-
2225-
if (hasNestedOpaqueArchetype)
2226-
return false;
2223+
return false;
2224+
});
2225+
2226+
if (hasNestedOpaqueArchetype)
2227+
return false;
2228+
}
22272229

22282230
return true;
22292231

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// RUN: %target-swift-frontend -target x86_64-apple-macosx10.99 -parse-stdlib -emit-ir %s | %FileCheck %s --check-prefix=CHECK --check-prefix=SWIFT_52
2+
// RUN: %target-swift-frontend -target x86_64-apple-macosx10.15 -parse-stdlib -emit-ir %s | %FileCheck %s --check-prefix=CHECK --check-prefix=SWIFT_PRE_52
3+
4+
protocol P {
5+
associatedtype A
6+
var a: A { get }
7+
}
8+
9+
@_silgen_name("useMetadata") func useMetadata<T>(_: T)
10+
11+
struct X: P { var a: X { return self } }
12+
13+
dynamic func foo() -> some P { return X() }
14+
15+
// CHECK-LABEL: define{{.*}}3bar
16+
public func bar() {
17+
// SWIFT_52: @__swift_instantiateConcreteTypeFromMangledName({{.*}} @"$s39access_type_metadata_by_mangled_name_513fooQryFQOyQo_1AAA1PPQxMD")
18+
// SWIFT_PRE_52: @"$s39access_type_metadata_by_mangled_name_513fooQryFQOyQo_1AAA1PPQxMa"(
19+
useMetadata(foo().a)
20+
}

0 commit comments

Comments
 (0)