-
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
Use the project cone information in Scope.FindAssetsAsync (part 2) #72512
Merged
Merged
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
aa63897
Use the project cone information in Scope.FindAssetsAsync
ToddGrun 95b7e38
Use contract to verify the projectId is valid in the solutionstate
ToddGrun efd7530
Contract verify the non-project cone case too
ToddGrun 4769457
Merge remote-tracking branch 'upstream/main' into UseProjectConeInfoI…
CyrusNajmabadi b26cf95
Add more project cone info
CyrusNajmabadi 7a83e99
Add more project cone info
CyrusNajmabadi 42752cf
undo
CyrusNajmabadi 643cd2f
fix
CyrusNajmabadi 931f784
fix
CyrusNajmabadi b10a170
Simplify
CyrusNajmabadi 833777d
Simplify
CyrusNajmabadi 22521fc
Extract file
CyrusNajmabadi 2f82a01
Add assert
CyrusNajmabadi 32904a7
Add assert
CyrusNajmabadi 79d4a49
Add assert
CyrusNajmabadi 9c8996b
Revert
CyrusNajmabadi 4174498
Revert
CyrusNajmabadi 60810f3
Revert
CyrusNajmabadi 615b6e9
Revert
CyrusNajmabadi 0aa9398
Revert
CyrusNajmabadi 7dc12fa
Revert
CyrusNajmabadi 15e75cf
Revert
CyrusNajmabadi 175874f
Revert
CyrusNajmabadi e63278f
Comment
CyrusNajmabadi 5bb7218
Simplify
CyrusNajmabadi 1a62751
REmove
CyrusNajmabadi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
src/Workspaces/Core/Portable/Workspace/Solution/ProjectCone.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System; | ||
using System.Collections.Frozen; | ||
using Roslyn.Utilities; | ||
|
||
namespace Microsoft.CodeAnalysis; | ||
|
||
/// <summary> | ||
/// Represents a 'cone' of projects that is being sync'ed between the local and remote hosts. A project cone starts | ||
/// with a <see cref="RootProjectId"/>, and contains both it and all dependent projects within <see cref="_projectIds"/>. | ||
/// </summary> | ||
internal sealed class ProjectCone : IEquatable<ProjectCone> | ||
{ | ||
public readonly ProjectId RootProjectId; | ||
private readonly FrozenSet<ProjectId> _projectIds; | ||
|
||
public ProjectCone(ProjectId rootProjectId, FrozenSet<ProjectId> projectIds) | ||
{ | ||
Contract.ThrowIfFalse(projectIds.Contains(rootProjectId)); | ||
RootProjectId = rootProjectId; | ||
_projectIds = projectIds; | ||
} | ||
|
||
public bool Contains(ProjectId projectId) | ||
=> _projectIds.Contains(projectId); | ||
|
||
public override bool Equals(object? obj) | ||
=> obj is ProjectCone cone && Equals(cone); | ||
|
||
public bool Equals(ProjectCone? other) | ||
=> other is not null && this.RootProjectId == other.RootProjectId && this._projectIds.SetEquals(other._projectIds); | ||
|
||
public override int GetHashCode() | ||
=> throw new NotImplementedException(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
// See the LICENSE file in the project root for more information. | ||
|
||
using System; | ||
using System.Collections.Frozen; | ||
using System.Collections.Generic; | ||
using System.Collections.Immutable; | ||
using System.Diagnostics.CodeAnalysis; | ||
|
@@ -78,21 +79,15 @@ public async Task<SolutionStateChecksums> GetStateChecksumsAsync( | |
{ | ||
if (!_lazyProjectChecksums.TryGetValue(projectId, out checksums)) | ||
{ | ||
checksums = Compute(projectId); | ||
checksums = AsyncLazy.Create( | ||
static (arg, cancellationToken) => arg.self.ComputeChecksumsAsync(arg.projectId, cancellationToken), | ||
arg: (self: this, projectId)); | ||
_lazyProjectChecksums.Add(projectId, checksums); | ||
} | ||
} | ||
|
||
var collection = await checksums.GetValueAsync(cancellationToken).ConfigureAwait(false); | ||
return collection; | ||
|
||
// Extracted as a local function to prevent delegate allocations when not needed. | ||
AsyncLazy<SolutionStateChecksums> Compute(ProjectId projectConeId) | ||
{ | ||
return AsyncLazy.Create(static (arg, c) => | ||
arg.self.ComputeChecksumsAsync(arg.projectConeId, c), | ||
arg: (self: this, projectConeId)); | ||
} | ||
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. inlined this. no need for the local function since Todd moved this to static lambdas. |
||
} | ||
|
||
/// <summary>Gets the checksum for only the requested project (and any project it depends on)</summary> | ||
|
@@ -141,11 +136,18 @@ private async Task<SolutionStateChecksums> ComputeChecksumsAsync( | |
var analyzerReferenceChecksums = ChecksumCache.GetOrCreateChecksumCollection( | ||
this.AnalyzerReferences, this.Services.GetRequiredService<ISerializerService>(), cancellationToken); | ||
|
||
return new SolutionStateChecksums( | ||
var stateChecksums = new SolutionStateChecksums( | ||
projectConeId, | ||
this.SolutionAttributes.Checksum, | ||
new(new ChecksumCollection(projectChecksums), projectIds), | ||
analyzerReferenceChecksums); | ||
|
||
#if DEBUG | ||
var projectConeTemp = projectConeId is null ? null : new ProjectCone(projectConeId, projectCone.Object.ToFrozenSet()); | ||
RoslynDebug.Assert(Equals(projectConeTemp, stateChecksums.ProjectCone)); | ||
#endif | ||
|
||
return stateChecksums; | ||
} | ||
} | ||
catch (Exception e) when (FatalError.ReportAndPropagateUnlessCanceled(e, cancellationToken)) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
style preference. i like to use
cancellationToken
for callbacks. that way if there is a cancellationToken in scope, it will hide it and we don't accidentally capture the wrong thing. less relevant for static lambdas. but i like to be consistent with that.