-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Mix the source generator version info into the dependent checksum we get for projects #77273
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1096,40 +1096,50 @@ public Task<Checksum> GetDependentChecksumAsync( | |
Interlocked.CompareExchange( | ||
ref _lazyDependentChecksum, | ||
AsyncLazy.Create(static (arg, c) => | ||
arg.self.ComputeDependentChecksumAsync(arg.SolutionState, c), | ||
arg: (self: this, compilationState.SolutionState)), | ||
arg.self.ComputeDependentChecksumAsync(arg.compilationState, c), | ||
arg: (self: this, compilationState)), | ||
null); | ||
} | ||
|
||
return _lazyDependentChecksum.GetValueAsync(cancellationToken); | ||
} | ||
|
||
private async Task<Checksum> ComputeDependentChecksumAsync(SolutionState solution, CancellationToken cancellationToken) | ||
private async Task<Checksum> ComputeDependentChecksumAsync( | ||
SolutionCompilationState solution, CancellationToken cancellationToken) | ||
{ | ||
using var _ = ArrayBuilder<Checksum>.GetInstance(out var tempChecksumArray); | ||
|
||
// Mix in the SG information for this project. That way if it changes, we will have a different | ||
// checksum (since semantics could have changed because of this). | ||
if (solution.SourceGeneratorExecutionVersionMap.Map.TryGetValue(this.ProjectState.Id, out var executionVersion)) | ||
tempChecksumArray.Add(executionVersion.Checksum); | ||
|
||
// Get the checksum for the project itself. | ||
var projectChecksum = await this.ProjectState.GetChecksumAsync(cancellationToken).ConfigureAwait(false); | ||
tempChecksumArray.Add(projectChecksum); | ||
|
||
// Calculate a checksum this project and for each dependent project that could affect semantics for | ||
// this project. Ensure that the checksum calculation orders the projects consistently so that we get | ||
// the same checksum across sessions of VS. Note: we use the project filepath+name as a unique way | ||
// to reference a project. This matches the logic in our persistence-service implemention as to how | ||
// information is associated with a project. | ||
var transitiveDependencies = solution.GetProjectDependencyGraph().GetProjectsThatThisProjectTransitivelyDependsOn(this.ProjectState.Id); | ||
// Calculate a checksum this project and for each dependent project that could affect semantics for this | ||
// project. We order the projects so that we are resilient to the underlying in-memory graph structure | ||
// changing this arbitrarily. We do not want that to cause us to change our semantic version.. Note: we | ||
// use the project filepath+name as a unique way to reference a project. This matches the logic in our | ||
// persistence-service implementation as to how information is associated with a project. | ||
var transitiveDependencies = solution.SolutionState.GetProjectDependencyGraph().GetProjectsThatThisProjectTransitivelyDependsOn(this.ProjectState.Id); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Asking a general question which doesn't need to impact this PR: Is there a reason this gets the full transitive list versus just asking the immediate project references and mixing in their checksums, which would themselves depend on their immediate project references...etc? Are we going to be generating extra dependency graph entries here even though we don't need to? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i have a followup pr that does that :) |
||
var orderedProjectIds = transitiveDependencies.OrderBy(id => | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Asking a general question which doesn't need to impact this PR: Why do we sort this way versus just sorting by GUID or something? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that would work as well! |
||
{ | ||
var depProject = solution.GetRequiredProjectState(id); | ||
var depProject = solution.SolutionState.GetRequiredProjectState(id); | ||
return (depProject.FilePath, depProject.Name); | ||
}); | ||
|
||
foreach (var projectId in orderedProjectIds) | ||
{ | ||
var referencedProject = solution.GetRequiredProjectState(projectId); | ||
// Mix in the SG information for the dependent project. That way if it changes, we will have a | ||
// different checksum (since semantics could have changed because of this). | ||
if (solution.SourceGeneratorExecutionVersionMap.Map.TryGetValue(projectId, out executionVersion)) | ||
tempChecksumArray.Add(executionVersion.Checksum); | ||
|
||
// Note that these checksums should only actually be calculated once, if the project is unchanged | ||
// the same checksum will be returned. | ||
var referencedProject = solution.SolutionState.GetRequiredProjectState(projectId); | ||
var referencedProjectChecksum = await referencedProject.GetChecksumAsync(cancellationToken).ConfigureAwait(false); | ||
tempChecksumArray.Add(referencedProjectChecksum); | ||
} | ||
|
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.