Skip to content
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

Remove 'open file only' concept from analyzer driver #74340

Merged
merged 6 commits into from
Jul 11, 2024

Conversation

CyrusNajmabadi
Copy link
Member

This logic existed at a time when we unilaterally ran all analyzers all the time. This was far too slow for some of these analyzers, and so we had a special back-door to have them opt out of running.

We no longer need this as our move to pull diagnostics (with separate categories for analyzers vs compiler errors), and our user options around how/when analyzers and compiler diagnostics should run supersedes this.

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Analyzers untriaged Issues and PRs which have not yet been triaged by a lead labels Jul 10, 2024
@@ -945,24 +945,6 @@ public override void Initialize(AnalysisContext context)
}
}

private class OpenFileOnlyAnalyzer : DiagnosticAnalyzer, IBuiltInAnalyzer
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

never referenced.

@@ -23,9 +23,6 @@ public static bool IsWorkspaceDiagnosticAnalyzer(this DiagnosticAnalyzer analyze
public static bool IsBuiltInAnalyzer(this DiagnosticAnalyzer analyzer)
=> analyzer is IBuiltInAnalyzer || analyzer.IsWorkspaceDiagnosticAnalyzer() || analyzer.IsCompilerAnalyzer();

public static bool IsOpenFileOnly(this DiagnosticAnalyzer analyzer, SimplifierOptions? options)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now only returns false. was inlined as appropriate into callsites.

@@ -33,12 +33,8 @@ internal partial class DiagnosticIncrementalAnalyzer
var version = await GetDiagnosticVersionAsync(project, cancellationToken).ConfigureAwait(false);
var existingData = await ProjectAnalysisData.CreateAsync(project, stateSets, avoidLoadingData, cancellationToken).ConfigureAwait(false);

// We can't return here if we have open file only analyzers since saved data for open file only analyzer
// is incomplete -- it only contains info on open files rather than whole project.
if (existingData.Version == version && !CompilationHasOpenFileOnlyAnalyzers(compilationWithAnalyzers, ideOptions.SimplifierOptions))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this method only returns false now. so inlined and updated as appropriate.

@@ -213,8 +191,7 @@ private static bool CompilationHasOpenFileOnlyAnalyzers(CompilationWithAnalyzers
foreach (var analyzer in existingAnalyzers)
{
if (existing.TryGetValue(analyzer, out var analysisResult) &&
analysisResult.Version == version &&
!analyzer.IsOpenFileOnly(ideOptions.SimplifierOptions))
analysisResult.Version == version)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inlined and elided.

@@ -195,8 +193,7 @@ public async Task<ImmutableArray<Diagnostic>> GetSourceGeneratorDiagnosticsAsync

var ideOptions = ((WorkspaceAnalyzerOptions)compilationWithAnalyzers.AnalysisOptions.Options!).IdeOptions;

var analyzers = documentAnalysisScope?.Analyzers ??
compilationWithAnalyzers.Analyzers.Where(a => forceExecuteAllAnalyzers || !a.IsOpenFileOnly(ideOptions.SimplifierOptions));
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the right side of the || became true. So this Where was unnecessary. which made forceExecuteAllAnalyzers unnecessary. which led to the callsite updates.

@CyrusNajmabadi CyrusNajmabadi marked this pull request as ready for review July 10, 2024 23:18
@CyrusNajmabadi CyrusNajmabadi requested a review from a team as a code owner July 10, 2024 23:18
@CyrusNajmabadi
Copy link
Member Author

@tmat ptal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Analyzers untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants