[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:
Harlan
2018-08-21 18:22:59 -07:00
committed by GitHub
parent 98e95bdbef
commit 096e6adb3f
6 changed files with 46 additions and 34 deletions

View File

@@ -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();
}