Skip to content

Revert "[Driver] Load the standard library before starting parallel frontend invocations" #26135

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
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
21 changes: 1 addition & 20 deletions include/swift/Driver/Action.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,9 @@ class Action {
GenerateDSYMJob,
VerifyDebugInfoJob,
GeneratePCHJob,
LoadModuleJob,

JobFirst = CompileJob,
JobLast = LoadModuleJob
JobLast = GeneratePCHJob
};

static const char *getClassName(Kind AC);
Expand Down Expand Up @@ -339,24 +338,6 @@ class StaticLinkJobAction : public JobAction {
}
};

/// An action that will attempt to load a specific module before any other
/// actions.
class LoadModuleJobAction : public JobAction {
virtual void anchor();
std::string moduleName;

public:
LoadModuleJobAction(StringRef moduleName)
: JobAction(Action::Kind::LoadModuleJob, {}, file_types::TY_Nothing),
moduleName(moduleName) {}

StringRef getModuleName() const { return moduleName; }

static bool classof(const Action *A) {
return A->getKind() == Action::Kind::LoadModuleJob;
}
};

} // end namespace driver
} // end namespace swift

Expand Down
3 changes: 0 additions & 3 deletions include/swift/Driver/ToolChain.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,6 @@ class ToolChain {
virtual InvocationInfo constructInvocation(const StaticLinkJobAction &job,
const JobContext &context) const;

virtual InvocationInfo constructInvocation(const LoadModuleJobAction &job,
const JobContext &context) const;

/// Searches for the given executable in appropriate paths relative to the
/// Swift binary.
///
Expand Down
3 changes: 0 additions & 3 deletions lib/Driver/Action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ const char *Action::getClassName(Kind AC) {
case Kind::GenerateDSYMJob: return "generate-dSYM";
case Kind::VerifyDebugInfoJob: return "verify-debug-info";
case Kind::GeneratePCHJob: return "generate-pch";
case Kind::LoadModuleJob: return "load-module";
}

llvm_unreachable("invalid class");
Expand Down Expand Up @@ -66,5 +65,3 @@ void GenerateDSYMJobAction::anchor() {}
void VerifyDebugInfoJobAction::anchor() {}

void GeneratePCHJobAction::anchor() {}

void LoadModuleJobAction::anchor() {}
46 changes: 4 additions & 42 deletions lib/Driver/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1731,25 +1731,6 @@ Driver::computeCompilerMode(const DerivedArgList &Args,
return OutputInfo::Mode::SingleCompile;
}

/// Determines whether the given set of inputs has multiple .swift, .sil, or
/// .sib inputs, which will require loading the standard library.
static bool hasMultipleSourceFileInputs(ArrayRef<InputPair> inputs) {
bool hasFoundOneSourceFileAlready = false;
for (const InputPair &input : inputs) {
switch (input.first) {
case file_types::TY_Swift:
case file_types::TY_SIL:
case file_types::TY_SIB:
if (hasFoundOneSourceFileAlready)
return true;
hasFoundOneSourceFileAlready = true;
break;
default: break;
}
}
return false;
}

void Driver::buildActions(SmallVectorImpl<const Action *> &TopLevelActions,
const ToolChain &TC, const OutputInfo &OI,
const InputInfoMap *OutOfDateMap,
Expand All @@ -1768,18 +1749,6 @@ void Driver::buildActions(SmallVectorImpl<const Action *> &TopLevelActions,
switch (OI.CompilerMode) {
case OutputInfo::Mode::StandardCompile: {

// If we're not compiling the standard library, and we're going to schedule
// multiple parallel compile jobs, add an action before any others that
// will quickly load the standard library module.
// This will ensure that, if we need to build the standard library from
// a module interface, it happens once, rather than once per parallel
// invocation.
LoadModuleJobAction *preLoadStdlib = nullptr;
if (!Args.hasArg(options::OPT_parse_stdlib) &&
hasMultipleSourceFileInputs(Inputs)) {
preLoadStdlib = C.createAction<LoadModuleJobAction>(STDLIB_NAME);
}

// If the user is importing a textual (.h) bridging header and we're in
// standard-compile (non-WMO) mode, we take the opportunity to precompile
// the header into a temporary PCH, and replace the import argument with the
Expand All @@ -1803,15 +1772,6 @@ void Driver::buildActions(SmallVectorImpl<const Action *> &TopLevelActions,
}
}

// Adds the implicit dependencies for this job action, either generating
// a PCH, or pre-loading the standard library, or both.
auto addImplicitDeps = [&](Action *action) {
if (PCH)
cast<JobAction>(action)->addInput(PCH);
if (preLoadStdlib)
cast<JobAction>(action)->addInput(preLoadStdlib);
};

for (const InputPair &Input : Inputs) {
file_types::ID InputType = Input.first;
const Arg *InputArg = Input.second;
Expand All @@ -1833,15 +1793,17 @@ void Driver::buildActions(SmallVectorImpl<const Action *> &TopLevelActions,
if (Args.hasArg(options::OPT_embed_bitcode)) {
Current = C.createAction<CompileJobAction>(
Current, file_types::TY_LLVM_BC, previousBuildState);
addImplicitDeps(Current);
if (PCH)
cast<JobAction>(Current)->addInput(PCH);
AllModuleInputs.push_back(Current);
Current = C.createAction<BackendJobAction>(Current,
OI.CompilerOutputType, 0);
} else {
Current = C.createAction<CompileJobAction>(Current,
OI.CompilerOutputType,
previousBuildState);
addImplicitDeps(Current);
if (PCH)
cast<JobAction>(Current)->addInput(PCH);
AllModuleInputs.push_back(Current);
}
AllLinkerInputs.push_back(Current);
Expand Down
7 changes: 1 addition & 6 deletions lib/Driver/Job.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -383,14 +383,9 @@ void Job::printSummary(raw_ostream &os) const {
if (const auto *IA = dyn_cast<InputAction>(A))
Inputs.push_back(IA->getInputArg().getValue());

for (const Job *J : getInputs()) {
// Some jobs might produce no output, so don't include them in the
// list of inputs.
if (J->getOutput().getPrimaryOutputType() == file_types::TY_Nothing)
continue;
for (const Job *J : getInputs())
for (StringRef f : J->getOutput().getPrimaryOutputFilenames())
Inputs.push_back(f);
}

size_t limit = 3;
size_t actual_in = Inputs.size();
Expand Down
24 changes: 2 additions & 22 deletions lib/Driver/ParseableOutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,27 +146,13 @@ class DetailedCommandBasedMessage : public CommandBasedMessage {
});
}

/// Subclasses can override this to determine if they should print empty
/// arrays for `inputs` and `output`, or if they can omit them.
virtual bool requireInputsAndOutputs() {
return false;
}

void provideMapping(swift::json::Output &out) override {
Message::provideMapping(out);
out.mapRequired("command", CommandLine); // Deprecated, do not document
out.mapRequired("command_executable", Executable);
out.mapRequired("command_arguments", Arguments);

// Some commands can choose to print empty arrays if their inputs and
// outputs are empty.
if (requireInputsAndOutputs()) {
out.mapRequired("inputs", Inputs);
out.mapRequired("outputs", Outputs);
} else {
out.mapOptional("inputs", Inputs);
out.mapOptional("outputs", Outputs);
}
out.mapOptional("inputs", Inputs);
out.mapOptional("outputs", Outputs);
}
};

Expand All @@ -191,12 +177,6 @@ class BeganMessage : public DetailedCommandBasedMessage {
: DetailedCommandBasedMessage("began", Cmd), Pid(Pid),
ProcInfo(ProcInfo) {}

bool requireInputsAndOutputs() override {
/// `began` messages should always print inputs and outputs, even if they
/// are empty.
return true;
}

void provideMapping(swift::json::Output &out) override {
DetailedCommandBasedMessage::provideMapping(out);
out.mapRequired("pid", Pid);
Expand Down
1 change: 0 additions & 1 deletion lib/Driver/ToolChain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ std::unique_ptr<Job> ToolChain::constructJob(
CASE(GeneratePCHJob)
CASE(AutolinkExtractJob)
CASE(REPLJob)
CASE(LoadModuleJob)
#undef CASE
case Action::Kind::Input:
llvm_unreachable("not a JobAction");
Expand Down
34 changes: 0 additions & 34 deletions lib/Driver/ToolChains.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1113,40 +1113,6 @@ ToolChain::constructInvocation(const StaticLinkJobAction &job,
llvm_unreachable("archiving not implemented for this toolchain");
}

ToolChain::InvocationInfo
ToolChain::constructInvocation(const LoadModuleJobAction &job,
const JobContext &context) const {

// Invoke the frontend, passing `-import-module ModuleName` for whatever
// module the job is supposed to load.

InvocationInfo II{SWIFT_EXECUTABLE_NAME};
ArgStringList &Arguments = II.Arguments;
II.allowsResponseFiles = true;

for (auto &s : getDriver().getSwiftProgramArgs())
Arguments.push_back(s.c_str());

Arguments.push_back("-frontend");
Arguments.push_back("-typecheck");

// Force importing the module that this job specifies.

Arguments.push_back("-import-module");
Arguments.push_back(context.Args.MakeArgString(job.getModuleName()));

// Pass along the relevant arguments to the frontend invocation.

addCommonFrontendArgs(*this, context.OI, context.Output, context.Args,
Arguments);

// Create an empty temporary file to typecheck.
auto tempFile = context.getTemporaryFilePath("tmp", "swift");
Arguments.push_back(context.Args.MakeArgString(tempFile));

return II;
}

void ToolChain::addPathEnvironmentVariableIfNeeded(
Job::EnvironmentVector &env, const char *name, const char *separator,
options::ID optionID, const ArgList &args,
Expand Down
5 changes: 0 additions & 5 deletions test/Driver/Dependencies/Inputs/fake-build-for-bitcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@

assert sys.argv[1] == '-frontend'

# If we're handling a frontend action that doesn't produce output or have a
# primary-file, (e.g. a -typecheck action), then don't do anything.
if '-primary-file' not in sys.argv or '-o' not in sys.argv:
sys.exit(0)

primaryFile = sys.argv[sys.argv.index('-primary-file') + 1]
outputFile = sys.argv[sys.argv.index('-o') + 1]

Expand Down
5 changes: 0 additions & 5 deletions test/Driver/Dependencies/Inputs/modify-non-primary-files.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@

assert sys.argv[1] == '-frontend'

# If we're handling a frontend action that doesn't produce output
# (e.g. a -typecheck action), then don't do anything.
if '-o' not in sys.argv:
sys.exit(0)

if '-primary-file' in sys.argv:
primaryFileIndex = sys.argv.index('-primary-file') + 1
primaryFile = sys.argv[primaryFileIndex]
Expand Down
5 changes: 0 additions & 5 deletions test/Driver/Dependencies/Inputs/update-dependencies-bad.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@

assert sys.argv[1] == '-frontend'

# If we don't have a -primary-file, for example if this is a -typecheck job,
# then don't do anything with this script.
if '-primary-file' not in sys.argv:
sys.exit(0)

primaryFile = sys.argv[sys.argv.index('-primary-file') + 1]

if (os.path.basename(primaryFile) == 'bad.swift' or
Expand Down
5 changes: 0 additions & 5 deletions test/Driver/Dependencies/Inputs/update-dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,6 @@

assert sys.argv[1] == '-frontend'

# If we're handling a frontend action that doesn't produce output
# (e.g. a -typecheck action), then don't do anything.
if '-o' not in sys.argv:
sys.exit(0)

# NB: The bitcode options automatically specify a -primary-file, even in cases
# where we do not wish to use a dependencies file in the test.
if '-primary-file' in sys.argv \
Expand Down
18 changes: 9 additions & 9 deletions test/Driver/Dependencies/bindings-build-record-options.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@
// RUN: cd %t && %swiftc_driver -c -module-name main -driver-print-bindings ./main.swift ./other.swift ./yet-another.swift -incremental -output-file-map %t/output.json 2>&1 | %FileCheck %s -check-prefix=MUST-EXEC-INITIAL

// MUST-EXEC-INITIAL-NOT: warning
// MUST-EXEC-INITIAL: inputs: ["./main.swift", ""], output: {{[{].*[}]}}, condition: run-without-cascading
// MUST-EXEC-INITIAL: inputs: ["./other.swift", ""], output: {{[{].*[}]}}, condition: run-without-cascading
// MUST-EXEC-INITIAL: inputs: ["./yet-another.swift", ""], output: {{[{].*[}]}}, condition: run-without-cascading
// MUST-EXEC-INITIAL: inputs: ["./main.swift"], output: {{[{].*[}]}}, condition: run-without-cascading
// MUST-EXEC-INITIAL: inputs: ["./other.swift"], output: {{[{].*[}]}}, condition: run-without-cascading
// MUST-EXEC-INITIAL: inputs: ["./yet-another.swift"], output: {{[{].*[}]}}, condition: run-without-cascading

// MUST-EXEC-ALL-NOT: warning
// MUST-EXEC-ALL: inputs: ["./main.swift", ""], output: {{[{].*[}]$}}
// MUST-EXEC-ALL: inputs: ["./other.swift", ""], output: {{[{].*[}]$}}
// MUST-EXEC-ALL: inputs: ["./yet-another.swift", ""], output: {{[{].*[}]$}}
// MUST-EXEC-ALL: inputs: ["./main.swift"], output: {{[{].*[}]$}}
// MUST-EXEC-ALL: inputs: ["./other.swift"], output: {{[{].*[}]$}}
// MUST-EXEC-ALL: inputs: ["./yet-another.swift"], output: {{[{].*[}]$}}

// RUN: cd %t && %swiftc_driver -c -module-name main -driver-use-frontend-path "%{python};%S/Inputs/update-dependencies.py" ./main.swift ./other.swift ./yet-another.swift -incremental -output-file-map %t/output.json
// RUN: cd %t && %swiftc_driver -c -module-name main -driver-print-bindings ./main.swift ./other.swift ./yet-another.swift -incremental -output-file-map %t/output.json 2>&1 | %FileCheck %s -check-prefix=NO-EXEC

// NO-EXEC: inputs: ["./main.swift", ""], output: {{[{].*[}]}}, condition: check-dependencies
// NO-EXEC: inputs: ["./other.swift", ""], output: {{[{].*[}]}}, condition: check-dependencies
// NO-EXEC: inputs: ["./yet-another.swift", ""], output: {{[{].*[}]}}, condition: check-dependencies
// NO-EXEC: inputs: ["./main.swift"], output: {{[{].*[}]}}, condition: check-dependencies
// NO-EXEC: inputs: ["./other.swift"], output: {{[{].*[}]}}, condition: check-dependencies
// NO-EXEC: inputs: ["./yet-another.swift"], output: {{[{].*[}]}}, condition: check-dependencies


// RUN: cd %t && %swiftc_driver -c -module-name main -driver-print-bindings -serialize-diagnostics ./main.swift ./other.swift ./yet-another.swift -incremental -output-file-map %t/output.json 2>&1 | %FileCheck %s -check-prefix=NO-EXEC
Expand Down
36 changes: 18 additions & 18 deletions test/Driver/Dependencies/bindings-build-record.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,48 +6,48 @@
// RUN: cd %t && %swiftc_driver -driver-print-bindings ./main.swift ./other.swift ./yet-another.swift -incremental -output-file-map %t/output.json 2>&1 | %FileCheck %s -check-prefix=MUST-EXEC

// MUST-EXEC-NOT: warning
// MUST-EXEC: inputs: ["./main.swift", ""], output: {{[{].*[}]}}, condition: run-without-cascading
// MUST-EXEC: inputs: ["./other.swift", ""], output: {{[{].*[}]}}, condition: run-without-cascading
// MUST-EXEC: inputs: ["./yet-another.swift", ""], output: {{[{].*[}]}}, condition: run-without-cascading
// MUST-EXEC: inputs: ["./main.swift"], output: {{[{].*[}]}}, condition: run-without-cascading
// MUST-EXEC: inputs: ["./other.swift"], output: {{[{].*[}]}}, condition: run-without-cascading
// MUST-EXEC: inputs: ["./yet-another.swift"], output: {{[{].*[}]}}, condition: run-without-cascading

// RUN: echo '{version: "'$(%swiftc_driver_plain -version | head -n1)'", inputs: {"./main.swift": [443865900, 0], "./other.swift": [443865900, 0], "./yet-another.swift": [443865900, 0]}, build_time: [443865901, 0]}' > %t/main~buildrecord.swiftdeps
// RUN: cd %t && %swiftc_driver -driver-print-bindings ./main.swift ./other.swift ./yet-another.swift -incremental -output-file-map %t/output.json 2>&1 | %FileCheck %s -check-prefix=NO-EXEC

// NO-EXEC: inputs: ["./main.swift", ""], output: {{[{].*[}]}}, condition: check-dependencies
// NO-EXEC: inputs: ["./other.swift", ""], output: {{[{].*[}]}}, condition: check-dependencies
// NO-EXEC: inputs: ["./yet-another.swift", ""], output: {{[{].*[}]}}, condition: check-dependencies
// NO-EXEC: inputs: ["./main.swift"], output: {{[{].*[}]}}, condition: check-dependencies
// NO-EXEC: inputs: ["./other.swift"], output: {{[{].*[}]}}, condition: check-dependencies
// NO-EXEC: inputs: ["./yet-another.swift"], output: {{[{].*[}]}}, condition: check-dependencies


// RUN: echo '{version: "'$(%swiftc_driver_plain -version | head -n1)'", inputs: {"./main.swift": [443865900, 0], "./other.swift": !private [443865900, 0], "./yet-another.swift": !dirty [443865900, 0]}, build_time: [443865901, 0]}' > %t/main~buildrecord.swiftdeps
// RUN: cd %t && %swiftc_driver -driver-print-bindings ./main.swift ./other.swift ./yet-another.swift -incremental -output-file-map %t/output.json 2>&1 | %FileCheck %s -check-prefix=BUILD-RECORD

// BUILD-RECORD: inputs: ["./main.swift", ""], output: {{[{].*[}]}}, condition: check-dependencies{{$}}
// BUILD-RECORD: inputs: ["./other.swift", ""], output: {{[{].*[}]}}, condition: run-without-cascading{{$}}
// BUILD-RECORD: inputs: ["./yet-another.swift", ""], output: {{[{].*[}]$}}
// BUILD-RECORD: inputs: ["./main.swift"], output: {{[{].*[}]}}, condition: check-dependencies{{$}}
// BUILD-RECORD: inputs: ["./other.swift"], output: {{[{].*[}]}}, condition: run-without-cascading{{$}}
// BUILD-RECORD: inputs: ["./yet-another.swift"], output: {{[{].*[}]$}}

// RUN: cd %t && %swiftc_driver -driver-print-bindings ./main.swift ./other.swift ./yet-another.swift ./added.swift -incremental -output-file-map %t/output.json 2>&1 > %t/added.txt
// RUN: %FileCheck %s -check-prefix=BUILD-RECORD < %t/added.txt
// RUN: %FileCheck %s -check-prefix=FILE-ADDED < %t/added.txt

// FILE-ADDED: inputs: ["./added.swift", ""], output: {{[{].*[}]}}, condition: newly-added{{$}}
// FILE-ADDED: inputs: ["./added.swift"], output: {{[{].*[}]}}, condition: newly-added{{$}}

// RUN: %{python} %S/Inputs/touch.py 443865960 %t/main.swift
// RUN: cd %t && %swiftc_driver -driver-print-bindings ./main.swift ./other.swift ./yet-another.swift -incremental -output-file-map %t/output.json 2>&1 | %FileCheck %s -check-prefix=BUILD-RECORD-PLUS-CHANGE
// BUILD-RECORD-PLUS-CHANGE: inputs: ["./main.swift", ""], output: {{[{].*[}]}}, condition: run-without-cascading
// BUILD-RECORD-PLUS-CHANGE: inputs: ["./other.swift", ""], output: {{[{].*[}]}}, condition: run-without-cascading{{$}}
// BUILD-RECORD-PLUS-CHANGE: inputs: ["./yet-another.swift", ""], output: {{[{].*[}]$}}
// BUILD-RECORD-PLUS-CHANGE: inputs: ["./main.swift"], output: {{[{].*[}]}}, condition: run-without-cascading
// BUILD-RECORD-PLUS-CHANGE: inputs: ["./other.swift"], output: {{[{].*[}]}}, condition: run-without-cascading{{$}}
// BUILD-RECORD-PLUS-CHANGE: inputs: ["./yet-another.swift"], output: {{[{].*[}]$}}

// RUN: %{python} %S/Inputs/touch.py 443865900 %t/*
// RUN: cd %t && %swiftc_driver -driver-print-bindings ./main.swift ./other.swift -incremental -output-file-map %t/output.json 2>&1 | %FileCheck %s -check-prefix=FILE-REMOVED
// FILE-REMOVED: inputs: ["./main.swift", ""], output: {{[{].*[}]$}}
// FILE-REMOVED: inputs: ["./other.swift", ""], output: {{[{].*[}]$}}
// FILE-REMOVED: inputs: ["./main.swift"], output: {{[{].*[}]$}}
// FILE-REMOVED: inputs: ["./other.swift"], output: {{[{].*[}]$}}
// FILE-REMOVED-NOT: yet-another.swift


// RUN: echo '{version: "bogus", inputs: {"./main.swift": [443865900, 0], "./other.swift": !private [443865900, 0], "./yet-another.swift": !dirty [443865900, 0]}}' > %t/main~buildrecord.swiftdeps
// RUN: cd %t && %swiftc_driver -driver-print-bindings ./main.swift ./other.swift ./yet-another.swift -incremental -output-file-map %t/output.json 2>&1 | %FileCheck %s -check-prefix=INVALID-RECORD

// INVALID-RECORD-NOT: warning
// INVALID-RECORD: inputs: ["./main.swift", ""], output: {{[{].*[}]$}}
// INVALID-RECORD: inputs: ["./other.swift", ""], output: {{[{].*[}]$}}
// INVALID-RECORD: inputs: ["./yet-another.swift", ""], output: {{[{].*[}]$}}
// INVALID-RECORD: inputs: ["./main.swift"], output: {{[{].*[}]$}}
// INVALID-RECORD: inputs: ["./other.swift"], output: {{[{].*[}]$}}
// INVALID-RECORD: inputs: ["./yet-another.swift"], output: {{[{].*[}]$}}
Loading