Skip to content

Commit f74d61f

Browse files
authored
Merge pull request #18344 from CodaFi/unseen-university
[Frontend] Track SwiftOnoneSupport as a system dependency
2 parents f3ae03d + 0a3731d commit f74d61f

File tree

4 files changed

+44
-14
lines changed

4 files changed

+44
-14
lines changed

include/swift/Frontend/FrontendOptions.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,6 @@ class FrontendOptions {
141141
EmitObject, ///< Emit object file
142142
};
143143

144-
bool isCreatingSIL() { return RequestedAction >= ActionType::EmitSILGen; }
145-
146144
/// Indicates the action the user requested that the frontend perform.
147145
ActionType RequestedAction = ActionType::NoneAction;
148146

@@ -310,6 +308,7 @@ class FrontendOptions {
310308
static bool canActionEmitInterface(ActionType);
311309

312310
public:
311+
static bool doesActionRunSILPasses(ActionType);
313312
static bool doesActionProduceOutput(ActionType);
314313
static bool doesActionProduceTextualOutput(ActionType);
315314
static bool needsProperModuleName(ActionType);

lib/Frontend/Frontend.cpp

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -401,13 +401,6 @@ static void addAdditionalInitialImportsTo(
401401
SF->addImports(additionalImports);
402402
}
403403

404-
static bool shouldImportSwiftOnoneModuleIfNoneOrImplicitOptimization(
405-
FrontendOptions::ActionType RequestedAction) {
406-
return RequestedAction == FrontendOptions::ActionType::EmitObject ||
407-
RequestedAction == FrontendOptions::ActionType::Immediate ||
408-
RequestedAction == FrontendOptions::ActionType::EmitSIL;
409-
}
410-
411404
/// Implicitly import the SwiftOnoneSupport module in non-optimized
412405
/// builds. This allows for use of popular specialized functions
413406
/// from the standard library, which makes the non-optimized builds
@@ -420,11 +413,14 @@ shouldImplicityImportSwiftOnoneSupportModule(CompilerInvocation &Invocation) {
420413
if (Invocation.getSILOptions().shouldOptimize())
421414
return false;
422415

423-
if (shouldImportSwiftOnoneModuleIfNoneOrImplicitOptimization(
424-
Invocation.getFrontendOptions().RequestedAction)) {
425-
return true;
426-
}
427-
return Invocation.getFrontendOptions().isCreatingSIL();
416+
// If we are not going through the SIL Optimizer with the
417+
// given frontend action, do not load SwiftOnoneSupport.
418+
//
419+
// This optimization is disabled by -track-system-dependencies to preserve
420+
// the explicit dependency.
421+
const auto &options = Invocation.getFrontendOptions();
422+
return options.TrackSystemDeps
423+
|| FrontendOptions::doesActionRunSILPasses(options.RequestedAction);
428424
}
429425

430426
void CompilerInstance::performParseAndResolveImportsOnly() {

lib/Frontend/FrontendOptions.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,39 @@ bool FrontendOptions::doesActionProduceTextualOutput(ActionType action) {
454454
}
455455
}
456456

457+
bool FrontendOptions::doesActionRunSILPasses(ActionType action) {
458+
switch (action) {
459+
case ActionType::NoneAction:
460+
case ActionType::Parse:
461+
case ActionType::ResolveImports:
462+
case ActionType::Typecheck:
463+
case ActionType::DumpParse:
464+
case ActionType::DumpInterfaceHash:
465+
case ActionType::EmitSyntax:
466+
case ActionType::DumpAST:
467+
case ActionType::PrintAST:
468+
case ActionType::DumpScopeMaps:
469+
case ActionType::DumpTypeRefinementContexts:
470+
case ActionType::EmitImportedModules:
471+
case ActionType::EmitPCH:
472+
case ActionType::EmitSILGen:
473+
return false;
474+
case ActionType::EmitSIL:
475+
case ActionType::EmitModuleOnly:
476+
case ActionType::MergeModules:
477+
case ActionType::EmitSIBGen:
478+
case ActionType::EmitSIB:
479+
case ActionType::Immediate:
480+
case ActionType::REPL:
481+
case ActionType::EmitAssembly:
482+
case ActionType::EmitIR:
483+
case ActionType::EmitBC:
484+
case ActionType::EmitObject:
485+
return true;
486+
}
487+
}
488+
489+
457490
const PrimarySpecificPaths &
458491
FrontendOptions::getPrimarySpecificPathsForAtMostOnePrimary() const {
459492
return InputsAndOutputs.getPrimarySpecificPathsForAtMostOnePrimary();

test/Frontend/dependencies.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@
5959

6060
// CHECK-IMPORT-TRACK-SYSTEM-LABEL: - :
6161
// CHECK-IMPORT-TRACK-SYSTEM: dependencies.swift
62+
// CHECK-IMPORT-TRACK-SYSTEM-DAG: Swift.swiftmodule
63+
// CHECK-IMPORT-TRACK-SYSTEM-DAG: SwiftOnoneSupport.swiftmodule
6264
// CHECK-IMPORT-TRACK-SYSTEM-DAG: CoreFoundation.swift
6365
// CHECK-IMPORT-TRACK-SYSTEM-DAG: CoreGraphics.swift
6466
// CHECK-IMPORT-TRACK-SYSTEM-DAG: Foundation.swift

0 commit comments

Comments
 (0)