diff --git a/src/Workspaces/Core/Portable/Workspace/Solution/SolutionCompilationState.CompilationTracker.CompilationTrackerState.cs b/src/Workspaces/Core/Portable/Workspace/Solution/SolutionCompilationState.CompilationTracker.CompilationTrackerState.cs index ec73c3d3a832e..b8cb90e3b3deb 100644 --- a/src/Workspaces/Core/Portable/Workspace/Solution/SolutionCompilationState.CompilationTracker.CompilationTrackerState.cs +++ b/src/Workspaces/Core/Portable/Workspace/Solution/SolutionCompilationState.CompilationTracker.CompilationTrackerState.cs @@ -72,7 +72,7 @@ private sealed class InProgressState : CompilationTrackerState /// correct snapshot in that the generators have not been rerun, but may be reusable if the generators /// are later found to give the same output. /// - public readonly CancellableLazy LazyStaleCompilationWithGeneratedDocuments; + public readonly Lazy LazyStaleCompilationWithGeneratedDocuments; /// /// The list of changes that have happened since we last computed a compilation. The oldState corresponds to @@ -86,7 +86,7 @@ public InProgressState( CreationPolicy creationPolicy, Lazy compilationWithoutGeneratedDocuments, CompilationTrackerGeneratorInfo generatorInfo, - CancellableLazy staleCompilationWithGeneratedDocuments, + Lazy staleCompilationWithGeneratedDocuments, ImmutableList pendingTranslationActions) : base(creationPolicy, generatorInfo) { @@ -123,8 +123,8 @@ public InProgressState( { } - private static CancellableLazy CreateLazyCompilation(Compilation? staleCompilationWithGeneratedDocuments) - => new(staleCompilationWithGeneratedDocuments); + private static Lazy CreateLazyCompilation(Compilation? staleCompilationWithGeneratedDocuments) + => new(() => staleCompilationWithGeneratedDocuments); } /// diff --git a/src/Workspaces/Core/Portable/Workspace/Solution/SolutionCompilationState.CompilationTracker.cs b/src/Workspaces/Core/Portable/Workspace/Solution/SolutionCompilationState.CompilationTracker.cs index b9f493bb6c3e1..6a3f819e174fb 100644 --- a/src/Workspaces/Core/Portable/Workspace/Solution/SolutionCompilationState.CompilationTracker.cs +++ b/src/Workspaces/Core/Portable/Workspace/Solution/SolutionCompilationState.CompilationTracker.cs @@ -32,7 +32,7 @@ private partial class CompilationTracker : ICompilationTracker private static readonly Func s_logBuildCompilationAsync = state => string.Join(",", state.AssemblyName, state.DocumentStates.Count); - private static readonly CancellableLazy s_lazyNullCompilation = new CancellableLazy((Compilation?)null); + private static readonly Lazy s_lazyNullCompilation = new Lazy(() => null); public ProjectState ProjectState { get; } @@ -145,7 +145,7 @@ public ICompilationTracker Fork( var (compilationWithoutGeneratedDocuments, staleCompilationWithGeneratedDocuments) = state switch { InProgressState inProgressState => (inProgressState.LazyCompilationWithoutGeneratedDocuments, inProgressState.LazyStaleCompilationWithGeneratedDocuments), - FinalCompilationTrackerState finalState => (new Lazy(() => finalState.CompilationWithoutGeneratedDocuments), new CancellableLazy(finalState.FinalCompilationWithGeneratedDocuments)), + FinalCompilationTrackerState finalState => (new Lazy(() => finalState.CompilationWithoutGeneratedDocuments), new Lazy(() => finalState.FinalCompilationWithGeneratedDocuments)), _ => throw ExceptionUtilities.UnexpectedValue(state.GetType()), }; @@ -404,7 +404,7 @@ async Task CollapseInProgressStateAsync(InProgressState initial var translationAction = inProgressState.PendingTranslationActions[0]; var compilationWithoutGeneratedDocuments = inProgressState.CompilationWithoutGeneratedDocuments; - var staleCompilationWithGeneratedDocuments = inProgressState.LazyStaleCompilationWithGeneratedDocuments.GetValue(cancellationToken); + var staleCompilationWithGeneratedDocuments = inProgressState.LazyStaleCompilationWithGeneratedDocuments.Value; // If staleCompilationWithGeneratedDocuments is the same as compilationWithoutGeneratedDocuments, // then it means a prior run of generators didn't produce any files. In that case, we'll just make @@ -476,7 +476,7 @@ async Task FinalizeCompilationWorkerAsync(InProgre var creationPolicy = inProgressState.CreationPolicy; var generatorInfo = inProgressState.GeneratorInfo; var compilationWithoutGeneratedDocuments = inProgressState.CompilationWithoutGeneratedDocuments; - var staleCompilationWithGeneratedDocuments = inProgressState.LazyStaleCompilationWithGeneratedDocuments.GetValue(cancellationToken); + var staleCompilationWithGeneratedDocuments = inProgressState.LazyStaleCompilationWithGeneratedDocuments.Value; // Project is complete only if the following are all true: // 1. HasAllInformation flag is set for the project @@ -735,7 +735,7 @@ public ICompilationTracker WithCreateCreationPolicy(bool forceRegeneration) skeletonReferenceCacheToClone: _skeletonReferenceCache); } - public ICompilationTracker WithDoNotCreateCreationPolicy() + public ICompilationTracker WithDoNotCreateCreationPolicy(CancellationToken cancellationToken) { var state = this.ReadState(); @@ -792,7 +792,8 @@ public ICompilationTracker WithDoNotCreateCreationPolicy() var alreadyParsedTrees = alreadyParsedTreesBuilder.ToImmutableAndClear(); var lazyCompilationWithoutGeneratedDocuments = new Lazy(() => this.CreateEmptyCompilation().AddSyntaxTrees(alreadyParsedTrees)); - var lazyCompilationWithGeneratedDocuments = new CancellableLazy(cancellationToken => lazyCompilationWithoutGeneratedDocuments.Value); + // Safe cast to appease NRT system. + var lazyCompilationWithGeneratedDocuments = (Lazy)lazyCompilationWithoutGeneratedDocuments!; return new CompilationTracker( frozenProjectState, @@ -817,12 +818,8 @@ public ICompilationTracker WithDoNotCreateCreationPolicy() // us to a frozen state with that information. var generatorInfo = inProgressState.GeneratorInfo; var compilationWithoutGeneratedDocuments = inProgressState.LazyCompilationWithoutGeneratedDocuments; - - var compilationWithGeneratedDocuments = new CancellableLazy(cancellationToken => - { - var syntaxTrees = generatorInfo.Documents.States.Values.Select(state => state.GetSyntaxTree(cancellationToken)); - return compilationWithoutGeneratedDocuments.Value.AddSyntaxTrees(syntaxTrees); - }); + var compilationWithGeneratedDocuments = new Lazy(() => compilationWithoutGeneratedDocuments.Value.AddSyntaxTrees( + generatorInfo.Documents.States.Values.Select(state => state.GetSyntaxTree(cancellationToken)))); return new CompilationTracker( frozenProjectState, @@ -960,9 +957,9 @@ private void ValidateState(CompilationTrackerState? state) ValidateCompilationTreesMatchesProjectState(inProgressState.CompilationWithoutGeneratedDocuments, projectState, generatorInfo: null); - if (inProgressState.LazyStaleCompilationWithGeneratedDocuments.GetValue(CancellationToken.None) is Compilation staleCompilationWithGeneratedDocuments) + if (inProgressState.LazyStaleCompilationWithGeneratedDocuments.Value != null) { - ValidateCompilationTreesMatchesProjectState(staleCompilationWithGeneratedDocuments, projectState, inProgressState.GeneratorInfo); + ValidateCompilationTreesMatchesProjectState(inProgressState.LazyStaleCompilationWithGeneratedDocuments.Value, projectState, inProgressState.GeneratorInfo); } } else diff --git a/src/Workspaces/Core/Portable/Workspace/Solution/SolutionCompilationState.GeneratedFileReplacingCompilationTracker.cs b/src/Workspaces/Core/Portable/Workspace/Solution/SolutionCompilationState.GeneratedFileReplacingCompilationTracker.cs index 6ccd462c1c32a..f176a6b378116 100644 --- a/src/Workspaces/Core/Portable/Workspace/Solution/SolutionCompilationState.GeneratedFileReplacingCompilationTracker.cs +++ b/src/Workspaces/Core/Portable/Workspace/Solution/SolutionCompilationState.GeneratedFileReplacingCompilationTracker.cs @@ -83,9 +83,9 @@ public ICompilationTracker WithCreateCreationPolicy(bool forceRegeneration) : new GeneratedFileReplacingCompilationTracker(underlyingTracker, _replacementDocumentStates); } - public ICompilationTracker WithDoNotCreateCreationPolicy() + public ICompilationTracker WithDoNotCreateCreationPolicy(CancellationToken cancellationToken) { - var underlyingTracker = this.UnderlyingTracker.WithDoNotCreateCreationPolicy(); + var underlyingTracker = this.UnderlyingTracker.WithDoNotCreateCreationPolicy(cancellationToken); return underlyingTracker == this.UnderlyingTracker ? this : new GeneratedFileReplacingCompilationTracker(underlyingTracker, _replacementDocumentStates); diff --git a/src/Workspaces/Core/Portable/Workspace/Solution/SolutionCompilationState.ICompilationTracker.cs b/src/Workspaces/Core/Portable/Workspace/Solution/SolutionCompilationState.ICompilationTracker.cs index f9ed7892ea275..73c4ec43554f9 100644 --- a/src/Workspaces/Core/Portable/Workspace/Solution/SolutionCompilationState.ICompilationTracker.cs +++ b/src/Workspaces/Core/Portable/Workspace/Solution/SolutionCompilationState.ICompilationTracker.cs @@ -49,7 +49,7 @@ bool ContainsAssemblyOrModuleOrDynamic( /// /// Updates the creation policy for this tracker. Setting it to . /// - ICompilationTracker WithDoNotCreateCreationPolicy(); + ICompilationTracker WithDoNotCreateCreationPolicy(CancellationToken cancellationToken); Task GetDependentVersionAsync(SolutionCompilationState compilationState, CancellationToken cancellationToken); Task GetDependentSemanticVersionAsync(SolutionCompilationState compilationState, CancellationToken cancellationToken); diff --git a/src/Workspaces/Core/Portable/Workspace/Solution/SolutionCompilationState.cs b/src/Workspaces/Core/Portable/Workspace/Solution/SolutionCompilationState.cs index a121b1a255418..3b1f467913490 100644 --- a/src/Workspaces/Core/Portable/Workspace/Solution/SolutionCompilationState.cs +++ b/src/Workspaces/Core/Portable/Workspace/Solution/SolutionCompilationState.cs @@ -1323,7 +1323,7 @@ private SolutionCompilationState ComputeFrozenSnapshot(CancellationToken cancell // Since we're freezing, set both generators and skeletons to not be created. We don't want to take any // perf hit on either of those at all for our clients. - var newTracker = oldTracker.WithDoNotCreateCreationPolicy(); + var newTracker = oldTracker.WithDoNotCreateCreationPolicy(cancellationToken); if (oldTracker == newTracker) continue;