未验证 提交 63457148 编写于 作者: J Jason Malinowski 提交者: GitHub

Merge pull request #41412 from jasonmalinowski/simplify-latestprojectversion

Delete the lazy caching of GetLatestProjectVersion()
...@@ -44,7 +44,6 @@ internal partial class SolutionState ...@@ -44,7 +44,6 @@ internal partial class SolutionState
private readonly IReadOnlyList<ProjectId> _projectIds; private readonly IReadOnlyList<ProjectId> _projectIds;
private readonly ImmutableDictionary<ProjectId, ProjectState> _projectIdToProjectStateMap; private readonly ImmutableDictionary<ProjectId, ProjectState> _projectIdToProjectStateMap;
private readonly ImmutableDictionary<string, ImmutableArray<DocumentId>> _filePathToDocumentIdsMap; private readonly ImmutableDictionary<string, ImmutableArray<DocumentId>> _filePathToDocumentIdsMap;
private readonly Lazy<VersionStamp> _lazyLatestProjectVersion;
private readonly ProjectDependencyGraph _dependencyGraph; private readonly ProjectDependencyGraph _dependencyGraph;
// Values for all these are created on demand. // Values for all these are created on demand.
...@@ -63,8 +62,7 @@ internal partial class SolutionState ...@@ -63,8 +62,7 @@ internal partial class SolutionState
ImmutableDictionary<ProjectId, ProjectState> idToProjectStateMap, ImmutableDictionary<ProjectId, ProjectState> idToProjectStateMap,
ImmutableDictionary<ProjectId, CompilationTracker> projectIdToTrackerMap, ImmutableDictionary<ProjectId, CompilationTracker> projectIdToTrackerMap,
ImmutableDictionary<string, ImmutableArray<DocumentId>> filePathToDocumentIdsMap, ImmutableDictionary<string, ImmutableArray<DocumentId>> filePathToDocumentIdsMap,
ProjectDependencyGraph dependencyGraph, ProjectDependencyGraph dependencyGraph)
Lazy<VersionStamp> lazyLatestProjectVersion)
{ {
_branchId = branchId; _branchId = branchId;
_workspaceVersion = workspaceVersion; _workspaceVersion = workspaceVersion;
...@@ -76,7 +74,6 @@ internal partial class SolutionState ...@@ -76,7 +74,6 @@ internal partial class SolutionState
_projectIdToTrackerMap = projectIdToTrackerMap; _projectIdToTrackerMap = projectIdToTrackerMap;
_filePathToDocumentIdsMap = filePathToDocumentIdsMap; _filePathToDocumentIdsMap = filePathToDocumentIdsMap;
_dependencyGraph = dependencyGraph; _dependencyGraph = dependencyGraph;
_lazyLatestProjectVersion = lazyLatestProjectVersion;
// when solution state is changed, we re-calcuate its checksum // when solution state is changed, we re-calcuate its checksum
_lazyChecksums = new AsyncLazy<SolutionStateChecksums>(ComputeChecksumsAsync, cacheResult: true); _lazyChecksums = new AsyncLazy<SolutionStateChecksums>(ComputeChecksumsAsync, cacheResult: true);
...@@ -99,12 +96,8 @@ internal partial class SolutionState ...@@ -99,12 +96,8 @@ internal partial class SolutionState
idToProjectStateMap: ImmutableDictionary<ProjectId, ProjectState>.Empty, idToProjectStateMap: ImmutableDictionary<ProjectId, ProjectState>.Empty,
projectIdToTrackerMap: ImmutableDictionary<ProjectId, CompilationTracker>.Empty, projectIdToTrackerMap: ImmutableDictionary<ProjectId, CompilationTracker>.Empty,
filePathToDocumentIdsMap: ImmutableDictionary.Create<string, ImmutableArray<DocumentId>>(StringComparer.OrdinalIgnoreCase), filePathToDocumentIdsMap: ImmutableDictionary.Create<string, ImmutableArray<DocumentId>>(StringComparer.OrdinalIgnoreCase),
dependencyGraph: ProjectDependencyGraph.Empty, dependencyGraph: ProjectDependencyGraph.Empty)
#nullable disable warnings // we are passing null here but we're immediately overwriting it -- better to keep the parameter non-null
lazyLatestProjectVersion: null)
#nullable enable warnings
{ {
_lazyLatestProjectVersion = new Lazy<VersionStamp>(() => ComputeLatestProjectVersion());
} }
public SolutionState WithNewWorkspace(Workspace workspace, int workspaceVersion) public SolutionState WithNewWorkspace(Workspace workspace, int workspaceVersion)
...@@ -118,19 +111,6 @@ public SolutionState WithNewWorkspace(Workspace workspace, int workspaceVersion) ...@@ -118,19 +111,6 @@ public SolutionState WithNewWorkspace(Workspace workspace, int workspaceVersion)
return CreatePrimarySolution(branchId: workspace.PrimaryBranchId, workspaceVersion: workspaceVersion, services: services); return CreatePrimarySolution(branchId: workspace.PrimaryBranchId, workspaceVersion: workspaceVersion, services: services);
} }
private VersionStamp ComputeLatestProjectVersion()
{
// this may produce a version that is out of sync with the actual Document versions.
var latestVersion = VersionStamp.Default;
foreach (var projectId in this.ProjectIds)
{
var project = this.GetProjectState(projectId);
latestVersion = project!.Version.GetNewerVersion(latestVersion);
}
return latestVersion;
}
public SolutionInfo.SolutionAttributes SolutionAttributes => _solutionAttributes; public SolutionInfo.SolutionAttributes SolutionAttributes => _solutionAttributes;
public ImmutableDictionary<ProjectId, ProjectState> ProjectStates => _projectIdToProjectStateMap; public ImmutableDictionary<ProjectId, ProjectState> ProjectStates => _projectIdToProjectStateMap;
...@@ -195,8 +175,7 @@ private void CheckInvariants() ...@@ -195,8 +175,7 @@ private void CheckInvariants()
ImmutableDictionary<ProjectId, ProjectState>? idToProjectStateMap = null, ImmutableDictionary<ProjectId, ProjectState>? idToProjectStateMap = null,
ImmutableDictionary<ProjectId, CompilationTracker>? projectIdToTrackerMap = null, ImmutableDictionary<ProjectId, CompilationTracker>? projectIdToTrackerMap = null,
ImmutableDictionary<string, ImmutableArray<DocumentId>>? filePathToDocumentIdsMap = null, ImmutableDictionary<string, ImmutableArray<DocumentId>>? filePathToDocumentIdsMap = null,
ProjectDependencyGraph? dependencyGraph = null, ProjectDependencyGraph? dependencyGraph = null)
Lazy<VersionStamp>? lazyLatestProjectVersion = null)
{ {
var branchId = GetBranchId(); var branchId = GetBranchId();
...@@ -207,7 +186,6 @@ private void CheckInvariants() ...@@ -207,7 +186,6 @@ private void CheckInvariants()
projectIdToTrackerMap ??= _projectIdToTrackerMap; projectIdToTrackerMap ??= _projectIdToTrackerMap;
filePathToDocumentIdsMap ??= _filePathToDocumentIdsMap; filePathToDocumentIdsMap ??= _filePathToDocumentIdsMap;
dependencyGraph ??= _dependencyGraph; dependencyGraph ??= _dependencyGraph;
lazyLatestProjectVersion ??= _lazyLatestProjectVersion;
if (branchId == _branchId && if (branchId == _branchId &&
solutionAttributes == _solutionAttributes && solutionAttributes == _solutionAttributes &&
...@@ -216,8 +194,7 @@ private void CheckInvariants() ...@@ -216,8 +194,7 @@ private void CheckInvariants()
idToProjectStateMap == _projectIdToProjectStateMap && idToProjectStateMap == _projectIdToProjectStateMap &&
projectIdToTrackerMap == _projectIdToTrackerMap && projectIdToTrackerMap == _projectIdToTrackerMap &&
filePathToDocumentIdsMap == _filePathToDocumentIdsMap && filePathToDocumentIdsMap == _filePathToDocumentIdsMap &&
dependencyGraph == _dependencyGraph && dependencyGraph == _dependencyGraph)
lazyLatestProjectVersion == _lazyLatestProjectVersion)
{ {
return this; return this;
} }
...@@ -233,8 +210,7 @@ private void CheckInvariants() ...@@ -233,8 +210,7 @@ private void CheckInvariants()
idToProjectStateMap, idToProjectStateMap,
projectIdToTrackerMap, projectIdToTrackerMap,
filePathToDocumentIdsMap, filePathToDocumentIdsMap,
dependencyGraph, dependencyGraph);
lazyLatestProjectVersion);
} }
private SolutionState CreatePrimarySolution( private SolutionState CreatePrimarySolution(
...@@ -259,8 +235,7 @@ private void CheckInvariants() ...@@ -259,8 +235,7 @@ private void CheckInvariants()
_projectIdToProjectStateMap, _projectIdToProjectStateMap,
_projectIdToTrackerMap, _projectIdToTrackerMap,
_filePathToDocumentIdsMap, _filePathToDocumentIdsMap,
_dependencyGraph, _dependencyGraph);
_lazyLatestProjectVersion);
} }
private BranchId GetBranchId() private BranchId GetBranchId()
...@@ -277,7 +252,14 @@ private BranchId GetBranchId() ...@@ -277,7 +252,14 @@ private BranchId GetBranchId()
/// </summary> /// </summary>
public VersionStamp GetLatestProjectVersion() public VersionStamp GetLatestProjectVersion()
{ {
return _lazyLatestProjectVersion.Value; // this may produce a version that is out of sync with the actual Document versions.
var latestVersion = VersionStamp.Default;
foreach (var project in this.ProjectStates.Values)
{
latestVersion = project.Version.GetNewerVersion(latestVersion);
}
return latestVersion;
} }
/// <summary> /// <summary>
...@@ -489,8 +471,7 @@ private SolutionState AddProject(ProjectId projectId, ProjectState projectState) ...@@ -489,8 +471,7 @@ private SolutionState AddProject(ProjectId projectId, ProjectState projectState)
idToProjectStateMap: newStateMap, idToProjectStateMap: newStateMap,
projectIdToTrackerMap: newTrackerMap, projectIdToTrackerMap: newTrackerMap,
filePathToDocumentIdsMap: newFilePathToDocumentIdsMap, filePathToDocumentIdsMap: newFilePathToDocumentIdsMap,
dependencyGraph: newDependencyGraph, dependencyGraph: newDependencyGraph);
lazyLatestProjectVersion: new Lazy<VersionStamp>(() => projectState.Version)); // this is the newest!
} }
/// <summary> /// <summary>
...@@ -1772,15 +1753,11 @@ private SolutionState WithAnalyzerConfigDocumentState(AnalyzerConfigDocumentStat ...@@ -1772,15 +1753,11 @@ private SolutionState WithAnalyzerConfigDocumentState(AnalyzerConfigDocumentStat
} }
} }
var modifiedDocumentOnly = translate is CompilationTranslationAction.TouchDocumentAction;
var newLatestProjectVersion = modifiedDocumentOnly ? _lazyLatestProjectVersion : new Lazy<VersionStamp>(() => newProjectState.Version);
return this.Branch( return this.Branch(
idToProjectStateMap: newStateMap, idToProjectStateMap: newStateMap,
projectIdToTrackerMap: newTrackerMap, projectIdToTrackerMap: newTrackerMap,
dependencyGraph: newDependencyGraph, dependencyGraph: newDependencyGraph,
filePathToDocumentIdsMap: newFilePathToDocumentIdsMap ?? _filePathToDocumentIdsMap, filePathToDocumentIdsMap: newFilePathToDocumentIdsMap ?? _filePathToDocumentIdsMap);
lazyLatestProjectVersion: newLatestProjectVersion);
} }
/// <summary> /// <summary>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册