Skip to content

Commit 04eef65

Browse files
committed
SIL: Validate stored properties and enum elements as needed
1 parent 25e4ca9 commit 04eef65

File tree

1 file changed

+34
-10
lines changed

1 file changed

+34
-10
lines changed

lib/SIL/TypeLowering.cpp

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1267,10 +1267,20 @@ namespace {
12671267
if (handleResilience(structType, D, properties))
12681268
return handleAddressOnly(structType, properties);
12691269

1270+
auto subMap = structType->getContextSubstitutionMap(
1271+
M.getSwiftModule(), D);
1272+
12701273
// Classify the type according to its stored properties.
12711274
for (auto field : D->getStoredProperties()) {
1275+
// FIXME: Remove this once getInterfaceType() is a request.
1276+
if (!field->hasInterfaceType())
1277+
M.getASTContext().getLazyResolver()->resolveDeclSignature(field);
1278+
12721279
auto substFieldType =
1273-
structType->getTypeOfMember(D->getModuleContext(), field, nullptr);
1280+
field->getInterfaceType()
1281+
.subst(subMap, SubstFlags::UseErrorType)
1282+
->getCanonicalType();
1283+
12741284
properties.addSubobject(classifyType(substFieldType->getCanonicalType(),
12751285
M, Sig, Expansion));
12761286
}
@@ -1297,6 +1307,9 @@ namespace {
12971307
Expansion);
12981308
}
12991309

1310+
auto subMap = enumType->getContextSubstitutionMap(
1311+
M.getSwiftModule(), D);
1312+
13001313
// Accumulate the properties of all direct payloads.
13011314
for (auto elt : D->getAllElements()) {
13021315
// No-payload elements do not affect any recursive properties.
@@ -1308,11 +1321,15 @@ namespace {
13081321
properties.setNonTrivial();
13091322
continue;
13101323
}
1311-
1312-
auto substEltType = enumType->getTypeOfMember(
1313-
D->getModuleContext(), elt,
1314-
elt->getArgumentInterfaceType())
1315-
->getCanonicalType();
1324+
1325+
// FIXME: Remove this once getInterfaceType() is a request.
1326+
if (!elt->hasInterfaceType())
1327+
M.getASTContext().getLazyResolver()->resolveDeclSignature(elt);
1328+
1329+
auto substEltType =
1330+
elt->getArgumentInterfaceType()
1331+
.subst(subMap, SubstFlags::UseErrorType)
1332+
->getCanonicalType();
13161333

13171334
properties.addSubobject(classifyType(substEltType, M, Sig, Expansion));
13181335
}
@@ -2591,6 +2608,10 @@ CanSILBoxType TypeConverter::getBoxTypeForEnumElement(SILType enumType,
25912608

25922609
auto &C = M.getASTContext();
25932610

2611+
// FIXME: Remove this once getInterfaceType() is a request.
2612+
if (!elt->hasInterfaceType())
2613+
C.getLazyResolver()->resolveDeclSignature(elt);
2614+
25942615
auto boxSignature = getEffectiveGenericSignature(enumDecl);
25952616

25962617
if (boxSignature == CanGenericSignature()) {
@@ -2655,12 +2676,15 @@ static void countNumberOfInnerFields(unsigned &fieldsCount, SILModule &Module,
26552676
unsigned fieldsCountBefore = fieldsCount;
26562677
unsigned maxEnumCount = 0;
26572678
for (auto elt : enumDecl->getAllElements()) {
2658-
if (!elt->getArgumentInterfaceType()) {
2679+
if (!elt->hasAssociatedValues())
26592680
continue;
2660-
}
2661-
if (elt->isIndirect()) {
2681+
2682+
if (elt->isIndirect())
26622683
continue;
2663-
}
2684+
2685+
if (!elt->hasInterfaceType())
2686+
enumDecl->getASTContext().getLazyResolver()->resolveDeclSignature(elt);
2687+
26642688
// Although one might assume enums have a fields count of 1
26652689
// Which holds true for current uses of this code
26662690
// (we shouldn't expand enums)

0 commit comments

Comments
 (0)