Skip to content

Commit

Permalink
please ant with filenames, add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
adriaanm committed Feb 21, 2013
1 parent 6a7078c commit 18a2ba2
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 21 deletions.
Expand Up @@ -125,7 +125,7 @@ trait TreeAndTypeAnalysis extends Debugging {
}
}

trait Analysis extends TreeAndTypeAnalysis { self: PatternMatching =>
trait MatchAnalysis extends TreeAndTypeAnalysis { self: PatternMatching =>
import PatternMatchingStats._
import global.{Tree, Type, Symbol, CaseDef, atPos,
Select, Block, ThisType, SingleType, NoPrefix, NoType, definitions, needsOuterTest,
Expand Down
Expand Up @@ -12,7 +12,12 @@ import scala.reflect.internal.util.Statistics
import scala.reflect.internal.util.Position
import scala.reflect.internal.util.NoPosition

trait CodeGen { self: PatternMatching =>
/** Factory methods used by TreeMakers to make the actual trees.
*
* We have two modes in which to emit trees: optimized (the default)
* and pure (aka "virtualized": match is parametric in its monad).
*/
trait MatchCodeGen { self: PatternMatching =>
import PatternMatchingStats._
import global.{nme, treeInfo, definitions, gen, Tree, Type, Symbol, NoSymbol,
appliedType, NoType, MethodType, newTermName, Name,
Expand Down
Expand Up @@ -13,7 +13,13 @@ import scala.reflect.internal.util.Statistics
import scala.reflect.internal.util.Position
import scala.reflect.internal.util.NoPosition

trait Optimization { self: PatternMatching =>
/** Optimize and analyze matches based on their TreeMaker-representation.
*
* The patmat translation doesn't rely on this, so it could be disabled in principle.
*
* TODO: split out match analysis
*/
trait MatchOptimization { self: PatternMatching =>
import PatternMatchingStats._
import global.{Tree, Type, Symbol, NoSymbol, CaseDef, atPos,
ConstantType, Literal, Constant, gen, EmptyTree,
Expand Down
Expand Up @@ -10,7 +10,9 @@ import scala.language.postfixOps
import scala.collection.mutable
import scala.reflect.internal.util.Statistics

trait Translation { self: PatternMatching =>
/** Translate typed Trees that represent pattern matches into the patternmatching IR, defined by TreeMakers.
*/
trait MatchTranslation { self: PatternMatching =>
import PatternMatchingStats._
import global.{phase, currentRun, Symbol,
Apply, Bind, CaseDef, ClassInfoType, Ident, Literal, Match,
Expand All @@ -22,7 +24,7 @@ trait Translation { self: PatternMatching =>
repeatedToSeq, isRepeatedParamType, getProductArgs}
import global.analyzer.{ErrorUtils, formalTypes}

trait MatchTranslation extends MatchMonadInterface { self: TreeMakers with CodegenCore =>
trait MatchTranslator extends MatchMonadInterface { self: TreeMakers with CodegenCore =>
import typer.context

// Why is it so difficult to say "here's a name and a context, give me any
Expand Down Expand Up @@ -669,5 +671,4 @@ trait Translation { self: PatternMatching =>
}
}
}

}
Expand Up @@ -6,18 +6,19 @@

package scala.tools.nsc.transform.patmat

//import scala.tools.nsc.{ast, symtab, typechecker, transform, Global}
//import transform._
//import typechecker._
//import symtab._
import scala.tools.nsc.symtab.Flags.{SYNTHETIC, ARTIFACT}
import scala.language.postfixOps
import scala.collection.mutable
import scala.reflect.internal.util.Statistics
import scala.reflect.internal.util.Position
import scala.reflect.internal.util.NoPosition

trait TreeMaking { self: PatternMatching =>
/** Translate our IR (TreeMakers) into actual Scala Trees using the factory methods in MatchCodeGen.
*
* The IR is mostly concerned with sequencing, substitution, and rendering all necessary conditions,
* mostly agnostic to whether we're in optimized/pure (virtualized) mode.
*/
trait MatchTreeMaking { self: PatternMatching =>
import PatternMatchingStats._
import global.{Tree, Type, Symbol, CaseDef, atPos, settings,
Select, Block, ThisType, SingleType, NoPrefix, NoType, needsOuterTest,
Expand Down
23 changes: 13 additions & 10 deletions src/compiler/scala/tools/nsc/transform/patmat/PatternMatching.scala
Expand Up @@ -17,8 +17,8 @@ import scala.reflect.internal.util.Position

/** Translate pattern matching.
*
* Either into optimized if/then/else's,
* or virtualized as method calls (these methods form a zero-plus monad), similar in spirit to how for-comprehensions are compiled.
* Either into optimized if/then/else's, or virtualized as method calls (these methods form a zero-plus monad),
* similar in spirit to how for-comprehensions are compiled.
*
* For each case, express all patterns as extractor calls, guards as 0-ary extractors, and sequence them using `flatMap`
* (lifting the body of the case into the monad using `one`).
Expand All @@ -37,12 +37,12 @@ import scala.reflect.internal.util.Position
trait PatternMatching extends Transform with TypingTransformers with ast.TreeDSL
with Debugging
with Interface
with Translation
with TreeMaking
with CodeGen
with MatchTranslation
with MatchTreeMaking
with MatchCodeGen
with ScalaLogic
with Analysis
with Optimization {
with MatchAnalysis
with MatchOptimization {
import global._

val phaseName: String = "patmat"
Expand Down Expand Up @@ -70,13 +70,16 @@ trait PatternMatching extends Transform with TypingTransformers with ast.TreeDSL
case _ => super.transform(tree)
}

def translator: MatchTranslation with CodegenCore = {
// TODO: only instantiate new match translator when localTyper has changed
// override def atOwner[A](tree: Tree, owner: Symbol)(trans: => A): A
// as this is the only time TypingTransformer changes it
def translator: MatchTranslator with CodegenCore = {
new OptimizingMatchTranslator(localTyper)
}
}

class PureMatchTranslator(val typer: analyzer.Typer, val matchStrategy: Tree) extends MatchTranslation with TreeMakers with PureCodegen
class OptimizingMatchTranslator(val typer: analyzer.Typer) extends MatchTranslation with TreeMakers with MatchOptimizations
class PureMatchTranslator(val typer: analyzer.Typer, val matchStrategy: Tree) extends MatchTranslator with TreeMakers with PureCodegen
class OptimizingMatchTranslator(val typer: analyzer.Typer) extends MatchTranslator with TreeMakers with MatchOptimizations
}

trait HasGlobal {
Expand Down

0 comments on commit 18a2ba2

Please sign in to comment.