Skip to content

Commit 24857ab

Browse files
committed
SIL: Remove unused DeclContext in getLoweredLocalCaptures()
1 parent d222470 commit 24857ab

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

lib/SIL/IR/TypeLowering.cpp

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4139,11 +4139,21 @@ TypeConverter::getLoweredLocalCaptures(SILDeclRef fn) {
41394139
DynamicSelfType *capturesDynamicSelf = nullptr;
41404140
OpaqueValueExpr *capturesOpaqueValue = nullptr;
41414141

4142-
std::function<void (CaptureInfo captureInfo, DeclContext *dc)> collectCaptures;
4142+
std::function<void (CaptureInfo captureInfo)> collectCaptures;
41434143
std::function<void (AnyFunctionRef)> collectFunctionCaptures;
41444144
std::function<void (SILDeclRef)> collectConstantCaptures;
41454145

4146-
collectCaptures = [&](CaptureInfo captureInfo, DeclContext *dc) {
4146+
auto recordCapture = [&](CapturedValue capture) {
4147+
ValueDecl *value = capture.getDecl();
4148+
auto existing = captures.find(value);
4149+
if (existing != captures.end()) {
4150+
existing->second = existing->second.mergeFlags(capture);
4151+
} else {
4152+
captures.insert(std::pair<ValueDecl *, CapturedValue>(value, capture));
4153+
}
4154+
};
4155+
4156+
collectCaptures = [&](CaptureInfo captureInfo) {
41474157
assert(captureInfo.hasBeenComputed());
41484158

41494159
if (captureInfo.hasGenericParamCaptures())
@@ -4288,13 +4298,7 @@ TypeConverter::getLoweredLocalCaptures(SILDeclRef fn) {
42884298
}
42894299

42904300
// Collect non-function captures.
4291-
ValueDecl *value = capture.getDecl();
4292-
auto existing = captures.find(value);
4293-
if (existing != captures.end()) {
4294-
existing->second = existing->second.mergeFlags(capture);
4295-
} else {
4296-
captures.insert(std::pair<ValueDecl *, CapturedValue>(value, capture));
4297-
}
4301+
recordCapture(capture);
42984302
}
42994303
};
43004304

@@ -4306,8 +4310,7 @@ TypeConverter::getLoweredLocalCaptures(SILDeclRef fn) {
43064310
return;
43074311

43084312
PrettyStackTraceAnyFunctionRef("lowering local captures", curFn);
4309-
auto dc = curFn.getAsDeclContext();
4310-
collectCaptures(curFn.getCaptureInfo(), dc);
4313+
collectCaptures(curFn.getCaptureInfo());
43114314

43124315
// A function's captures also include its default arguments, because
43134316
// when we reference a function we don't track which default arguments
@@ -4318,7 +4321,7 @@ TypeConverter::getLoweredLocalCaptures(SILDeclRef fn) {
43184321
if (auto *AFD = curFn.getAbstractFunctionDecl()) {
43194322
for (auto *P : *AFD->getParameters()) {
43204323
if (P->hasDefaultExpr())
4321-
collectCaptures(P->getDefaultArgumentCaptureInfo(), dc);
4324+
collectCaptures(P->getDefaultArgumentCaptureInfo());
43224325
}
43234326
}
43244327
};
@@ -4331,10 +4334,8 @@ TypeConverter::getLoweredLocalCaptures(SILDeclRef fn) {
43314334
if (auto *afd = dyn_cast<AbstractFunctionDecl>(curFn.getDecl())) {
43324335
auto *param = getParameterAt(static_cast<ValueDecl *>(afd),
43334336
curFn.defaultArgIndex);
4334-
if (param->hasDefaultExpr()) {
4335-
auto dc = afd->getInnermostDeclContext();
4336-
collectCaptures(param->getDefaultArgumentCaptureInfo(), dc);
4337-
}
4337+
if (param->hasDefaultExpr())
4338+
collectCaptures(param->getDefaultArgumentCaptureInfo());
43384339
return;
43394340
}
43404341

0 commit comments

Comments
 (0)