Skip to content

Commit a924c92

Browse files
gregomnijckarter
authored andcommitted
Switch away from using a SetVector here because we want each ValueDecl to appear in the transitive capture list only once, not potentially repeated with different flags.
1 parent 3146921 commit a924c92

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

lib/SIL/TypeLowering.cpp

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2063,7 +2063,8 @@ TypeConverter::getLoweredLocalCaptures(AnyFunctionRef fn) {
20632063

20642064
// Recursively collect transitive captures from captured local functions.
20652065
llvm::DenseSet<AnyFunctionRef> visitedFunctions;
2066-
llvm::SetVector<CapturedValue> captures;
2066+
llvm::DenseSet<ValueDecl*> capturedValues;
2067+
llvm::SmallVector<CapturedValue, 4> captures;
20672068

20682069
// If there is a capture of 'self' with dynamic 'Self' type, it goes last so
20692070
// that IRGen can pass dynamic 'Self' metadata.
@@ -2144,10 +2145,22 @@ TypeConverter::getLoweredLocalCaptures(AnyFunctionRef fn) {
21442145
}
21452146
}
21462147
}
2147-
21482148
capture_value:
21492149
// Collect non-function captures.
2150-
captures.insert(capture);
2150+
ValueDecl *value = capture.getDecl();
2151+
if (capturedValues.count(value)) {
2152+
for (auto it = captures.begin(); it != captures.end(); ++it) {
2153+
if (it->getDecl() == value) {
2154+
// The value is already in the list, it needs to have the logical
2155+
// AND of each flag of all uses.
2156+
*it = CapturedValue(value, it->getFlags() & capture.getFlags());
2157+
break;
2158+
}
2159+
}
2160+
} else {
2161+
capturedValues.insert(value);
2162+
captures.push_back(capture);
2163+
}
21512164
}
21522165
};
21532166
collectFunctionCaptures(fn);
@@ -2156,10 +2169,10 @@ TypeConverter::getLoweredLocalCaptures(AnyFunctionRef fn) {
21562169
// add it as the final capture. Otherwise, add a fake hidden capture for
21572170
// the dynamic 'Self' metatype.
21582171
if (selfCapture.hasValue()) {
2159-
captures.insert(*selfCapture);
2172+
captures.push_back(*selfCapture);
21602173
} else if (capturesDynamicSelf) {
21612174
selfCapture = CapturedValue::getDynamicSelfMetadata();
2162-
captures.insert(*selfCapture);
2175+
captures.push_back(*selfCapture);
21632176
}
21642177

21652178
// Cache the uniqued set of transitive captures.

0 commit comments

Comments
 (0)