Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

please ant with filenames, add comments

  • Loading branch information...
commit 18a2ba2f27004e74952ea88c1ea2eb8086c44ea4 1 parent 6a7078c
@adriaanm adriaanm authored
View
2  src/compiler/scala/tools/nsc/transform/patmat/MatchAnalysis.scala
@@ -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,
View
7 src/compiler/scala/tools/nsc/transform/patmat/MatchCodeGen.scala
@@ -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,
View
8 src/compiler/scala/tools/nsc/transform/patmat/MatchOptimization.scala
@@ -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,
View
7 src/compiler/scala/tools/nsc/transform/patmat/MatchTranslation.scala
@@ -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,
@@ -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
@@ -669,5 +671,4 @@ trait Translation { self: PatternMatching =>
}
}
}
-
}
View
11 .../tools/nsc/transform/patmat/MatchTreeMakers.scala → .../tools/nsc/transform/patmat/MatchTreeMaking.scala
@@ -6,10 +6,6 @@
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
@@ -17,7 +13,12 @@ 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,
View
23 src/compiler/scala/tools/nsc/transform/patmat/PatternMatching.scala
@@ -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`).
@@ -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"
@@ -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 {
Please sign in to comment.
Something went wrong with that request. Please try again.