-
Notifications
You must be signed in to change notification settings - Fork 204
[Incremental] Harness immutability to make inputDependencySourceMap
robust
#675
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@swift-ci please test |
3cae5b2
to
2d81f55
Compare
@@ -121,7 +121,8 @@ extension ModuleDependencyGraph.Tracer { | |||
path.compactMap { node in | |||
node.dependencySource.map { | |||
source in | |||
graph.inputDependencySourceMap[source].map { input in | |||
graph.inputDependencySourceMap.input(ifKnownFor: source).map { | |||
input in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove this change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this request still relevant now that the map has been turned into its own, domain-specific type?
|
||
|
||
extension OutputFileMap { | ||
fileprivate static func mock(maxIndex: Int) -> Self { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Whitespace here is quite weird
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the white space there still weird? I hope I've fixed it.
11c4f8c
to
9b3e681
Compare
@swift-ci please test |
7d88e76
to
b6cc8ec
Compare
inputDependencyMap
inputDependencyMap
immutable
inputDependencyMap
immutableinputDependencySourceMap
immutable
@CodaFi Would you mind taking a look at this? Because you uncovered and explored the issues before with this map, you'll be a great reviewer to assess the correctness of this change. Thanks! |
@swift-ci please test |
@CodaFi Any word on when you might have time for this? Thanks! |
inputDependencySourceMap
immutableinputDependencySourceMap
robust
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On the surface, this change seems like and improvement to me, and the problems Robert outlined shouldn't be possible with this data-structure being immutable. It seems reasonable to have the outputFileMap be the canonical source of dependencies for each input and it simplifies the logic quite a bit.
I'd still really like @CodaFi to weigh in because I'm less familiar with the scenarios that previously led to conflict and whether we were relying on serialized priors containing dependency sources in a way I'm not familiar with. And whether that could have implications on incremental build performance.
return nil | ||
} | ||
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: trailing whitespace.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch! I'll fix it.
@@ -671,27 +634,6 @@ extension ModuleDependencyGraph { | |||
throw ReadError.malformedDependsOnRecord | |||
} | |||
self.nodeUses.append( (key, Int(record.fields[0])) ) | |||
case .mapNode: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This tells me that we are no longer reading in swiftdeps files from serialized priors. I'm lacking context here to understand the implications of this, where were these deserialized files used?
They are one of the examples that made the SourceMap
not-truly-bijective, is it the case that they never led to correct behavior? Or if they resulted in another behavior, where were we relying on it that we now choose not to?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I understand the confusion here.
The intention of this change is to no longer serialize and deserialize the inputDependencySourceMap
. Serialized mapNode
s were only used for that purpose. We still read in ModuleDependencyGraph
s from the priors.
Yes, serializing the map and then deserialized it created confusion because the deserialized version might be inconsistent with the info from the OutputFileMap
. This PR is premised on the believe that it is the OutputFileMap
that should be the source of truth.
Does this explanation satisfy? Have I missed something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes that makes sense, thank you. And it also makes sense for the output-file-map to be the canonical source of truth. Probably so much so that I am wondering why we serialized the inputDependencySourceMap
in the first place, hence the confusion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for validating the notion of output-file-map as canonical. Wrt to serializing the inputDependencySourceMap
I have to plead mea culpa. It seemed like a good idea at the time because the inputDependencySourceMap
was being dynamically build as swiftdeps
files were processed. When @CodaFi added the prior deserialization code, IIRC, there was a moment when we had deserialized priors with an empty map. So I (wrongly) fixed it by serializing the inputDependencySourceMap
. My mistake, in conjuction with the build system's proclivity to change file names when a C++ file and Swift file had the same basename-without-extension, led to hilarity ensuing. @CodaFi got to the bottom of things there, and identified the problems with that design.
Later, I realized that the output-file-map should just be the truth, and that, consequently, the inputDependencySourceMap
could be both immutable and a bijection. I hope I'm right this time!
Thank you for your review. Yes, it would still be ideal for @CodaFi to weigh in. As I haven't received any indication of how long it will be till he can review this PR, I plan to fix the white-space issue and merge. |
@swift-ci please test |
[Incremental] Harness immutability to make `inputDependencySourceMap` robust # Conflicts: # Sources/SwiftDriver/IncrementalCompilation/ModuleDependencyGraph.swift
rdar://77998890 |
Make the
inputDependencyMap
immutable, solely reflecting theOutputFileMap
.Do not include it in the priors.
In a previous PR, @CodaFi uncovered and explained issues with the `inputDependencySourceMap:
This PR solves the problem in a simpler way. The key insight is that the output file map contains the information linking a source file to the swiftdeps file for any build. Thus, the output file map should just determine the entries in the
inputDependencySourceMap
, just as it did before the introduction of incremental imports. Then the map in question does become a true bijection. It can also be made immutable, which greatly eases reasoning about the code.It will also make it easy to cull removed file nodes from priors in a future PR.