@@ -1213,15 +1213,37 @@ class CaptureDescriptorBuilder : public ReflectionMetadataBuilder {
1213
1213
Subs(Subs),
1214
1214
Layout(Layout) {}
1215
1215
1216
- using MetadataSourceMap
1217
- = std::vector<std::pair<CanType, const reflection::MetadataSource*>>;
1216
+ struct Entry {
1217
+ enum Kind {
1218
+ Metadata,
1219
+ Shape
1220
+ };
1218
1221
1219
- void addMetadataSource (const reflection::MetadataSource *Source) {
1222
+ Kind kind;
1223
+
1224
+ CanType type;
1225
+ const reflection::MetadataSource *source;
1226
+
1227
+ Entry (Kind kind, CanType type, const reflection::MetadataSource *source)
1228
+ : kind(kind), type(type), source(source) {}
1229
+ };
1230
+
1231
+ using MetadataSourceMap = std::vector<Entry>;
1232
+
1233
+ void addMetadataSource (Entry::Kind Kind, const reflection::MetadataSource *Source) {
1220
1234
if (Source == nullptr ) {
1221
1235
B.addInt32 (0 );
1222
1236
} else {
1223
1237
SmallString<16 > EncodeBuffer;
1224
1238
llvm::raw_svector_ostream OS (EncodeBuffer);
1239
+ switch (Kind) {
1240
+ case Entry::Kind::Shape:
1241
+ OS << " s" ;
1242
+ break ;
1243
+ case Entry::Kind::Metadata:
1244
+ break ;
1245
+ }
1246
+
1225
1247
MetadataSourceEncoder Encoder (OS);
1226
1248
Encoder.visit (Source);
1227
1249
@@ -1287,24 +1309,31 @@ class CaptureDescriptorBuilder : public ReflectionMetadataBuilder {
1287
1309
// the bindings structure directly.
1288
1310
auto &Bindings = Layout.getBindings ();
1289
1311
for (unsigned i = 0 ; i < Bindings.size (); ++i) {
1290
- // Skip protocol requirements (FIXME: for now?)
1291
- if (Bindings[i].isAnyWitnessTable ())
1292
- continue ;
1293
-
1294
- // FIXME: bind pack counts in the source map
1295
- assert (Bindings[i].isAnyMetadata ());
1296
-
1297
- auto Source = SourceBuilder.createClosureBinding (i);
1298
- auto BindingType = Bindings[i].getTypeParameter ();
1299
- auto InterfaceType = BindingType->mapTypeOutOfContext ();
1300
- SourceMap.push_back ({InterfaceType->getCanonicalType (), Source});
1312
+ switch (Bindings[i].getKind ()) {
1313
+ case GenericRequirement::Kind::Shape:
1314
+ case GenericRequirement::Kind::Metadata:
1315
+ case GenericRequirement::Kind::MetadataPack: {
1316
+ auto Kind = (Bindings[i].getKind () == GenericRequirement::Kind::Shape
1317
+ ? Entry::Kind::Shape
1318
+ : Entry::Kind::Metadata);
1319
+ auto Source = SourceBuilder.createClosureBinding (i);
1320
+ auto BindingType = Bindings[i].getTypeParameter ();
1321
+ auto InterfaceType = BindingType->mapTypeOutOfContext ();
1322
+ SourceMap.emplace_back (Kind, InterfaceType->getCanonicalType (), Source);
1323
+ break ;
1324
+ }
1325
+ case GenericRequirement::Kind::WitnessTable:
1326
+ case GenericRequirement::Kind::WitnessTablePack:
1327
+ // Skip protocol requirements (FIXME: for now?)
1328
+ break ;
1329
+ }
1301
1330
}
1302
1331
1303
1332
// Check if any requirements were fulfilled by metadata stored inside a
1304
1333
// captured value.
1305
1334
1306
1335
enumerateGenericParamFulfillments (IGM, OrigCalleeType,
1307
- [&](CanType GenericParam ,
1336
+ [&](GenericRequirement Req ,
1308
1337
const irgen::MetadataSource &Source,
1309
1338
const MetadataPath &Path) {
1310
1339
@@ -1332,15 +1361,31 @@ class CaptureDescriptorBuilder : public ReflectionMetadataBuilder {
1332
1361
break ;
1333
1362
}
1334
1363
1364
+ Entry::Kind Kind;
1365
+ switch (Req.getKind ()) {
1366
+ case GenericRequirement::Kind::Shape:
1367
+ Kind = Entry::Kind::Shape;
1368
+ break ;
1369
+
1370
+ case GenericRequirement::Kind::Metadata:
1371
+ case GenericRequirement::Kind::MetadataPack:
1372
+ Kind = Entry::Kind::Metadata;
1373
+ break ;
1374
+
1375
+ case GenericRequirement::Kind::WitnessTable:
1376
+ case GenericRequirement::Kind::WitnessTablePack:
1377
+ llvm_unreachable (" Bad kind" );
1378
+ }
1379
+
1335
1380
// The metadata might be reached via a non-trivial path (eg,
1336
1381
// dereferencing an isa pointer or a generic argument). Record
1337
1382
// the path. We assume captured values map 1-1 with function
1338
1383
// parameters.
1339
1384
auto Src = Path.getMetadataSource (SourceBuilder, Root);
1340
1385
1341
- auto SubstType = GenericParam .subst (Subs);
1386
+ auto SubstType = Req. getTypeParameter () .subst (Subs);
1342
1387
auto InterfaceType = SubstType->mapTypeOutOfContext ();
1343
- SourceMap.push_back ({ InterfaceType->getCanonicalType (), Src} );
1388
+ SourceMap.emplace_back (Kind, InterfaceType->getCanonicalType (), Src);
1344
1389
});
1345
1390
1346
1391
return SourceMap;
@@ -1398,12 +1443,9 @@ class CaptureDescriptorBuilder : public ReflectionMetadataBuilder {
1398
1443
1399
1444
// Add the pairs that make up the generic param -> metadata source map
1400
1445
// to the struct.
1401
- for (auto GenericAndSource : MetadataSources) {
1402
- auto GenericParam = GenericAndSource.first ->getCanonicalType ();
1403
- auto Source = GenericAndSource.second ;
1404
-
1405
- addTypeRef (GenericParam, sig);
1406
- addMetadataSource (Source);
1446
+ for (auto entry : MetadataSources) {
1447
+ addTypeRef (entry.type , sig);
1448
+ addMetadataSource (entry.kind , entry.source );
1407
1449
}
1408
1450
}
1409
1451
0 commit comments