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