Skip to content

Commit 53d5038

Browse files
committed
Translate the pattern type of a pack expansion when emitting
type metadata for layout. Fixes rdar://110971671
1 parent 1009db9 commit 53d5038

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

lib/IRGen/MetadataRequest.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3307,11 +3307,10 @@ class GetFormalTypeWithSameLayout
33073307
}
33083308

33093309
CanType visitPackExpansionType(CanPackExpansionType ty) {
3310-
return ty;
3311-
}
3312-
3313-
CanType visitPackElementType(CanPackElementType ty) {
3314-
llvm_unreachable("not implemented for PackElementType");
3310+
CanType pattern = ty.getPatternType();
3311+
CanType loweredPattern = visit(ty.getPatternType());
3312+
if (pattern == loweredPattern) return ty;
3313+
return CanPackExpansionType::get(loweredPattern, ty.getCountType());
33153314
}
33163315

33173316
CanType visitTupleType(CanTupleType ty) {

test/IRGen/variadic_generics.sil

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,3 +183,19 @@ bb0:
183183
%len = pack_length $Pack{repeat each T, repeat each T, Int, Float, String}
184184
return %len : $Builtin.Word
185185
}
186+
187+
// Translate the pattern type of a pack expansion type when
188+
// emitting tuple type metadata for layout. rdar://110971671
189+
190+
// CHECK-LABEL: define{{.*}} @test_pack_expansion_for_layout
191+
// CHECK: [[PACK_LEN:%.*]] = add [[INT]] %0, 1
192+
// CHECK-NEXT: [[VANISHES:%.*]] = icmp eq [[INT]] [[PACK_LEN]], 1
193+
// CHECK-NEXT: br i1 [[VANISHES]],
194+
// CHECK: call swiftcc %swift.metadata_response @swift_getTupleTypeMetadata(
195+
sil @test_pack_expansion_for_layout : $<each T> () -> () {
196+
bb0:
197+
%tuple = alloc_stack $(Int, repeat () async throws -> each T)
198+
dealloc_stack %tuple : $*(Int, repeat () async throws -> each T)
199+
%result = tuple ()
200+
return %result : $()
201+
}

0 commit comments

Comments
 (0)