Skip to content

Commit

Permalink
Add a few more dag dumps
Browse files Browse the repository at this point in the history
  • Loading branch information
alrz committed Sep 10, 2021
1 parent bb1be2b commit 1e93434
Showing 1 changed file with 111 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2178,6 +2178,42 @@ void Test(int[] a, int[] b)
// (9,18): error CS8120: The switch case is unreachable. It has already been handled by a previous case or it is impossible to match.
// case ([42], [43]):
Diagnostic(ErrorCode.ERR_SwitchCaseSubsumed, "([42], [43])").WithLocation(9, 18));

var tree = comp.SyntaxTrees.First();
var @switch = tree.GetRoot().DescendantNodes().OfType<SwitchStatementSyntax>().Single();
var model = (CSharpSemanticModel)comp.GetSemanticModel(tree);
var binder = model.GetEnclosingBinder(@switch.SpanStart);
var boundSwitch = (BoundSwitchStatement)binder.BindStatement(@switch, BindingDiagnosticBag.Discarded);
AssertEx.Equal(
@"[0]: t1 = t0.a; [1]
[1]: t1 != null ? [2] : [22]
[2]: t2 = t1.Length; [3]
[3]: t2 >= 1 ? [4] : [22]
[4]: t3 = t1[-1]; [5]
[5]: t3 == 42 ? [6] : [19]
[6]: t4 = t0.b; [7]
[7]: t4 != null ? [8] : [22]
[8]: t5 = t4.Length; [9]
[9]: t5 >= 1 ? [10] : [22]
[10]: t6 = t4[-1]; [11]
[11]: t6 == 43 ? [12] : [13]
[12]: leaf `case ([.., 42], [.., 43]):`
[13]: t2 == 1 ? [14] : [22]
[14]: t7 = t1[0]; [15]
[15]: t7 <-- t3; [16]
[16]: t5 == 1 ? [17] : [22]
[17]: t9 = t4[0]; [18]
[18]: t9 <-- t6; [22]
[19]: t2 == 1 ? [20] : [22]
[20]: t7 = t1[0]; [21]
[21]: t7 <-- t3; [22]
[22]: leaf <break> `switch (a, b)
{
case ([.., 42], [.., 43]):
case ([42], [43]):
break;
}`
", boundSwitch.DecisionDag.Dump());
}

[Fact]
Expand Down Expand Up @@ -2235,6 +2271,33 @@ void Test(int[] a)
// case [1, 2, 3]:
Diagnostic(ErrorCode.ERR_SwitchCaseSubsumed, "[1, 2, 3]").WithLocation(9, 18)
);

var tree = comp.SyntaxTrees.First();
var @switch = tree.GetRoot().DescendantNodes().OfType<SwitchStatementSyntax>().Single();
var model = (CSharpSemanticModel)comp.GetSemanticModel(tree);
var binder = model.GetEnclosingBinder(@switch.SpanStart);
var boundSwitch = (BoundSwitchStatement)binder.BindStatement(@switch, BindingDiagnosticBag.Discarded);
AssertEx.Equal(
@"[0]: t0 != null ? [1] : [13]
[1]: t1 = t0.Length; [2]
[2]: t1 >= 2 ? [3] : [13]
[3]: t2 = t0[0]; [4]
[4]: t2 == 1 ? [5] : [13]
[5]: t3 = t0[-1]; [6]
[6]: t3 == 3 ? [7] : [8]
[7]: leaf `case [1, .., 3]:`
[8]: t1 == 3 ? [9] : [13]
[9]: t4 = t0[1]; [10]
[10]: t4 == 2 ? [11] : [13]
[11]: t5 = t0[2]; [12]
[12]: t5 <-- t3; [13]
[13]: leaf <break> `switch (a)
{
case [1, .., 3]:
case [1, 2, 3]:
break;
}`
", boundSwitch.DecisionDag.Dump());
}

[Fact]
Expand Down Expand Up @@ -2268,6 +2331,33 @@ static void Main()
var comp = CreateCompilationWithIndexAndRange(src, parseOptions: TestOptions.RegularWithListPatterns, options: TestOptions.ReleaseExe);
comp.VerifyEmitDiagnostics();
CompileAndVerify(comp, expectedOutput: expectedOutput);

var tree = comp.SyntaxTrees.First();
var @switch = tree.GetRoot().DescendantNodes().OfType<SwitchStatementSyntax>().Single();
var model = (CSharpSemanticModel)comp.GetSemanticModel(tree);
var binder = model.GetEnclosingBinder(@switch.SpanStart);
var boundSwitch = (BoundSwitchStatement)binder.BindStatement(@switch, BindingDiagnosticBag.Discarded);
AssertEx.Equal(
@"[0]: t0 != null ? [1] : [18]
[1]: t1 = t0.Length; [2]
[2]: t1 == 3 ? [3] : [12]
[3]: t2 = t0[0]; [4]
[4]: t2 == 1 ? [5] : [18]
[5]: t3 = t0[1]; [6]
[6]: t3 == 2 ? [7] : [15]
[7]: t4 = t0[2]; [8]
[8]: t4 == 3 ? [9] : [10]
[9]: leaf `case [1, 2, 3]:`
[10]: t5 = t0[-1]; [11]
[11]: t5 <-- t4; [18]
[12]: t1 >= 2 ? [13] : [18]
[13]: t2 = t0[0]; [14]
[14]: t2 == 1 ? [15] : [18]
[15]: t5 = t0[-1]; [16]
[16]: t5 == 3 ? [17] : [18]
[17]: leaf `case [1, .., 3]:`
[18]: leaf `default`
", boundSwitch.DecisionDag.Dump());
}

[Fact]
Expand Down Expand Up @@ -2301,6 +2391,27 @@ static void Main()
var comp = CreateCompilationWithIndexAndRange(src, parseOptions: TestOptions.RegularWithListPatterns, options: TestOptions.ReleaseExe);
comp.VerifyEmitDiagnostics();
CompileAndVerify(comp, expectedOutput: expectedOutput);

var tree = comp.SyntaxTrees.First();
var @switch = tree.GetRoot().DescendantNodes().OfType<SwitchStatementSyntax>().Single();
var model = (CSharpSemanticModel)comp.GetSemanticModel(tree);
var binder = model.GetEnclosingBinder(@switch.SpanStart);
var boundSwitch = (BoundSwitchStatement)binder.BindStatement(@switch, BindingDiagnosticBag.Discarded);
AssertEx.Equal(
@"[0]: t0 != null ? [1] : [12]
[1]: t1 = t0.Length; [2]
[2]: t1 == 1 ? [3] : [8]
[3]: t2 = t0[0]; [4]
[4]: t2 == 42 ? [5] : [6]
[5]: leaf `case [42]:`
[6]: t3 = t0[-1]; [7]
[7]: t3 <-- t2; [12]
[8]: t1 >= 1 ? [9] : [12]
[9]: t3 = t0[-1]; [10]
[10]: t3 == 42 ? [11] : [12]
[11]: leaf `case [..,42]:`
[12]: leaf `default`
", boundSwitch.DecisionDag.Dump());
}

[Fact]
Expand Down

0 comments on commit 1e93434

Please sign in to comment.