Remove the AnalyzerManager singleton to prevent storing analyzer exec…#20109
Remove the AnalyzerManager singleton to prevent storing analyzer exec…#20109mavasani merged 6 commits intodotnet:dev15.6from
Conversation
…ution state across compilations Now we throw away all the analyzer execution state once the CompilationWithAnalyzers goes out of scope.
| // This map stores the tasks to compute HostCompilationStartAnalysisScope for per-compilation analyzer actions, i.e. AnalyzerActions registered by analyzer's CompilationStartActions. | ||
| // Compilation start actions will get executed once per-each AnalyzerAndOptions as user might want to return different set of custom actions for each compilation/analyzer options. | ||
| private Dictionary<AnalyzerOptions, ConditionalWeakTable<Compilation, Task<HostCompilationStartAnalysisScope>>> _lazyCompilationScopeMap; | ||
| private readonly Dictionary<AnalyzerOptions, Task<HostCompilationStartAnalysisScope>> _compilationScopeMap; |
There was a problem hiding this comment.
I believe AnalyzerManager is per compilationWithAnalyzer now which is for one compilation meaning AnalyzerOption will be same for all? we might not need this map anymore? #Resolved
There was a problem hiding this comment.
Hmm given that each CompilationWithAnalyzers instance will create a new cloned compilation with a new event queue, your claim seems to be correct. Let me cleanup a bit more. #Resolved
| // This cache stores the analyzer execution context per-analyzer (i.e. registered actions, supported descriptors, etc.). | ||
| private readonly ConditionalWeakTable<DiagnosticAnalyzer, AnalyzerExecutionContext> _analyzerExecutionContextMap = | ||
| new ConditionalWeakTable<DiagnosticAnalyzer, AnalyzerExecutionContext>(); | ||
| private readonly Dictionary<DiagnosticAnalyzer, AnalyzerExecutionContext> _analyzerExecutionContextMap = |
There was a problem hiding this comment.
concurrent dictionary and remove the lock? or just create whole map in immutable map at once might better? since this seems get called many times? #Resolved
|
Test failure: https://ci.dot.net/job/dotnet_roslyn/job/dev15.6/job/windows_debug_unit32_prtest/176/
|
|
@dotnet-bot retest windows_debug_unit32_prtest please |
|
Tagging @dotnet/roslyn-analysis @dotnet/roslyn-compiler for review. This change is a follow up cleanup change to #20096 |
| /// Gets the default instance of the AnalyzerManager for the lifetime of the analyzer host process. | ||
| /// </summary> | ||
| public static readonly AnalyzerManager Instance = new AnalyzerManager(); | ||
| private readonly object _gate = new object(); |
There was a problem hiding this comment.
Ah yes, not after the refactoring in the last commit. Thanks, will remove.
| /// It clears the cached internal state (supported descriptors, registered actions, exception handlers, etc.) for analyzers. | ||
| /// </summary> | ||
| /// <param name="analyzers">Analyzers whose state needs to be cleared.</param> | ||
| [Obsolete("This API is no longer required to be invoked. Analyzer state is automatically cleaned up when CompilationWithAnalyzers instance is released.")] |
| _analyzerExecutionContextMap = CreateAnalyzerExecutionContextMap(SpecializedCollections.SingletonEnumerable(analyzer)); | ||
| } | ||
|
|
||
| private ImmutableDictionary<DiagnosticAnalyzer, AnalyzerExecutionContext> CreateAnalyzerExecutionContextMap(IEnumerable<DiagnosticAnalyzer> analyzers) |
There was a problem hiding this comment.
ImmutableArray instead of IEnumerable for analyzers?
Can this method be made static? #ByDesign
There was a problem hiding this comment.
Hum, the singleton case may fit better with IEnumerable (than ImmutableArray). Ignore that comment.
In reply to: 121486170 [](ancestors = 121486170)
|
Done with review pass. #Closed |
| namespace Microsoft.CodeAnalysis.UnitTests.Diagnostics | ||
| { | ||
| public class TestDiagnosticAnalyzerDriver : IDisposable | ||
| public class TestDiagnosticAnalyzerDriver |
There was a problem hiding this comment.
public class TestDiagnosticAnalyzerDriver [](start = 4, length = 41)
Isn't removal of the interface a breaking change? The class is public, some clients could implicitly convert it to IDisposable, which is going to be an error now.
There was a problem hiding this comment.
Yes, I don't think test types are part of our public/supported API.
There was a problem hiding this comment.
This is a test only type though
Sorry, missed this part.
|
Done with review pass. |
|
@dotnet/roslyn-infrastructure I thought the VS integration tests are currently failing, and hence we are allowed to merge without requiring them to pass. However, merging the pull request still seems to be blocked on these tests. |
|
@mavasani the underlying problem with the VS integration tests was fixed yesterday afternoon. Hence the tests are required again. |
|
retest windows_debug_vs-integration_prtest please |
|
retest windows_release_vs-integration_prtest please |
|
Thanks @jaredpar. The Debug integration test failed with following output: |
|
retest windows_debug_vs-integration_prtest please |
|
Actually, I only disabled the requirement in master, but didn't do it here. 😦 |
|
@jasonmalinowski @jaredpar - The debug integration test job is consistently failing with the same error as above on branches other then master. See https://ci.dot.net/job/dotnet_roslyn/job/dev15.6/job/windows_debug_vs-integration_prtest/260/ for this PR (dev15.6 branch) and also the failure for #20177 (features/ioperation branch) |
|
Please ignore integration tests for a while. |
|
@ivanbasov - Merge pull request is still disabled for dev15.6 branch, can we remove this requirement? |
|
I think, yes: we should disable integration tests in 15.6 too for a while. @jaredpar, @jasonmalinowski to confirm. If yes, will it be enough to cherry-pick #20216, once it will be merged to master? |
|
And to your second question: yes. I'd just have @jimmy9988 do the merge as he'll be doing that flow anyways. |
|
@ivanbasov I am still blocked on VSI failures for this PR. Please advise how to get this through. |
|
@jimmy9988 could you please help with the merge? We have integration tests optional in master. We even have them passed in master. |
|
@dotnet retest windows_debug_vs-integration_prtest please |
|
@dotnet-bot retest windows_release_vs-integration_prtest please |
|
retest this please |
|
@dotnet-bot retest windows_debug_vs-integration_prtest please |
|
@dotnet-bot retest windows_release_vs-integration_prtest please |
|
@dotnet/roslyn-infrastructure Seems like dev15.6 is in broken state:
Are we fixing this soon? Is there any commit I can cherry-pick from master to fix it? |
|
@mavasani Yes. Cyrus changed a type to struct in master which is used in 15.6. This change brought from master breaks 15.6. @heejaechang is working on this. |
…ution state across compilations
Now we throw away all the analyzer execution state once the CompilationWithAnalyzers goes out of scope.