Separated out the Onone module handling from stdlib handling

Also refactored the Onone module predicate. I believe there is no functional change, but I don't understand the correctness of what was there.
This commit is contained in:
David Ungar
2017-09-07 14:48:37 -07:00
parent 249718e1bd
commit add13798be
3 changed files with 26 additions and 20 deletions

View File

@@ -449,7 +449,7 @@ public:
void freeContextAndSIL(); void freeContextAndSIL();
private: private:
bool loadStdlibAndMaybeSwiftOnoneSupport(); bool loadStdlib();
ModuleDecl *importUnderlyingModule(); ModuleDecl *importUnderlyingModule();
ModuleDecl *importBridgingHeader(); ModuleDecl *importBridgingHeader();

View File

@@ -195,6 +195,15 @@ public:
EmitObject, ///< Emit object file EmitObject, ///< Emit object file
}; };
bool isCreatingSIL() { return RequestedAction >= EmitSILGen; }
bool shouldImportSwiftOnoneModuleIfNoneOrImplicitOptimization() {
return
RequestedAction == EmitObject ||
RequestedAction == Immediate ||
RequestedAction == EmitSIL;
}
/// Indicates the action the user requested that the frontend perform. /// Indicates the action the user requested that the frontend perform.
ActionType RequestedAction = NoneAction; ActionType RequestedAction = NoneAction;

View File

@@ -294,15 +294,15 @@ addAdditionalInitialImportsTo(SourceFile *SF, CompilerInstance::ImplicitImports
/// builds. This allows for use of popular specialized functions /// builds. This allows for use of popular specialized functions
/// from the standard library, which makes the non-optimized builds /// from the standard library, which makes the non-optimized builds
/// execute much faster. /// execute much faster.
static bool shouldImplicityImportSwiftOnoneSupportModule( static bool shouldImplicityImportSwiftOnoneSupportModule(CompilerInvocation &Invocation) {
SILOptions::SILOptMode optimization, if (Invocation.getImplicitModuleImportKind() != SourceFile::ImplicitModuleImportKind::Stdlib)
FrontendOptions::ActionType requestedAction) { return false;
return ((optimization <= SILOptions::SILOptMode::None && SILOptions::SILOptMode optimization = Invocation.getSILOptions().Optimization;
(requestedAction == FrontendOptions::EmitObject || if (optimization <= SILOptions::SILOptMode::None &&
requestedAction == FrontendOptions::Immediate || Invocation.getFrontendOptions().shouldImportSwiftOnoneModuleIfNoneOrImplicitOptimization()) {
requestedAction == FrontendOptions::EmitSIL)) || return true;
(optimization == SILOptions::SILOptMode::None && }
requestedAction >= FrontendOptions::EmitSILGen)); return optimization == SILOptions::SILOptMode::None && Invocation.getFrontendOptions().isCreatingSIL();
} }
void CompilerInstance::performSema() { void CompilerInstance::performSema() {
@@ -316,9 +316,12 @@ void CompilerInstance::performSema() {
} }
if (Invocation.getImplicitModuleImportKind() == SourceFile::ImplicitModuleImportKind::Stdlib) { if (Invocation.getImplicitModuleImportKind() == SourceFile::ImplicitModuleImportKind::Stdlib) {
if (!loadStdlibAndMaybeSwiftOnoneSupport()) if (!loadStdlib())
return; return;
} }
if (shouldImplicityImportSwiftOnoneSupportModule(Invocation)) {
Invocation.getFrontendOptions().ImplicitImportModuleNames.push_back(SWIFT_ONONE_SUPPORT);
}
ImplicitImports implicitImports(*this); ImplicitImports implicitImports(*this);
@@ -359,8 +362,8 @@ CompilerInstance::ImplicitImports::ImplicitImports(CompilerInstance &compiler) {
} }
// Return true if should continue, i.e. no error // Return true if should continue, i.e. no error
bool CompilerInstance::loadStdlibAndMaybeSwiftOnoneSupport() { bool CompilerInstance::loadStdlib() {
SharedTimer timer("performSema-loadStdlibAndMaybeSwiftOnoneSupport"); SharedTimer timer("performSema-loadStdlib");
ModuleDecl *M = Context->getStdlibModule(true); ModuleDecl *M = Context->getStdlibModule(true);
if (!M) { if (!M) {
@@ -375,12 +378,6 @@ bool CompilerInstance::loadStdlibAndMaybeSwiftOnoneSupport() {
"Module failed to load but nothing was diagnosed?"); "Module failed to load but nothing was diagnosed?");
return false; return false;
} }
if (shouldImplicityImportSwiftOnoneSupportModule(
Invocation.getSILOptions().Optimization,
Invocation.getFrontendOptions().RequestedAction)) {
Invocation.getFrontendOptions().ImplicitImportModuleNames.push_back(
SWIFT_ONONE_SUPPORT);
}
return true; return true;
} }