mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[TBDGen] Fix check for global accessors (#18883)
Previously, TBDGen skipped emitting lazy initializers for globals that appeared in any file with an entry point. This breaks, however on files that have an NSApplicationMain/UIApplicationMain class in them, where the entry point is synthesized but top-level globals are not locally scoped. This change re-uses SILGen's check and only skips variable declarations that appear at top level in a script mode file. Resolves rdar://43549749
This commit is contained in:
@@ -4481,6 +4481,27 @@ bool VarDecl::isSettable(const DeclContext *UseDC,
|
||||
return false;
|
||||
}
|
||||
|
||||
bool VarDecl::isLazilyInitializedGlobal() const {
|
||||
assert(!getDeclContext()->isLocalContext() &&
|
||||
"not a global variable!");
|
||||
assert(hasStorage() && "not a stored global variable!");
|
||||
|
||||
// Imports from C are never lazily initialized.
|
||||
if (hasClangNode())
|
||||
return false;
|
||||
|
||||
if (isDebuggerVar())
|
||||
return false;
|
||||
|
||||
// Top-level global variables in the main source file and in the REPL are not
|
||||
// lazily initialized.
|
||||
auto sourceFileContext = dyn_cast<SourceFile>(getDeclContext());
|
||||
if (!sourceFileContext)
|
||||
return true;
|
||||
|
||||
return !sourceFileContext->isScriptMode();
|
||||
}
|
||||
|
||||
bool SubscriptDecl::isSettable() const {
|
||||
return supportsMutation();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user