Skip to content

Commit d829c58

Browse files
committed
[TypeLowering] Record packs used in signatures.
To determine whether an instruction may require pack metadata, the types of its operands are examined. Previously, the top level type was checked for having a pack in its signature, and the whole type was checked for having a type anywhere in its layout (via TypeLowering). This didn't account for the case where the metadata was required for a resilient type which uses a pack in its signature. Here, during type lowering, a type having a pack in its signature is counted towards the type having a pack. Fixes a compiler crash. rdar://147207926
1 parent bb67d1e commit d829c58

File tree

3 files changed

+69
-1
lines changed

3 files changed

+69
-1
lines changed

lib/SIL/IR/SILInstruction.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1353,7 +1353,7 @@ bool SILInstruction::isDeallocatingStack() const {
13531353
}
13541354

13551355
static bool typeOrLayoutInvolvesPack(SILType ty, SILFunction const &F) {
1356-
return ty.hasAnyPack() || ty.isOrContainsPack(F);
1356+
return ty.isOrContainsPack(F);
13571357
}
13581358

13591359
bool SILInstruction::mayRequirePackMetadata(SILFunction const &F) const {

lib/SIL/IR/TypeLowering.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2490,6 +2490,7 @@ namespace {
24902490
IsTypeExpansionSensitive_t isSensitive) {
24912491
RecursiveProperties properties =
24922492
getReferenceRecursiveProperties(isSensitive);
2493+
properties = mergeHasPack(HasPack_t(classType->hasAnyPack()), properties);
24932494

24942495
if (C->getLifetimeAnnotation() == LifetimeAnnotation::EagerMove)
24952496
properties.setLexical(IsNotLexical);
@@ -2506,6 +2507,7 @@ namespace {
25062507
RecursiveProperties properties;
25072508

25082509
properties = mergeIsTypeExpansionSensitive(isSensitive, properties);
2510+
properties = mergeHasPack(HasPack_t(structType->hasAnyPack()), properties);
25092511

25102512
// Bail out if the struct layout relies on itself.
25112513
TypeConverter::LowerAggregateTypeRAII loweringStruct(TC, structType);
@@ -2624,6 +2626,7 @@ namespace {
26242626
RecursiveProperties properties;
26252627

26262628
properties = mergeIsTypeExpansionSensitive(isSensitive, properties);
2629+
properties = mergeHasPack(HasPack_t(enumType->hasAnyPack()), properties);
26272630

26282631
// Bail out if the enum layout relies on itself.
26292632
TypeConverter::LowerAggregateTypeRAII loweringEnum(TC, enumType);
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: split-file %s %t
3+
4+
// RUN: %target-swift-frontend \
5+
// RUN: %t/Library.swift \
6+
// RUN: -emit-module \
7+
// RUN: -target %target-swift-5.9-abi-triple \
8+
// RUN: -enable-library-evolution \
9+
// RUN: -module-name Library \
10+
// RUN: -emit-module-path %t/Library.swiftmodule
11+
12+
// RUN: %target-build-swift \
13+
// RUN: %t/Downstream.swift \
14+
// RUN: -c \
15+
// RUN: -target %target-swift-5.9-abi-triple \
16+
// RUN: -parse-as-library \
17+
// RUN: -module-name main \
18+
// RUN: -lLibrary \
19+
// RUN: -I %t \
20+
// RUN: -o %t/Executable.o
21+
22+
//--- Library.swift
23+
24+
public struct Paq<each T> {
25+
public var uette: (repeat each T)
26+
}
27+
28+
public class Loq<each T> {
29+
}
30+
31+
// Enums don't take packs yet.
32+
33+
// public enum Orq<each T> {
34+
// case uette(repeat each T)
35+
// case uettette(repeat each T, repeat each T)
36+
// }
37+
38+
//--- Downstream.swift
39+
40+
import Library
41+
42+
struct Sleeve<T> {
43+
var impl: Paq<T>
44+
}
45+
46+
func bin<Moribund>(_ s: consuming Sleeve<Moribund>) {
47+
}
48+
49+
struct Laq<T> {
50+
var impl: Loq<T>
51+
var t: T
52+
}
53+
54+
@_silgen_name("bun")
55+
func bun<T>(_ l: consuming Laq<T>) {
56+
}
57+
58+
// Enums don't take packs yet.
59+
60+
// struct Etiq<T> {
61+
// var impl: Orq<T>
62+
// }
63+
//
64+
// func bon<Moribund>(_ i: consuming Etiq<Moribund>) {
65+
// }

0 commit comments

Comments
 (0)