@@ -666,6 +666,31 @@ void SILGenFunction::emitArtificialTopLevel(ClassDecl *mainClass) {
666
666
}
667
667
}
668
668
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
+
669
694
void SILGenFunction::emitGeneratorFunction (SILDeclRef function, Expr *value,
670
695
bool EmitProfilerIncrement) {
671
696
auto *dc = function.getDecl ()->getInnermostDeclContext ();
@@ -707,10 +732,7 @@ void SILGenFunction::emitGeneratorFunction(SILDeclRef function, Expr *value,
707
732
if (function.getAnyFunctionRef ())
708
733
captureInfo = SGM.M .Types .getLoweredLocalCaptures (function);
709
734
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));
714
736
captureInfo = CaptureInfo::empty ();
715
737
}
716
738
0 commit comments