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

Skipping analyzers when compiling in release mode #3208

Merged
merged 1 commit into from
Jul 30, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,18 @@ public async Task<Assembly> EmitAsync(CancellationToken cancellationToken)
using (var assemblyStream = new MemoryStream())
using (var pdbStream = new MemoryStream())
{
var compilationWithAnalyzers = _compilation.WithAnalyzers(GetAnalyzers());
var diagnostics = await compilationWithAnalyzers.GetAnalyzerDiagnosticsAsync();
Compilation compilation = _compilation;
var diagnostics = ImmutableArray<Diagnostic>.Empty;

if (compilation.Options.OptimizationLevel == OptimizationLevel.Debug)
{
var compilationWithAnalyzers = compilation.WithAnalyzers(GetAnalyzers());
Copy link
Member

Choose a reason for hiding this comment

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

What about the WithAnalyzers call in GetDiagnostics()? When is that path exercised?

Copy link
Member Author

Choose a reason for hiding this comment

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

That is only exercised in active development scenarios (on non-emit paths), so we want to keep that information.

diagnostics = await compilationWithAnalyzers.GetAnalyzerDiagnosticsAsync();
compilation = compilationWithAnalyzers.Compilation;
}

var emitOptions = new EmitOptions().WithDebugInformationFormat(PlatformHelper.IsMono ? DebugInformationFormat.PortablePdb : DebugInformationFormat.Pdb);
var emitResult = compilationWithAnalyzers.Compilation.Emit(assemblyStream, pdbStream, options: emitOptions, cancellationToken: cancellationToken);
var emitResult = compilation.Emit(assemblyStream, pdbStream, options: emitOptions, cancellationToken: cancellationToken);

diagnostics = diagnostics.AddRange(emitResult.Diagnostics);

Expand Down