Skip to content

Commit

Permalink
PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
alrz committed Sep 10, 2021
1 parent 2df2a20 commit bb1be2b
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Compilers/CSharp/Portable/Binder/DecisionDagBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -847,6 +847,8 @@ DagState uniqifyState(ImmutableArray<StateForCase> cases, ImmutableDictionary<Bo
// if apropos, which has the effect of flowing the remaining values from the other test in the analysis of subsequent states.
if (state.RemainingValues.TryGetValue(e.Target, out IValueSet? targetValues))
{
// Take the intersection of entries as we have ruled out any impossible
// values for each alias of an element, and now we're dealiasing them.
currentValues = currentValues.Intersect(targetValues);
}
state.TrueBranch = uniqifyState(RemoveEvaluation(state.Cases, e), state.RemainingValues.SetItem(e.Target, currentValues));
Expand Down Expand Up @@ -1638,7 +1640,7 @@ string dumpDagTest(BoundDagTest d)
case BoundDagIndexerEvaluation e:
return $"t{tempIdentifier(e)}={e.Kind}({tempName(e.Input)}[{e.Index}])";
case BoundDagAssignmentEvaluation e:
return $"{e.Kind}({tempName(e.Target)}={tempName(e.Input)})";
return $"{e.Kind}({tempName(e.Target)}<--{tempName(e.Input)})";
case BoundDagEvaluation e:
return $"t{tempIdentifier(e)}={e.Kind}({tempName(e.Input)})";
case BoundDagTypeTest b:
Expand Down
2 changes: 2 additions & 0 deletions src/Compilers/CSharp/Portable/BoundTree/BoundDagTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ public override int GetHashCode()
return $"{i.GetOutputTempDebuggerDisplay()} = {i.Input.GetDebuggerDisplay()}[{i.Index}]";
case BoundDagIndexerEvaluation i:
return $"{i.GetOutputTempDebuggerDisplay()} = {i.Input.GetDebuggerDisplay()}[{i.Index}]";
case BoundDagAssignmentEvaluation i:
return $"{i.Target.GetDebuggerDisplay()} <-- {i.Input.GetDebuggerDisplay()}";
case BoundDagEvaluation e:
return $"{e.GetOutputTempDebuggerDisplay()} = {e.Kind}({e.Input.GetDebuggerDisplay()})";
case BoundDagTypeTest b:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2567,6 +2567,47 @@ void Test(int[][] a)
// (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]]:
Diagnostic(ErrorCode.ERR_SwitchCaseSubsumed, "[[42]]").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] : [27]
[1]: t1 = t0.Length; [2]
[2]: t1 >= 1 ? [3] : [27]
[3]: t2 = t0[-1]; [4]
[4]: t2 != null ? [5] : [24]
[5]: t3 = t2.Length; [6]
[6]: t3 >= 1 ? [7] : [19]
[7]: t4 = t2[-1]; [8]
[8]: t4 == 42 ? [9] : [10]
[9]: leaf `case [.., [.., 42]]:`
[10]: t1 == 1 ? [11] : [27]
[11]: t5 = t0[0]; [12]
[12]: t5 <-- t2; [13]
[13]: t7 = t5.Length; [14]
[14]: t7 <-- t3; [15]
[15]: t7 == 1 ? [16] : [27]
[16]: t9 = t5[0]; [17]
[17]: t3 <-- t7; [18]
[18]: t9 <-- t4; [27]
[19]: t1 == 1 ? [20] : [27]
[20]: t5 = t0[0]; [21]
[21]: t5 <-- t2; [22]
[22]: t7 = t5.Length; [23]
[23]: t7 <-- t3; [27]
[24]: t1 == 1 ? [25] : [27]
[25]: t5 = t0[0]; [26]
[26]: t5 <-- t2; [27]
[27]: leaf <break> `switch (a)
{
case [.., [.., 42]]:
case [[42]]:
break;
}`
", boundSwitch.DecisionDag.Dump());
}

[Fact]
Expand Down

0 comments on commit bb1be2b

Please sign in to comment.