diff --git a/src/Compilers/CSharp/Portable/Binder/DecisionDagBuilder.cs b/src/Compilers/CSharp/Portable/Binder/DecisionDagBuilder.cs index 3647e3cd73010705ba77f3a8bac229890fc918ef..94cd93f3418d61c3347547590629de0ab3311a10 100644 --- a/src/Compilers/CSharp/Portable/Binder/DecisionDagBuilder.cs +++ b/src/Compilers/CSharp/Portable/Binder/DecisionDagBuilder.cs @@ -386,7 +386,7 @@ out ImmutableArray<(BoundExpression, BoundDagTemp)> bindings) /// when an assertion fails (it is unaffected by exception filters on enclosing frames). /// [Conditional("DEBUG")] - private void Assert(bool condition, string message = null) + private static void Assert(bool condition, string message = null) { if (!condition) { @@ -573,7 +573,7 @@ DagState uniqifyState(DagState state) workList.Free(); // Now process the states in topological order, leaves first, and assign a BoundDecisionDag to each DagState. - ImmutableArray sortedStates = initialState.TopologicallySortedReachableStates; + ImmutableArray sortedStates = initialState.TopologicallySortedReachableStates(); Debug.Assert(_defaultLabel != null); var finalStates = PooledDictionary.GetInstance(); finalStates.Add(_defaultLabel, defaultDecision); @@ -935,27 +935,24 @@ public DagState(ImmutableArray cases) public BoundDagDecision SelectedDecision; public DagState TrueBranch, FalseBranch; - public ImmutableArray TopologicallySortedReachableStates + public ImmutableArray TopologicallySortedReachableStates() { - get + // A successor function used to topologically sort the DagState set. + IEnumerable succ(DagState state) { - // A successor function used to topologically sort the DagState set. - IEnumerable succ(DagState state) + if (state.TrueBranch != null) { - if (state.TrueBranch != null) - { - yield return state.TrueBranch; - } - - if (state.FalseBranch != null) - { - yield return state.FalseBranch; - } + yield return state.TrueBranch; } - // Now process the states in topological order, leaves first, and assign a BoundDecisionDag to each DagState. - return TopologicalSort.IterativeSort(SpecializedCollections.SingletonEnumerable(this), succ); + if (state.FalseBranch != null) + { + yield return state.FalseBranch; + } } + + // Now process the states in topological order, leaves first, and assign a BoundDecisionDag to each DagState. + return TopologicalSort.IterativeSort(SpecializedCollections.SingletonEnumerable(this), succ); } // After the entire graph of DagState objects is complete, we translate each into its Dag. @@ -987,7 +984,7 @@ internal BoundDagDecision ComputeSelectedDecision() /// internal string Dump() { - var allStates = this.TopologicallySortedReachableStates; + var allStates = this.TopologicallySortedReachableStates(); var stateIdentifierMap = PooledDictionary.GetInstance(); for (int i = 0; i < allStates.Length; i++) { diff --git a/src/Compilers/CSharp/Portable/Binder/PatternSwitchBinder.cs b/src/Compilers/CSharp/Portable/Binder/PatternSwitchBinder.cs index c0d5d3abdf07a5a5172ee7574c2e76de52f6def6..3b9ec1b9e0522683ca5ffbe66cfcc3d73eefb92c 100644 --- a/src/Compilers/CSharp/Portable/Binder/PatternSwitchBinder.cs +++ b/src/Compilers/CSharp/Portable/Binder/PatternSwitchBinder.cs @@ -4,7 +4,7 @@ using System.Collections.Generic; using System.Collections.Immutable; using System.Diagnostics; -using System.Threading; +using System.Linq; using Microsoft.CodeAnalysis.CSharp.Symbols; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.PooledObjects; @@ -84,7 +84,7 @@ bool isSubsumed(BoundPatternSwitchLabel switchLabel) } // If no switch sections are subsumed, just return - if (switchSections.Count(s => s.SwitchLabels.Count(l => isSubsumed(l)) != 0) == 0) + if (!switchSections.Any(s => s.SwitchLabels.Any(l => isSubsumed(l)))) { return; } diff --git a/src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_BasePatternSwitchLocalRewriter.cs b/src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_BasePatternSwitchLocalRewriter.cs index cdf0cd0bd52629ca6f26a1de2b12244946ef20d1..60b49169e95b0bf17a5d5496891f3c781b7c4041 100644 --- a/src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_BasePatternSwitchLocalRewriter.cs +++ b/src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_BasePatternSwitchLocalRewriter.cs @@ -65,7 +65,7 @@ private void ComputeLabelSet(ImmutableArray sortedNodes) { // Nodes with more than one predecessor are assigned a label var hasPredecessor = PooledHashSet.GetInstance(); - void notePreedecesssor(BoundDecisionDag successor) + void notePredecessor(BoundDecisionDag successor) { if (successor != null && !hasPredecessor.Add(successor)) { @@ -92,11 +92,11 @@ void notePreedecesssor(BoundDecisionDag successor) _dagNodeLabels[node] = d.Label; break; case BoundEvaluationPoint e: - notePreedecesssor(e.Next); + notePredecessor(e.Next); break; case BoundDecisionPoint p: - notePreedecesssor(p.WhenTrue); - notePreedecesssor(p.WhenFalse); + notePredecessor(p.WhenTrue); + notePredecessor(p.WhenFalse); break; default: throw ExceptionUtilities.UnexpectedValue(node.Kind);