diff --git a/lib/SIL/IR/SILType.cpp b/lib/SIL/IR/SILType.cpp index e3feb8378fe7c..57caf3d5277b9 100644 --- a/lib/SIL/IR/SILType.cpp +++ b/lib/SIL/IR/SILType.cpp @@ -851,6 +851,16 @@ bool SILType::isLoweringOf(TypeExpansionContext context, SILModule &Mod, } } + // The pattern of a pack expansion is lowered. + if (auto formalExpansion = dyn_cast(formalType)) { + if (auto loweredExpansion = loweredType.getAs()) { + return loweredExpansion.getCountType() == formalExpansion.getCountType() + && SILType::getPrimitiveAddressType(loweredExpansion.getPatternType()) + .isLoweringOf(context, Mod, formalExpansion.getPatternType()); + } + return false; + } + // Dynamic self has the same lowering as its contained type. if (auto dynamicSelf = dyn_cast(formalType)) formalType = dynamicSelf.getSelfType(); diff --git a/test/SILGen/variadic-generic-tuples.swift b/test/SILGen/variadic-generic-tuples.swift index 300c599d969ff..c5d97cfd0713e 100644 --- a/test/SILGen/variadic-generic-tuples.swift +++ b/test/SILGen/variadic-generic-tuples.swift @@ -352,3 +352,18 @@ func testStructOfLoadableTuple() -> StructOfLoadableTuple { // CHECK-NEXT: [[PACK_ELT_ADDR:%.*]] = pack_element_get [[INDEX]] of %1 : $*Pack{repeat GenericButLoadable} as $*GenericButLoadable<@pack_element([[UUID]]) each S, @pack_element([[UUID]]) each S> // CHECK-NEXT: [[PACK_ELT:%.*]] = load [trivial] [[PACK_ELT_ADDR]] : // CHECK-NEXT: store [[PACK_ELT]] to [trivial] [[TUPLE_ELT_ADDR]] : + +// rdar://107290521 +// The verifier had some home-grown type-lowering logic that didn't +// know about pack expansions. +// CHECK-LABEL: sil {{.*}}@$s4main22testExistentialErasureyyxxQpRvzlF1gL_yyqd__qd__QpRvzRvd__r__lF : +// CHECK: [[T0:%.*]] = init_existential_addr {{.*}} : $*Any, $(repeat each T.Type) +// CHECK: tuple_pack_element_addr {{.*}} of [[T0]] : $*(repeat @thick each T.Type) as $*@thick (@pack_element("{{.*}}") each T).Type +func testExistentialErasure(_: repeat each T) { + func g(_: repeat each U) { + print((repeat (each T).self)) + print((repeat (each U).self)) + } + + g(1, "hi", false) +}