1. 31 5月, 2019 1 次提交
    • M
      Add new analyzer API (DiagnosticSuppressor) to allow programmatic suppression... · f2f7a069
      Manish Vasani 提交于
      Add new analyzer API (DiagnosticSuppressor) to allow programmatic suppression of analyzer and/or compiler non-error diagnostics
      
      Fixes #20242 and #30172
      
      Detailed design proposal [here](https://gist.github.com/mavasani/fcac17a9581b5c54cef8a689eeec954a).
      
      Added public APIs with documentation comments:
      ```cs
      namespace Microsoft.CodeAnalysis.Diagnostics
      {
          /// <summary>
          /// The base type for diagnostic suppressors that can programmatically suppress analyzer and/or compiler non-error diagnostics.
          /// </summary>
          public abstract class DiagnosticSuppressor : DiagnosticAnalyzer
          {
              // Disallow suppressors from reporting diagnostics or registering analysis actions.
              public sealed override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics => ImmutableArray<DiagnosticDescriptor>.Empty;
      
              public sealed override void Initialize(AnalysisContext context) { }
      
              /// <summary>
              /// Returns a set of descriptors for the suppressions that this suppressor is capable of producing.
              /// </summary>
              public abstract ImmutableArray<SuppressionDescriptor> SupportedSuppressions { get; }
      
              /// <summary>
              /// Suppress analyzer and/or compiler non-error diagnostics reported for the compilation.
              /// This may be a subset of the full set of reported diagnostics, as an optimization for
              /// supporting incremental and partial analysis scenarios.
              /// A diagnostic is considered suppressible by a DiagnosticSuppressor if *all* of the following conditions are met:
              ///     1. Diagnostic is not already suppressed in source via pragma/suppress message attribute.
              ///     2. Diagnostic's <see cref="Diagnostic.DefaultSeverity"/> is not <see cref="DiagnosticSeverity.Error"/>.
              ///     3. Diagnostic is not tagged with <see cref="WellKnownDiagnosticTags.NotConfigurable"/> custom tag.
              /// </summary>
              public abstract void ReportSuppressions(SuppressionAnalysisContext context);
          }
      
          /// <summary>
          /// Provides a description about a programmatic suppression of a <see cref="Diagnostic"/> by a <see cref="DiagnosticSuppressor"/>.
          /// </summary>
          public sealed class SuppressionDescriptor : IEquatable<SuppressionDescriptor>
          {
              /// <summary>
              /// An unique identifier for the suppression.
              /// </summary>
              public string Id { get; }
      
              /// <summary>
              /// Identifier of the suppressed diagnostic, i.e. <see cref="Diagnostic.Id"/>.
              /// </summary>
              public string SuppressedDiagnosticId { get; }
      
              /// <summary>
              /// A localizable description about the suppression.
              /// </summary>
              public LocalizableString Description { get; }
          }
      
          /// <summary>
          /// Context for suppressing analyzer and/or compiler non-error diagnostics reported for the compilation.
          /// </summary>
          public struct SuppressionAnalysisContext
          {
              /// <summary>
              /// Suppressible analyzer and/or compiler non-error diagnostics reported for the compilation.
              /// This may be a subset of the full set of reported diagnostics, as an optimization for
              /// supporting incremental and partial analysis scenarios.
              /// A diagnostic is considered suppressible by a DiagnosticSuppressor if *all* of the following conditions are met:
              ///     1. Diagnostic is not already suppressed in source via pragma/suppress message attribute.
              ///     2. Diagnostic's <see cref="Diagnostic.DefaultSeverity"/> is not <see cref="DiagnosticSeverity.Error"/>.
              ///     3. Diagnostic is not tagged with <see cref="WellKnownDiagnosticTags.NotConfigurable"/> custom tag.
              /// </summary>
              public ImmutableArray<Diagnostic> ReportedDiagnostics { get; }
      
              /// <summary>
              /// Report a <see cref="Suppression"/> for a reported diagnostic.
              /// </summary>
              public void ReportSuppression(Suppression suppression);
      
              /// <summary>
              /// Gets a <see cref="SemanticModel"/> for the given <see cref="SyntaxTree"/>, which is shared across all analyzers.
              /// </summary>
              public SemanticModel GetSemanticModel(SyntaxTree syntaxTree);
      
              /// <summary>
              /// <see cref="CodeAnalysis.Compilation"/> for the context.
              /// </summary>
              public Compilation Compilation { get; }
      
              /// <summary>
              /// Options specified for the analysis.
              /// </summary>
              public AnalyzerOptions Options { get; }
      
              /// <summary>
              /// Token to check for requested cancellation of the analysis.
              /// </summary>
              public CancellationToken CancellationToken { get; }
          }
      
          /// <summary>
          /// Programmatic suppression of a <see cref="Diagnostic"/> by a <see cref="DiagnosticSuppressor"/>.
          /// </summary>
          public struct Suppression
          {
              /// <summary>
              /// Creates a suppression of a <see cref="Diagnostic"/> with the given <see cref="SuppressionDescriptor"/>.
              /// </summary>
              /// <param name="descriptor">
              /// Descriptor for the suppression, which must be from <see cref="DiagnosticSuppressor.SupportedSuppressions"/>
              /// for the <see cref="DiagnosticSuppressor"/> creating this suppression.
              /// </param>
              /// <param name="suppressedDiagnostic">
              /// <see cref="Diagnostic"/> to be suppressed, which must be from <see cref="SuppressionAnalysisContext.ReportedDiagnostics"/>
              /// for the suppression context in which this suppression is being created.</param>
              public static Suppression Create(SuppressionDescriptor descriptor, Diagnostic suppressedDiagnostic);
      
              /// <summary>
              /// Descriptor for this suppression.
              /// </summary>
              public SuppressionDescriptor Descriptor { get; }
      
              /// <summary>
              /// Diagnostic suppressed by this suppression.
              /// </summary>
              public Diagnostic SuppressedDiagnostic { get; }
          }
      }
      ```
      
      For batch compilation, suppressors always run after all the analyzer diagnostics have been computed.
      For IDE partial/incremental analysis scenario, we may run the suppressors with partial diagnostics.
      Suppressed diagnostics from diagnostic suppressors are equivalent to source suppressed diagnostics: they show up in the error list with "Suppression State" column as "Suppressed" and are also output to errorlog as suppressed diagnostics.
      f2f7a069
  2. 19 10月, 2018 1 次提交
  3. 28 7月, 2018 1 次提交
    • M
      Add new DiagnosticAnalyzer API for Symbol Start/End analysis. · 94103bf8
      Manish Vasani 提交于
      This new proposed diagnostic analyzer API enables analyzing all executable code (syntax nodes/operations/code blocks) with a symbol and it's member.
      
      1. `AnalysisContext.RegisterSymbolStartAction(Action<SymbolStartAnalysisContext>, SymbolKind)` and `CompilationStartAnalysisContext.RegisterSymbolStartAction(Action<SymbolStartAnalysisContext>, SymbolKind)` to register actions to be invoked for every symbol of a given kind, prior to invoking any other actions within the symbol and it's members.
      2. `SymbolStartAnalysisContext.RegisterXXXEndAction` APIs to register symbol-specific syntax node/operation/code block actions.
      3. `SymbolStartAnalysisContext.RegisterSymbolEndAction` to register an action to be invoked at the end of all analysis of symbol, its members and all executable code within it.
      
      This change ports the MakeFieldReadonlyAnalyzer to use the new API, which adds support for partial types to this analyzer.
      Fixes #25652
      94103bf8
  4. 17 6月, 2017 1 次提交
  5. 10 6月, 2017 1 次提交
  6. 09 6月, 2017 1 次提交
  7. 29 4月, 2017 1 次提交
    • J
      Upgrade Roslyn to consume newer Microsoft.Net.RoslynDiagnostics · 54d48b75
      Jason Malinowski 提交于
      My motivation for doing this is to pick up the new PublicAPI checker
      that understands type forwards. In doing so I disabled a bunch of new
      warnings that are either broken or not really applicable to Roslyn.
      One new warning (don't rethrow exceptions with throw ex;) seemed useful
      enough to keep on so I left it on and fixed the one offense in the
      codebase.
      54d48b75
  8. 12 11月, 2016 1 次提交
  9. 31 8月, 2016 1 次提交
    • M
      Move back to generating compilation events using GetDiagnostics (#12109) · c3a2ba73
      Manish Vasani 提交于
      In Update2, we switched over to simulated event queue generation to work around the performance issues from computing closed file diagnostics. New IDE diagnostics engine added in Update3 doesn't compute syntax/semantic diagnostics for each closed file separately, so this performance issue shouldn't show up anymore. This change moves us back to populating the event queue using GetDiagnostics.
      c3a2ba73
  10. 21 5月, 2016 1 次提交
  11. 30 4月, 2016 1 次提交
  12. 21 4月, 2016 1 次提交
    • M
      Address performance regression in... · e3840c1f
      Manish Vasani 提交于
      Address performance regression in CompilationWithAnalyzers.GetAnalyzerDiagnosticsAsync and new public APIs 'GetAnalysisResultAsync' to fetch the entire analysis result with diagnostics categorized by kind (syntax, semantic, compilation), tree and analyzer.
      
      Now only the partial analysis APIs (GetAnalyzerSyntaxDiagnosticsAsync, GetAnalyzerSemanticDiagnosticsAsync and GetAnalyzerCompilationDiagnosticsAsync) do analyzer state tracking. Rest of the APIs execute analyzers without state tracking, improving overall performance.
      
      Fixes https://github.com/dotnet/roslyn/issues/10530
      e3840c1f
  13. 20 4月, 2016 1 次提交
    • M
      Address performance regression in... · 0fd82023
      Manish Vasani 提交于
      Address performance regression in CompilationWithAnalyzers.GetAnalyzerDiagnosticsAsync and new public APIs 'GetAnalysisResultAsync' to fetch the entire analysis result with diagnostics categorized by kind (syntax, semantic, compilation), tree and analyzer.
      
      Now only the partial analysis APIs (GetAnalyzerSyntaxDiagnosticsAsync, GetAnalyzerSemanticDiagnosticsAsync and GetAnalyzerCompilationDiagnosticsAsync) do analyzer state tracking. Rest of the APIs execute analyzers without state tracking, improving overall performance.
      
      Fixes https://github.com/dotnet/roslyn/issues/10530
      0fd82023
  14. 10 3月, 2016 2 次提交
  15. 02 3月, 2016 1 次提交
  16. 18 2月, 2016 1 次提交
  17. 06 2月, 2016 1 次提交
  18. 13 1月, 2016 1 次提交
  19. 24 12月, 2015 1 次提交
    • M
      Improve analyzer performance for CompilationWithAnalyzers (IDE host): · da03de0e
      Manish Vasani 提交于
      1. Add support for a simulated event queue to generate compilation events by computing declarations in the tree. Invoking GetDiagnostics to populate the event queue is one of the main reason for large allocations/VM in our perf tests. We can get back to using the compilation event queue when the compiler supports attaching an event queue to an existing compilation, without requiring a complete clone.
      
      2. Move the cached compilation data (declarations, suppression state, etc.) out of a conditional weak table and strongly reference it in CompilationWithAnalyzers.
      
      3. Reduce allocations in per-analyzer state maintenance by tracking analyzed declarations instead of pending declarations - latter can be very large for symbols with many declarations (e.g. global namespace).
      da03de0e
  20. 09 12月, 2015 1 次提交
  21. 20 11月, 2015 2 次提交
    • M
      [Performance] Make core AnalyzerExecutor async · 34460a3c
      Manish Vasani 提交于
      This change replaces synchronous lock statements in the core analyzer executor and analyzer state tracker (for IDE live analysis) with semaphore slim DisposableWaitAsync invocations. This ensures that most of the analyzer driver and analyzer executor code is now async, with only the eventual callback into the analyzers being a synchronous method ([ExecuteAndCatchIfThrows_NoLock](http://source.roslyn.io/Microsoft.CodeAnalysis/R/02d7df8203d3591e.html))
      
      Testing: I verified that the self-build time of Roslyn.sln (which uses a few analyzers), is almost identical after this change. We are hoping that this will improve build performance when there is lot of lock contention, which has shown up from perf traces (see https://github.com/dotnet/roslyn/issues/6053).
      
      Fixes #6399
      34460a3c
    • M
      [Performance] Make core AnalyzerExecutor async · 01df6918
      Manish Vasani 提交于
      This change replaces synchronous lock statements in the core analyzer executor and analyzer state tracker (for IDE live analysis) with semaphore slim DisposableWaitAsync invocations. This ensures that most of the analyzer driver and analyzer executor code is now async, with only the eventual callback into the analyzers being a synchronous method ([ExecuteAndCatchIfThrows_NoLock](http://source.roslyn.io/Microsoft.CodeAnalysis/R/02d7df8203d3591e.html))
      
      Testing: I verified that the self-build time of Roslyn.sln (which uses a few analyzers), is almost identical after this change. We are hoping that this will improve build performance when there is lot of lock contention, which has shown up from perf traces (see https://github.com/dotnet/roslyn/issues/6053).
      
      Fixes #6399
      01df6918
  22. 07 11月, 2015 1 次提交
  23. 04 11月, 2015 1 次提交
  24. 22 10月, 2015 1 次提交
  25. 16 10月, 2015 1 次提交
  26. 09 10月, 2015 1 次提交
  27. 07 10月, 2015 1 次提交
  28. 17 9月, 2015 1 次提交
    • M
      Add a new CompilationOption "ReportSuppressedDiagnostics" to enable reporting... · 18aabe22
      Manish Vasani 提交于
      Add a new CompilationOption "ReportSuppressedDiagnostics" to enable reporting compiler diagnostics suppressed in source. Note that the command line compilers will report such suppressed diagnostics in the SARIF errorlog file but not on the console output.
      
      This new compilation option was approved by the design team.
      
      Fixes #5216
      18aabe22
  29. 12 9月, 2015 1 次提交
    • M
      Fix a deadlock in the analyzer driver · e5430878
      Manish Vasani 提交于
      Primary issue is that we currently try to force complete and decode SuppressMessageAttributes in the analyzer callbacks to report a diagnostic. We need to decode these attributes to apply source suppressions to reported diagnostics. However, force completing attributes can lead to us binding more symbols, and subsequently generating more symbol declared events and attempting to callback into the analyzer again.
      
      Fix is to decode the suppress message attributes as a post pass in the analyzer driver and avoid any symbol force completion during analyzer callbacks to report diagnostics.
      
      Fixes #4858
      e5430878
  30. 11 9月, 2015 2 次提交
    • M
      Emit "isSuppressedInSource" boolean property for diagnostics in the ErrorLog... · a3b4dd49
      Manish Vasani 提交于
      Emit "isSuppressedInSource" boolean property for diagnostics in the ErrorLog file and report suppressed analyzer diagnostics in the error log.
      a3b4dd49
    • M
      Initial work for "Disconnected baselining" scenario: · 08b9efdc
      Manish Vasani 提交于
      1. CompilationWithAnalyzers can now report analyzer diagnostics with source suppressions (pragma/SuppressMessageAttribute). This will eventually allow us to surface diagnostics with source suppressions in the error list. Note that the behavior of command line compilers and all the GetDiagnostics APIs is unchanged, only the compiler analyzer will report diagnostics with source suppressions.
      
      2. Add FixAll support for Suppression code fixes. Light bulb suppression fixes now show the "Fix all occurrences" options for Document/Project/Solution. This change adds the basic functionality to bulk suppress diagnostics. This will eventually be consumed for baselining all/selected diagnostics from error list/solution explorer.
      
      3. Simplify the Suppression light bulb menu to remove the option to add a local SuppressMessageAttribute. The only options now are to suppress in source (pragma) or suppressions file (assembly level SuppressMessageAttribute).
      08b9efdc
  31. 05 9月, 2015 1 次提交
    • M
      Fix performance regression in the IDE diagnostic analyzer service. · 4dfefe7b
      Manish Vasani 提交于
      1) Reduce number allocations in the analyzer driver that show up perf traces for Picasso.
      2) Currently we maintain a cache of CompilationWithAnalyzers for projects being actively analyzed. This is causing the VM to rise and also forcing GC to kick in at different phases causing regressions at various scenarios. The fix is to just create a new CompilationCompilationWithAnalyzers instance for each document/project analysis request.
      4dfefe7b
  32. 19 8月, 2015 1 次提交
  33. 07 8月, 2015 1 次提交
    • M
      Report diagnostics for exceptions within the analyzer driver. · ff66368e
      Manish Vasani 提交于
      We execute the analyzer driver's initialization and core analysis tasks on a background thread. Any exceptions from the driver itself (not the analyzer callbacks, we already report diagnostics for those) were getting swallowed and analyzer execution also skipped silently. See #2980 (comment) for an example.
      
      We now report an exception diagnostic for analyzer driver crash (with the complete exception trace), so that the user knows what happened and we can diagnose the bug when the issue is reported.
      
      Fixes #3005
      ff66368e
  34. 05 8月, 2015 1 次提交
    • M
      Implementation for Analyzer driver v2 for IDE analyzer host. · 3298740f
      Manish Vasani 提交于
      Changes include:
      
      1. Enhance CompilationWithAnalyzers to allow computing analyzer diagnostics for a specific tree/span within a compilation and/or for a subset of analyzers. Implementation ensures no duplicate analysis by tracking partial analysis state and caching the reported analyzer diagnostics.
      
      2. Overview of the new APIs added to CompilationWithAnalyzers:
          1. GetAnalyzerSyntaxDiagnostics(tree, analyzers, ct)
              1. Analogous to SyntaxTree.GetDiagnostics(ct)
              2. Gets analyzer diagnostics reported by executing syntax tree actions on the given tree.
          2. GetAnalyzerSemanticDiagnostics(semanticModel, spanOpt, analyzers, ct)
              1. Analogous to SemanticModel.GetDiagnostics(spanOpt, ct)
              2. Gets analyzer diagnostics reported by executing rest of the non-compilation actions on the given tree span.
          3. GetAnalyzerCompilationDiagnostics(analyzers, ct)
              1. Gets rest of the analyzer diagnostics which are reported by either of the following means:
                  1. Compilation actions (and compilation end actions)
                  2. Non-compilation actions reporting diagnostics on different tree: Executing a symbol action on a symbol definition in a tree, can report diagnostic on its partial definition in some other tree.
      
      3. Simplify IDE analyzer driver by switching it to using the new CompilationWithAnalyzers APIs for analyzer diagnostic computation. Both the IDE and compiler drivers now use the compilation event queue model for driving analysis.
      3298740f
  35. 24 6月, 2015 1 次提交
    • M
      Add DiagnosticDescriptor.GetEffectiveSeverity(CompilationOptions) API to get... · 05a7e645
      Manish Vasani 提交于
      Add DiagnosticDescriptor.GetEffectiveSeverity(CompilationOptions) API to get the effective severity of diagnostics created based on the descriptor for the given compilation options.
      
      This change also removes the clone of this functionality in the IDE layer used by the solution explorer rule severity display and error list/diagnostic service. It now uses this public API.
      
      Fixes #2598
      05a7e645
  36. 16 5月, 2015 2 次提交
    • M
      Expose a public API for consumers of CompilationWithAnalyzers to clear off... · 76bc499e
      Manish Vasani 提交于
      Expose a public API for consumers of CompilationWithAnalyzers to clear off analyzer state cached during analyzer execution.
      
      Executing analyzers requires us to internally store state such as supported diagnostics, registered actions, exception handlers for analyzer exceptions, etc. for the entire lifetime of analyzers. However, the lifetime of the analyzer instances is controlled only by the analyzer host, i.e. the consumer of CompilationWithAnalyzers. We cannot implicitly clear this internal state when disposing CompilationWithAnalyzers as the analyzer host might be re-using the same analyzer instances across multiple CompilationWithAnalyzers instances.
      
      Fix is to expose an API on CompilationWithAnalyzers to allow the analyzer host to explicitly clear stored analyzer state, when it is done using analyzer instances.
      
      Long term solution is to make the AnalyzerManager public and remove its static instance, so that the analyzer host can explicitly control its lifetime.
      76bc499e
    • M
      Add a new command line compiler switch "/reportanalyzer" to report analyzer... · 3de55924
      Manish Vasani 提交于
      Add a new command line compiler switch "/reportanalyzer" to report analyzer execution times. Output is grouped by analyzer assemblies and is displayed in descending order of execution times.
      
      NOTE: We do not display the total build time or the ratios between build time and analyzer execution time as the the actual wall clock time for analyzer execution is likely lesser due to multithreaded analyzer execution.
      3de55924