Skip to content

Commit 3defe3b

Browse files
committed
Refine The Frontend's Understanding of SwiftOnoneSupport
Continuing work from #18344, be more conservative about when we load SwiftOnoneSupport. Specifically, -emit-silgen and -emit-sibgen, despite not going through the SIL Optimizer, may silently introduce dependencies on SwiftOnoneSupport. Because we want to support the ability to posthumously compile SILGen and SIBGen'd files with these implicit dependencies, and because SIL is not yet capable of expressing the dependency itself, we must always assume we need to load SwiftOnoneSupport.
1 parent 571b29b commit 3defe3b

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
@@ -413,14 +413,21 @@ shouldImplicityImportSwiftOnoneSupportModule(CompilerInvocation &Invocation) {
413413
if (Invocation.getSILOptions().shouldOptimize())
414414
return false;
415415

416-
// If we are not going through the SIL Optimizer with the
417-
// given frontend action, do not load SwiftOnoneSupport.
416+
// If we are not executing an action that has a dependency on
417+
// SwiftOnoneSupport, don't load it.
418+
//
419+
// FIXME: Knowledge of SwiftOnoneSupport loading in the Frontend is a layering
420+
// violation. However, SIL currently does not have a way to express this
421+
// dependency itself for the benefit of autolinking. In the mean time, we
422+
// will be conservative and say that actions like -emit-silgen and
423+
// -emit-sibgen - that don't really involve the optimizer - have a
424+
// strict dependency on SwiftOnoneSupport.
418425
//
419426
// This optimization is disabled by -track-system-dependencies to preserve
420427
// the explicit dependency.
421428
const auto &options = Invocation.getFrontendOptions();
422429
return options.TrackSystemDeps
423-
|| FrontendOptions::doesActionRunSILPasses(options.RequestedAction);
430+
|| FrontendOptions::doesActionGenerateSIL(options.RequestedAction);
424431
}
425432

426433
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
@@ -996,7 +996,7 @@ static bool performCompile(CompilerInstance &Instance,
996996
if (writeTBDIfNeeded(Invocation, Instance))
997997
return true;
998998

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

10021002
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)