Skip to content

[Bridging PCH] Move dependency-on-bridging-PCH to -emit-bc JobAction … #10736

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
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
38 changes: 23 additions & 15 deletions lib/Driver/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1300,6 +1300,27 @@ void Driver::buildOutputInfo(const ToolChain &TC, const DerivedArgList &Args,
OI.SelectedSanitizer);
}

static void
currentDependsOnPCHIfPresent(JobAction *PCH,
std::unique_ptr<Action> &Current,
ActionList &Actions) {
if (PCH) {
// FIXME: When we have a PCH job, it's officially owned by the Actions
// array; but it's also a secondary input to each of the current
// JobActions, which means that we need to flip the "owns inputs" bit
// on the JobActions so they don't try to free it. That in turn means
// we need to transfer ownership of all the JobActions' existing
// inputs to the Actions array, since the JobActions either own or
// don't own _all_ of their inputs. Ownership can't vary
// input-by-input.
auto *job = cast<JobAction>(Current.get());
auto inputs = job->getInputs();
Actions.append(inputs.begin(), inputs.end());
job->setOwnsInputs(false);
job->addInput(PCH);
}
}

void Driver::buildActions(const ToolChain &TC,
const DerivedArgList &Args,
const InputFileList &Inputs,
Expand Down Expand Up @@ -1364,30 +1385,17 @@ void Driver::buildActions(const ToolChain &TC,
Current.reset(new CompileJobAction(Current.release(),
types::TY_LLVM_BC,
previousBuildState));
currentDependsOnPCHIfPresent(PCH, Current, Actions);
AllModuleInputs.push_back(Current.get());
Current.reset(new BackendJobAction(Current.release(),
OI.CompilerOutputType, 0));
} else {
Current.reset(new CompileJobAction(Current.release(),
OI.CompilerOutputType,
previousBuildState));
currentDependsOnPCHIfPresent(PCH, Current, Actions);
AllModuleInputs.push_back(Current.get());
}
if (PCH) {
// FIXME: When we have a PCH job, it's officially owned by the Actions
// array; but it's also a secondary input to each of the current
// JobActions, which means that we need to flip the "owns inputs" bit
// on the JobActions so they don't try to free it. That in turn means
// we need to transfer ownership of all the JobActions' existing
// inputs to the Actions array, since the JobActions either own or
// don't own _all_ of their inputs. Ownership can't vary
// input-by-input.
auto *job = cast<JobAction>(Current.get());
auto inputs = job->getInputs();
Actions.append(inputs.begin(), inputs.end());
job->setOwnsInputs(false);
job->addInput(PCH);
}
AllLinkerInputs.push_back(Current.release());
break;
}
Expand Down
6 changes: 6 additions & 0 deletions test/Driver/bridging-pch.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@
// PERSISTENT-YESPCHACT: 2: input, "{{.*}}bridging-pch.swift", swift
// PERSISTENT-YESPCHACT: 3: compile, {2, 1}, none

// RUN: %swiftc_driver -c -driver-print-actions -embed-bitcode -import-objc-header %S/Inputs/bridging-header.h -pch-output-dir %t/pch %s 2>&1 | %FileCheck %s -check-prefix=PERSISTENT-YESPCHACTBC
// PERSISTENT-YESPCHACTBC: 0: input, "{{.*}}Inputs/bridging-header.h", objc-header
// PERSISTENT-YESPCHACTBC: 1: generate-pch, {0}, none
// PERSISTENT-YESPCHACTBC: 2: input, "{{.*}}bridging-pch.swift", swift
// PERSISTENT-YESPCHACTBC: 3: compile, {2, 1}, llvm-bc

// RUN: %swiftc_driver -typecheck -disable-bridging-pch -driver-print-actions -import-objc-header %S/Inputs/bridging-header.h -pch-output-dir %t/pch %s 2>&1 | %FileCheck %s -check-prefix=NOPCHACT

// RUN: %swiftc_driver -typecheck -driver-print-jobs -import-objc-header %S/Inputs/bridging-header.h -pch-output-dir %t/pch -disable-bridging-pch %s 2>&1 | %FileCheck %s -check-prefix=PERSISTENT-DISABLED-YESPCHJOB
Expand Down