Skip to content

Refine The Frontend's Understanding of SwiftOnoneSupport #18410

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
Aug 1, 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
2 changes: 1 addition & 1 deletion include/swift/Frontend/FrontendOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ class FrontendOptions {
static bool canActionEmitInterface(ActionType);

public:
static bool doesActionRunSILPasses(ActionType);
static bool doesActionGenerateSIL(ActionType);
static bool doesActionProduceOutput(ActionType);
static bool doesActionProduceTextualOutput(ActionType);
static bool needsProperModuleName(ActionType);
Expand Down
13 changes: 10 additions & 3 deletions lib/Frontend/Frontend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -413,14 +413,21 @@ shouldImplicityImportSwiftOnoneSupportModule(CompilerInvocation &Invocation) {
if (Invocation.getSILOptions().shouldOptimize())
return false;

// If we are not going through the SIL Optimizer with the
// given frontend action, do not load SwiftOnoneSupport.
// If we are not executing an action that has a dependency on
// SwiftOnoneSupport, don't load it.
//
// FIXME: Knowledge of SwiftOnoneSupport loading in the Frontend is a layering
// violation. However, SIL currently does not have a way to express this
// dependency itself for the benefit of autolinking. In the mean time, we
// will be conservative and say that actions like -emit-silgen and
// -emit-sibgen - that don't really involve the optimizer - have a
// strict dependency on 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);
|| FrontendOptions::doesActionGenerateSIL(options.RequestedAction);
}

void CompilerInstance::performParseAndResolveImportsOnly() {
Expand Down
10 changes: 5 additions & 5 deletions lib/Frontend/FrontendOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ bool FrontendOptions::doesActionProduceTextualOutput(ActionType action) {
}
}

bool FrontendOptions::doesActionRunSILPasses(ActionType action) {
bool FrontendOptions::doesActionGenerateSIL(ActionType action) {
switch (action) {
case ActionType::NoneAction:
case ActionType::Parse:
Expand All @@ -478,22 +478,22 @@ bool FrontendOptions::doesActionRunSILPasses(ActionType action) {
case ActionType::PrintAST:
case ActionType::DumpScopeMaps:
case ActionType::DumpTypeRefinementContexts:
case ActionType::DumpTypeInfo:
case ActionType::EmitImportedModules:
case ActionType::EmitPCH:
case ActionType::EmitSILGen:
return false;
case ActionType::EmitSILGen:
case ActionType::EmitSIBGen:
case ActionType::EmitSIL:
case ActionType::EmitSIB:
case ActionType::EmitModuleOnly:
case ActionType::MergeModules:
case ActionType::EmitSIBGen:
case ActionType::EmitSIB:
case ActionType::Immediate:
case ActionType::REPL:
case ActionType::EmitAssembly:
case ActionType::EmitIR:
case ActionType::EmitBC:
case ActionType::EmitObject:
case ActionType::DumpTypeInfo:
return true;
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/FrontendTool/FrontendTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -996,7 +996,7 @@ static bool performCompile(CompilerInstance &Instance,
if (writeTBDIfNeeded(Invocation, Instance))
return true;

assert(Action >= FrontendOptions::ActionType::EmitSILGen &&
assert(FrontendOptions::doesActionGenerateSIL(Action) &&
"All actions not requiring SILGen must have been handled!");

std::deque<PostSILGenInputs> PSGIs = generateSILModules(Invocation, Instance);
Expand Down
3 changes: 3 additions & 0 deletions test/Driver/emit-sib-single-file.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
// CHECK: Hello World
// CHECK: Hello Bob, today is Tuesday.

// This test intentionally mirrors /Driver/emit-sil-single-file to ensure that
// SwiftOnoneSupport is always a dependency of -Onone -emit-si*gen builds.

@inlinable
@usableFromInline
func greet(_ name: String, _ day: String) -> String {
Expand Down
28 changes: 28 additions & 0 deletions test/Driver/emit-sil-single-file.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// RUN: %target-build-swift -Onone -emit-silgen %s -o %t.sil
// RUN: %target-build-swift -parse-sil %t.sil -o %t
// RUN: %target-run %t | %FileCheck %s

// RUN: %target-build-swift -Onone -c %t.sil -o %t.o
// RUN: %target-build-swift %t.o -o %t
// RUN: %target-run %t | %FileCheck %s
// REQUIRES: executable_test

// CHECK: Hello World
// CHECK: Hello Bob, today is Tuesday.

// This test intentionally mirrors /Driver/emit-sib-single-file to ensure that
// SwiftOnoneSupport is always a dependency of -Onone -emit-si*gen builds.

// FIXME: The Frontend's understanding of the situations in which to load
// SwiftOnoneSupport is a tacit part of the rest of the compile pipeline and
// pervades the AST. SIL could probably sink knowledge of module dependencies
// internally and make this test unnecessary.

@inlinable
@usableFromInline
func greet(_ name: String, _ day: String) -> String {
return "Hello \(name), today is \(day)."
}

print("Hello World")
print(greet("Bob", "Tuesday"))