Skip to content

Commit d4ff453

Browse files
committed
[Bridging PCH] Move dependency-on-bridging-PCH to -emit-bc JobAction itself.
1 parent e4fbb38 commit d4ff453

File tree

2 files changed

+29
-15
lines changed

2 files changed

+29
-15
lines changed

lib/Driver/Driver.cpp

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1329,6 +1329,27 @@ void Driver::buildOutputInfo(const ToolChain &TC, const DerivedArgList &Args,
13291329
OI.SelectedSanitizer);
13301330
}
13311331

1332+
static void
1333+
currentDependsOnPCHIfPresent(JobAction *PCH,
1334+
std::unique_ptr<Action> &Current,
1335+
ActionList &Actions) {
1336+
if (PCH) {
1337+
// FIXME: When we have a PCH job, it's officially owned by the Actions
1338+
// array; but it's also a secondary input to each of the current
1339+
// JobActions, which means that we need to flip the "owns inputs" bit
1340+
// on the JobActions so they don't try to free it. That in turn means
1341+
// we need to transfer ownership of all the JobActions' existing
1342+
// inputs to the Actions array, since the JobActions either own or
1343+
// don't own _all_ of their inputs. Ownership can't vary
1344+
// input-by-input.
1345+
auto *job = cast<JobAction>(Current.get());
1346+
auto inputs = job->getInputs();
1347+
Actions.append(inputs.begin(), inputs.end());
1348+
job->setOwnsInputs(false);
1349+
job->addInput(PCH);
1350+
}
1351+
}
1352+
13321353
void Driver::buildActions(const ToolChain &TC,
13331354
const DerivedArgList &Args,
13341355
const InputFileList &Inputs,
@@ -1393,30 +1414,17 @@ void Driver::buildActions(const ToolChain &TC,
13931414
Current.reset(new CompileJobAction(Current.release(),
13941415
types::TY_LLVM_BC,
13951416
previousBuildState));
1417+
currentDependsOnPCHIfPresent(PCH, Current, Actions);
13961418
AllModuleInputs.push_back(Current.get());
13971419
Current.reset(new BackendJobAction(Current.release(),
13981420
OI.CompilerOutputType, 0));
13991421
} else {
14001422
Current.reset(new CompileJobAction(Current.release(),
14011423
OI.CompilerOutputType,
14021424
previousBuildState));
1425+
currentDependsOnPCHIfPresent(PCH, Current, Actions);
14031426
AllModuleInputs.push_back(Current.get());
14041427
}
1405-
if (PCH) {
1406-
// FIXME: When we have a PCH job, it's officially owned by the Actions
1407-
// array; but it's also a secondary input to each of the current
1408-
// JobActions, which means that we need to flip the "owns inputs" bit
1409-
// on the JobActions so they don't try to free it. That in turn means
1410-
// we need to transfer ownership of all the JobActions' existing
1411-
// inputs to the Actions array, since the JobActions either own or
1412-
// don't own _all_ of their inputs. Ownership can't vary
1413-
// input-by-input.
1414-
auto *job = cast<JobAction>(Current.get());
1415-
auto inputs = job->getInputs();
1416-
Actions.append(inputs.begin(), inputs.end());
1417-
job->setOwnsInputs(false);
1418-
job->addInput(PCH);
1419-
}
14201428
AllLinkerInputs.push_back(Current.release());
14211429
break;
14221430
}

test/Driver/bridging-pch.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@
3232
// PERSISTENT-YESPCHACT: 2: input, "{{.*}}bridging-pch.swift", swift
3333
// PERSISTENT-YESPCHACT: 3: compile, {2, 1}, none
3434

35+
// 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
36+
// PERSISTENT-YESPCHACTBC: 0: input, "{{.*}}Inputs/bridging-header.h", objc-header
37+
// PERSISTENT-YESPCHACTBC: 1: generate-pch, {0}, none
38+
// PERSISTENT-YESPCHACTBC: 2: input, "{{.*}}bridging-pch.swift", swift
39+
// PERSISTENT-YESPCHACTBC: 3: compile, {2, 1}, llvm-bc
40+
3541
// 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
3642

3743
// 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

0 commit comments

Comments
 (0)