@@ -1251,26 +1251,21 @@ class AccessorConformanceInfo : public ConformanceInfo {
1251
1251
};
1252
1252
1253
1253
// / A class which lays out a specific conformance to a protocol.
1254
- class WitnessTableBuilder : public WitnessTableBuilderBase ,
1255
- public SILWitnessVisitor<WitnessTableBuilder > {
1254
+ class FragileWitnessTableBuilder : public WitnessTableBuilderBase ,
1255
+ public SILWitnessVisitor<FragileWitnessTableBuilder > {
1256
1256
ConstantArrayBuilder &Table;
1257
1257
unsigned TableSize = ~0U ; // will get overwritten unconditionally
1258
1258
SmallVector<std::pair<size_t , const ConformanceInfo *>, 4 >
1259
1259
SpecializedBaseConformances;
1260
1260
1261
- bool ResilientConformance;
1262
-
1263
1261
const ProtocolInfo &PI;
1264
1262
1265
1263
public:
1266
- WitnessTableBuilder (IRGenModule &IGM, ConstantArrayBuilder &table,
1267
- SILWitnessTable *SILWT)
1264
+ FragileWitnessTableBuilder (IRGenModule &IGM, ConstantArrayBuilder &table,
1265
+ SILWitnessTable *SILWT)
1268
1266
: WitnessTableBuilderBase(IGM, SILWT), Table(table),
1269
- ResilientConformance (IGM.isResilientConformance(&Conformance)),
1270
1267
PI (IGM.getProtocolInfo(SILWT->getConformance ()->getProtocol(),
1271
- (ResilientConformance
1272
- ? ProtocolInfoKind::RequirementSignature
1273
- : ProtocolInfoKind::Full))) {}
1268
+ ProtocolInfoKind::Full)) {}
1274
1269
1275
1270
// / The number of entries in the witness table.
1276
1271
unsigned getTableSize () const { return TableSize; }
@@ -1294,10 +1289,6 @@ class AccessorConformanceInfo : public ConformanceInfo {
1294
1289
#endif
1295
1290
SILEntries = SILEntries.slice (1 );
1296
1291
1297
- // Resilient conformances get a resilient witness table.
1298
- if (ResilientConformance)
1299
- return ;
1300
-
1301
1292
#ifndef NDEBUG
1302
1293
assert (entry.getKind () == SILWitnessTable::BaseProtocol
1303
1294
&& " sil witness table does not match protocol" );
@@ -1332,10 +1323,6 @@ class AccessorConformanceInfo : public ConformanceInfo {
1332
1323
auto &entry = SILEntries.front ();
1333
1324
SILEntries = SILEntries.slice (1 );
1334
1325
1335
- // Resilient conformances get a resilient witness table.
1336
- if (ResilientConformance)
1337
- return ;
1338
-
1339
1326
#ifndef NDEBUG
1340
1327
assert (entry.getKind () == SILWitnessTable::Method
1341
1328
&& " sil witness table does not match protocol" );
@@ -1372,10 +1359,6 @@ class AccessorConformanceInfo : public ConformanceInfo {
1372
1359
auto &entry = SILEntries.front ();
1373
1360
SILEntries = SILEntries.slice (1 );
1374
1361
1375
- // Resilient conformances get a resilient witness table.
1376
- if (ResilientConformance)
1377
- return ;
1378
-
1379
1362
#ifndef NDEBUG
1380
1363
assert (entry.getKind () == SILWitnessTable::AssociatedType
1381
1364
&& " sil witness table does not match protocol" );
@@ -1411,9 +1394,6 @@ class AccessorConformanceInfo : public ConformanceInfo {
1411
1394
(void )entry;
1412
1395
SILEntries = SILEntries.slice (1 );
1413
1396
1414
- if (ResilientConformance)
1415
- return ;
1416
-
1417
1397
auto associate =
1418
1398
ConformanceInContext.getAssociatedType (
1419
1399
requirement.getAssociation ())->getCanonicalType ();
@@ -1450,8 +1430,17 @@ class AccessorConformanceInfo : public ConformanceInfo {
1450
1430
// / Build the instantiation function that runs at the end of witness
1451
1431
// / table specialization.
1452
1432
llvm::Constant *buildInstantiationFunction ();
1433
+ };
1453
1434
1435
+ class ResilientWitnessTableBuilder : public WitnessTableBuilderBase {
1454
1436
public:
1437
+ ResilientWitnessTableBuilder (IRGenModule &IGM, SILWitnessTable *SILWT)
1438
+ : WitnessTableBuilderBase(IGM, SILWT) {}
1439
+
1440
+ void build () {
1441
+ WitnessTableBuilderBase::build ();
1442
+ }
1443
+
1455
1444
// / Collect the set of resilient witnesses, which will become part of the
1456
1445
// / protocol conformance descriptor.
1457
1446
void collectResilientWitnesses (
@@ -1460,7 +1449,7 @@ class AccessorConformanceInfo : public ConformanceInfo {
1460
1449
} // end anonymous namespace
1461
1450
1462
1451
// / Build the witness table.
1463
- void WitnessTableBuilder ::build () {
1452
+ void FragileWitnessTableBuilder ::build () {
1464
1453
WitnessTableBuilderBase::build ();
1465
1454
visitProtocolDecl (Conformance.getProtocol ());
1466
1455
TableSize = Table.size ();
@@ -1627,11 +1616,8 @@ void WitnessTableBuilderBase::defineAssociatedTypeWitnessTableAccessFunction(
1627
1616
IGF.Builder .CreateRet (wtable);
1628
1617
}
1629
1618
1630
- void WitnessTableBuilder ::collectResilientWitnesses (
1619
+ void ResilientWitnessTableBuilder ::collectResilientWitnesses (
1631
1620
SmallVectorImpl<llvm::Constant *> &resilientWitnesses) {
1632
- if (!ResilientConformance)
1633
- return ;
1634
-
1635
1621
assert (isa<NormalProtocolConformance>(Conformance) &&
1636
1622
" resilient conformance should always be normal" );
1637
1623
auto &conformance = cast<NormalProtocolConformance>(Conformance);
@@ -1707,7 +1693,7 @@ void WitnessTableBuilder::collectResilientWitnesses(
1707
1693
}
1708
1694
}
1709
1695
1710
- llvm::Constant *WitnessTableBuilder ::buildInstantiationFunction () {
1696
+ llvm::Constant *FragileWitnessTableBuilder ::buildInstantiationFunction () {
1711
1697
// We need an instantiation function if any base conformance
1712
1698
// is non-dependent.
1713
1699
if (SpecializedBaseConformances.empty ())
@@ -2172,7 +2158,7 @@ void IRGenModule::emitSILWitnessTable(SILWitnessTable *wt) {
2172
2158
// Build the witness table.
2173
2159
ConstantInitBuilder builder (*this );
2174
2160
auto wtableContents = builder.beginArray (Int8PtrTy);
2175
- WitnessTableBuilder wtableBuilder (*this , wtableContents, wt);
2161
+ FragileWitnessTableBuilder wtableBuilder (*this , wtableContents, wt);
2176
2162
wtableBuilder.build ();
2177
2163
2178
2164
// Produce the initializer value.
@@ -2193,18 +2179,12 @@ void IRGenModule::emitSILWitnessTable(SILWitnessTable *wt) {
2193
2179
instantiationFunction = wtableBuilder.buildInstantiationFunction ();
2194
2180
} else {
2195
2181
// Build the witness table.
2196
- ConstantInitBuilder builder (*this );
2197
- auto wtableContents = builder.beginArray (Int8PtrTy);
2198
- WitnessTableBuilder wtableBuilder (*this , wtableContents, wt);
2182
+ ResilientWitnessTableBuilder wtableBuilder (*this , wt);
2199
2183
wtableBuilder.build ();
2200
2184
2201
2185
// Collect the resilient witnesses to go into the conformance descriptor.
2202
2186
wtableBuilder.collectResilientWitnesses (resilientWitnesses);
2203
2187
2204
- // Produce the initializer value.
2205
- auto initializer = wtableContents.finishAndCreateFuture ();
2206
- initializer.abandon ();
2207
-
2208
2188
tableSize = 0 ;
2209
2189
tablePrivateSize = wtableBuilder.getTablePrivateSize ();
2210
2190
}
0 commit comments