Skip to content

Commit 501a5ef

Browse files
authored
Merge pull request #18410 from CodaFi/in-sib-id-attitudes
Refine The Frontend's Understanding of SwiftOnoneSupport
2 parents 203a253 + 3defe3b commit 501a5ef

File tree

6 files changed

+48
-10
lines changed

6 files changed

+48
-10
lines changed

include/swift/Frontend/FrontendOptions.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ class FrontendOptions {
310310
static bool canActionEmitInterface(ActionType);
311311

312312
public:
313-
static bool doesActionRunSILPasses(ActionType);
313+
static bool doesActionGenerateSIL(ActionType);
314314
static bool doesActionProduceOutput(ActionType);
315315
static bool doesActionProduceTextualOutput(ActionType);
316316
static bool needsProperModuleName(ActionType);

lib/Frontend/Frontend.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -463,14 +463,21 @@ shouldImplicityImportSwiftOnoneSupportModule(CompilerInvocation &Invocation) {
463463
if (Invocation.getSILOptions().shouldOptimize())
464464
return false;
465465

466-
// If we are not going through the SIL Optimizer with the
467-
// given frontend action, do not load SwiftOnoneSupport.
466+
// If we are not executing an action that has a dependency on
467+
// SwiftOnoneSupport, don't load it.
468+
//
469+
// FIXME: Knowledge of SwiftOnoneSupport loading in the Frontend is a layering
470+
// violation. However, SIL currently does not have a way to express this
471+
// dependency itself for the benefit of autolinking. In the mean time, we
472+
// will be conservative and say that actions like -emit-silgen and
473+
// -emit-sibgen - that don't really involve the optimizer - have a
474+
// strict dependency on SwiftOnoneSupport.
468475
//
469476
// This optimization is disabled by -track-system-dependencies to preserve
470477
// the explicit dependency.
471478
const auto &options = Invocation.getFrontendOptions();
472479
return options.TrackSystemDeps
473-
|| FrontendOptions::doesActionRunSILPasses(options.RequestedAction);
480+
|| FrontendOptions::doesActionGenerateSIL(options.RequestedAction);
474481
}
475482

476483
void CompilerInstance::performParseAndResolveImportsOnly() {

lib/Frontend/FrontendOptions.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ bool FrontendOptions::doesActionProduceTextualOutput(ActionType action) {
465465
}
466466
}
467467

468-
bool FrontendOptions::doesActionRunSILPasses(ActionType action) {
468+
bool FrontendOptions::doesActionGenerateSIL(ActionType action) {
469469
switch (action) {
470470
case ActionType::NoneAction:
471471
case ActionType::Parse:
@@ -478,22 +478,22 @@ bool FrontendOptions::doesActionRunSILPasses(ActionType action) {
478478
case ActionType::PrintAST:
479479
case ActionType::DumpScopeMaps:
480480
case ActionType::DumpTypeRefinementContexts:
481-
case ActionType::DumpTypeInfo:
482481
case ActionType::EmitImportedModules:
483482
case ActionType::EmitPCH:
484-
case ActionType::EmitSILGen:
485483
return false;
484+
case ActionType::EmitSILGen:
485+
case ActionType::EmitSIBGen:
486486
case ActionType::EmitSIL:
487+
case ActionType::EmitSIB:
487488
case ActionType::EmitModuleOnly:
488489
case ActionType::MergeModules:
489-
case ActionType::EmitSIBGen:
490-
case ActionType::EmitSIB:
491490
case ActionType::Immediate:
492491
case ActionType::REPL:
493492
case ActionType::EmitAssembly:
494493
case ActionType::EmitIR:
495494
case ActionType::EmitBC:
496495
case ActionType::EmitObject:
496+
case ActionType::DumpTypeInfo:
497497
return true;
498498
}
499499
}

lib/FrontendTool/FrontendTool.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -997,7 +997,7 @@ static bool performCompile(CompilerInstance &Instance,
997997
if (writeTBDIfNeeded(Invocation, Instance))
998998
return true;
999999

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

10031003
std::deque<PostSILGenInputs> PSGIs = generateSILModules(Invocation, Instance);

test/Driver/emit-sib-single-file.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
// CHECK: Hello World
1919
// CHECK: Hello Bob, today is Tuesday.
2020

21+
// This test intentionally mirrors /Driver/emit-sil-single-file to ensure that
22+
// SwiftOnoneSupport is always a dependency of -Onone -emit-si*gen builds.
23+
2124
@inlinable
2225
@usableFromInline
2326
func greet(_ name: String, _ day: String) -> String {
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// RUN: %target-build-swift -Onone -emit-silgen %s -o %t.sil
2+
// RUN: %target-build-swift -parse-sil %t.sil -o %t
3+
// RUN: %target-run %t | %FileCheck %s
4+
5+
// RUN: %target-build-swift -Onone -c %t.sil -o %t.o
6+
// RUN: %target-build-swift %t.o -o %t
7+
// RUN: %target-run %t | %FileCheck %s
8+
// REQUIRES: executable_test
9+
10+
// CHECK: Hello World
11+
// CHECK: Hello Bob, today is Tuesday.
12+
13+
// This test intentionally mirrors /Driver/emit-sib-single-file to ensure that
14+
// SwiftOnoneSupport is always a dependency of -Onone -emit-si*gen builds.
15+
16+
// FIXME: The Frontend's understanding of the situations in which to load
17+
// SwiftOnoneSupport is a tacit part of the rest of the compile pipeline and
18+
// pervades the AST. SIL could probably sink knowledge of module dependencies
19+
// internally and make this test unnecessary.
20+
21+
@inlinable
22+
@usableFromInline
23+
func greet(_ name: String, _ day: String) -> String {
24+
return "Hello \(name), today is \(day)."
25+
}
26+
27+
print("Hello World")
28+
print(greet("Bob", "Tuesday"))

0 commit comments

Comments
 (0)