Skip to content

Commit 9ae952e

Browse files
committed
IRGen: Metadata lookup failure
Metadata lookup uses getRuntimeReifiedType(X) in places, fill the cache with key entries for X and getRuntimeReifiedType(X) such that they can be found on lookup. rdar://139234543
1 parent 8feb497 commit 9ae952e

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

lib/IRGen/LocalTypeData.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,17 @@ void IRGenFunction::setScopedLocalTypeData(LocalTypeDataKey key,
599599

600600
getOrCreateLocalTypeData().addConcrete(getActiveDominancePoint(),
601601
isConditional, key, value);
602+
603+
// We query reified types in places so also put a key mapping in for them.
604+
auto reified = IGM.getRuntimeReifiedType(key.Type);
605+
if (reified != key.Type) {
606+
auto reifiedKey = LocalTypeDataKey(reified, key.Kind);
607+
if (isConditional) {
608+
registerConditionalLocalTypeDataKey(reifiedKey);
609+
}
610+
getOrCreateLocalTypeData().addConcrete(getActiveDominancePoint(),
611+
isConditional, reifiedKey, value);
612+
}
602613
}
603614

604615
void IRGenFunction::setUnscopedLocalTypeMetadata(CanType type,
@@ -627,6 +638,15 @@ void IRGenFunction::setUnscopedLocalTypeData(LocalTypeDataKey key,
627638

628639
getOrCreateLocalTypeData().addConcrete(DominancePoint::universal(),
629640
/*conditional*/ false, key, value);
641+
642+
// We query reified types in places so also put a key mapping in for them.
643+
auto reified = IGM.getRuntimeReifiedType(key.Type);
644+
if (reified != key.Type) {
645+
auto reifiedKey = LocalTypeDataKey(reified, key.Kind);
646+
getOrCreateLocalTypeData().addConcrete(DominancePoint::universal(),
647+
/*conditional*/ false, reifiedKey,
648+
value);
649+
}
630650
}
631651

632652
void IRGenFunction::bindLocalTypeDataFromTypeMetadata(CanType type,
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %build-irgen-test-overlays
3+
// RUN: %target-swift-frontend(mock-sdk: -sdk %S/Inputs -I %t) %s -emit-ir | %FileCheck %s
4+
5+
import Builtin
6+
import Swift
7+
import gizmo
8+
9+
protocol Q<T> {
10+
associatedtype T
11+
func f()
12+
}
13+
14+
// This used to assert/crash on a local type metadata lookup.
15+
16+
sil @metadata_lookup_crash : $@convention(method) (@in_guaranteed any Q<ObjcGenericClass<Gizmo>>, Builtin.Int1) -> () {
17+
bb0(%0 : $*any Q<ObjcGenericClass<Gizmo>>, %1: $Builtin.Int1):
18+
%2 = open_existential_addr immutable_access %0 : $*any Q<ObjcGenericClass<Gizmo>> to $*@opened("AA505436-9CC9-11EF-8085-32F16C24A34B", any Q<ObjcGenericClass<Gizmo>>) Self
19+
%3 = witness_method $@opened("AA505436-9CC9-11EF-8085-32F16C24A34B", any Q<ObjcGenericClass<Gizmo>>) Self, #Q.f : <Self where Self : Q> (Self) -> () -> (), %2 : $*@opened("AA505436-9CC9-11EF-8085-32F16C24A34B", any Q<ObjcGenericClass<Gizmo>>) Self : $@convention(witness_method: Q) <τ_0_0 where τ_0_0 : Q> (@in_guaranteed τ_0_0) -> ()
20+
%4 = apply %3<@opened("AA505436-9CC9-11EF-8085-32F16C24A34B", any Q<ObjcGenericClass<Gizmo>>) Self>(%2) : $@convention(witness_method: Q) <τ_0_0 where τ_0_0 : Q> (@in_guaranteed τ_0_0) -> ()
21+
cond_br %1, bb1, bb2
22+
23+
bb1:
24+
br bb3
25+
26+
bb2:
27+
%5 = open_existential_addr immutable_access %0 : $*any Q<ObjcGenericClass<Gizmo>> to $*@opened("AA505436-9CC9-11EF-8085-42F16C24A34B", any Q<ObjcGenericClass<Gizmo>>) Self
28+
%6 = witness_method $@opened("AA505436-9CC9-11EF-8085-42F16C24A34B", any Q<ObjcGenericClass<Gizmo>>) Self, #Q.f : <Self where Self : Q> (Self) -> () -> (), %5 : $*@opened("AA505436-9CC9-11EF-8085-42F16C24A34B", any Q<ObjcGenericClass<Gizmo>>) Self : $@convention(witness_method: Q) <τ_0_0 where τ_0_0 : Q> (@in_guaranteed τ_0_0) -> ()
29+
%7 = apply %6<@opened("AA505436-9CC9-11EF-8085-42F16C24A34B", any Q<ObjcGenericClass<Gizmo>>) Self>(%5) : $@convention(witness_method: Q) <τ_0_0 where τ_0_0 : Q> (@in_guaranteed τ_0_0) -> ()
30+
br bb3
31+
32+
bb3:
33+
%t = tuple ()
34+
return %t : $()
35+
}
36+
37+
// CHECK: define swiftcc void @metadata_lookup_crash
38+
// CHECK: call ptr @__swift_project_boxed_opaque_existential_1
39+
// CHECK: br i1
40+
41+
// CHECK: call ptr @__swift_project_boxed_opaque_existential_1
42+
// CHECK: ret void

0 commit comments

Comments
 (0)