@@ -1132,6 +1132,7 @@ emitStoredPropertyInitialization(PatternBindingDecl *pbd, unsigned i) {
1132
1132
auto *var = pbdEntry.getAnchoringVarDecl ();
1133
1133
auto *init = pbdEntry.getInit ();
1134
1134
auto *initDC = pbdEntry.getInitContext ();
1135
+ auto &captureInfo = pbdEntry.getCaptureInfo ();
1135
1136
assert (!pbdEntry.isInitializerSubsumed ());
1136
1137
1137
1138
// If this is the backing storage for a property with an attached wrapper
@@ -1148,12 +1149,23 @@ emitStoredPropertyInitialization(PatternBindingDecl *pbd, unsigned i) {
1148
1149
1149
1150
SILDeclRef constant (var, SILDeclRef::Kind::StoredPropertyInitializer);
1150
1151
emitOrDelayFunction (*this , constant,
1151
- [this ,constant,init,initDC](SILFunction *f) {
1152
+ [this ,var,captureInfo, constant,init,initDC](SILFunction *f) {
1152
1153
preEmitFunction (constant, init, f, init);
1153
1154
PrettyStackTraceSILFunction X (" silgen emitStoredPropertyInitialization" , f);
1154
1155
f->createProfiler (init, constant, ForDefinition);
1155
- SILGenFunction (*this , *f, initDC)
1156
- .emitGeneratorFunction (constant, init, /* EmitProfilerIncrement=*/ true );
1156
+ SILGenFunction SGF (*this , *f, initDC);
1157
+
1158
+ // If this is a stored property initializer inside a type at global scope,
1159
+ // it may close over a global variable. If we're emitting top-level code,
1160
+ // then emit a "mark_function_escape" that lists the captured global
1161
+ // variables so that definite initialization can reason about this
1162
+ // escape point.
1163
+ if (!var->getDeclContext ()->isLocalContext () &&
1164
+ TopLevelSGF && TopLevelSGF->B .hasValidInsertionPoint ()) {
1165
+ emitMarkFunctionEscapeForTopLevelCodeGlobals (var, captureInfo);
1166
+ }
1167
+
1168
+ SGF.emitGeneratorFunction (constant, init, /* EmitProfilerIncrement=*/ true );
1157
1169
postEmitFunction (constant, f);
1158
1170
});
1159
1171
}
0 commit comments