Skip to content

Commit 8b030e1

Browse files
committed
SIL: Update getLoweredLocalCaptures() for PackElementExpr captures
1 parent ff59e5e commit 8b030e1

File tree

1 file changed

+30
-8
lines changed

1 file changed

+30
-8
lines changed

lib/SIL/IR/TypeLowering.cpp

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4241,7 +4241,10 @@ TypeConverter::getLoweredLocalCaptures(SILDeclRef fn) {
42414241

42424242
// Recursively collect transitive captures from captured local functions.
42434243
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;
42454248

42464249
// If there is a capture of 'self' with dynamic 'Self' type, it goes last so
42474250
// that IRGen can pass dynamic 'Self' metadata.
@@ -4259,12 +4262,23 @@ TypeConverter::getLoweredLocalCaptures(SILDeclRef fn) {
42594262
std::function<void (SILDeclRef)> collectConstantCaptures;
42604263

42614264
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+
}
42664273
} 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+
}
42684282
}
42694283
};
42704284

@@ -4284,6 +4298,11 @@ TypeConverter::getLoweredLocalCaptures(SILDeclRef fn) {
42844298
}
42854299

42864300
for (auto capture : captureInfo.getCaptures()) {
4301+
if (capture.isPackElement()) {
4302+
recordCapture(capture);
4303+
continue;
4304+
}
4305+
42874306
if (!capture.isLocalCapture())
42884307
continue;
42894308

@@ -4492,7 +4511,10 @@ TypeConverter::getLoweredLocalCaptures(SILDeclRef fn) {
44924511
collectConstantCaptures(fn);
44934512

44944513
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) {
44964518
resultingCaptures.push_back(capturePair.second);
44974519
}
44984520

@@ -4511,7 +4533,7 @@ TypeConverter::getLoweredLocalCaptures(SILDeclRef fn) {
45114533
resultingCaptures.push_back(*selfCapture);
45124534
}
45134535

4514-
// Cache the uniqued set of transitive captures.
4536+
// Cache the result.
45154537
CaptureInfo info(Context, resultingCaptures,
45164538
capturesDynamicSelf, capturesOpaqueValue,
45174539
capturesGenericParams, genericEnv.getArrayRef());

0 commit comments

Comments
 (0)