Skip to content

Commit 472b57a

Browse files
committed
[sil-verifier] Verify correctly that lowered SIL optional types are lowered types of formal optional types.
Recently, the lowering of Optional<T> was changed to be more like the lowering of tuples. Specifically this means that we recursively propagate types into the optional's component type rather than treating the component type as a standalone formal type ala other nominal types. This patch updates the function isLoweringOf in the SILVerifier that was missed as apart of the aforementioned updates. Specifically, previously isLoweringOf assumed that the optional's component type was always a formal type implying that it could just compare the lowered SIL types corresponding formal type and the passed in formal type. Now since we are propagating types down into the optional's component types, we need to recurse performing isLoweringOf on the maximally abstracted version of the optional SIL type (i.e. the primitive address form). I would like to thank John for his patience in explaining the big picture here. rdar://28536812
1 parent acf1063 commit 472b57a

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

lib/SIL/SILVerifier.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1491,8 +1491,9 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
14911491
if (auto dynamicSelf = dyn_cast<DynamicSelfType>(formalObjectType)) {
14921492
formalObjectType = dynamicSelf->getSelfType()->getCanonicalType();
14931493
}
1494-
return ((loweredOptionalKind == formalOptionalKind) &&
1495-
loweredObjectType == formalObjectType);
1494+
return loweredOptionalKind == formalOptionalKind &&
1495+
isLoweringOf(SILType::getPrimitiveAddressType(loweredObjectType),
1496+
formalObjectType);
14961497
}
14971498

14981499
// Metatypes preserve their instance type through lowering.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// RUN: %target-sil-opt -module-name Swift %s
2+
// REQUIRES: asserts
3+
//
4+
// Make sure that we properly verify the lowering of optional value
5+
// metatypes. This shouldn't crash.
6+
//
7+
// rdar://28536812
8+
9+
enum Optional<T> {
10+
case none
11+
case some(T)
12+
}
13+
14+
sil @foo : $@convention(thin) () -> () {
15+
%0 = enum $Optional<@thick Any.Type>, #Optional.none!enumelt
16+
%1 = alloc_stack $Optional<@thick Any.Type>
17+
store %0 to %1 : $*Optional<@thick Any.Type>
18+
%2 = value_metatype $@thick Optional<Any.Type>.Type, %1 : $*Optional<@thick Any.Type>
19+
dealloc_stack %1 : $*Optional<@thick Any.Type>
20+
%3 = tuple()
21+
return %3 : $()
22+
}

0 commit comments

Comments
 (0)