Skip to content
Permalink
Browse files

EnC emit tests for C# 8.0 patterns (#37025)

* EnC LocalSlotMappingTests for C# 8.0 patterns
* PDBTest
* EditAndContinueTest
  • Loading branch information...
ivanbasov authored and gafter committed Jul 11, 2019
1 parent 582ca81 commit d4a4944f4c78722ad13d096373ae4b72ee2951a6
@@ -9850,6 +9850,215 @@ .maxstack 2
IL_0007: add
IL_0008: ret
}
");
}

[ConditionalFact(typeof(WindowsDesktopOnly), Reason = ConditionalSkipReason.EditAndContinueRequiresDesktop, AlwaysSkip = "https://github.com/dotnet/roslyn/issues/37047")]
public void OutVar_InSwitchExpression()
{
var source0 = MarkedSource(@"
public class Program
{
static object G(int i)
{
return i switch
{
0 => 0,
_ => 1
};
}
static object N(out int x) { x = 1; return null; }
}");
var source1 = MarkedSource(@"
public class Program
{
static object G(int i)
{
return i + N(out var x) switch
{
0 => 0,
_ => 1
};
}
static int N(out int x) { x = 1; return 0; }
}");
var compilation0 = CreateCompilation(source0.Tree, options: ComSafeDebugDll);
var compilation1 = compilation0.WithSource(source1.Tree);
var compilation2 = compilation1.WithSource(source0.Tree);

var n0 = compilation0.GetMember<MethodSymbol>("Program.G");
var n1 = compilation1.GetMember<MethodSymbol>("Program.G");
var n2 = compilation2.GetMember<MethodSymbol>("Program.G");

var v0 = CompileAndVerify(compilation0);
v0.VerifyIL("Program.G(int)", @"
{
// Code size 27 (0x1b)
.maxstack 1
.locals init (int V_0,
int V_1,
object V_2)
IL_0000: nop
IL_0001: ldarg.0
IL_0002: brfalse.s IL_0006
IL_0004: br.s IL_000a
IL_0006: ldc.i4.0
IL_0007: stloc.0
IL_0008: br.s IL_000e
IL_000a: ldc.i4.1
IL_000b: stloc.0
IL_000c: br.s IL_000e
IL_000e: ldloc.0
IL_000f: stloc.1
IL_0010: ldloc.1
IL_0011: box ""int""
IL_0016: stloc.2
IL_0017: br.s IL_0019
IL_0019: ldloc.2
IL_001a: ret
}
");
v0.VerifyIL("Program.N(out int)", @"
{
// Code size 10 (0xa)
.maxstack 2
.locals init (object V_0)
IL_0000: nop
IL_0001: ldarg.0
IL_0002: ldc.i4.1
IL_0003: stind.i4
IL_0004: ldnull
IL_0005: stloc.0
IL_0006: br.s IL_0008
IL_0008: ldloc.0
IL_0009: ret
}
");

var md0 = ModuleMetadata.CreateFromImage(v0.EmittedAssemblyData);

var generation0 = EmitBaseline.CreateInitialBaseline(md0, v0.CreateSymReader().GetEncMethodDebugInfo);
var diff1 = compilation1.EmitDifference(
generation0,
ImmutableArray.Create(
new SemanticEdit(SemanticEditKind.Update, n0, n1, GetSyntaxMapFromMarkers(source0, source1), preserveLocalVariables: true)));

diff1.VerifySynthesizedMembers();

diff1.VerifyIL("Program.G(int)", @"
{
// Code size 50 (0x32)
.maxstack 2
.locals init ([int] V_0,
[int] V_1,
[object] V_2,
int V_3, //x
int V_4,
int V_5,
int V_6,
int V_7,
object V_8)
IL_0000: nop
IL_0001: ldarg.0
IL_0002: stloc.s V_4
IL_0004: ldloca.s V_3
IL_0006: call ""int Program.N(out int)""
IL_000b: stloc.s V_6
IL_000d: ldloc.s V_6
IL_000f: brfalse.s IL_0013
IL_0011: br.s IL_0018
IL_0013: ldc.i4.0
IL_0014: stloc.s V_5
IL_0016: br.s IL_001d
IL_0018: ldc.i4.1
IL_0019: stloc.s V_5
IL_001b: br.s IL_001d
IL_001d: ldloc.s V_5
IL_001f: stloc.s V_7
IL_0021: ldloc.s V_4
IL_0023: ldloc.s V_7
IL_0025: add
IL_0026: box ""int""
IL_002b: stloc.s V_8
IL_002d: br.s IL_002f
IL_002f: ldloc.s V_8
IL_0031: ret
}
");
diff1.VerifyIL("Program.N(out int)", @"
{
// Code size 10 (0xa)
.maxstack 2
.locals init (int V_0)
IL_0000: nop
IL_0001: ldarg.0
IL_0002: ldc.i4.1
IL_0003: stind.i4
IL_0004: ldc.i4.0
IL_0005: stloc.0
IL_0006: br.s IL_0008
IL_0008: ldloc.0
IL_0009: ret
}
");

var diff2 = compilation2.EmitDifference(
diff1.NextGeneration,
ImmutableArray.Create(
new SemanticEdit(SemanticEditKind.Update, n1, n2, GetSyntaxMapFromMarkers(source1, source0), preserveLocalVariables: true)));

diff2.VerifySynthesizedMembers();

diff2.VerifyIL("Program.G(int)", @"
{
// Code size 53 (0x35)
.maxstack 4
.locals init (System.Collections.Generic.IEnumerable<int> V_0) //query
IL_0000: nop
IL_0001: ldc.i4.2
IL_0002: newarr ""int""
IL_0007: dup
IL_0008: ldc.i4.0
IL_0009: ldc.i4.1
IL_000a: stelem.i4
IL_000b: dup
IL_000c: ldc.i4.1
IL_000d: ldc.i4.2
IL_000e: stelem.i4
IL_000f: ldsfld ""System.Func<int, int> Program.<>c.<>9__1_0""
IL_0014: dup
IL_0015: brtrue.s IL_002e
IL_0017: pop
IL_0018: ldsfld ""Program.<>c Program.<>c.<>9""
IL_001d: ldftn ""int Program.<>c.<N>b__1_0(int)""
IL_0023: newobj ""System.Func<int, int>..ctor(object, System.IntPtr)""
IL_0028: dup
IL_0029: stsfld ""System.Func<int, int> Program.<>c.<>9__1_0""
IL_002e: call ""System.Collections.Generic.IEnumerable<int> System.Linq.Enumerable.Select<int, int>(System.Collections.Generic.IEnumerable<int>, System.Func<int, int>)""
IL_0033: stloc.0
IL_0034: ret
}
");
diff2.VerifyIL("Program.N(out int)", @"
{
// Code size 20 (0x14)
.maxstack 3
.locals init (int V_0, //x
[int] V_1,
int V_2) //y
IL_0000: ldarg.1
IL_0001: ldloca.s V_0
IL_0003: call ""int Program.M(int, out int)""
IL_0008: ldloc.0
IL_0009: add
IL_000a: ldarg.1
IL_000b: ldloca.s V_2
IL_000d: call ""int Program.M(int, out int)""
IL_0012: add
IL_0013: ret
}
");
}
}

0 comments on commit d4a4944

Please sign in to comment.
You can’t perform that action at this time.