提交 99ddc726 编写于 作者: J Jinu Joseph

Resolving Merge Conflict

上级 95f9846d
......@@ -66,6 +66,12 @@
DependsOnTargets="PrepareForBuild"
Condition="('$(Language)' == 'C#' or '$(Language)' == 'VB')">
<CreateItem Include="System.Reflection.AssemblyMetadataAttribute"
AdditionalMetadata="_Parameter1=Serviceable;_Parameter2=True"
Condition="'$(ServiceablePackage)' == 'true'">
<Output TaskParameter="Include" ItemName="AssemblyVersionAttribute" />
</CreateItem>
<!-- The necessity of this Task is tracked by https://github.com/dotnet/roslyn/issues/8421 -->
<WriteCodeFragmentEx
AssemblyAttributes="@(AssemblyVersionAttribute)"
......
......@@ -3,8 +3,7 @@
"MicroBuild.Core": "0.2.0",
"Microsoft.NETCore.Platforms": "1.0.0",
"Microsoft.CodeAnalysis.Test.Resources.Proprietary": "1.2.0-beta1-20160105-04",
"Microsoft.Build.Mono.Debug": "14.1.0",
"Microsoft.DiaSymReader.Native": "1.4.0-rc",
"Microsoft.DiaSymReader.Native": "1.4.0-rc2",
"Microsoft.Net.Compilers": "1.2.1",
"Microsoft.Net.RoslynDiagnostics": "1.2.0-beta2",
"FakeSign": "0.9.2",
......
......@@ -38,8 +38,7 @@ chmod +x crossgen
./crossgen -nologo -platform_assemblies_paths $BIN_DIR System.Reflection.Metadata.dll
# The bootstrap build is currently not copying a dependency. See dotnet/roslyn #7907
./crossgen -nologo -MissingDependenciesOK -platform_assemblies_paths $BIN_DIR Microsoft.CodeAnalysis.dll
./crossgen -nologo -platform_assemblies_paths $BIN_DIR Microsoft.CodeAnalysis.dll
./crossgen -nologo -platform_assemblies_paths $BIN_DIR Microsoft.CodeAnalysis.CSharp.dll
......
无法预览此类型文件
......@@ -17,6 +17,7 @@
<SolutionDir Condition="'$(SolutionDir)' == '' OR '$(SolutionDir)' == '*Undefined*'">..\..\..\..\</SolutionDir>
<OutDir>$(OutDir)csccore\</OutDir>
<RestorePackages>true</RestorePackages>
<ServiceablePackage>true</ServiceablePackage>
<AutoGenerateBindingRedirects>True</AutoGenerateBindingRedirects>
<ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<TargetFrameworkIdentifier>.NETPortable</TargetFrameworkIdentifier>
......
......@@ -18,6 +18,7 @@
<TargetFrameworkIdentifier>.NETPortable</TargetFrameworkIdentifier>
<ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<RestorePackages>true</RestorePackages>
<ServiceablePackage>true</ServiceablePackage>
</PropertyGroup>
<ItemGroup Label="Project References">
<ProjectReference Include="..\..\..\Tools\Source\CompilerGeneratorTools\DeployCompilerGeneratorToolsRuntime\DeployCompilerGeneratorToolsRuntime.csproj">
......
......@@ -301,6 +301,7 @@ private static bool IsSafeForReordering(BoundExpression expression, RefKind kind
case ConversionKind.MethodGroup:
case ConversionKind.NullLiteral:
return true;
case ConversionKind.Boxing:
case ConversionKind.ImplicitDynamic:
case ConversionKind.ExplicitDynamic:
......@@ -321,12 +322,23 @@ private static bool IsSafeForReordering(BoundExpression expression, RefKind kind
case ConversionKind.IntegerToPointer:
current = conv.Operand;
break;
case ConversionKind.ExplicitUserDefined:
case ConversionKind.ImplicitUserDefined:
// expression trees rewrite this later.
// it is a kind of user defined conversions on IntPtr and in some cases can fail
case ConversionKind.IntPtr:
return false;
default:
// Unhandled conversion kind in reordering logic
throw ExceptionUtilities.UnexpectedValue(conv.ConversionKind);
// when this assert is hit, examine whether such conversion kind is
// 1) actually expected to get this far
// 2) figure if it is possibly not producing or consuming any sideeffects (rare case)
// 3) add a case for it
Debug.Assert(false, "Unexpected conversion kind" + conv.ConversionKind);
// it is safe to assume that conversion is not reorderable
return false;
}
break;
}
......
......@@ -995,5 +995,41 @@ .maxstack 1
IL_0030: ret
}");
}
[Fact]
[WorkItem(11751, "https://github.com/dotnet/roslyn/issues/11751")]
public void ExprTreeCOM_IntPtr()
{
var source =
@"
using System;
using System.Linq.Expressions;
using System.Runtime.InteropServices;
unsafe class Program
{
static void Main(string[] args)
{
IntPtr y = new IntPtr();
IAaa i = null;
Expression<Action> e = () => i.Test((ulong)y, null);
}
}
[ComImport]
[Guid(""A88A175D-2448-447A-B786-64682CBEF156"")]
public interface IAaa
{
void Test(ulong y, object z);
}
";
var compilation = CreateCompilationWithMscorlib45AndCSruntime(source, options: TestOptions.ReleaseExe.WithAllowUnsafe(true));
CompileAndVerify(compilation);
}
}
}
......@@ -3,6 +3,7 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Reflection.Metadata;
......@@ -7024,5 +7025,99 @@ public void ManyGenerations()
generation0 = diff1.NextGeneration;
}
}
[WorkItem(187868, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/187868")]
[Fact]
public void PdbReadingErrors()
{
var source0 = MarkedSource(@"
using System;
class C
{
static void F()
{
<N:0>Console.WriteLine(1);</N:0>
}
}");
var source1 = MarkedSource(@"
using System;
class C
{
static void F()
{
<N:0>Console.WriteLine(2);</N:0>
}
}");
var compilation0 = CreateCompilationWithMscorlib(source0.Tree, new[] { SystemCoreRef }, options: TestOptions.DebugDll, assemblyName: "PdbReadingErrorsAssembly");
var compilation1 = compilation0.WithSource(source1.Tree);
var v0 = CompileAndVerify(compilation0);
var md0 = ModuleMetadata.CreateFromImage(v0.EmittedAssemblyData);
var f0 = compilation0.GetMember<MethodSymbol>("C.F");
var f1 = compilation1.GetMember<MethodSymbol>("C.F");
var generation0 = EmitBaseline.CreateInitialBaseline(md0, methodHandle =>
{
throw new InvalidDataException("Bad PDB!");
});
var diff1 = compilation1.EmitDifference(
generation0,
ImmutableArray.Create(new SemanticEdit(SemanticEditKind.Update, f0, f1, GetSyntaxMapFromMarkers(source0, source1), preserveLocalVariables: true)));
// TODO: better error code
diff1.EmitResult.Diagnostics.Verify(
// (6,14): error CS7038: Failed to emit module 'Unable to read debug information of method 'C.F()' (token 0x06000001) from assembly 'PdbReadingErrorsAssembly, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null''.
Diagnostic(ErrorCode.ERR_ModuleEmitFailure, "F").WithArguments("Unable to read debug information of method 'C.F()' (token 0x06000001) from assembly 'PdbReadingErrorsAssembly, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'").WithLocation(6, 14));
}
[Fact]
public void PdbReadingErrors_PassThruExceptions()
{
var source0 = MarkedSource(@"
using System;
class C
{
static void F()
{
<N:0>Console.WriteLine(1);</N:0>
}
}");
var source1 = MarkedSource(@"
using System;
class C
{
static void F()
{
<N:0>Console.WriteLine(2);</N:0>
}
}");
var compilation0 = CreateCompilationWithMscorlib(source0.Tree, new[] { SystemCoreRef }, options: TestOptions.DebugDll, assemblyName: "PdbReadingErrorsAssembly");
var compilation1 = compilation0.WithSource(source1.Tree);
var v0 = CompileAndVerify(compilation0);
var md0 = ModuleMetadata.CreateFromImage(v0.EmittedAssemblyData);
var f0 = compilation0.GetMember<MethodSymbol>("C.F");
var f1 = compilation1.GetMember<MethodSymbol>("C.F");
var generation0 = EmitBaseline.CreateInitialBaseline(md0, methodHandle =>
{
throw new ArgumentOutOfRangeException();
});
// the compiler shound't swallow any exceptions but InvalidDataException
Assert.Throws<ArgumentOutOfRangeException>(() =>
compilation1.EmitDifference(
generation0,
ImmutableArray.Create(new SemanticEdit(SemanticEditKind.Update, f0, f1, GetSyntaxMapFromMarkers(source0, source1), preserveLocalVariables: true))));
}
}
}
{
"dependencies": {
"Microsoft.DiaSymReader.Native": "1.4.0-rc"
"Microsoft.DiaSymReader.Native": "1.4.0-rc2"
},
"frameworks": {
"net46": { }
......
......@@ -113,6 +113,7 @@
ReportAnalyzer="$(ReportAnalyzer)"
Resources="@(_CoreCompileResourceInputs);@(CompiledLicenseFile)"
ResponseFiles="$(CompilerResponseFile)"
RuntimeMetadataVersion="$(RuntimeMetadataVersion)"
SkipCompilerExecution="$(SkipCompilerExecution)"
Sources="@(Compile)"
SubsystemVersion="$(SubsystemVersion)"
......
......@@ -107,6 +107,7 @@
Resources="@(_CoreCompileResourceInputs);@(CompiledLicenseFile)"
ResponseFiles="$(CompilerResponseFile)"
RootNamespace="$(RootNamespace)"
RuntimeMetadataVersion="$(RuntimeMetadataVersion)"
SdkPath="$(FrameworkPathOverride)"
SkipCompilerExecution="$(SkipCompilerExecution)"
Sources="@(Compile)"
......
......@@ -18,6 +18,7 @@
<TargetFrameworkIdentifier>.NETPortable</TargetFrameworkIdentifier>
<ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<RestorePackages>true</RestorePackages>
<ServiceablePackage>true</ServiceablePackage>
<DefineConstants>$(DefineConstants);COMPILERCORE</DefineConstants>
<CodeAnalysisRuleSet>..\CodeAnalysisRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
......
......@@ -10,6 +10,7 @@
using Microsoft.CodeAnalysis.Symbols;
using System.Reflection.Metadata.Ecma335;
using Roslyn.Utilities;
using System.IO;
namespace Microsoft.CodeAnalysis.Emit
{
......@@ -225,7 +226,22 @@ internal VariableSlotAllocator TryCreateVariableSlotAllocator(EmitBaseline basel
{
// Method has not changed since initial generation. Generate a map
// using the local names provided with the initial metadata.
var debugInfo = baseline.DebugInformationProvider(previousHandle);
EditAndContinueMethodDebugInformation debugInfo;
try
{
debugInfo = baseline.DebugInformationProvider(previousHandle);
}
catch (InvalidDataException)
{
// TODO: localize message & use better error code (https://github.com/dotnet/roslyn/issues/11512):
diagnostics.Add(MessageProvider.CreateDiagnostic(
MessageProvider.ERR_ModuleEmitFailure,
method.Locations.First(),
$"Unable to read debug information of method '{MessageProvider.GetErrorDisplayString(method)}' (token 0x{MetadataTokens.GetToken(previousHandle):X8}) " +
$"from assembly '{MessageProvider.GetErrorDisplayString(method.ContainingAssembly)}'"));
return null;
}
methodId = new DebugId(debugInfo.MethodOrdinal, 0);
......
......@@ -87,6 +87,8 @@ public MetadataSymbols(IReadOnlyDictionary<AnonymousTypeKey, AnonymousTypeValue>
/// <param name="module">The metadata of the module before editing.</param>
/// <param name="debugInformationProvider">
/// A function that for a method handle returns Edit and Continue debug information emitted by the compiler into the PDB.
/// The function shall throw <see cref="System.IO.InvalidDataException"/> if the debug information can't be read for the specified method.
/// This exception is caught and converted to an emit diagnostic. Other exceptions are passed through.
/// </param>
/// <returns>An <see cref="EmitBaseline"/> for the module.</returns>
/// <remarks>
......@@ -203,8 +205,9 @@ public static EmitBaseline CreateInitialBaseline(ModuleMetadata module, Func<Met
internal readonly IReadOnlyDictionary<int, AddedOrChangedMethodInfo> AddedOrChangedMethods;
/// <summary>
/// Local variable names for methods from metadata,
/// indexed by method row.
/// Reads EnC debug information of a method from the initial baseline PDB.
/// The function shall throw <see cref="System.IO.InvalidDataException"/> if the debug information can't be read for the specified method.
/// This exception is caught and converted to an emit diagnostic. Other exceptions are passed through.
/// </summary>
internal readonly Func<MethodDefinitionHandle, EditAndContinueMethodDebugInformation> DebugInformationProvider;
......
......@@ -5,6 +5,7 @@
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.IO;
using System.Reflection.Metadata;
using System.Runtime.InteropServices;
using Roslyn.Utilities;
......@@ -504,9 +505,13 @@ private TypeSymbol GetTypeOfTypeRef(TypeReferenceHandle typeRef, out bool isNoPi
if (tokenType == HandleKind.AssemblyReference)
{
// TODO: Can refer to the containing assembly?
isNoPiaLocalType = false;
return LookupTopLevelTypeDefSymbol(Module.GetAssemblyReferenceIndexOrThrow((AssemblyReferenceHandle)tokenResolutionScope), ref fullName);
var assemblyRef = (AssemblyReferenceHandle)tokenResolutionScope;
if (assemblyRef.IsNil)
{
throw new BadImageFormatException();
}
return LookupTopLevelTypeDefSymbol(Module.GetAssemblyReferenceIndexOrThrow(assemblyRef), ref fullName);
}
if (tokenType == HandleKind.ModuleReference)
......@@ -1028,12 +1033,7 @@ internal bool TryGetLocals(MethodDefinitionHandle handle, out ImmutableArray<Loc
localInfo = ImmutableArray<LocalInfo<TypeSymbol>>.Empty;
}
}
catch (UnsupportedSignatureContent)
{
localInfo = ImmutableArray<LocalInfo<TypeSymbol>>.Empty;
return false;
}
catch (BadImageFormatException)
catch (Exception e) when (e is UnsupportedSignatureContent || e is BadImageFormatException || e is IOException)
{
localInfo = ImmutableArray<LocalInfo<TypeSymbol>>.Empty;
return false;
......
......@@ -16,6 +16,7 @@
<TargetFrameworkIdentifier>.NETPortable</TargetFrameworkIdentifier>
<ProjectTypeGuids>{14182A97-F7F0-4C62-8B27-98AA8AE2109A};{F184B08F-C81C-45F6-A57F-5ABD9991F28F}</ProjectTypeGuids>
<RestorePackages>true</RestorePackages>
<ServiceablePackage>true</ServiceablePackage>
</PropertyGroup>
<ItemGroup Label="Project References">
<ProjectReference Include="..\..\..\Tools\Source\CompilerGeneratorTools\DeployCompilerGeneratorToolsRuntime\DeployCompilerGeneratorToolsRuntime.csproj">
......
' Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
Imports System.Runtime.CompilerServices
Imports CompilationCreationTestHelpers
Imports System.Collections.Immutable
Imports Microsoft.CodeAnalysis.Test.Utilities
Imports Microsoft.CodeAnalysis.Text
Imports Microsoft.CodeAnalysis.VisualBasic
Imports Microsoft.CodeAnalysis.VisualBasic.Symbols.Metadata.PE
Imports Microsoft.CodeAnalysis.VisualBasic.Symbols
Imports Microsoft.CodeAnalysis.VisualBasic.Syntax
Imports Roslyn.Test.Utilities
Namespace Microsoft.CodeAnalysis.VisualBasic.UnitTests.Symbols.Metadata.PE
Public Class HasUnsupportedMetadata : Inherits BasicTestBase
......@@ -435,6 +432,86 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.UnitTests.Symbols.Metadata.PE
Assert.True(tok.HasUnsupportedMetadata)
End Sub
''' <summary>
''' Throw a (handled) BadImageFormatException from MetadataDecoder
''' for a TypeRef assembly resolution scope with Nil AssemblyRef.
''' </summary>
<Fact>
<WorkItem(217689, "https://devdiv.visualstudio.com/DefaultCollection/DevDiv/_workitems?_a=edit&id=217689")>
Public Sub ResolutionScopeNilAssembly()
Dim options = TestOptions.ReleaseDll.WithDeterministic(True)
Dim comp1 = CreateCompilationWithMscorlib(
{"Public Class A
End Class"},
options:=options,
assemblyName:="4D94B345-92CE-46BB-891E-048109648A0A")
comp1.VerifyDiagnostics()
Dim bytes1 = comp1.EmitToArray()
Dim ref1 = AssemblyMetadata.CreateFromImage(bytes1).GetReference()
Dim comp2 = CreateCompilationWithMscorlib(
{"Public Class B
Inherits A
End Class"},
options:=options,
assemblyName:="D4954046-BDDC-42C4-98F8-7E5573C16C33",
references:=New MetadataReference() {ref1})
comp2.VerifyDiagnostics()
Dim bytes2 = comp2.EmitToArray()
' Construct an unexpected assembly resolution scope from the valid compilation.
' Metadata contains a single TypeRef with assembly resolution scope where the
' scope is AssemblyRef 2: specifically the TypeRef to base class A. Replace that
' assembly resolution scope with AssemblyRef 0 (the unexpected value). In the
' TypeRef signatures below, 10 and 2 are the assembly scopes (AssemblyRef << 2 | 2).
' (To verify, break in MetadataWriter.SerializeTypeRefTable when emitting comp2.)
bytes2 = ReplaceBytes(bytes2, {10, 0, 82, 0, 0, 0}, {2, 0, 82, 0, 0, 0})
Dim ref2 = AssemblyMetadata.CreateFromImage(bytes2).GetReference()
Dim comp3 = CreateCompilationWithMscorlib(
{"Class C
Shared Sub Main()
Dim o As New B()
End Sub
End Class"},
options:=options,
references:=New MetadataReference() {ref2})
comp3.VerifyDiagnostics()
Dim tree = comp3.SyntaxTrees(0)
Dim model = comp3.GetSemanticModel(tree)
Dim decl = tree.GetRoot().DescendantNodes.OfType(Of ObjectCreationExpressionSyntax).Single()
Dim type = DirectCast(model.GetTypeInfo(decl).Type, TypeSymbol)
Assert.Equal("B", type.ToTestDisplayString())
Assert.False(type.IsErrorType())
Assert.True(type.BaseType.IsErrorType()) ' Handled exception decoding base type TypeRef.
End Sub
Private Shared Function ReplaceBytes(bytes As ImmutableArray(Of Byte), before As Byte(), after As Byte()) As ImmutableArray(Of Byte)
Dim index = IndexOfBytes(bytes, before, 0)
Debug.Assert(index >= 0)
Debug.Assert(IndexOfBytes(bytes, before, index + 1) < 0)
Dim builder = ArrayBuilder(Of Byte).GetInstance()
builder.AddRange(bytes.Take(index))
builder.AddRange(after)
builder.AddRange(bytes.Skip(index + before.Length))
Return builder.ToImmutableAndFree()
End Function
Private Shared Function IndexOfBytes(bytes As ImmutableArray(Of Byte), pattern As Byte(), startIndex As Integer) As Integer
Dim n = bytes.Length
Dim m = pattern.Length
For i = startIndex To n - m - 1
For j = 0 To m - 1
If bytes(i + j) <> pattern(j) Then
GoTo EndOfLoop
End If
Next
Return i
EndOfLoop:
Next
Return -1
End Function
End Class
End Namespace
......
......@@ -17,6 +17,7 @@
<SolutionDir Condition="'$(SolutionDir)' == '' OR '$(SolutionDir)' == '*Undefined*'">..\..\..\..\</SolutionDir>
<OutDir>$(OutDir)vbccore\</OutDir>
<RestorePackages>true</RestorePackages>
<ServiceablePackage>true</ServiceablePackage>
<AutoGenerateBindingRedirects>True</AutoGenerateBindingRedirects>
<ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<TargetFrameworkIdentifier>.NETPortable</TargetFrameworkIdentifier>
......
{
"dependencies": {
"Microsoft.DiaSymReader.Native": "1.4.0-rc"
"Microsoft.DiaSymReader.Native": "1.4.0-rc2"
},
"frameworks": {
"net46": { }
......
......@@ -147,44 +147,58 @@ public IEnumerable<DiagnosticData> ConvertToLocalDiagnostics(Document targetDocu
public async Task<ImmutableDictionary<DiagnosticAnalyzer, AnalysisResult>> ComputeDiagnosticsAsync(
CompilationWithAnalyzers analyzerDriverOpt, Project project, IEnumerable<StateSet> stateSets, CancellationToken cancellationToken)
{
var result = ImmutableDictionary<DiagnosticAnalyzer, AnalysisResult>.Empty;
// analyzerDriver can be null if given project doesn't support compilation.
if (analyzerDriverOpt != null)
try
{
// calculate regular diagnostic analyzers diagnostics
var compilerResult = await analyzerDriverOpt.AnalyzeAsync(project, cancellationToken).ConfigureAwait(false);
result = compilerResult.AnalysisResult;
var result = ImmutableDictionary<DiagnosticAnalyzer, AnalysisResult>.Empty;
// record telemetry data
UpdateAnalyzerTelemetryData(compilerResult, project, cancellationToken);
}
// analyzerDriver can be null if given project doesn't support compilation.
if (analyzerDriverOpt != null)
{
// calculate regular diagnostic analyzers diagnostics
var compilerResult = await analyzerDriverOpt.AnalyzeAsync(project, cancellationToken).ConfigureAwait(false);
result = compilerResult.AnalysisResult;
// check whether there is IDE specific project diagnostic analyzer
return await MergeProjectDiagnosticAnalyzerDiagnosticsAsync(project, stateSets, analyzerDriverOpt?.Compilation, result, cancellationToken).ConfigureAwait(false);
// record telemetry data
UpdateAnalyzerTelemetryData(compilerResult, project, cancellationToken);
}
// check whether there is IDE specific project diagnostic analyzer
return await MergeProjectDiagnosticAnalyzerDiagnosticsAsync(project, stateSets, analyzerDriverOpt?.Compilation, result, cancellationToken).ConfigureAwait(false);
}
catch (Exception e) when (FatalError.ReportUnlessCanceled(e))
{
throw ExceptionUtilities.Unreachable;
}
}
private async Task<ImmutableDictionary<DiagnosticAnalyzer, AnalysisResult>> ComputeDiagnosticsAsync(
CompilationWithAnalyzers analyzerDriverOpt, Project project, IEnumerable<StateSet> stateSets,
ImmutableDictionary<DiagnosticAnalyzer, AnalysisResult> existing, CancellationToken cancellationToken)
{
// PERF: check whether we can reduce number of analyzers we need to run.
// this can happen since caller could have created the driver with different set of analyzers that are different
// than what we used to create the cache.
var version = await GetDiagnosticVersionAsync(project, cancellationToken).ConfigureAwait(false);
ImmutableArray<DiagnosticAnalyzer> analyzersToRun;
if (TryReduceAnalyzersToRun(analyzerDriverOpt, version, existing, out analyzersToRun))
try
{
// it looks like we can reduce the set. create new CompilationWithAnalyzer.
var analyzerDriverWithReducedSet = await _owner._compilationManager.CreateAnalyzerDriverAsync(
project, analyzersToRun, analyzerDriverOpt.AnalysisOptions.ReportSuppressedDiagnostics, cancellationToken).ConfigureAwait(false);
// PERF: check whether we can reduce number of analyzers we need to run.
// this can happen since caller could have created the driver with different set of analyzers that are different
// than what we used to create the cache.
var version = await GetDiagnosticVersionAsync(project, cancellationToken).ConfigureAwait(false);
ImmutableArray<DiagnosticAnalyzer> analyzersToRun;
if (TryReduceAnalyzersToRun(analyzerDriverOpt, version, existing, out analyzersToRun))
{
// it looks like we can reduce the set. create new CompilationWithAnalyzer.
var analyzerDriverWithReducedSet = await _owner._compilationManager.CreateAnalyzerDriverAsync(
project, analyzersToRun, analyzerDriverOpt.AnalysisOptions.ReportSuppressedDiagnostics, cancellationToken).ConfigureAwait(false);
var result = await ComputeDiagnosticsAsync(analyzerDriverWithReducedSet, project, stateSets, cancellationToken).ConfigureAwait(false);
return MergeExistingDiagnostics(version, existing, result);
}
var result = await ComputeDiagnosticsAsync(analyzerDriverWithReducedSet, project, stateSets, cancellationToken).ConfigureAwait(false);
return MergeExistingDiagnostics(version, existing, result);
}
// we couldn't reduce the set.
return await ComputeDiagnosticsAsync(analyzerDriverOpt, project, stateSets, cancellationToken).ConfigureAwait(false);
// we couldn't reduce the set.
return await ComputeDiagnosticsAsync(analyzerDriverOpt, project, stateSets, cancellationToken).ConfigureAwait(false);
}
catch (Exception e) when (FatalError.ReportUnlessCanceled(e))
{
throw ExceptionUtilities.Unreachable;
}
}
private ImmutableDictionary<DiagnosticAnalyzer, AnalysisResult> MergeExistingDiagnostics(
......@@ -254,49 +268,56 @@ public IEnumerable<DiagnosticData> ConvertToLocalDiagnostics(Document targetDocu
private async Task<ImmutableDictionary<DiagnosticAnalyzer, AnalysisResult>> MergeProjectDiagnosticAnalyzerDiagnosticsAsync(
Project project, IEnumerable<StateSet> stateSets, Compilation compilationOpt, ImmutableDictionary<DiagnosticAnalyzer, AnalysisResult> result, CancellationToken cancellationToken)
{
// check whether there is IDE specific project diagnostic analyzer
var ideAnalyzers = stateSets.Select(s => s.Analyzer).Where(a => a is ProjectDiagnosticAnalyzer || a is DocumentDiagnosticAnalyzer).ToImmutableArrayOrEmpty();
if (ideAnalyzers.Length <= 0)
try
{
return result;
}
// check whether there is IDE specific project diagnostic analyzer
var ideAnalyzers = stateSets.Select(s => s.Analyzer).Where(a => a is ProjectDiagnosticAnalyzer || a is DocumentDiagnosticAnalyzer).ToImmutableArrayOrEmpty();
if (ideAnalyzers.Length <= 0)
{
return result;
}
// create result map
var version = await GetDiagnosticVersionAsync(project, cancellationToken).ConfigureAwait(false);
var builder = new CompilerDiagnosticExecutor.Builder(project, version);
// create result map
var version = await GetDiagnosticVersionAsync(project, cancellationToken).ConfigureAwait(false);
var builder = new CompilerDiagnosticExecutor.Builder(project, version);
foreach (var analyzer in ideAnalyzers)
{
var documentAnalyzer = analyzer as DocumentDiagnosticAnalyzer;
if (documentAnalyzer != null)
foreach (var analyzer in ideAnalyzers)
{
foreach (var document in project.Documents)
var documentAnalyzer = analyzer as DocumentDiagnosticAnalyzer;
if (documentAnalyzer != null)
{
if (document.SupportsSyntaxTree)
foreach (var document in project.Documents)
{
var tree = await document.GetSyntaxTreeAsync(cancellationToken).ConfigureAwait(false);
builder.AddSyntaxDiagnostics(tree, await ComputeDocumentDiagnosticAnalyzerDiagnosticsAsync(document, documentAnalyzer, AnalysisKind.Syntax, compilationOpt, cancellationToken).ConfigureAwait(false));
builder.AddSemanticDiagnostics(tree, await ComputeDocumentDiagnosticAnalyzerDiagnosticsAsync(document, documentAnalyzer, AnalysisKind.Semantic, compilationOpt, cancellationToken).ConfigureAwait(false));
}
else
{
builder.AddExternalSyntaxDiagnostics(document.Id, await ComputeDocumentDiagnosticAnalyzerDiagnosticsAsync(document, documentAnalyzer, AnalysisKind.Syntax, compilationOpt, cancellationToken).ConfigureAwait(false));
builder.AddExternalSemanticDiagnostics(document.Id, await ComputeDocumentDiagnosticAnalyzerDiagnosticsAsync(document, documentAnalyzer, AnalysisKind.Semantic, compilationOpt, cancellationToken).ConfigureAwait(false));
if (document.SupportsSyntaxTree)
{
var tree = await document.GetSyntaxTreeAsync(cancellationToken).ConfigureAwait(false);
builder.AddSyntaxDiagnostics(tree, await ComputeDocumentDiagnosticAnalyzerDiagnosticsAsync(document, documentAnalyzer, AnalysisKind.Syntax, compilationOpt, cancellationToken).ConfigureAwait(false));
builder.AddSemanticDiagnostics(tree, await ComputeDocumentDiagnosticAnalyzerDiagnosticsAsync(document, documentAnalyzer, AnalysisKind.Semantic, compilationOpt, cancellationToken).ConfigureAwait(false));
}
else
{
builder.AddExternalSyntaxDiagnostics(document.Id, await ComputeDocumentDiagnosticAnalyzerDiagnosticsAsync(document, documentAnalyzer, AnalysisKind.Syntax, compilationOpt, cancellationToken).ConfigureAwait(false));
builder.AddExternalSemanticDiagnostics(document.Id, await ComputeDocumentDiagnosticAnalyzerDiagnosticsAsync(document, documentAnalyzer, AnalysisKind.Semantic, compilationOpt, cancellationToken).ConfigureAwait(false));
}
}
}
}
var projectAnalyzer = analyzer as ProjectDiagnosticAnalyzer;
if (projectAnalyzer != null)
{
builder.AddCompilationDiagnostics(await ComputeProjectDiagnosticAnalyzerDiagnosticsAsync(project, projectAnalyzer, compilationOpt, cancellationToken).ConfigureAwait(false));
var projectAnalyzer = analyzer as ProjectDiagnosticAnalyzer;
if (projectAnalyzer != null)
{
builder.AddCompilationDiagnostics(await ComputeProjectDiagnosticAnalyzerDiagnosticsAsync(project, projectAnalyzer, compilationOpt, cancellationToken).ConfigureAwait(false));
}
// merge the result to existing one.
result = result.Add(analyzer, builder.ToResult());
}
// merge the result to existing one.
result = result.Add(analyzer, builder.ToResult());
return result;
}
catch (Exception e) when (FatalError.ReportUnlessCanceled(e))
{
throw ExceptionUtilities.Unreachable;
}
return result;
}
private async Task<IEnumerable<Diagnostic>> ComputeProjectDiagnosticAnalyzerDiagnosticsAsync(
......
......@@ -388,9 +388,10 @@ public async Task<Deltas> EmitProjectDeltaAsync(Project project, EmitBaseline ba
return new Deltas(ilStream.ToArray(), metadataStream.ToArray(), updateMethodTokens, pdbStream, changes.LineChanges, result);
}
}
catch (Exception e) when (FatalError.ReportUnlessCanceled(e))
catch (Exception e) when (FatalError.ReportWithoutCrash(e))
{
throw ExceptionUtilities.Unreachable;
// recover (cancel EnC)
return null;
}
}
......
{
"dependencies": {
"System.AppContext": "4.1.0-rc3-24128-00"
},
"dependencies": {},
"frameworks": {
"NETCoreApp1.0": {
"imports": ["portable-net452", "dotnet"]
......
{
"dependencies": {
"System.AppContext": "4.1.0-rc3-24128-00"
},
"dependencies": {},
"frameworks": {
"NETCoreApp1.0": {
"imports": ["portable-net452", "dotnet"]
......
......@@ -21,6 +21,7 @@ Supported Platforms:
<projectUrl>$projectUrl$</projectUrl>
<releaseNotes>$releaseNotes$</releaseNotes>
<tags>$tags$</tags>
<serviceable>true</serviceable>
</metadata>
<files>
<file src="Microsoft.CodeAnalysis.CSharp.Workspaces.dll" target="lib\portable-net45+win8" />
......
......@@ -22,6 +22,7 @@ Supported Platforms:
<projectUrl>$projectUrl$</projectUrl>
<releaseNotes>$releaseNotes$</releaseNotes>
<tags>$tags$</tags>
<serviceable>true</serviceable>
</metadata>
<files>
<file src="Microsoft.CodeAnalysis.CSharp.dll" target="lib\portable-net45+win8" />
......
......@@ -70,6 +70,7 @@ Supported Platforms:
<projectUrl>$projectUrl$</projectUrl>
<releaseNotes>$releaseNotes$</releaseNotes>
<tags>$tags$</tags>
<serviceable>true</serviceable>
</metadata>
<files>
<file src="Microsoft.CodeAnalysis.dll" target="lib\portable-net45+win8" />
......
......@@ -24,6 +24,7 @@ Supported Platforms:
<projectUrl>$projectUrl$</projectUrl>
<releaseNotes>$releaseNotes$</releaseNotes>
<tags>$tags$</tags>
<serviceable>true</serviceable>
</metadata>
<files>
<file src="$thirdPartyNoticesPath$" target="" />
......
......@@ -21,6 +21,7 @@ Supported Platforms:
<projectUrl>$projectUrl$</projectUrl>
<releaseNotes>$releaseNotes$</releaseNotes>
<tags>$tags$</tags>
<serviceable>true</serviceable>
</metadata>
<files>
<file src="Microsoft.CodeAnalysis.VisualBasic.Workspaces.dll" target="lib\portable-net45+win8" />
......
......@@ -22,6 +22,7 @@ Supported Platforms:
<projectUrl>$projectUrl$</projectUrl>
<releaseNotes>$releaseNotes$</releaseNotes>
<tags>$tags$</tags>
<serviceable>true</serviceable>
</metadata>
<files>
<file src="Microsoft.CodeAnalysis.VisualBasic.dll" target="lib\portable-net45+win8" />
......
......@@ -24,6 +24,7 @@ Supported Platforms:
<projectUrl>$projectUrl$</projectUrl>
<releaseNotes>$releaseNotes$</releaseNotes>
<tags>$tags$</tags>
<serviceable>true</serviceable>
</metadata>
<files>
<file src="Microsoft.CodeAnalysis.Workspaces.dll" target="lib\portable-net45+win8" />
......
......@@ -15,6 +15,7 @@
<licenseUrl>$licenseUrl$</licenseUrl>
<projectUrl>$projectUrl$</projectUrl>
<tags>$tags$</tags>
<serviceable>true</serviceable>
<dependencies>
<group targetFramework="NETCoreApp1.0">
<dependency id="Microsoft.CodeAnalysis.Compilers" version="[$version$]" />
......
{
"supports": {},
"dependencies": {
"Microsoft.DiaSymReader.Native": "1.4.0-rc"
"Microsoft.DiaSymReader.Native": "1.4.0-rc2"
},
"frameworks": {
".NETPortable,Version=v4.5,Profile=Profile7": {}
......
{
"dependencies": {
"Microsoft.CodeAnalysis.Test.Resources.Proprietary": "1.2.0-beta1-20160105-04",
"Microsoft.DiaSymReader.Native": "1.4.0-rc",
"Microsoft.DiaSymReader.Native": "1.4.0-rc2"
},
"frameworks": {
"net46": { }
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Immutable;
using System.IO;
using System.Reflection.Metadata;
using Microsoft.CodeAnalysis;
......@@ -16,7 +17,7 @@ public static EditAndContinueMethodDebugInformation GetEncMethodDebugInfo(this I
var cdi = CustomDebugInfoUtilities.GetCustomDebugInfoBytes(symReader, handle, methodVersion: 1);
if (cdi == null)
{
return default(EditAndContinueMethodDebugInformation);
return EditAndContinueMethodDebugInformation.Create(default(ImmutableArray<byte>), default(ImmutableArray<byte>));
}
return GetEncMethodDebugInfo(cdi);
......
......@@ -976,6 +976,12 @@ public unsafe int BuildForEnc(object pUpdatePE)
using (NonReentrantContext)
{
delta = emitTask.Result;
if (delta == null)
{
// Non-fatal Watson has already been reported by the emit task
return VSConstants.E_FAIL;
}
}
var errorId = new EncErrorId(_encService.DebuggingSession, EditAndContinueDiagnosticUpdateSource.EmitErrorId);
......@@ -1070,42 +1076,64 @@ private Deltas EmitProjectDelta()
return emitTask.Result;
}
/// <summary>
/// Returns EnC debug information for initial version of the specified method.
/// </summary>
/// <exception cref="InvalidDataException">The debug information data is corrupt or can't be retrieved from the debugger.</exception>
private EditAndContinueMethodDebugInformation GetBaselineEncDebugInfo(MethodDefinitionHandle methodHandle)
{
Debug.Assert(Thread.CurrentThread.GetApartmentState() == ApartmentState.MTA);
if (_pdbReader == null)
{
// Unmarshal the symbol reader (being marshalled cross thread from STA -> MTA).
Debug.Assert(_pdbReaderObjAsStream != IntPtr.Zero);
object pdbReaderObjMta;
int hr = NativeMethods.GetObjectForStream(_pdbReaderObjAsStream, out pdbReaderObjMta);
_pdbReaderObjAsStream = IntPtr.Zero;
if (hr != VSConstants.S_OK)
var exception = Marshal.GetExceptionForHR(NativeMethods.GetObjectForStream(_pdbReaderObjAsStream, out pdbReaderObjMta));
if (exception != null)
{
log.Write("Error unmarshaling object from stream.");
return default(EditAndContinueMethodDebugInformation);
// likely a bug in the compiler/debugger
FatalError.ReportWithoutCrash(exception);
throw new InvalidDataException(exception.Message, exception);
}
_pdbReaderObjAsStream = IntPtr.Zero;
_pdbReader = (ISymUnmanagedReader3)pdbReaderObjMta;
}
int methodToken = MetadataTokens.GetToken(methodHandle);
byte[] debugInfo = _pdbReader.GetCustomDebugInfoBytes(methodToken, methodVersion: 1);
if (debugInfo != null)
byte[] debugInfo;
try
{
debugInfo = _pdbReader.GetCustomDebugInfoBytes(methodToken, methodVersion: 1);
}
catch (Exception e) when (FatalError.ReportWithoutCrash(e)) // likely a bug in the compiler/debugger
{
throw new InvalidDataException(e.Message, e);
}
try
{
try
ImmutableArray<byte> localSlots, lambdaMap;
if (debugInfo != null)
{
var localSlots = CustomDebugInfoReader.TryGetCustomDebugInfoRecord(debugInfo, CustomDebugInfoKind.EditAndContinueLocalSlotMap);
var lambdaMap = CustomDebugInfoReader.TryGetCustomDebugInfoRecord(debugInfo, CustomDebugInfoKind.EditAndContinueLambdaMap);
return EditAndContinueMethodDebugInformation.Create(localSlots, lambdaMap);
localSlots = CustomDebugInfoReader.TryGetCustomDebugInfoRecord(debugInfo, CustomDebugInfoKind.EditAndContinueLocalSlotMap);
lambdaMap = CustomDebugInfoReader.TryGetCustomDebugInfoRecord(debugInfo, CustomDebugInfoKind.EditAndContinueLambdaMap);
}
catch (Exception e) when (e is InvalidOperationException || e is InvalidDataException)
else
{
log.Write($"Error reading CDI of method 0x{methodToken:X8}: {e.Message}");
localSlots = lambdaMap = default(ImmutableArray<byte>);
}
}
return default(EditAndContinueMethodDebugInformation);
return EditAndContinueMethodDebugInformation.Create(localSlots, lambdaMap);
}
catch (InvalidOperationException e) when (FatalError.ReportWithoutCrash(e)) // likely a bug in the compiler/debugger
{
// TODO: CustomDebugInfoReader should throw InvalidDataException
throw new InvalidDataException(e.Message, e);
}
}
public int EncApplySucceeded(int hrApplyResult)
......
......@@ -18,6 +18,7 @@
<TargetFrameworkIdentifier>.NETPortable</TargetFrameworkIdentifier>
<ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<RestorePackages>true</RestorePackages>
<ServiceablePackage>true</ServiceablePackage>
</PropertyGroup>
<ItemGroup Label="Project References">
<ProjectReference Include="..\..\..\Compilers\Core\Portable\CodeAnalysis.csproj">
......
......@@ -17,6 +17,7 @@
<TargetFrameworkProfile>Profile7</TargetFrameworkProfile>
<TargetFrameworkIdentifier>.NETPortable</TargetFrameworkIdentifier>
<ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<ServiceablePackage>true</ServiceablePackage>
</PropertyGroup>
<ItemGroup Label="Project References">
<ProjectReference Include="..\..\..\Compilers\Core\Portable\CodeAnalysis.csproj">
......
......@@ -16,6 +16,7 @@
<TargetFrameworkIdentifier>.NETPortable</TargetFrameworkIdentifier>
<ProjectTypeGuids>{14182A97-F7F0-4C62-8B27-98AA8AE2109A};{F184B08F-C81C-45F6-A57F-5ABD9991F28F}</ProjectTypeGuids>
<RestorePackages>true</RestorePackages>
<ServiceablePackage>true</ServiceablePackage>
</PropertyGroup>
<ItemGroup Label="Project References">
<ProjectReference Include="..\..\..\Compilers\Core\Portable\CodeAnalysis.csproj">
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册