Skip to content

Commit 36247f2

Browse files
author
David Ungar
committed
Step 1: Isolate the map to be replaced
1 parent bcc9a3b commit 36247f2

File tree

2 files changed

+48
-14
lines changed

2 files changed

+48
-14
lines changed

Sources/SwiftDriver/IncrementalCompilation/ModuleDependencyGraph.swift

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,7 @@ import SwiftOptions
2424
@_spi(Testing) public var nodeFinder = NodeFinder()
2525

2626
/// Maps input files (e.g. .swift) to and from the DependencySource object.
27-
///
28-
// FIXME: The map between swiftdeps and swift files is absolutely *not*
29-
// a bijection. In particular, more than one swiftdeps file can be encountered
30-
// in the course of deserializing priors *and* reading the output file map
31-
// *and* re-reading swiftdeps files after frontends complete
32-
// that correspond to the same swift file. These cause two problems:
33-
// - overwrites in this data structure that lose data and
34-
// - cache misses in `getInput(for:)` that cause the incremental build to
35-
// turn over when e.g. entries in the output file map change. This should be
36-
// replaced by a multi-map from swift files to dependency sources,
37-
// and a regular map from dependency sources to swift files -
38-
// since that direction really is one-to-one.
39-
@_spi(Testing) public private(set) var inputDependencySourceMap = BidirectionalMap<TypedVirtualPath, DependencySource>()
27+
@_spi(Testing) public private(set) var inputDependencySourceMap = InputDependencySourceMap()
4028

4129
// The set of paths to external dependencies known to be in the graph
4230
public internal(set) var fingerprintedExternalDependencies = Set<FingerprintedExternalDependency>()
@@ -1111,7 +1099,7 @@ extension Set where Element == ModuleDependencyGraph.Node {
11111099
}
11121100
}
11131101

1114-
extension BidirectionalMap where T1 == TypedVirtualPath, T2 == DependencySource {
1102+
extension InputDependencySourceMap {
11151103
fileprivate func matches(_ other: Self) -> Bool {
11161104
self == other
11171105
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
//===------------- InputDependencySourceMap.swift ---------------- --------===//
2+
// This source file is part of the Swift.org open source project
3+
//
4+
// Copyright (c) 2021 Apple Inc. and the Swift project authors
5+
// Licensed under Apache License v2.0 with Runtime Library Exception
6+
//
7+
// See https://swift.org/LICENSE.txt for license information
8+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
9+
//
10+
//===----------------------------------------------------------------------===//
11+
import Foundation
12+
13+
@_spi(Testing) public struct InputDependencySourceMap: Equatable, Sequence {
14+
15+
/// Maps input files (e.g. .swift) to and from the DependencySource object.
16+
///
17+
// FIXME: The map between swiftdeps and swift files is absolutely *not*
18+
// a bijection. In particular, more than one swiftdeps file can be encountered
19+
// in the course of deserializing priors *and* reading the output file map
20+
// *and* re-reading swiftdeps files after frontends complete
21+
// that correspond to the same swift file. These cause two problems:
22+
// - overwrites in this data structure that lose data and
23+
// - cache misses in `getInput(for:)` that cause the incremental build to
24+
// turn over when e.g. entries in the output file map change. This should be
25+
// replaced by a multi-map from swift files to dependency sources,
26+
// and a regular map from dependency sources to swift files -
27+
// since that direction really is one-to-one.
28+
29+
public typealias BiMap = BidirectionalMap<TypedVirtualPath, DependencySource>
30+
@_spi(Testing) public var biMap = BiMap()
31+
32+
@_spi(Testing) public subscript(input: TypedVirtualPath) -> DependencySource? {
33+
get { biMap[input] }
34+
set { biMap[input] = newValue }
35+
}
36+
37+
@_spi(Testing) public private(set) subscript(dependencySource: DependencySource) -> TypedVirtualPath? {
38+
get { biMap[dependencySource] }
39+
set { biMap[dependencySource] = newValue }
40+
}
41+
42+
public func makeIterator() -> BiMap.Iterator {
43+
biMap.makeIterator()
44+
}
45+
46+
}

0 commit comments

Comments
 (0)