Skip to content

Commit

Permalink
Revert "Merge pull request #75007 from ToddGrun/dev/toddgrun/release-…
Browse files Browse the repository at this point in the history
…dev17.11-CancellationToken"

This reverts commit 652cb83, reversing
changes made to 1ea9c39.
  • Loading branch information
Cosifne committed Sep 9, 2024
1 parent 652cb83 commit b8ce367
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
/// </summary>
public readonly CancellableLazy<Compilation?> LazyStaleCompilationWithGeneratedDocuments;
public readonly Lazy<Compilation?> LazyStaleCompilationWithGeneratedDocuments;

/// <summary>
/// The list of changes that have happened since we last computed a compilation. The oldState corresponds to
Expand All @@ -86,7 +86,7 @@ public InProgressState(
CreationPolicy creationPolicy,
Lazy<Compilation> compilationWithoutGeneratedDocuments,
CompilationTrackerGeneratorInfo generatorInfo,
CancellableLazy<Compilation?> staleCompilationWithGeneratedDocuments,
Lazy<Compilation?> staleCompilationWithGeneratedDocuments,
ImmutableList<TranslationAction> pendingTranslationActions)
: base(creationPolicy, generatorInfo)
{
Expand Down Expand Up @@ -123,8 +123,8 @@ public InProgressState(
{
}

private static CancellableLazy<Compilation?> CreateLazyCompilation(Compilation? staleCompilationWithGeneratedDocuments)
=> new(staleCompilationWithGeneratedDocuments);
private static Lazy<Compilation?> CreateLazyCompilation(Compilation? staleCompilationWithGeneratedDocuments)
=> new(() => staleCompilationWithGeneratedDocuments);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ private partial class CompilationTracker : ICompilationTracker
private static readonly Func<ProjectState, string> s_logBuildCompilationAsync =
state => string.Join(",", state.AssemblyName, state.DocumentStates.Count);

private static readonly CancellableLazy<Compilation?> s_lazyNullCompilation = new CancellableLazy<Compilation?>((Compilation?)null);
private static readonly Lazy<Compilation?> s_lazyNullCompilation = new Lazy<Compilation?>(() => null);

public ProjectState ProjectState { get; }

Expand Down Expand Up @@ -145,7 +145,7 @@ public ICompilationTracker Fork(
var (compilationWithoutGeneratedDocuments, staleCompilationWithGeneratedDocuments) = state switch
{
InProgressState inProgressState => (inProgressState.LazyCompilationWithoutGeneratedDocuments, inProgressState.LazyStaleCompilationWithGeneratedDocuments),
FinalCompilationTrackerState finalState => (new Lazy<Compilation>(() => finalState.CompilationWithoutGeneratedDocuments), new CancellableLazy<Compilation?>(finalState.FinalCompilationWithGeneratedDocuments)),
FinalCompilationTrackerState finalState => (new Lazy<Compilation>(() => finalState.CompilationWithoutGeneratedDocuments), new Lazy<Compilation?>(() => finalState.FinalCompilationWithGeneratedDocuments)),
_ => throw ExceptionUtilities.UnexpectedValue(state.GetType()),
};

Expand Down Expand Up @@ -404,7 +404,7 @@ async Task<InProgressState> 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
Expand Down Expand Up @@ -476,7 +476,7 @@ async Task<FinalCompilationTrackerState> 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
Expand Down Expand Up @@ -735,7 +735,7 @@ public ICompilationTracker WithCreateCreationPolicy(bool forceRegeneration)
skeletonReferenceCacheToClone: _skeletonReferenceCache);
}

public ICompilationTracker WithDoNotCreateCreationPolicy()
public ICompilationTracker WithDoNotCreateCreationPolicy(CancellationToken cancellationToken)
{
var state = this.ReadState();

Expand Down Expand Up @@ -792,7 +792,8 @@ public ICompilationTracker WithDoNotCreateCreationPolicy()
var alreadyParsedTrees = alreadyParsedTreesBuilder.ToImmutableAndClear();
var lazyCompilationWithoutGeneratedDocuments = new Lazy<Compilation>(() => this.CreateEmptyCompilation().AddSyntaxTrees(alreadyParsedTrees));

var lazyCompilationWithGeneratedDocuments = new CancellableLazy<Compilation?>(cancellationToken => lazyCompilationWithoutGeneratedDocuments.Value);
// Safe cast to appease NRT system.
var lazyCompilationWithGeneratedDocuments = (Lazy<Compilation?>)lazyCompilationWithoutGeneratedDocuments!;

return new CompilationTracker(
frozenProjectState,
Expand All @@ -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<Compilation?>(cancellationToken =>
{
var syntaxTrees = generatorInfo.Documents.States.Values.Select(state => state.GetSyntaxTree(cancellationToken));
return compilationWithoutGeneratedDocuments.Value.AddSyntaxTrees(syntaxTrees);
});
var compilationWithGeneratedDocuments = new Lazy<Compilation?>(() => compilationWithoutGeneratedDocuments.Value.AddSyntaxTrees(
generatorInfo.Documents.States.Values.Select(state => state.GetSyntaxTree(cancellationToken))));

return new CompilationTracker(
frozenProjectState,
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ bool ContainsAssemblyOrModuleOrDynamic(
/// <summary>
/// Updates the creation policy for this tracker. Setting it to <see cref="CreationPolicy.DoNotCreate"/>.
/// </summary>
ICompilationTracker WithDoNotCreateCreationPolicy();
ICompilationTracker WithDoNotCreateCreationPolicy(CancellationToken cancellationToken);

Task<VersionStamp> GetDependentVersionAsync(SolutionCompilationState compilationState, CancellationToken cancellationToken);
Task<VersionStamp> GetDependentSemanticVersionAsync(SolutionCompilationState compilationState, CancellationToken cancellationToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit b8ce367

Please sign in to comment.