-
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
Sync solution contents consistently #72860
Changes from 14 commits
f32ae1b
f5d3c3e
97c7ef5
7c5153d
b06a4ac
68fab4d
fb039e9
84e0135
fa328f2
50f31d5
1a4d197
7c5c48a
d8e2733
ebcead6
cfed4b3
5049919
5a01bf6
dedfe2d
b1560c9
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 |
---|---|---|
|
@@ -206,6 +206,35 @@ async ValueTask DecrementInFlightCountAsync(InFlightSolution inFlightSolution) | |
} | ||
} | ||
|
||
private async Task<Solution> GetOrCreateSolutionToUpdateAsync( | ||
AssetProvider assetProvider, | ||
Checksum solutionChecksum, | ||
CancellationToken cancellationToken) | ||
{ | ||
// See if we can just incrementally update the current solution. | ||
var currentSolution = this.CurrentSolution; | ||
if (await IsIncrementalUpdateAsync().ConfigureAwait(false)) | ||
return currentSolution; | ||
|
||
// If not, have to create a new, fresh, solution instance to update. | ||
var solutionInfo = await assetProvider.CreateSolutionInfoAsync(solutionChecksum, cancellationToken).ConfigureAwait(false); | ||
return CreateSolutionFromInfo(solutionInfo); | ||
|
||
async Task<bool> IsIncrementalUpdateAsync() | ||
{ | ||
var newSolutionCompilationChecksums = await assetProvider.GetAssetAsync<SolutionCompilationStateChecksums>( | ||
AssetPathKind.SolutionCompilationStateChecksums, solutionChecksum, cancellationToken).ConfigureAwait(false); | ||
var newSolutionChecksums = await assetProvider.GetAssetAsync<SolutionStateChecksums>( | ||
AssetPathKind.SolutionStateChecksums, newSolutionCompilationChecksums.SolutionState, cancellationToken).ConfigureAwait(false); | ||
|
||
var newSolutionInfo = await assetProvider.GetAssetAsync<SolutionInfo.SolutionAttributes>( | ||
AssetPathKind.SolutionAttributes, newSolutionChecksums.Attributes, cancellationToken).ConfigureAwait(false); | ||
|
||
// if either solution id or file path changed, then we consider it as new solution | ||
return currentSolution.Id == newSolutionInfo.Id && currentSolution.FilePath == newSolutionInfo.FilePath; | ||
} | ||
} | ||
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. simple logic. determine if we're updating the existing solution (and return it if so), or creating a new solution (and create it if so). |
||
|
||
/// <summary> | ||
/// Create an appropriate <see cref="Solution"/> instance corresponding to the <paramref | ||
/// name="newSolutionChecksum"/> passed in. Note: this method changes no Workspace state and exists purely to | ||
|
@@ -230,37 +259,12 @@ private async Task<Solution> ComputeDisconnectedSolutionAsync( | |
{ | ||
try | ||
{ | ||
// Try to create the solution snapshot incrementally off of the workspaces CurrentSolution first. | ||
var updater = new SolutionCreator(Services.HostServices, assetProvider, this.CurrentSolution); | ||
if (await updater.IsIncrementalUpdateAsync(newSolutionChecksum, cancellationToken).ConfigureAwait(false)) | ||
{ | ||
return await updater.CreateSolutionAsync(newSolutionChecksum, cancellationToken).ConfigureAwait(false); | ||
} | ||
else | ||
{ | ||
// Otherwise, this is a different solution, or the first time we're creating this solution. Bulk | ||
// sync over all assets for it. | ||
await assetProvider.SynchronizeSolutionAssetsAsync(newSolutionChecksum, cancellationToken).ConfigureAwait(false); | ||
|
||
// get new solution info and options | ||
var solutionInfo = await assetProvider.CreateSolutionInfoAsync(newSolutionChecksum, cancellationToken).ConfigureAwait(false); | ||
var solution = CreateSolutionFromInfo(solutionInfo); | ||
var solutionToUpdate = await GetOrCreateSolutionToUpdateAsync( | ||
assetProvider, newSolutionChecksum, cancellationToken).ConfigureAwait(false); | ||
|
||
// ensure that the solution has the correct source generator execution versions. note we should do | ||
// this all in a unified fashion with CreateSolutionAsync above. However, that is blocked in | ||
// https://github.com/dotnet/roslyn/pull/72860 | ||
{ | ||
var newSolutionCompilationChecksums = await assetProvider.GetAssetAsync<SolutionCompilationStateChecksums>( | ||
AssetPathKind.SolutionCompilationStateChecksums, newSolutionChecksum, cancellationToken).ConfigureAwait(false); | ||
|
||
var newVersions = await assetProvider.GetAssetAsync<SourceGeneratorExecutionVersionMap>( | ||
AssetPathKind.SolutionSourceGeneratorExecutionVersionMap, newSolutionCompilationChecksums.SourceGeneratorExecutionVersionMap, cancellationToken).ConfigureAwait(false); | ||
|
||
solution = solution.UpdateSpecificSourceGeneratorExecutionVersions(newVersions); | ||
} | ||
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. note: this logic intentionally disappears. because we now just have it fall out from calling into the normal CreateSolutionAsync copdepath which does the appropraite checksum diffing/syncing. (It also does a validation sanity check in debug, which this codepath never did). 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. Nice! |
||
|
||
return solution; | ||
} | ||
// Now, bring that solution in line with the snapshot defined by solutionChecksum. | ||
var updater = new SolutionCreator(Services.HostServices, assetProvider, solutionToUpdate); | ||
return await updater.CreateSolutionAsync(newSolutionChecksum, cancellationToken).ConfigureAwait(false); | ||
} | ||
catch (Exception e) when (FatalError.ReportAndPropagateUnlessCanceled(e, cancellationToken)) | ||
{ | ||
|
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.
moved to inlined helper in the containing type.