Skip to content
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

Merged
merged 19 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,6 @@ private readonly struct SolutionCreator(HostServices hostServices, AssetProvider
private readonly AssetProvider _assetProvider = assetService;
private readonly Solution _baseSolution = baseSolution;

public async Task<bool> IsIncrementalUpdateAsync(Checksum newSolutionChecksum, CancellationToken cancellationToken)
Copy link
Member Author

@CyrusNajmabadi CyrusNajmabadi Apr 3, 2024

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.

{
var newSolutionCompilationChecksums = await _assetProvider.GetAssetAsync<SolutionCompilationStateChecksums>(
AssetPathKind.SolutionCompilationStateChecksums, newSolutionChecksum, 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 _baseSolution.Id == newSolutionInfo.Id && _baseSolution.FilePath == newSolutionInfo.FilePath;
}

public async Task<Solution> CreateSolutionAsync(Checksum newSolutionChecksum, CancellationToken cancellationToken)
{
try
Expand Down
64 changes: 34 additions & 30 deletions src/Workspaces/Remote/ServiceHub/Host/RemoteWorkspace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Copy link
Member Author

Choose a reason for hiding this comment

The 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
Expand All @@ -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);
}
Copy link
Member Author

Choose a reason for hiding this comment

The 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).

Copy link
Contributor

Choose a reason for hiding this comment

The 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))
{
Expand Down
Loading