Skip to content

Commit 5dc59a5

Browse files
authored
Merge pull request #66683 from rjmccall/lowered-pack-expansion-verification
Handle pack expansion types when verifying lowered types in SIL
2 parents 14f7161 + 9b7123b commit 5dc59a5

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

lib/SIL/IR/SILType.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -851,6 +851,16 @@ bool SILType::isLoweringOf(TypeExpansionContext context, SILModule &Mod,
851851
}
852852
}
853853

854+
// The pattern of a pack expansion is lowered.
855+
if (auto formalExpansion = dyn_cast<PackExpansionType>(formalType)) {
856+
if (auto loweredExpansion = loweredType.getAs<PackExpansionType>()) {
857+
return loweredExpansion.getCountType() == formalExpansion.getCountType()
858+
&& SILType::getPrimitiveAddressType(loweredExpansion.getPatternType())
859+
.isLoweringOf(context, Mod, formalExpansion.getPatternType());
860+
}
861+
return false;
862+
}
863+
854864
// Dynamic self has the same lowering as its contained type.
855865
if (auto dynamicSelf = dyn_cast<DynamicSelfType>(formalType))
856866
formalType = dynamicSelf.getSelfType();

test/SILGen/variadic-generic-tuples.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,3 +352,18 @@ func testStructOfLoadableTuple() -> StructOfLoadableTuple<Int> {
352352
// CHECK-NEXT: [[PACK_ELT_ADDR:%.*]] = pack_element_get [[INDEX]] of %1 : $*Pack{repeat GenericButLoadable<each S, each S>} as $*GenericButLoadable<@pack_element([[UUID]]) each S, @pack_element([[UUID]]) each S>
353353
// CHECK-NEXT: [[PACK_ELT:%.*]] = load [trivial] [[PACK_ELT_ADDR]] :
354354
// CHECK-NEXT: store [[PACK_ELT]] to [trivial] [[TUPLE_ELT_ADDR]] :
355+
356+
// rdar://107290521
357+
// The verifier had some home-grown type-lowering logic that didn't
358+
// know about pack expansions.
359+
// CHECK-LABEL: sil {{.*}}@$s4main22testExistentialErasureyyxxQpRvzlF1gL_yyqd__qd__QpRvzRvd__r__lF :
360+
// CHECK: [[T0:%.*]] = init_existential_addr {{.*}} : $*Any, $(repeat each T.Type)
361+
// CHECK: tuple_pack_element_addr {{.*}} of [[T0]] : $*(repeat @thick each T.Type) as $*@thick (@pack_element("{{.*}}") each T).Type
362+
func testExistentialErasure<each T>(_: repeat each T) {
363+
func g<each U>(_: repeat each U) {
364+
print((repeat (each T).self))
365+
print((repeat (each U).self))
366+
}
367+
368+
g(1, "hi", false)
369+
}

0 commit comments

Comments
 (0)