Skip to content

Commit 6239326

Browse files
author
ematejska
authored
Merge pull request #10735 from graydon/rdar-32984579-emit-bc-depends-on-bridging-pch-as-well-swift-4.0-branch
[Bridging PCH] Move dependency-on-bridging-PCH to -emit-bc JobAction itself.
2 parents e7095cb + 3a9508d commit 6239326

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
@@ -1311,6 +1311,27 @@ void Driver::buildOutputInfo(const ToolChain &TC, const DerivedArgList &Args,
13111311
OI.SelectedSanitizer);
13121312
}
13131313

1314+
static void
1315+
currentDependsOnPCHIfPresent(JobAction *PCH,
1316+
std::unique_ptr<Action> &Current,
1317+
ActionList &Actions) {
1318+
if (PCH) {
1319+
// FIXME: When we have a PCH job, it's officially owned by the Actions
1320+
// array; but it's also a secondary input to each of the current
1321+
// JobActions, which means that we need to flip the "owns inputs" bit
1322+
// on the JobActions so they don't try to free it. That in turn means
1323+
// we need to transfer ownership of all the JobActions' existing
1324+
// inputs to the Actions array, since the JobActions either own or
1325+
// don't own _all_ of their inputs. Ownership can't vary
1326+
// input-by-input.
1327+
auto *job = cast<JobAction>(Current.get());
1328+
auto inputs = job->getInputs();
1329+
Actions.append(inputs.begin(), inputs.end());
1330+
job->setOwnsInputs(false);
1331+
job->addInput(PCH);
1332+
}
1333+
}
1334+
13141335
void Driver::buildActions(const ToolChain &TC,
13151336
const DerivedArgList &Args,
13161337
const InputFileList &Inputs,
@@ -1375,30 +1396,17 @@ void Driver::buildActions(const ToolChain &TC,
13751396
Current.reset(new CompileJobAction(Current.release(),
13761397
types::TY_LLVM_BC,
13771398
previousBuildState));
1399+
currentDependsOnPCHIfPresent(PCH, Current, Actions);
13781400
AllModuleInputs.push_back(Current.get());
13791401
Current.reset(new BackendJobAction(Current.release(),
13801402
OI.CompilerOutputType, 0));
13811403
} else {
13821404
Current.reset(new CompileJobAction(Current.release(),
13831405
OI.CompilerOutputType,
13841406
previousBuildState));
1407+
currentDependsOnPCHIfPresent(PCH, Current, Actions);
13851408
AllModuleInputs.push_back(Current.get());
13861409
}
1387-
if (PCH) {
1388-
// FIXME: When we have a PCH job, it's officially owned by the Actions
1389-
// array; but it's also a secondary input to each of the current
1390-
// JobActions, which means that we need to flip the "owns inputs" bit
1391-
// on the JobActions so they don't try to free it. That in turn means
1392-
// we need to transfer ownership of all the JobActions' existing
1393-
// inputs to the Actions array, since the JobActions either own or
1394-
// don't own _all_ of their inputs. Ownership can't vary
1395-
// input-by-input.
1396-
auto *job = cast<JobAction>(Current.get());
1397-
auto inputs = job->getInputs();
1398-
Actions.append(inputs.begin(), inputs.end());
1399-
job->setOwnsInputs(false);
1400-
job->addInput(PCH);
1401-
}
14021410
AllLinkerInputs.push_back(Current.release());
14031411
break;
14041412
}

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)