Skip to content

Commit e4b233d

Browse files
committed
no postfixops in patmat
1 parent 5a1ba87 commit e4b233d

File tree

6 files changed

+14
-26
lines changed

6 files changed

+14
-26
lines changed

src/compiler/scala/tools/nsc/transform/patmat/Logic.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,14 @@
1313
package scala
1414
package tools.nsc.transform.patmat
1515

16-
import scala.language.postfixOps
1716
import scala.collection.mutable
1817
import scala.collection.immutable.ArraySeq
1918
import scala.reflect.internal.util.{HashSet, NoPosition, Position, StatisticsStatics}
2019

2120
trait Logic extends Debugging {
2221
import global.statistics
2322

24-
private def max(xs: Seq[Int]) = if (xs isEmpty) 0 else xs max
23+
private def max(xs: Seq[Int]) = if (xs.isEmpty) 0 else xs.max
2524
private def alignedColumns(cols: Seq[Any]): Seq[String] = {
2625
def toString(x: Any) = if (x == null) "" else x.toString
2726
if (cols.isEmpty || cols.tails.isEmpty) cols map toString

src/compiler/scala/tools/nsc/transform/patmat/MatchCodeGen.scala

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212

1313
package scala.tools.nsc.transform.patmat
1414

15-
import scala.language.postfixOps
16-
1715
import scala.tools.nsc.symtab.Flags.SYNTHETIC
1816
import scala.reflect.internal.util.Position
1917

@@ -128,11 +126,11 @@ trait MatchCodeGen extends Interface {
128126
// must compute catchAll after caseLabels (side-effects nextCase)
129127
// catchAll.isEmpty iff no synthetic default case needed (the (last) user-defined case is a default)
130128
// if the last user-defined case is a default, it will never jump to the next case; it will go immediately to matchEnd
131-
val catchAllDef = matchFailGen map { matchFailGen =>
129+
val catchAllDef = matchFailGen.map { matchFailGen =>
132130
val scrutRef = scrutSym.fold(EmptyTree: Tree)(REF) // for alternatives
133131

134-
LabelDef(_currCase, Nil, matchEnd APPLY (matchFailGen(scrutRef)))
135-
} toList // at most 1 element
132+
LabelDef(_currCase, Nil, matchEnd APPLY matchFailGen(scrutRef))
133+
}.toList // at most 1 element
136134

137135
// scrutSym == NoSymbol when generating an alternatives matcher
138136
val scrutDef = scrutSym.fold(List[Tree]())(ValDef(_, scrut) :: Nil) // for alternatives

src/compiler/scala/tools/nsc/transform/patmat/MatchOptimization.scala

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212

1313
package scala.tools.nsc.transform.patmat
1414

15-
import scala.language.postfixOps
16-
1715
import scala.tools.nsc.symtab.Flags.MUTABLE
1816
import scala.collection.mutable
1917
import scala.reflect.internal.util.Position
@@ -62,7 +60,7 @@ trait MatchOptimization extends MatchTreeMaking with MatchAnalysis {
6260
if (conds(False)) false // stop when we encounter a definite "no" or a "not sure"
6361
else {
6462
val nonTrivial = conds - True
65-
if (nonTrivial nonEmpty) {
63+
if (!nonTrivial.isEmpty) {
6664
tested ++= nonTrivial
6765

6866
// is there an earlier test that checks our condition and whose dependencies are implied by ours?
@@ -468,7 +466,7 @@ trait MatchOptimization extends MatchTreeMaking with MatchAnalysis {
468466
// a switch with duplicate cases yields a verify error,
469467
// and a switch with duplicate cases and guards cannot soundly be rewritten to an unguarded switch
470468
// (even though the verify error would disappear, the behaviour would change)
471-
val allReachable = unreachableCase(caseDefsWithGuards) map (cd => reportUnreachable(cd.body.pos)) isEmpty
469+
val allReachable = unreachableCase(caseDefsWithGuards).map(cd => reportUnreachable(cd.body.pos)).isEmpty
472470

473471
if (!allReachable) Nil
474472
else if (noGuards(caseDefsWithGuards)) {
@@ -536,7 +534,7 @@ trait MatchOptimization extends MatchTreeMaking with MatchAnalysis {
536534
// TODO: if patterns allow switch but the type of the scrutinee doesn't, cast (type-test) the scrutinee to the corresponding switchable type and switch on the result
537535
if (regularSwitchMaker.switchableTpe(dealiasWiden(scrutSym.tpe))) {
538536
val caseDefsWithDefault = regularSwitchMaker(cases map {c => (scrutSym, c)}, pt)
539-
if (caseDefsWithDefault isEmpty) None // not worth emitting a switch.
537+
if (caseDefsWithDefault.isEmpty) None // not worth emitting a switch.
540538
else {
541539
// match on scrutSym -- converted to an int if necessary -- not on scrut directly (to avoid duplicating scrut)
542540
val scrutToInt: Tree =
@@ -586,7 +584,7 @@ trait MatchOptimization extends MatchTreeMaking with MatchAnalysis {
586584
// TODO: drop null checks
587585
override def emitTypeSwitch(bindersAndCases: List[(Symbol, List[TreeMaker])], pt: Type): Option[List[CaseDef]] = {
588586
val caseDefsWithDefault = typeSwitchMaker(bindersAndCases, pt)
589-
if (caseDefsWithDefault isEmpty) None
587+
if (caseDefsWithDefault.isEmpty) None
590588
else Some(caseDefsWithDefault)
591589
}
592590
}

src/compiler/scala/tools/nsc/transform/patmat/MatchTranslation.scala

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@
1212

1313
package scala.tools.nsc.transform.patmat
1414

15-
import scala.language.postfixOps
1615
import scala.reflect.internal.util.StatisticsStatics
1716

18-
1917
/** Translate typed Trees that represent pattern matches into the patternmatching IR, defined by TreeMakers.
2018
*/
2119
trait MatchTranslation {
@@ -30,8 +28,6 @@ trait MatchTranslation {
3028
private def setVarInfo(sym: Symbol, info: Type) =
3129
sym setInfo debug.patmatResult(s"changing ${sym.defString} to")(repeatedToSeq(info))
3230

33-
private def hasSym(t: Tree) = t.symbol != null && t.symbol != NoSymbol
34-
3531
trait MatchTranslator extends TreeMakers with TreeMakerWarnings {
3632
import typer.context
3733
def selectorPos: Position
@@ -62,8 +58,8 @@ trait MatchTranslation {
6258

6359
object SymbolBound {
6460
def unapply(tree: Tree): Option[(Symbol, Tree)] = tree match {
65-
case Bind(_, expr) if hasSym(tree) => Some(tree.symbol -> expr)
66-
case _ => None
61+
case Bind(_, expr) if tree.hasExistingSymbol => Some(tree.symbol -> expr)
62+
case _ => None
6763
}
6864
}
6965

@@ -408,7 +404,7 @@ trait MatchTranslation {
408404
}
409405

410406
// never store these in local variables (for PreserveSubPatBinders)
411-
lazy val ignoredSubPatBinders: Set[Symbol] = subPatBinders zip args collect { case (b, PatternBoundToUnderscore()) => b } toSet
407+
lazy val ignoredSubPatBinders: Set[Symbol] = (subPatBinders zip args).collect { case (b, PatternBoundToUnderscore()) => b }.toSet
412408

413409
// there are `productArity` non-seq elements in the tuple.
414410
protected def firstIndexingBinder = productArity

src/compiler/scala/tools/nsc/transform/patmat/MatchTreeMaking.scala

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212

1313
package scala.tools.nsc.transform.patmat
1414

15-
import scala.language.postfixOps
16-
1715
import scala.tools.nsc.symtab.Flags.{SYNTHETIC, ARTIFACT}
1816
import scala.collection.mutable
1917
import scala.reflect.internal.util.Position
@@ -632,7 +630,7 @@ trait MatchTreeMaking extends MatchCodeGen with Debugging {
632630
emitSwitch(scrut, scrutSym, casesNoSubstOnly, pt, matchFailGenOverride, unchecked = suppression.suppressExhaustive).getOrElse{
633631
if (requireSwitch) reporter.warning(scrut.pos, "could not emit switch for @switch annotated match")
634632

635-
if (casesNoSubstOnly nonEmpty) {
633+
if (!casesNoSubstOnly.isEmpty) {
636634
// before optimizing, check casesNoSubstOnly for presence of a default case,
637635
// since DCE will eliminate trivial cases like `case _ =>`, even if they're the last one
638636
// exhaustivity and reachability must be checked before optimization as well
@@ -652,7 +650,7 @@ trait MatchTreeMaking extends MatchCodeGen with Debugging {
652650

653651
val matchRes = codegen.matcher(scrut, scrutSym, pt)(cases map combineExtractors, synthCatchAll)
654652

655-
if (toHoist isEmpty) matchRes else Block(toHoist, matchRes)
653+
if (toHoist.isEmpty) matchRes else Block(toHoist, matchRes)
656654
} else {
657655
codegen.matcher(scrut, scrutSym, pt)(Nil, matchFailGen)
658656
}

src/compiler/scala/tools/nsc/transform/patmat/PatternMatching.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ package scala.tools.nsc.transform.patmat
1515
import scala.collection.mutable.ListBuffer
1616
import scala.tools.nsc.Global
1717
import scala.tools.nsc.ast
18-
import scala.language.postfixOps
1918
import scala.tools.nsc.transform.TypingTransformers
2019
import scala.tools.nsc.transform.Transform
2120
import scala.reflect.internal.util.Statistics
@@ -207,7 +206,7 @@ trait Interface extends ast.TreeDSL {
207206
def apply(from: Symbol, to: Tree): Substitution = new Substitution(from :: Nil, to :: Nil)
208207
// requires sameLength(from, to)
209208
def apply(from: List[Symbol], to: List[Tree]): Substitution =
210-
if (from nonEmpty) new Substitution(from, to) else EmptySubstitution
209+
if (from.isEmpty) EmptySubstitution else new Substitution(from, to)
211210
}
212211

213212
class Substitution(val from: List[Symbol], val to: List[Tree]) {

0 commit comments

Comments
 (0)