Skip to content

Commit a4ea4d1

Browse files
committed
Tolerate scalars when opening a non-opaque existential l-value component.
rdar://45956703
1 parent 44e0f44 commit a4ea4d1

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

lib/SILGen/SILGenLValue.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -903,9 +903,11 @@ namespace {
903903
auto refType = base.getType().getObjectType();
904904
auto &TL = SGF.getTypeLowering(refType);
905905

906-
// Load the original value.
907-
auto result = SGF.emitLoad(loc, base.getValue(), TL,
908-
SGFContext(), IsNotTake);
906+
// Load the original value if necessary.
907+
auto result = base.getType().isAddress()
908+
? SGF.emitLoad(loc, base.getValue(), TL,
909+
SGFContext(), IsNotTake)
910+
: base;
909911

910912
assert(refType.isAnyExistentialType() &&
911913
"base for open existential component must be an existential");

test/SILGen/existential_metatypes.swift

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
@_semantics("typechecker.type(of:)")
44
public func type<T, Metatype>(of value: T) -> Metatype {}
55

6-
struct Value {}
6+
struct Value {
7+
func method() {}
8+
}
79

810
protocol P {
911
init()
@@ -73,3 +75,18 @@ func existentialMetatypeVarProperty() -> Value {
7375
var type: P.Type = S.self
7476
return type.value
7577
}
78+
79+
// rdar://45956703
80+
// CHECK-LABEL: sil hidden @$s21existential_metatypes31getterResultStaticStorageAccessyyF
81+
var _type: P.Type { get {return S.self } set {} }
82+
func getterResultStaticStorageAccess() {
83+
// CHECK: [[GET_TYPE:%.*]] = function_ref @$s21existential_metatypes5_typeAA1P_pXpvg
84+
// CHECK-NEXT: [[TYPE:%.*]] = apply [[GET_TYPE]]() : $@convention(thin) () -> @thick P.Type
85+
// CHECK-NEXT: [[OPEN:%.*]] = open_existential_metatype [[TYPE]] : $@thick P.Type to $@thick ([[ARCHETYPE:@opened(.*) P]]).Type
86+
// CHECK-NEXT: [[GET_VALUE:%.*]] = witness_method $[[ARCHETYPE]], #P.value!getter
87+
// CHECK-NEXT: [[VALUE:%.*]] = apply [[GET_VALUE]]<[[ARCHETYPE]]>([[OPEN]])
88+
// CHECK-NEXT: // function_ref
89+
// CHECK-NEXT: [[METHOD:%.*]] = function_ref @$s21existential_metatypes5ValueV6methodyyF
90+
// CHECK-NEXT: apply [[METHOD]]([[VALUE]])
91+
_type.value.method()
92+
}

0 commit comments

Comments
 (0)