Skip to content

[Frontend] Track SwiftOnoneSupport as a system dependency #18344

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 31, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions include/swift/Frontend/FrontendOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,6 @@ class FrontendOptions {
EmitObject, ///< Emit object file
};

bool isCreatingSIL() { return RequestedAction >= ActionType::EmitSILGen; }

/// Indicates the action the user requested that the frontend perform.
ActionType RequestedAction = ActionType::NoneAction;

Expand Down Expand Up @@ -310,6 +308,7 @@ class FrontendOptions {
static bool canActionEmitInterface(ActionType);

public:
static bool doesActionRunSILPasses(ActionType);
static bool doesActionProduceOutput(ActionType);
static bool doesActionProduceTextualOutput(ActionType);
static bool needsProperModuleName(ActionType);
Expand Down
20 changes: 8 additions & 12 deletions lib/Frontend/Frontend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -401,13 +401,6 @@ static void addAdditionalInitialImportsTo(
SF->addImports(additionalImports);
}

static bool shouldImportSwiftOnoneModuleIfNoneOrImplicitOptimization(
FrontendOptions::ActionType RequestedAction) {
return RequestedAction == FrontendOptions::ActionType::EmitObject ||
RequestedAction == FrontendOptions::ActionType::Immediate ||
RequestedAction == FrontendOptions::ActionType::EmitSIL;
}

/// Implicitly import the SwiftOnoneSupport module in non-optimized
/// builds. This allows for use of popular specialized functions
/// from the standard library, which makes the non-optimized builds
Expand All @@ -420,11 +413,14 @@ shouldImplicityImportSwiftOnoneSupportModule(CompilerInvocation &Invocation) {
if (Invocation.getSILOptions().shouldOptimize())
return false;

if (shouldImportSwiftOnoneModuleIfNoneOrImplicitOptimization(
Invocation.getFrontendOptions().RequestedAction)) {
return true;
}
return Invocation.getFrontendOptions().isCreatingSIL();
// If we are not going through the SIL Optimizer with the
// given frontend action, do not load SwiftOnoneSupport.
//
// This optimization is disabled by -track-system-dependencies to preserve
// the explicit dependency.
const auto &options = Invocation.getFrontendOptions();
return options.TrackSystemDeps
|| FrontendOptions::doesActionRunSILPasses(options.RequestedAction);
}

void CompilerInstance::performParseAndResolveImportsOnly() {
Expand Down
33 changes: 33 additions & 0 deletions lib/Frontend/FrontendOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,39 @@ bool FrontendOptions::doesActionProduceTextualOutput(ActionType action) {
}
}

bool FrontendOptions::doesActionRunSILPasses(ActionType action) {
switch (action) {
case ActionType::NoneAction:
case ActionType::Parse:
case ActionType::ResolveImports:
case ActionType::Typecheck:
case ActionType::DumpParse:
case ActionType::DumpInterfaceHash:
case ActionType::EmitSyntax:
case ActionType::DumpAST:
case ActionType::PrintAST:
case ActionType::DumpScopeMaps:
case ActionType::DumpTypeRefinementContexts:
case ActionType::EmitImportedModules:
case ActionType::EmitPCH:
case ActionType::EmitSILGen:
return false;
case ActionType::EmitSIL:
case ActionType::EmitModuleOnly:
case ActionType::MergeModules:
case ActionType::EmitSIBGen:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're going to change behavior anyway, we may as well pull EmitSIBGen out of this list.

case ActionType::EmitSIB:
case ActionType::Immediate:
case ActionType::REPL:
case ActionType::EmitAssembly:
case ActionType::EmitIR:
case ActionType::EmitBC:
case ActionType::EmitObject:
return true;
}
}


const PrimarySpecificPaths &
FrontendOptions::getPrimarySpecificPathsForAtMostOnePrimary() const {
return InputsAndOutputs.getPrimarySpecificPathsForAtMostOnePrimary();
Expand Down
2 changes: 2 additions & 0 deletions test/Frontend/dependencies.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@

// CHECK-IMPORT-TRACK-SYSTEM-LABEL: - :
// CHECK-IMPORT-TRACK-SYSTEM: dependencies.swift
// CHECK-IMPORT-TRACK-SYSTEM-DAG: Swift.swiftmodule
// CHECK-IMPORT-TRACK-SYSTEM-DAG: SwiftOnoneSupport.swiftmodule
// CHECK-IMPORT-TRACK-SYSTEM-DAG: CoreFoundation.swift
// CHECK-IMPORT-TRACK-SYSTEM-DAG: CoreGraphics.swift
// CHECK-IMPORT-TRACK-SYSTEM-DAG: Foundation.swift
Expand Down