Skip to content

Commit 3cba230

Browse files
author
David Ungar
committed
Moving tests and driver refactoring.
1 parent 98dcc5e commit 3cba230

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+969
-216
lines changed

include/swift/Driver/Compilation.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ class Compilation {
286286
const bool EnableSourceRangeDependencies;
287287

288288
/// May not actually use them if e.g. there is a new input
289-
bool UseSourceRangeDependencies = false;
289+
bool UseSourceRangeDependencies;
290290

291291
public:
292292
/// Will contain a comparator if an argument demands it.

include/swift/Driver/ExperimentalDependencyDriverGraph.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ class ModuleDepGraph {
313313
/// Record a new (to this graph) Job.
314314
void addIndependentNode(const driver::Job *);
315315

316-
std::vector<std::string> getExternalDependencies() const;
316+
std::vector<StringRef> getExternalDependencies() const;
317317

318318
void markExternal(SmallVectorImpl<const driver::Job *> &uses,
319319
StringRef externalDependency);

lib/Driver/Compilation.cpp

Lines changed: 298 additions & 209 deletions
Large diffs are not rendered by default.

lib/Driver/ExperimentalDependencyDriverGraph.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,9 @@ void ModuleDepGraph::addIndependentNode(const Job *job) {
133133
jobsBySwiftDeps.insert(std::make_pair(getSwiftDeps(job), job));
134134
}
135135

136-
std::vector<std::string> ModuleDepGraph::getExternalDependencies() const {
137-
return std::vector<std::string>(externalDependencies.begin(),
138-
externalDependencies.end());
136+
std::vector<StringRef> ModuleDepGraph::getExternalDependencies() const {
137+
return std::vector<StringRef>(externalDependencies.begin(),
138+
externalDependencies.end());
139139
}
140140

141141
// Add every (swiftdeps) use of the external dependency to uses.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
func func1InA() {
2+
_ = Struct1InB()
3+
print(3)
4+
}
5+
func func2InA() {
6+
_ = 3423
7+
}
8+
func func3InA() {}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
### Swift dependencies file v0 ###
2+
provides-top-level:
3+
- "func1InA"
4+
- "func2InA"
5+
- "func3InA"
6+
provides-nominal:
7+
provides-member:
8+
provides-dynamic-lookup:
9+
depends-top-level:
10+
- "AssignmentPrecedence"
11+
- !private "FloatLiteralType"
12+
- !private "IntegerLiteralType"
13+
- !private "Struct1InB"
14+
- "func1InA"
15+
- "func2InA"
16+
- "func3InA"
17+
- !private "print"
18+
depends-member:
19+
- !private ["4main10Struct1InBV", "init"]
20+
depends-nominal:
21+
- !private "4main10Struct1InBV"
22+
depends-dynamic-lookup:
23+
depends-external:
24+
- "/Users/ungar/s/exp-dep-3/build/Ninja-DebugAssert/swift-macosx-x86_64/lib/swift/macosx/Swift.swiftmodule/x86_64.swiftmodule"
25+
- "/Users/ungar/s/exp-dep-3/build/Ninja-DebugAssert/swift-macosx-x86_64/lib/swift/macosx/SwiftOnoneSupport.swiftmodule/x86_64.swiftmodule"
26+
- "./imported.swiftmodule"
27+
interface-hash: "4e340eb9a7fef5aa22a4edfb8db0f783"
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
struct Struct1InB { // used by A
2+
// asdf
3+
var instVar1 = 0
4+
var instVar2 = 0
5+
func watchMe<T: SignedInteger>(_: T) -> String {"SignedInteger"}
6+
}
7+
struct Struct2InB { // not used
8+
var instVar1 = 0
9+
var instVar2 = 0
10+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
struct Struct1InB { // used by A
2+
// asdf
3+
var instVar1 = 0
4+
var instVar2 = 0
5+
func watchMe<T: SignedInteger>(_: T) -> String {"SignedInteger"}
6+
}
7+
struct Struct2InB { // not used
8+
var instVar1 = 0
9+
var instVar2 = 0
10+
var addedVar = "hooha"
11+
}

test/Driver/SourceRanges/Inputs/disjoint-exposes-flaw/imported.swiftmodule

Whitespace-only changes.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
private var privateInMain = 33
2+
// watchMe will get more and more specific
3+
// By running the program at various stages, one can see if the incrementality
4+
// is correct.
5+
func watchMe(_: Any) -> String {"Any"}
6+
print ("watchMe is", watchMe(17))
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"./main.swift": {
3+
"object": "./main.o",
4+
"swift-dependencies": "./main.swiftdeps"
5+
},
6+
"./fileA.swift": {
7+
"object": "./fileA.o",
8+
"swift-dependencies": "./fileA.swiftdeps"
9+
},
10+
"./fileB.swift": {
11+
"object": "./fileB.o",
12+
"swift-dependencies": "./fileB.swiftdeps"
13+
},
14+
"./fileC.swift": {
15+
"object": "./fileC.o",
16+
"swift-dependencies": "./fileC.swiftdeps"
17+
},
18+
"": {
19+
"swift-dependencies": "./main~buildrecord.swiftdeps"
20+
}
21+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
func func1InA() {
2+
_ = Struct1InB()
3+
print(3)
4+
}
5+
func func2InA() {
6+
_ = 3423
7+
}
8+
func func3InA() {}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
### Swift dependencies file v0 ###
2+
provides-top-level:
3+
- "func1InA"
4+
- "func2InA"
5+
- "func3InA"
6+
provides-nominal:
7+
provides-member:
8+
provides-dynamic-lookup:
9+
depends-top-level:
10+
- "AssignmentPrecedence"
11+
- !private "FloatLiteralType"
12+
- !private "IntegerLiteralType"
13+
- !private "Struct1InB"
14+
- "func1InA"
15+
- "func2InA"
16+
- "func3InA"
17+
- !private "print"
18+
depends-member:
19+
- !private ["4main10Struct1InBV", "init"]
20+
depends-nominal:
21+
- !private "4main10Struct1InBV"
22+
depends-dynamic-lookup:
23+
depends-external:
24+
- "/Users/ungar/s/exp-dep-3/build/Ninja-DebugAssert/swift-macosx-x86_64/lib/swift/macosx/Swift.swiftmodule/x86_64.swiftmodule"
25+
- "/Users/ungar/s/exp-dep-3/build/Ninja-DebugAssert/swift-macosx-x86_64/lib/swift/macosx/SwiftOnoneSupport.swiftmodule/x86_64.swiftmodule"
26+
- "./imported.swiftmodule"
27+
interface-hash: "4e340eb9a7fef5aa22a4edfb8db0f783"
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
struct Struct1InB { // used by A
2+
// asdf
3+
var instVar1 = 0
4+
var instVar2 = 0
5+
func watchMe<T: SignedInteger>(_: T) -> String {"SignedInteger"}
6+
}
7+
struct Struct2InB { // not used
8+
var instVar1 = 0
9+
var instVar2 = 0
10+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
struct Struct1InB { // used by A
2+
// asdf
3+
var instVar1 = 0
4+
var instVar2 = 0
5+
func watchMe<T: SignedInteger>(_: T) -> String {"SignedInteger"}
6+
}
7+
struct Struct2InB { // not used
8+
var instVar1 = 0
9+
var instVar2 = 0
10+
var addedVar = "hooha"
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
struct Struct1InB { // used by A
2+
// asdf
3+
var instVar1 = 0
4+
var instVar2 = 0
5+
func watchMe<T: SignedInteger>(_: T) -> String {"SignedInteger"}
6+
}
7+
struct Struct2InB { // not used
8+
var instVar1: Int {return 3}
9+
var instVar2 = 0
10+
var addedVar = "hooha"
11+
}

test/Driver/SourceRanges/Inputs/disjoint/imported.swiftmodule

Whitespace-only changes.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
private var privateInMain = 33
2+
// watchMe will get more and more specific
3+
// By running the program at various stages, one can see if the incrementality
4+
// is correct.
5+
func watchMe(_: Any) -> String {"Any"}
6+
print ("watchMe is", watchMe(17))
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"./main.swift": {
3+
"object": "./main.o",
4+
"swift-dependencies": "./main.swiftdeps"
5+
},
6+
"./fileA.swift": {
7+
"object": "./fileA.o",
8+
"swift-dependencies": "./fileA.swiftdeps"
9+
},
10+
"./fileB.swift": {
11+
"object": "./fileB.o",
12+
"swift-dependencies": "./fileB.swiftdeps"
13+
},
14+
"./fileC.swift": {
15+
"object": "./fileC.o",
16+
"swift-dependencies": "./fileC.swiftdeps"
17+
},
18+
"": {
19+
"swift-dependencies": "./main~buildrecord.swiftdeps"
20+
}
21+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// Test to verify disjointedness of dependency- and source-range-dependency graphs.
2+
// If they are not disjoint, then an external dependency on a file that would be
3+
// compiled anyway by dependencies gets marked, and then source-ranges fails
4+
// to pick up the external dependency, because it's already marked.
5+
6+
7+
8+
// RUN: %empty-directory(%t)
9+
// RUN: cp -r %S/Inputs/disjoint-exposes-flaw/* %t
10+
11+
// =============================================================================
12+
// Create the supplementary outputs & build record
13+
// =============================================================================
14+
15+
// RUN: cd %t && %swiftc_driver -driver-compare-incremental-schemes -enable-source-range-dependencies -output-file-map %t/output.json -incremental -enable-batch-mode ./main.swift ./fileA.swift ./fileB.swift -module-name main -j2 -driver-show-job-lifecycle -driver-show-incremental >& %t/output1
16+
17+
// RUN: %FileCheck -match-full-lines -check-prefix=CHECK-1 %s < %t/output1
18+
// CHECK-1: Adding non-batch job to task queue: {compile: main.o <= main.swift}
19+
// CHECK-1: Adding non-batch job to task queue: {compile: fileA.o <= fileA.swift}
20+
// CHECK-1: Adding non-batch job to task queue: {compile: fileB.o <= fileB.swift}
21+
// CHECK-1: Adding non-batch job to task queue: {link: main <= main.o fileA.o fileB.o}
22+
// CHECK-1: Added to TaskQueue: {link: main <= main.o fileA.o fileB.o}
23+
// CHECK-1: *** Incremental build disabled because could not read build record, cannot compare ***
24+
25+
26+
// =============================================================================
27+
// Modify fileB.swift; dependency-scheme will compile fileA.swift,
28+
// source ranges won't.
29+
// =============================================================================
30+
31+
// RUN: cp %S/Inputs/disjoint-exposes-flaw/fileA.swiftdeps %t
32+
// RUN: cp %S/Inputs/disjoint-exposes-flaw/fileB2.swift %t/fileB.swift
33+
34+
// RUN: cd %t && %swiftc_driver -driver-compare-incremental-schemes -enable-source-range-dependencies -output-file-map %t/output.json -incremental -enable-batch-mode ./main.swift ./fileA.swift ./fileB.swift -module-name main -j2 -driver-show-job-lifecycle -driver-show-incremental >& %t/output2
35+
// RUN: %FileCheck -match-full-lines -check-prefix=CHECK-2 %s < %t/output2
36+
// CHECK-2: Hypothetically: Skipping <Dependencies> file is up-to-date and output exists: {compile: main.o <= main.swift}
37+
// CHECK-2: Hypothetically: Skipping <Dependencies> file is up-to-date and output exists: {compile: fileA.o <= fileA.swift}
38+
// CHECK-2: Hypothetically: Queuing <Dependencies> (initial): {compile: fileB.o <= fileB.swift}
39+
// CHECK-2: Skipping <Ranges> nothing that this file parsed changed in any other file: {compile: main.o <= main.swift}
40+
// CHECK-2: Skipping <Ranges> nothing that this file parsed changed in any other file: {compile: fileA.o <= fileA.swift}
41+
// CHECK-2: Queuing <Ranges> (this file changed): {compile: fileB.o <= fileB.swift}
42+
// CHECK-2: Using ranges
43+
// CHECK-2: After completion of {compile: fileB.o <= fileB.swift}:
44+
// CHECK-2: - Dependencies would now schedule: {compile: fileA.o <= fileA.swift}
45+
// CHECK-2: *** Range benefit: 1 compilations, 1 stages, deps: 2, ranges: 1, total: 3, requested: ranges, used: ranges ***
46+
47+
// RUN: %FileCheck -match-full-lines -check-prefix=CHECK-2A %s < %t/output2
48+
// CHECK-2A-NOT: Queuing <Ranges> {{.*}}{compile: fileA.o <= fileA.swift}
49+
50+
51+
// =============================================================================
52+
// Modify fileB.swift again, and external dependency.
53+
// dependency-scheme will compile fileA.swift,
54+
// source ranges should, too.
55+
// =============================================================================
56+
57+
// RUN: cp %S/Inputs/disjoint-exposes-flaw/{fileA.swiftdeps,fileB.swift,imported.swiftmodule} %t
58+
// RUN: cd %t && %swiftc_driver -driver-compare-incremental-schemes -enable-source-range-dependencies -output-file-map %t/output.json -incremental -enable-batch-mode ./main.swift ./fileA.swift ./fileB.swift -module-name main -j2 -driver-show-job-lifecycle -driver-show-incremental >& %t/output3
59+
60+
// RUN: %FileCheck -match-full-lines -check-prefix=CHECK-3 %s < %t/output3
61+
// CHECK-3: Hypothetically: Skipping <Dependencies> file is up-to-date and output exists: {compile: main.o <= main.swift}
62+
// CHECK-3: Hypothetically: Skipping <Dependencies> file is up-to-date and output exists: {compile: fileA.o <= fileA.swift}
63+
// CHECK-3: Hypothetically: Queuing <Dependencies> (initial): {compile: fileB.o <= fileB.swift}
64+
// CHECK-3: Hypothetically: Queuing <Dependencies> because of external dependencies: {compile: fileA.o <= fileA.swift}
65+
// CHECK-3: Queuing <Ranges> (changed: fileB.swift:[10:1--10:25)): {compile: main.o <= main.swift}
66+
// CHECK-3: Queuing <Ranges> (this file changed): {compile: fileB.o <= fileB.swift}
67+
// CHECK-3: Skipping <Ranges> already have swiftdeps, source-range, and compiled-source files.: {compile: main.o <= main.swift}
68+
// CHECK-3: Skipping <Ranges> already have swiftdeps, source-range, and compiled-source files.: {compile: fileA.o <= fileA.swift}
69+
// CHECK-3: Skipping <Ranges> already have swiftdeps, source-range, and compiled-source files.: {compile: fileB.o <= fileB.swift}
70+
// CHECK-3: Queuing <Ranges> because of external dependencies: {compile: fileA.o <= fileA.swift}
71+
// CHECK-3: *** Range benefit: 0 compilations, 0 stages, deps: 2, ranges (falling back): 2, total: 3, requested: ranges, used: deps ***
72+
73+
// RUN: %FileCheck -match-full-lines -check-prefix=CHECK-3A %s < %t/output3
74+
// CHECK-3A-NOT: Queuing <Ranges> (changed: fileB.swift:{{.*}}): {compile: fileA.o <= fileA.swift}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// Test to verify disjointedness of dependency- and source-range-dependency graphs.
2+
// If they are not disjoint, then an external dependency on a file that would be
3+
// compiled anyway by dependencies gets marked, and then source-ranges fails
4+
// to pick up the external dependency, because it's already marked.
5+
6+
7+
8+
// RUN: %empty-directory(%t)
9+
// RUN: cp -r %S/Inputs/disjoint/* %t
10+
11+
// =============================================================================
12+
// Create the supplementary outputs & build record
13+
// =============================================================================
14+
15+
// RUN: cd %t && %swiftc_driver -driver-compare-incremental-schemes -enable-source-range-dependencies -output-file-map %t/output.json -incremental -enable-batch-mode ./main.swift ./fileA.swift ./fileB.swift -module-name main -j2 -driver-show-job-lifecycle -driver-show-incremental >& %t/output1
16+
17+
// RUN: %FileCheck -match-full-lines -check-prefix=CHECK-1 %s < %t/output1
18+
// CHECK-1: Adding non-batch job to task queue: {compile: main.o <= main.swift}
19+
// CHECK-1: Adding non-batch job to task queue: {compile: fileA.o <= fileA.swift}
20+
// CHECK-1: Adding non-batch job to task queue: {compile: fileB.o <= fileB.swift}
21+
// CHECK-1: Adding non-batch job to task queue: {link: main <= main.o fileA.o fileB.o}
22+
// CHECK-1: Added to TaskQueue: {link: main <= main.o fileA.o fileB.o}
23+
// CHECK-1: *** Incremental build disabled because could not read build record, cannot compare ***
24+
25+
26+
// =============================================================================
27+
// Modify fileB.swift; dependency-scheme will compile fileA.swift,
28+
// source ranges won't.
29+
// =============================================================================
30+
31+
// RUN: cp %S/Inputs/disjoint/fileA.swiftdeps %t
32+
// RUN: cp %S/Inputs/disjoint/fileB2.swift %t/fileB.swift
33+
34+
// RUN: cd %t && %swiftc_driver -driver-compare-incremental-schemes -enable-source-range-dependencies -output-file-map %t/output.json -incremental -enable-batch-mode ./main.swift ./fileA.swift ./fileB.swift -module-name main -j2 -driver-show-job-lifecycle -driver-show-incremental >& %t/output2
35+
// RUN: %FileCheck -match-full-lines -check-prefix=CHECK-2 %s < %t/output2
36+
// CHECK-2: Hypothetically: Skipping <Dependencies> file is up-to-date and output exists: {compile: main.o <= main.swift}
37+
// CHECK-2: Hypothetically: Skipping <Dependencies> file is up-to-date and output exists: {compile: fileA.o <= fileA.swift}
38+
// CHECK-2: Hypothetically: Queuing <Dependencies> (initial): {compile: fileB.o <= fileB.swift}
39+
// CHECK-2: Skipping <Ranges> nothing that this file parsed changed in any other file: {compile: main.o <= main.swift}
40+
// CHECK-2: Skipping <Ranges> nothing that this file parsed changed in any other file: {compile: fileA.o <= fileA.swift}
41+
// CHECK-2: Queuing <Ranges> (this file changed): {compile: fileB.o <= fileB.swift}
42+
// CHECK-2: Using ranges
43+
// CHECK-2: After completion of {compile: fileB.o <= fileB.swift}:
44+
// CHECK-2: - Dependencies would now schedule: {compile: fileA.o <= fileA.swift}
45+
// CHECK-2: *** Range benefit: 1 compilations, 1 stages, deps: 2, ranges: 1, total: 3, requested: ranges, used: ranges ***
46+
47+
// RUN: %FileCheck -match-full-lines -check-prefix=CHECK-2A %s < %t/output2
48+
// CHECK-2A-NOT: Queuing <Ranges> {{.*}}{compile: fileA.o <= fileA.swift}
49+
50+
51+
// =============================================================================
52+
// Modify fileB.swift again, and external dependency.
53+
// dependency-scheme will compile fileA.swift,
54+
// source ranges should, too.
55+
// =============================================================================
56+
57+
// RUN: cp %S/Inputs/disjoint/{fileA.swiftdeps,imported.swiftmodule} %t
58+
// RUN: cp %S/Inputs/disjoint/fileB3.swift %t/fileB.swift
59+
// RUN: cd %t && %swiftc_driver -driver-compare-incremental-schemes -enable-source-range-dependencies -output-file-map %t/output.json -incremental -enable-batch-mode ./main.swift ./fileA.swift ./fileB.swift -module-name main -j2 -driver-show-job-lifecycle -driver-show-incremental >& %t/output3
60+
61+
// RUN: %FileCheck -match-full-lines -check-prefix=CHECK-3 %s < %t/output3
62+
// CHECK-3: Hypothetically: Skipping <Dependencies> file is up-to-date and output exists: {compile: main.o <= main.swift}
63+
// CHECK-3: Hypothetically: Skipping <Dependencies> file is up-to-date and output exists: {compile: fileA.o <= fileA.swift}
64+
// CHECK-3: Hypothetically: Queuing <Dependencies> (initial): {compile: fileB.o <= fileB.swift}
65+
// CHECK-3: Hypothetically: Queuing <Dependencies> because of external dependencies: {compile: fileA.o <= fileA.swift}
66+
// CHECK-3: Queuing <Ranges> (this file changed): {compile: fileB.o <= fileB.swift}
67+
// CHECK-3: Queuing <Ranges> because of external dependencies: {compile: fileA.o <= fileA.swift}
68+
// CHECK-3: *** Range benefit: 0 compilations, 0 stages, deps: 2, ranges: 2, total: 3, requested: ranges, used: ranges ***
69+
70+
// RUN: %FileCheck -match-full-lines -check-prefix=CHECK-3A %s < %t/output3
71+
// CHECK-3A-NOT: Queuing <Ranges> (changed: fileB.swift:{{.*}}): {compile: fileA.o <= fileA.swift}

0 commit comments

Comments
 (0)