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

EnC - Tell the debugger about updated type def tokens #53217

Merged
merged 13 commits into from
May 17, 2021
Original file line number Diff line number Diff line change
Expand Up @@ -3352,7 +3352,6 @@ internal override EmitDifferenceResult EmitDifference(
Stream metadataStream,
Stream ilStream,
Stream pdbStream,
ICollection<MethodDefinitionHandle> updatedMethods,
CompilationTestData? testData,
CancellationToken cancellationToken)
{
Expand All @@ -3364,7 +3363,6 @@ internal override EmitDifferenceResult EmitDifference(
metadataStream,
ilStream,
pdbStream,
updatedMethods,
testData,
cancellationToken);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using System.Threading;
using Microsoft.CodeAnalysis.CodeGen;
using Microsoft.CodeAnalysis.Emit;
using Microsoft.CodeAnalysis.PooledObjects;
using Roslyn.Utilities;

namespace Microsoft.CodeAnalysis.CSharp.Emit
Expand All @@ -24,7 +25,6 @@ internal static EmitDifferenceResult EmitDifference(
Stream metadataStream,
Stream ilStream,
Stream pdbStream,
ICollection<MethodDefinitionHandle> updatedMethods,
CompilationTestData? testData,
CancellationToken cancellationToken)
{
Expand All @@ -35,6 +35,9 @@ internal static EmitDifferenceResult EmitDifference(
var serializationProperties = compilation.ConstructModuleSerializationProperties(emitOptions, runtimeMDVersion, baseline.ModuleVersionId);
var manifestResources = SpecializedCollections.EmptyEnumerable<ResourceDescription>();

var updatedMethods = ArrayBuilder<MethodDefinitionHandle>.GetInstance();
var updatedTypes = ArrayBuilder<TypeDefinitionHandle>.GetInstance();

PEDeltaAssemblyBuilder moduleBeingBuilt;
try
{
Expand All @@ -52,7 +55,7 @@ internal static EmitDifferenceResult EmitDifference(
{
// TODO: https://github.com/dotnet/roslyn/issues/9004
diagnostics.Add(ErrorCode.ERR_ModuleEmitFailure, NoLocation.Singleton, compilation.AssemblyName, e.Message);
return new EmitDifferenceResult(success: false, diagnostics: diagnostics.ToReadOnlyAndFree(), baseline: null);
return new EmitDifferenceResult(success: false, diagnostics: diagnostics.ToReadOnlyAndFree(), baseline: null, updatedMethods: updatedMethods.ToImmutableAndFree(), updatedTypes: updatedTypes.ToImmutableAndFree());
}

if (testData != null)
Expand Down Expand Up @@ -87,6 +90,7 @@ internal static EmitDifferenceResult EmitDifference(
ilStream,
pdbStream,
updatedMethods,
updatedTypes,
diagnostics,
testData?.SymWriterFactory,
emitOptions.PdbFilePath,
Expand All @@ -96,7 +100,9 @@ internal static EmitDifferenceResult EmitDifference(
return new EmitDifferenceResult(
success: newBaseline != null,
diagnostics: diagnostics.ToReadOnlyAndFree(),
baseline: newBaseline);
baseline: newBaseline,
updatedMethods: updatedMethods.ToImmutableAndFree(),
updatedTypes: updatedTypes.ToImmutableAndFree());
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class C
c2.GlobalNamespace.GetMember<NamedTypeSymbol>("C").GetMember("Main"))
};

c2.EmitDifference(baseline, edits, mdStream, ilStream, pdbStream, updatedMethods);
c2.EmitDifference(baseline, edits, s => false, mdStream, ilStream, pdbStream);

var actualIL = ImmutableArray.Create(ilStream.ToArray()).GetMethodIL();
var expectedIL = @"
Expand Down Expand Up @@ -152,7 +152,7 @@ class C
c2.GlobalNamespace.GetMember<NamedTypeSymbol>("C").GetMember("Main"))
};

c2.EmitDifference(baseline, edits, mdStream, ilStream, pdbStream, updatedMethods);
c2.EmitDifference(baseline, edits, s => false, mdStream, ilStream, pdbStream);

var actualIL = ImmutableArray.Create(ilStream.ToArray()).GetMethodIL();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ static IEnumerable<int> G()
using var md1 = diff1.GetMetadata();
var reader1 = md1.Reader;

diff1.VerifyUpdatedTypes("0x02000002");

CheckEncLog(reader1,
Row(2, TableIndex.AssemblyRef, EditAndContinueOperation.Default),
Row(17, TableIndex.MemberRef, EditAndContinueOperation.Default),
Expand Down Expand Up @@ -860,6 +862,8 @@ static async Task<int> F()
// only methods with sequence points should be listed in UpdatedMethods:
diff1.VerifyUpdatedMethods("0x06000004");

diff1.VerifyUpdatedTypes("0x02000002", "0x02000003");

using (var md1 = diff1.GetMetadata())
{
// Verify that no new TypeDefs, FieldDefs or MethodDefs were added,
Expand Down Expand Up @@ -3321,6 +3325,8 @@ .locals init (int V_0)
ImmutableArray.Create(
SemanticEdit.Create(SemanticEditKind.Update, f0, f1, GetSyntaxMapFromMarkers(source0, source1), preserveLocalVariables: true)));

diff1.VerifyUpdatedTypes("0x02000003", "0x02000004");

diff1.VerifySynthesizedMembers(
"C: {<F>d__0}",
"C.<F>d__0: {<>1__state, <>2__current, <>l__initialThreadId, <>4__this, <x>5__1, System.IDisposable.Dispose, MoveNext, System.Collections.Generic.IEnumerator<System.Int32>.get_Current, System.Collections.IEnumerator.Reset, System.Collections.IEnumerator.get_Current, System.Collections.Generic.IEnumerable<System.Int32>.GetEnumerator, System.Collections.IEnumerable.GetEnumerator, System.Collections.Generic.IEnumerator<System.Int32>.Current, System.Collections.IEnumerator.Current}",
Expand All @@ -3333,6 +3339,8 @@ .locals init (int V_0)
ImmutableArray.Create(
SemanticEdit.Create(SemanticEditKind.Update, f1, f2, GetSyntaxMapFromMarkers(source1, source2), preserveLocalVariables: true)));

diff2.VerifyUpdatedTypes("0x02000003", "0x02000004");

diff2.VerifySynthesizedMembers(
"C: {<F>d__0}",
"C.<F>d__0: {<>1__state, <>2__current, <>l__initialThreadId, <>4__this, <x>5__1, System.IDisposable.Dispose, MoveNext, System.Collections.Generic.IEnumerator<System.Int32>.get_Current, System.Collections.IEnumerator.Reset, System.Collections.IEnumerator.get_Current, System.Collections.Generic.IEnumerable<System.Int32>.GetEnumerator, System.Collections.IEnumerable.GetEnumerator, System.Collections.Generic.IEnumerator<System.Int32>.Current, System.Collections.IEnumerator.Current}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -863,6 +863,8 @@ public void AddField()
var reader1 = md1.Reader;
var readers = new[] { reader0, reader1 };

diff1.VerifyUpdatedTypes("0x02000002");

CheckNames(readers, reader1.GetTypeDefNames());
CheckNames(readers, reader1.GetFieldDefNames(), "G");
CheckNames(readers, reader1.GetMethodDefNames(), ".ctor");
Expand Down Expand Up @@ -1615,6 +1617,8 @@ static object F()
var reader1 = md1.Reader;
var readers = new[] { reader0, reader1 };

diff1.VerifyUpdatedTypes("0x02000002", "0x02000003");

CheckNames(readers, reader1.GetTypeDefNames(), "C`1");
Assert.Equal(1, reader1.GetTableRowCount(TableIndex.NestedClass));

Expand Down Expand Up @@ -2046,6 +2050,8 @@ interface J { }
var reader1 = md1.Reader;
var readers = new[] { reader0, reader1 };

diff1.VerifyUpdatedTypes("0x02000002");

CheckNames(readers, reader1.GetTypeDefNames(), "J");
CheckNames(readers, reader1.GetFieldDefNames(), "X", "Y");
CheckNames(readers, reader1.GetMethodDefNames(), "add_Y", "remove_Y", "M", "N", "get_P", "set_P", "get_Q", "set_Q", "add_E", "remove_E", "add_F", "remove_F", ".cctor");
Expand All @@ -2071,6 +2077,8 @@ interface J { }
var reader2 = md2.Reader;
readers = new[] { reader0, reader1, reader2 };

diff2.VerifyUpdatedTypes("0x02000002");

CheckNames(readers, reader2.GetTypeDefNames());
CheckNames(readers, reader2.GetFieldDefNames(), "X");
CheckNames(readers, reader2.GetMethodDefNames(), "M", "N", "get_P", "set_P", "get_Q", "set_Q", "add_E", "remove_E", "add_F", "remove_F", ".cctor");
Expand Down Expand Up @@ -2207,6 +2215,8 @@ [B] static void M2<[A]T>() { }
var reader1 = md1.Reader;
var readers = new[] { reader0, reader1 };

diff1.VerifyUpdatedTypes("0x02000004");

CheckNames(readers, reader1.GetTypeDefNames());
CheckNames(readers, reader1.GetMethodDefNames(), "M2", "get_P2", "add_E2", "remove_E2");

Expand Down Expand Up @@ -2352,6 +2362,9 @@ static void M()
// Verify delta metadata contains expected rows.
using var md1 = diff1.GetMetadata();
var readers = new[] { reader0, md1.Reader };

diff1.VerifyUpdatedTypes("0x02000002");

CheckNames(readers, md1.Reader.GetTypeDefNames());
CheckNames(readers, md1.Reader.GetMethodDefNames(), "M");
CheckEncLog(md1.Reader,
Expand Down Expand Up @@ -2422,6 +2435,9 @@ void M()
using var md1 = diff1.GetMetadata();
var reader1 = md1.Reader;
var readers = new[] { reader0, reader1 };

diff1.VerifyUpdatedTypes("0x02000003");
davidwengier marked this conversation as resolved.
Show resolved Hide resolved

CheckNames(readers, reader1.GetTypeDefNames());
CheckNames(readers, reader1.GetEventDefNames());
CheckNames(readers, reader1.GetFieldDefNames());
Expand Down Expand Up @@ -2465,6 +2481,8 @@ static void M()
var md1 = diff1.GetMetadata();
var reader1 = md1.Reader;

diff1.VerifyUpdatedTypes("0x02000002");

CheckEncLog(reader1,
Row(2, TableIndex.AssemblyRef, EditAndContinueOperation.Default),
Row(12, TableIndex.TypeRef, EditAndContinueOperation.Default),
Expand Down Expand Up @@ -2559,6 +2577,8 @@ class C
generation0,
ImmutableArray.Create(SemanticEdit.Create(SemanticEditKind.Insert, null, compilation1.GetMember<MethodSymbol>("C.puts"))));

diff1.VerifyUpdatedTypes("0x02000002");

using var md1 = diff1.GetMetadata();
var reader1 = md1.Reader;
CheckEncLog(reader1,
Expand Down Expand Up @@ -6178,7 +6198,7 @@ .locals init ([unchanged] V_0,
IL_0021: br.s IL_0023
-IL_0023: ldloc.s V_6
IL_0025: ret
}", methodToken: diff1.UpdatedMethods.Single());
}", methodToken: diff1.EmitResult.UpdatedMethods.Single());
}

/// <summary>
Expand Down Expand Up @@ -7381,7 +7401,6 @@ static string F()
var method1F = compilation1.GetMember<MethodSymbol>("C.F");

using MemoryStream mdStream = new MemoryStream(), ilStream = new MemoryStream(), pdbStream = new MemoryStream();
var updatedMethods = new List<MethodDefinitionHandle>();
var isAddedSymbol = new Func<ISymbol, bool>(s => false);

var badStream = new BrokenStream();
Expand All @@ -7394,7 +7413,6 @@ static string F()
badStream,
ilStream,
pdbStream,
updatedMethods,
new CompilationTestData(),
default);
Assert.False(result.Success);
Expand All @@ -7410,7 +7428,6 @@ static string F()
mdStream,
badStream,
pdbStream,
updatedMethods,
new CompilationTestData(),
default);
Assert.False(result.Success);
Expand All @@ -7426,7 +7443,6 @@ static string F()
mdStream,
ilStream,
badStream,
updatedMethods,
new CompilationTestData(),
default);
Assert.False(result.Success);
Expand Down Expand Up @@ -7470,7 +7486,6 @@ static string F()
var method1F = compilation1.GetMember<MethodSymbol>("C.F");

using MemoryStream mdStream = new MemoryStream(), ilStream = new MemoryStream(), pdbStream = new MemoryStream();
var updatedMethods = new List<MethodDefinitionHandle>();
var isAddedSymbol = new Func<ISymbol, bool>(s => false);

var badStream = new BrokenStream();
Expand All @@ -7483,7 +7498,6 @@ static string F()
mdStream,
ilStream,
badStream,
updatedMethods,
new CompilationTestData(),
default);
Assert.False(result.Success);
Expand Down Expand Up @@ -9380,6 +9394,8 @@ .maxstack 2
ImmutableArray.Create(
SemanticEdit.Create(SemanticEditKind.Update, ctor0, ctor1, GetSyntaxMapFromMarkers(source0, source1), preserveLocalVariables: true)));

diff1.VerifyUpdatedTypes("0x02000002", "0x02000004");

diff1.VerifySynthesizedMembers(
"C: {<>c__DisplayClass0_0}",
"C.<>c__DisplayClass0_0: {x, <.ctor>b__0}");
Expand Down Expand Up @@ -9423,6 +9439,8 @@ .maxstack 2
ImmutableArray.Create(
SemanticEdit.Create(SemanticEditKind.Update, ctor1, ctor2, GetSyntaxMapFromMarkers(source1, source0), preserveLocalVariables: true)));

diff1.VerifyUpdatedTypes("0x02000002", "0x02000004");

diff2.VerifySynthesizedMembers(
"C: {<>c__DisplayClass0_0}",
"C.<>c__DisplayClass0_0: {x, <.ctor>b__0}");
Expand Down
Loading