@@ -395,17 +395,12 @@ namespace {
395
395
// Tuples depend on their elements.
396
396
RetTy visitTupleType (CanTupleType type) {
397
397
bool hasReference = false ;
398
- // TODO: We ought to be able to early-exit as soon as we've established
399
- // that a type is address-only. However, we also currently rely on
400
- // SIL lowering to catch unsupported recursive value types.
401
- bool isAddressOnly = false ;
402
398
for (auto eltType : type.getElementTypes ()) {
403
399
switch (classifyType (eltType, M, Sig, Expansion)) {
404
400
case LoweredTypeKind::Trivial:
405
401
continue ;
406
402
case LoweredTypeKind::AddressOnly:
407
- isAddressOnly = true ;
408
- continue ;
403
+ return asImpl ().handleAddressOnly (type);
409
404
case LoweredTypeKind::Reference:
410
405
case LoweredTypeKind::AggWithReference:
411
406
hasReference = true ;
@@ -414,8 +409,6 @@ namespace {
414
409
llvm_unreachable (" bad type classification" );
415
410
}
416
411
417
- if (isAddressOnly)
418
- return asImpl ().handleAddressOnly (type);
419
412
if (hasReference)
420
413
return asImpl ().handleAggWithReference (type);
421
414
return asImpl ().handleTrivial (type);
@@ -1034,17 +1027,6 @@ namespace {
1034
1027
llvm_unreachable (" cannot destroy an UnsafeValueBuffer!" );
1035
1028
}
1036
1029
};
1037
-
1038
- // / A class that acts as a stand-in for improperly recursive types.
1039
- class RecursiveErrorTypeLowering : public AddressOnlyTypeLowering {
1040
- public:
1041
- RecursiveErrorTypeLowering (SILType type)
1042
- : AddressOnlyTypeLowering(type) {}
1043
-
1044
- bool isValid () const override {
1045
- return false ;
1046
- }
1047
- };
1048
1030
1049
1031
// / Build the appropriate TypeLowering subclass for the given type.
1050
1032
class LowerType
@@ -1136,39 +1118,30 @@ namespace {
1136
1118
const TypeLowering *visitTupleType (CanTupleType tupleType) {
1137
1119
typedef LoadableTupleTypeLowering::Child Child;
1138
1120
SmallVector<Child, 8 > childElts;
1139
- // TODO: We ought to be able to early-exit as soon as we've established
1140
- // that a type is address-only. However, we also currently rely on
1141
- // SIL lowering to catch unsupported recursive value types.
1142
- bool isAddressOnly = false ;
1143
1121
bool hasOnlyTrivialChildren = true ;
1144
1122
1145
1123
unsigned i = 0 ;
1146
1124
for (auto eltType : tupleType.getElementTypes ()) {
1147
1125
auto &lowering = TC.getTypeLowering (eltType);
1148
1126
if (lowering.isAddressOnly ())
1149
- isAddressOnly = true ;
1127
+ return handleAddressOnly (tupleType) ;
1150
1128
hasOnlyTrivialChildren &= lowering.isTrivial ();
1151
1129
childElts.push_back (Child (i, lowering));
1152
1130
++i;
1153
1131
}
1154
1132
1155
- if (isAddressOnly)
1156
- return handleAddressOnly (tupleType);
1157
1133
if (hasOnlyTrivialChildren)
1158
1134
return handleTrivial (tupleType);
1135
+
1159
1136
return new (TC, Dependent) LoadableTupleTypeLowering (OrigType);
1160
1137
}
1161
1138
1162
1139
const TypeLowering *visitAnyStructType (CanType structType, StructDecl *D) {
1163
- // TODO: We ought to be able to early-exit as soon as we've established
1164
- // that a type is address-only. However, we also currently rely on
1165
- // SIL lowering to catch unsupported recursive value types.
1166
- bool isAddressOnly = false ;
1167
-
1140
+
1168
1141
// For now, if the type does not have a fixed layout in all resilience
1169
1142
// domains, we will treat it as address-only in SIL.
1170
1143
if (!D->hasFixedLayout (M.getSwiftModule (), Expansion))
1171
- isAddressOnly = true ;
1144
+ return handleAddressOnly (structType) ;
1172
1145
1173
1146
// Classify the type according to its stored properties.
1174
1147
bool trivial = true ;
@@ -1178,8 +1151,7 @@ namespace {
1178
1151
switch (classifyType (substFieldType->getCanonicalType (),
1179
1152
M, Sig, Expansion)) {
1180
1153
case LoweredTypeKind::AddressOnly:
1181
- isAddressOnly = true ;
1182
- break ;
1154
+ return handleAddressOnly (structType);
1183
1155
case LoweredTypeKind::AggWithReference:
1184
1156
case LoweredTypeKind::Reference:
1185
1157
trivial = false ;
@@ -1189,23 +1161,17 @@ namespace {
1189
1161
}
1190
1162
}
1191
1163
1192
- if (isAddressOnly)
1193
- return handleAddressOnly (structType);
1194
1164
if (trivial)
1195
1165
return handleTrivial (structType);
1196
1166
return new (TC, Dependent) LoadableStructTypeLowering (OrigType);
1197
1167
}
1198
1168
1199
1169
const TypeLowering *visitAnyEnumType (CanType enumType, EnumDecl *D) {
1200
- // TODO: We ought to be able to early-exit as soon as we've established
1201
- // that a type is address-only. However, we also currently rely on
1202
- // SIL lowering to catch unsupported recursive value types.
1203
- bool isAddressOnly = false ;
1204
1170
1205
1171
// For now, if the type does not have a fixed layout in all resilience
1206
1172
// domains, we will treat it as address-only in SIL.
1207
1173
if (!D->hasFixedLayout (M.getSwiftModule (), Expansion))
1208
- isAddressOnly = true ;
1174
+ return handleAddressOnly (enumType) ;
1209
1175
1210
1176
// Lower Self? as if it were Whatever? and Self! as if it were Whatever!.
1211
1177
if (auto genericEnum = dyn_cast<BoundGenericEnumType>(enumType)) {
@@ -1238,8 +1204,6 @@ namespace {
1238
1204
// is still address only, because we don't know how many bits
1239
1205
// are used for the discriminator.
1240
1206
if (D->isIndirect ()) {
1241
- if (isAddressOnly)
1242
- return handleAddressOnly (OrigType);
1243
1207
return new (TC, Dependent) LoadableEnumTypeLowering (OrigType);
1244
1208
}
1245
1209
@@ -1267,8 +1231,7 @@ namespace {
1267
1231
switch (classifyType (substEltType->getCanonicalType (),
1268
1232
M, Sig, Expansion)) {
1269
1233
case LoweredTypeKind::AddressOnly:
1270
- isAddressOnly = true ;
1271
- break ;
1234
+ return handleAddressOnly (enumType);
1272
1235
case LoweredTypeKind::AggWithReference:
1273
1236
case LoweredTypeKind::Reference:
1274
1237
trivial = false ;
@@ -1278,8 +1241,6 @@ namespace {
1278
1241
}
1279
1242
1280
1243
}
1281
- if (isAddressOnly)
1282
- return handleAddressOnly (enumType);
1283
1244
if (trivial)
1284
1245
return handleTrivial (enumType);
1285
1246
return new (TC, Dependent) LoadableEnumTypeLowering (OrigType);
@@ -1326,35 +1287,17 @@ const TypeLowering *TypeConverter::find(TypeKey k) {
1326
1287
auto found = Types.find (ck);
1327
1288
if (found == Types.end ())
1328
1289
return nullptr ;
1329
- // We place a null placeholder in the hashtable to catch
1330
- // reentrancy, which arises as a result of improper recursion.
1331
- // TODO: We should diagnose nonterminating recursion in Sema, and implement
1332
- // terminating recursive enums, instead of diagnosing here.
1333
- // When that Sema check is in place, we should reinstate the early-exit
1334
- // behavior for address-only types (marked by other TODO: items throughout
1335
- // this file).
1336
- if (auto elt = found->second )
1337
- return elt;
1338
-
1339
- // Try to complain about a nominal type.
1340
- auto nomTy = k.SubstType .getAnyNominal ();
1341
- assert (nomTy && " non-nominal types should not be recursive" );
1342
-
1343
- auto result = new (*this , k.isDependent ()) RecursiveErrorTypeLowering (
1344
- SILType::getPrimitiveAddressType (k.SubstType ));
1345
- found->second = result;
1346
- return result;
1290
+
1291
+ assert (found->second && " type recursion not caught in Sema" );
1292
+ return found->second ;
1347
1293
}
1348
1294
1349
1295
void TypeConverter::insert (TypeKey k, const TypeLowering *tl) {
1350
1296
if (!k.isCacheable ()) return ;
1351
1297
1352
1298
auto &Types = k.isDependent () ? DependentTypes : IndependentTypes;
1353
- // TODO: Types[k] should always be null at this point, except that we
1354
- // rely on type lowering to discover recursive value types right now.
1355
- auto ck = k.getCachingKey ();
1356
- if (!Types[ck])
1357
- Types[ck] = tl;
1299
+
1300
+ Types[k.getCachingKey ()] = tl;
1358
1301
}
1359
1302
1360
1303
#ifndef NDEBUG
@@ -1629,11 +1572,11 @@ getTypeLoweringForUncachedLoweredFunctionType(TypeKey key) {
1629
1572
assert (isa<AnyFunctionType>(key.SubstType ));
1630
1573
assert (key.UncurryLevel == 0 );
1631
1574
1575
+ #ifdef DEBUG
1632
1576
// Catch recursions.
1633
- // FIXME: These should be bugs, so we shouldn't need to do this in release
1634
- // builds.
1635
1577
insert (key, nullptr );
1636
-
1578
+ #endif
1579
+
1637
1580
// Generic functions aren't first-class values and shouldn't end up lowered
1638
1581
// through this interface.
1639
1582
assert (!isa<PolymorphicFunctionType>(key.SubstType )
@@ -1657,10 +1600,10 @@ TypeConverter::getTypeLoweringForUncachedLoweredType(TypeKey key) {
1657
1600
assert (!find (key) && " re-entrant or already cached" );
1658
1601
assert (isLoweredType (key.SubstType ) && " didn't lower out l-value type?" );
1659
1602
1603
+ #ifdef DEBUG
1660
1604
// Catch reentrancy bugs.
1661
- // FIXME: These should be bugs, so we shouldn't need to do this in release
1662
- // builds.
1663
1605
insert (key, nullptr );
1606
+ #endif
1664
1607
1665
1608
CanType contextType = key.SubstType ;
1666
1609
// FIXME: Get expansion from SILFunction
0 commit comments