Skip to content

Commit f93c0ee

Browse files
committed
[NFC] Base emitGeneratorFunction() on canCaptureFromParent()
1 parent ca25640 commit f93c0ee

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

lib/SILGen/SILGenFunction.cpp

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,31 @@ void SILGenFunction::emitArtificialTopLevel(ClassDecl *mainClass) {
666666
}
667667
}
668668

669+
#ifndef NDEBUG
670+
/// If \c false, \c function is either a declaration that inherently cannot
671+
/// capture variables, or it is in a context it cannot capture variables from.
672+
/// In either case, it is expected that Sema may not have computed its
673+
/// \c CaptureInfo.
674+
///
675+
/// This call exists for use in assertions; do not use it to skip capture
676+
/// processing.
677+
static bool canCaptureFromParent(SILDeclRef function) {
678+
switch (function.kind) {
679+
case SILDeclRef::Kind::StoredPropertyInitializer:
680+
case SILDeclRef::Kind::PropertyWrapperBackingInitializer:
681+
return false;
682+
683+
default:
684+
if (function.hasDecl()) {
685+
if (auto dc = dyn_cast<DeclContext>(function.getDecl())) {
686+
return TypeConverter::canCaptureFromParent(dc);
687+
}
688+
}
689+
return false;
690+
}
691+
}
692+
#endif
693+
669694
void SILGenFunction::emitGeneratorFunction(SILDeclRef function, Expr *value,
670695
bool EmitProfilerIncrement) {
671696
auto *dc = function.getDecl()->getInnermostDeclContext();
@@ -707,10 +732,7 @@ void SILGenFunction::emitGeneratorFunction(SILDeclRef function, Expr *value,
707732
if (function.getAnyFunctionRef())
708733
captureInfo = SGM.M.Types.getLoweredLocalCaptures(function);
709734
else {
710-
// The expressions for these cannot capture.
711-
assert(function.kind == SILDeclRef::Kind::StoredPropertyInitializer ||
712-
function.kind == SILDeclRef::Kind::PropertyWrapperBackingInitializer ||
713-
(function.getDecl() && !function.getDecl()->getDeclContext()->isLocalContext()));
735+
assert(!canCaptureFromParent(function));
714736
captureInfo = CaptureInfo::empty();
715737
}
716738

0 commit comments

Comments
 (0)