@@ -4241,7 +4241,10 @@ TypeConverter::getLoweredLocalCaptures(SILDeclRef fn) {
4241
4241
4242
4242
// Recursively collect transitive captures from captured local functions.
4243
4243
llvm::DenseSet<AnyFunctionRef> visitedFunctions;
4244
- llvm::MapVector<ValueDecl*,CapturedValue> captures;
4244
+
4245
+ // FIXME: CapturedValue should just be a hash key
4246
+ llvm::MapVector<VarDecl *, CapturedValue> varCaptures;
4247
+ llvm::MapVector<PackElementExpr *, CapturedValue> packElementCaptures;
4245
4248
4246
4249
// If there is a capture of 'self' with dynamic 'Self' type, it goes last so
4247
4250
// that IRGen can pass dynamic 'Self' metadata.
@@ -4259,12 +4262,23 @@ TypeConverter::getLoweredLocalCaptures(SILDeclRef fn) {
4259
4262
std::function<void (SILDeclRef)> collectConstantCaptures;
4260
4263
4261
4264
auto recordCapture = [&](CapturedValue capture) {
4262
- ValueDecl *value = capture.getDecl ();
4263
- auto existing = captures.find (value);
4264
- if (existing != captures.end ()) {
4265
- existing->second = existing->second .mergeFlags (capture.getFlags ());
4265
+ if (auto *expr = capture.getPackElement ()) {
4266
+ auto existing = packElementCaptures.find (expr);
4267
+ if (existing != packElementCaptures.end ()) {
4268
+ existing->second = existing->second .mergeFlags (capture.getFlags ());
4269
+ } else {
4270
+ packElementCaptures.insert (std::pair<PackElementExpr *, CapturedValue>(
4271
+ expr, capture));
4272
+ }
4266
4273
} else {
4267
- captures.insert (std::pair<ValueDecl *, CapturedValue>(value, capture));
4274
+ VarDecl *value = cast<VarDecl>(capture.getDecl ());
4275
+ auto existing = varCaptures.find (value);
4276
+ if (existing != varCaptures.end ()) {
4277
+ existing->second = existing->second .mergeFlags (capture.getFlags ());
4278
+ } else {
4279
+ varCaptures.insert (std::pair<VarDecl *, CapturedValue>(
4280
+ value, capture));
4281
+ }
4268
4282
}
4269
4283
};
4270
4284
@@ -4284,6 +4298,11 @@ TypeConverter::getLoweredLocalCaptures(SILDeclRef fn) {
4284
4298
}
4285
4299
4286
4300
for (auto capture : captureInfo.getCaptures ()) {
4301
+ if (capture.isPackElement ()) {
4302
+ recordCapture (capture);
4303
+ continue ;
4304
+ }
4305
+
4287
4306
if (!capture.isLocalCapture ())
4288
4307
continue ;
4289
4308
@@ -4492,7 +4511,10 @@ TypeConverter::getLoweredLocalCaptures(SILDeclRef fn) {
4492
4511
collectConstantCaptures (fn);
4493
4512
4494
4513
SmallVector<CapturedValue, 4 > resultingCaptures;
4495
- for (auto capturePair : captures) {
4514
+ for (auto capturePair : varCaptures) {
4515
+ resultingCaptures.push_back (capturePair.second );
4516
+ }
4517
+ for (auto capturePair : packElementCaptures) {
4496
4518
resultingCaptures.push_back (capturePair.second );
4497
4519
}
4498
4520
@@ -4511,7 +4533,7 @@ TypeConverter::getLoweredLocalCaptures(SILDeclRef fn) {
4511
4533
resultingCaptures.push_back (*selfCapture);
4512
4534
}
4513
4535
4514
- // Cache the uniqued set of transitive captures .
4536
+ // Cache the result .
4515
4537
CaptureInfo info (Context, resultingCaptures,
4516
4538
capturesDynamicSelf, capturesOpaqueValue,
4517
4539
capturesGenericParams, genericEnv.getArrayRef ());
0 commit comments