@@ -52,9 +52,11 @@ class SILGlobalVariable
5252 // / The SIL module that the global variable belongs to.
5353 SILModule &Module;
5454
55- // / The module that defines this global variable. This member should only be
56- // / when a global variable is deserialized to be emitted into another module.
57- ModuleDecl *ParentModule = nullptr ;
55+ // / Either the declaration context of the global variable or the parent
56+ // / module in which the global variable resides.
57+ // /
58+ // / The latter is only used for a deserialized global variable.
59+ llvm::PointerUnion<DeclContext *, ModuleDecl *> DeclCtxOrParentModule;
5860
5961 // / The mangled name of the variable, which will be propagated to the
6062 // / binary. A pointer into the module's lookup table.
@@ -131,13 +133,21 @@ class SILGlobalVariable
131133
132134 SILModule &getModule () const { return Module; }
133135
134- // / Returns the module that defines this function .
136+ // / Returns the module that defines this global variable .
135137 ModuleDecl *getParentModule () const ;
136138
137- // / Sets \c ParentModule as fallback if \c DeclCtxt is not available to
138- // / provide the parent module.
139+ // / Get the declaration context of this global variable, if it has one.
140+ DeclContext *getDeclContext () const ;
141+
142+ // / Sets the parent module for a deserialized global variable.
139143 void setParentModule (ModuleDecl *module ) {
140- ParentModule = module ;
144+ DeclCtxOrParentModule = module ;
145+ }
146+
147+ // / Sets the declaration context for a global variable that's not anchored to
148+ // / a declaration.
149+ void setDeclContext (DeclContext *declCtx) {
150+ DeclCtxOrParentModule = declCtx;
141151 }
142152
143153 SILType getLoweredType () const { return LoweredType; }
0 commit comments