Skip to content

Commit e64d810

Browse files
authored
Merge pull request swiftlang#14975 from graydon/batch-mode-bridging-pch-inputactions
[BatchMode] Collect InputActions correctly when merging jobs.
2 parents 3715464 + 2de60a4 commit e64d810

File tree

2 files changed

+30
-6
lines changed

2 files changed

+30
-6
lines changed

lib/Driver/ToolChain.cpp

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -242,15 +242,19 @@ makeBatchCommandOutput(ArrayRef<const Job *> jobs, Compilation &C,
242242
return output;
243243
}
244244

245-
/// Set-union the \c Inputs and \c Actions from each \c Job in \p jobs into the
246-
/// provided \p inputJobs and \p inputActions vectors, further adding all \c
247-
/// Actions from the resulting merger to \p batchCJA. Do set-union rather than
248-
/// concatenation here to avoid mentioning the same input multiple times.
245+
/// Set-union the \c Inputs and \c InputActions from each \c Job in \p jobs into
246+
/// the provided \p inputJobs and \p inputActions vectors, further adding all \c
247+
/// Actions in the \p jobs -- InputActions or otherwise -- to \p batchCJA. Do
248+
/// set-union rather than concatenation here to avoid mentioning the same input
249+
/// multiple times.
249250
static bool
250251
mergeBatchInputs(ArrayRef<const Job *> jobs,
251252
llvm::SmallSetVector<const Job *, 16> &inputJobs,
252253
llvm::SmallSetVector<const Action *, 16> &inputActions,
253254
CompileJobAction *batchCJA) {
255+
256+
llvm::SmallSetVector<const Action *, 16> allActions;
257+
254258
for (auto const *J : jobs) {
255259
for (auto const *I : J->getInputs()) {
256260
inputJobs.insert(I);
@@ -259,11 +263,18 @@ mergeBatchInputs(ArrayRef<const Job *> jobs,
259263
if (!CJA)
260264
return true;
261265
for (auto const *I : CJA->getInputs()) {
262-
inputActions.insert(I);
266+
// Capture _all_ input actions -- whether or not they are InputActions --
267+
// in allActions, to set as the inputs for batchCJA below.
268+
allActions.insert(I);
269+
// Only collect input actions that _are InputActions_ in the inputActions
270+
// array, to load into the JobContext in our caller.
271+
if (auto const *IA = dyn_cast<InputAction>(I)) {
272+
inputActions.insert(IA);
273+
}
263274
}
264275
}
265276

266-
for (auto const *I : inputActions) {
277+
for (auto const *I : allActions) {
267278
batchCJA->addInput(I);
268279
}
269280
return false;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: touch %t/file-01.swift %t/file-02.swift %t/file-03.swift
3+
// RUN: echo 'public func main() {}' >%t/main.swift
4+
// RUN: echo 'extern int foo;' >%t/foo-bridging-header.h
5+
//
6+
// RUN: %swiftc_driver -enable-bridging-pch -v -import-objc-header %t/foo-bridging-header.h -enable-batch-mode -c -emit-module -module-name main -j 2 %t/file-01.swift %t/file-02.swift %t/file-03.swift %t/main.swift %s 2>&1 | %FileCheck %s
7+
//
8+
// CHECK: -emit-pch
9+
// CHECK: -primary-file {{.*}}/file-01.swift -primary-file {{.*}}/file-02.swift
10+
11+
func bar() {
12+
print(foo)
13+
}

0 commit comments

Comments
 (0)