diff --git a/src/Workspaces/Core/Portable/Workspace/Solution/SolutionState.cs b/src/Workspaces/Core/Portable/Workspace/Solution/SolutionState.cs index 8df4aa30621034f8bc57f0f716df824771285ce5..9f4b3c2716d50457300b2a77224d82f4f34ab71f 100644 --- a/src/Workspaces/Core/Portable/Workspace/Solution/SolutionState.cs +++ b/src/Workspaces/Core/Portable/Workspace/Solution/SolutionState.cs @@ -44,7 +44,6 @@ internal partial class SolutionState private readonly IReadOnlyList _projectIds; private readonly ImmutableDictionary _projectIdToProjectStateMap; private readonly ImmutableDictionary> _filePathToDocumentIdsMap; - private readonly Lazy _lazyLatestProjectVersion; private readonly ProjectDependencyGraph _dependencyGraph; // Values for all these are created on demand. @@ -63,8 +62,7 @@ internal partial class SolutionState ImmutableDictionary idToProjectStateMap, ImmutableDictionary projectIdToTrackerMap, ImmutableDictionary> filePathToDocumentIdsMap, - ProjectDependencyGraph dependencyGraph, - Lazy lazyLatestProjectVersion) + ProjectDependencyGraph dependencyGraph) { _branchId = branchId; _workspaceVersion = workspaceVersion; @@ -76,7 +74,6 @@ internal partial class SolutionState _projectIdToTrackerMap = projectIdToTrackerMap; _filePathToDocumentIdsMap = filePathToDocumentIdsMap; _dependencyGraph = dependencyGraph; - _lazyLatestProjectVersion = lazyLatestProjectVersion; // when solution state is changed, we re-calcuate its checksum _lazyChecksums = new AsyncLazy(ComputeChecksumsAsync, cacheResult: true); @@ -99,12 +96,8 @@ internal partial class SolutionState idToProjectStateMap: ImmutableDictionary.Empty, projectIdToTrackerMap: ImmutableDictionary.Empty, filePathToDocumentIdsMap: ImmutableDictionary.Create>(StringComparer.OrdinalIgnoreCase), - 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 + dependencyGraph: ProjectDependencyGraph.Empty) { - _lazyLatestProjectVersion = new Lazy(() => ComputeLatestProjectVersion()); } 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); } - 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 ImmutableDictionary ProjectStates => _projectIdToProjectStateMap; @@ -195,8 +175,7 @@ private void CheckInvariants() ImmutableDictionary? idToProjectStateMap = null, ImmutableDictionary? projectIdToTrackerMap = null, ImmutableDictionary>? filePathToDocumentIdsMap = null, - ProjectDependencyGraph? dependencyGraph = null, - Lazy? lazyLatestProjectVersion = null) + ProjectDependencyGraph? dependencyGraph = null) { var branchId = GetBranchId(); @@ -207,7 +186,6 @@ private void CheckInvariants() projectIdToTrackerMap ??= _projectIdToTrackerMap; filePathToDocumentIdsMap ??= _filePathToDocumentIdsMap; dependencyGraph ??= _dependencyGraph; - lazyLatestProjectVersion ??= _lazyLatestProjectVersion; if (branchId == _branchId && solutionAttributes == _solutionAttributes && @@ -216,8 +194,7 @@ private void CheckInvariants() idToProjectStateMap == _projectIdToProjectStateMap && projectIdToTrackerMap == _projectIdToTrackerMap && filePathToDocumentIdsMap == _filePathToDocumentIdsMap && - dependencyGraph == _dependencyGraph && - lazyLatestProjectVersion == _lazyLatestProjectVersion) + dependencyGraph == _dependencyGraph) { return this; } @@ -233,8 +210,7 @@ private void CheckInvariants() idToProjectStateMap, projectIdToTrackerMap, filePathToDocumentIdsMap, - dependencyGraph, - lazyLatestProjectVersion); + dependencyGraph); } private SolutionState CreatePrimarySolution( @@ -259,8 +235,7 @@ private void CheckInvariants() _projectIdToProjectStateMap, _projectIdToTrackerMap, _filePathToDocumentIdsMap, - _dependencyGraph, - _lazyLatestProjectVersion); + _dependencyGraph); } private BranchId GetBranchId() @@ -277,7 +252,14 @@ private BranchId GetBranchId() /// 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; } /// @@ -489,8 +471,7 @@ private SolutionState AddProject(ProjectId projectId, ProjectState projectState) idToProjectStateMap: newStateMap, projectIdToTrackerMap: newTrackerMap, filePathToDocumentIdsMap: newFilePathToDocumentIdsMap, - dependencyGraph: newDependencyGraph, - lazyLatestProjectVersion: new Lazy(() => projectState.Version)); // this is the newest! + dependencyGraph: newDependencyGraph); } /// @@ -1772,15 +1753,11 @@ private SolutionState WithAnalyzerConfigDocumentState(AnalyzerConfigDocumentStat } } - var modifiedDocumentOnly = translate is CompilationTranslationAction.TouchDocumentAction; - var newLatestProjectVersion = modifiedDocumentOnly ? _lazyLatestProjectVersion : new Lazy(() => newProjectState.Version); - return this.Branch( idToProjectStateMap: newStateMap, projectIdToTrackerMap: newTrackerMap, dependencyGraph: newDependencyGraph, - filePathToDocumentIdsMap: newFilePathToDocumentIdsMap ?? _filePathToDocumentIdsMap, - lazyLatestProjectVersion: newLatestProjectVersion); + filePathToDocumentIdsMap: newFilePathToDocumentIdsMap ?? _filePathToDocumentIdsMap); } ///