Permalink
Browse files

better names for components of MatchTranslator

  • Loading branch information...
1 parent 0a3219b commit 5b7cfe3c63c15488ed7d8a9bb3b8d7f2043874d8 @adriaanm adriaanm committed Feb 23, 2013
@@ -125,23 +125,15 @@ trait TreeAndTypeAnalysis extends Debugging {
}
}
-trait MatchAnalysis extends TreeAndTypeAnalysis with ScalaLogic with MatchTreeMaking {
- import PatternMatchingStats._
- import global.{Tree, Type, Symbol, CaseDef, atPos,
- Select, Block, ThisType, SingleType, NoPrefix, NoType, definitions, needsOuterTest,
- ConstantType, Literal, Constant, gen, This, analyzer, EmptyTree, map2, NoSymbol, Traverser,
- Function, Typed, treeInfo, DefTree, ValDef, nme, appliedType, Name, WildcardType, Ident, TypeRef,
- UniqueType, RefinedType, currentUnit, SingletonType, singleType, ModuleClassSymbol,
- nestedMemberType, TypeMap, EmptyScope, Apply, If, Bind, lub, Alternative, deriveCaseDef, Match, MethodType, LabelDef, TypeTree, Throw, newTermName}
-
- import definitions._
- import analyzer.{Typer, ErrorUtils, formalTypes}
+trait MatchApproximation extends TreeAndTypeAnalysis with ScalaLogic with MatchTreeMaking {
+ import global.{Tree, Type, NoType, Symbol, NoSymbol, ConstantType, Literal, Constant, Ident, UniqueType, RefinedType, EmptyScope}
+ import global.definitions.{ListClass, NilModule}
/**
* Represent a match as a formula in propositional logic that encodes whether the match matches (abstractly: we only consider types)
*
*/
- trait TreeMakerApproximation extends TreeMakers with TreesAndTypesDomain {
+ trait MatchApproximator extends TreeMakers with TreesAndTypesDomain {
object Test {
var currId = 0
}
@@ -348,7 +340,14 @@ trait MatchAnalysis extends TreeAndTypeAnalysis with ScalaLogic with MatchTreeMa
}
}
- trait MatchAnalyses extends TreeMakerApproximation {
+}
+
+trait MatchAnalysis extends MatchApproximation {
+ import PatternMatchingStats._
+ import global.{Tree, Type, Symbol, NoSymbol, Ident, Select}
+ import global.definitions.{isPrimitiveValueClass, ConsClass, isTupleSymbol}
+
+ trait MatchAnalyzer extends MatchApproximator {
def uncheckedWarning(pos: Position, msg: String) = global.currentUnit.uncheckedWarning(pos, msg)
def warn(pos: Position, ex: AnalysisBudget.Exception, kind: String) = uncheckedWarning(pos, s"Cannot check match for $kind.\n${ex.advice}")
@@ -498,7 +497,7 @@ trait MatchAnalysis extends TreeAndTypeAnalysis with ScalaLogic with MatchTreeMa
// a way to construct a value that will make the match fail: a constructor invocation, a constant, an object of some type)
class CounterExample {
- protected[MatchAnalyses] def flattenConsArgs: List[CounterExample] = Nil
+ protected[MatchAnalyzer] def flattenConsArgs: List[CounterExample] = Nil
def coveredBy(other: CounterExample): Boolean = this == other || other == WildcardExample
}
case class ValueExample(c: ValueConst) extends CounterExample { override def toString = c.toString }
@@ -513,11 +512,11 @@ trait MatchAnalysis extends TreeAndTypeAnalysis with ScalaLogic with MatchTreeMa
}
}
case class ListExample(ctorArgs: List[CounterExample]) extends CounterExample {
- protected[MatchAnalyses] override def flattenConsArgs: List[CounterExample] = ctorArgs match {
+ protected[MatchAnalyzer] override def flattenConsArgs: List[CounterExample] = ctorArgs match {
case hd :: tl :: Nil => hd :: tl.flattenConsArgs
case _ => Nil
}
- protected[MatchAnalyses] lazy val elems = flattenConsArgs
+ protected[MatchAnalyzer] lazy val elems = flattenConsArgs
override def coveredBy(other: CounterExample): Boolean =
other match {
@@ -30,7 +30,7 @@ trait MatchOptimization extends MatchTreeMaking with MatchAnalysis {
////
- trait CommonSubconditionElimination extends TreeMakerApproximation { self: OptimizedCodegen =>
+ trait CommonSubconditionElimination extends OptimizedCodegen with MatchApproximator {
/** a flow-sensitive, generalised, common sub-expression elimination
* reuse knowledge from performed tests
* the only sub-expressions we consider are the conditions and results of the three tests (type, type&equality, equality)
@@ -205,16 +205,16 @@ trait MatchOptimization extends MatchTreeMaking with MatchAnalysis {
//// DCE
- trait DeadCodeElimination extends TreeMakers {
- // TODO: non-trivial dead-code elimination
- // e.g., the following match should compile to a simple instanceof:
- // case class Ident(name: String)
- // for (Ident(name) <- ts) println(name)
- def doDCE(prevBinder: Symbol, cases: List[List[TreeMaker]], pt: Type): List[List[TreeMaker]] = {
- // do minimal DCE
- cases
- }
- }
+// trait DeadCodeElimination extends TreeMakers {
+// // TODO: non-trivial dead-code elimination
+// // e.g., the following match should compile to a simple instanceof:
+// // case class Ident(name: String)
+// // for (Ident(name) <- ts) println(name)
+// def doDCE(prevBinder: Symbol, cases: List[List[TreeMaker]], pt: Type): List[List[TreeMaker]] = {
+// // do minimal DCE
+// cases
+// }
+// }
//// SWITCHES -- TODO: operate on Tests rather than TreeMakers
trait SwitchEmission extends TreeMakers with OptimizedMatchMonadInterface {
@@ -589,12 +589,12 @@ trait MatchOptimization extends MatchTreeMaking with MatchAnalysis {
}
}
- trait MatchOptimizations extends CommonSubconditionElimination
- with DeadCodeElimination
- with SwitchEmission
- with OptimizedCodegen {
+ trait MatchOptimizer extends OptimizedCodegen
+ with SwitchEmission
+ with CommonSubconditionElimination {
override def optimizeCases(prevBinder: Symbol, cases: List[List[TreeMaker]], pt: Type): (List[List[TreeMaker]], List[Tree]) = {
- val optCases = doCSE(prevBinder, doDCE(prevBinder, cases, pt), pt)
+ // TODO: do CSE on result of doDCE(prevBinder, cases, pt)
+ val optCases = doCSE(prevBinder, cases, pt)
val toHoist = (
for (treeMakers <- optCases)
yield treeMakers.collect{case tm: ReusedCondTreeMaker => tm.treesToHoist}
@@ -85,8 +85,8 @@ trait PatternMatching extends Transform with TypingTransformers
}
class OptimizingMatchTranslator(val typer: analyzer.Typer) extends MatchTranslator
- with MatchOptimizations
- with MatchAnalyses
+ with MatchOptimizer
+ with MatchAnalyzer
with Solver
}

0 comments on commit 5b7cfe3

Please sign in to comment.