summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEugene Burmako <xeno.by@gmail.com>2012-09-19 13:15:22 +0200
committerEugene Burmako <xeno.by@gmail.com>2012-09-19 17:39:59 +0200
commiteadf1d2080e0ce763e4c1920a26b80c8b8609ca0 (patch)
treee172c5d2b9db0bf3786afa6ce5f40b13fd0eb1bd /src
parent50b5bdefec899bf441742a40f525234eac65cbaa (diff)
downloadscala-eadf1d2080e0ce763e4c1920a26b80c8b8609ca0.tar.gz
scala-eadf1d2080e0ce763e4c1920a26b80c8b8609ca0.tar.bz2
scala-eadf1d2080e0ce763e4c1920a26b80c8b8609ca0.zip
prepping for the refactoring
Reification (both tree-based and type-based) should be avoided before we release 2.10.0-final, since it impairs reflection refactorings like the upcoming one. Also the upcoming refactoring moves tag materialization anchors, and we have to add them to fast track in advance, so that they are treated as macros later.
Diffstat (limited to 'src')
-rw-r--r--src/compiler/scala/tools/reflect/FastTrack.scala3
-rw-r--r--src/library/scala/reflect/package.scala52
-rw-r--r--src/partest/scala/tools/partest/package.scala35
-rw-r--r--src/reflect/scala/reflect/api/package.scala3
-rw-r--r--src/reflect/scala/reflect/internal/Definitions.scala4
5 files changed, 66 insertions, 31 deletions
diff --git a/src/compiler/scala/tools/reflect/FastTrack.scala b/src/compiler/scala/tools/reflect/FastTrack.scala
index 38e4e3c9f1..1af2842d05 100644
--- a/src/compiler/scala/tools/reflect/FastTrack.scala
+++ b/src/compiler/scala/tools/reflect/FastTrack.scala
@@ -31,8 +31,11 @@ trait FastTrack {
var registry = Map[Symbol, FastTrackEntry]()
implicit class BindTo(sym: Symbol) { def bindTo(expander: FastTrackExpander): Unit = if (sym != NoSymbol) registry += sym -> FastTrackEntry(sym, expander) }
MacroInternal_materializeClassTag bindTo { case (c, Apply(TypeApply(_, List(tt)), List(u))) => c.materializeClassTag(u, tt.tpe) }
+ materializeClassTag bindTo { case (c, Apply(TypeApply(_, List(tt)), List(u))) => c.materializeClassTag(u, tt.tpe) }
MacroInternal_materializeWeakTypeTag bindTo { case (c, Apply(TypeApply(_, List(tt)), List(u))) => c.materializeTypeTag(u, EmptyTree, tt.tpe, concrete = false) }
+ materializeWeakTypeTag bindTo { case (c, Apply(TypeApply(_, List(tt)), List(u))) => c.materializeTypeTag(u, EmptyTree, tt.tpe, concrete = false) }
MacroInternal_materializeTypeTag bindTo { case (c, Apply(TypeApply(_, List(tt)), List(u))) => c.materializeTypeTag(u, EmptyTree, tt.tpe, concrete = true) }
+ materializeTypeTag bindTo { case (c, Apply(TypeApply(_, List(tt)), List(u))) => c.materializeTypeTag(u, EmptyTree, tt.tpe, concrete = true) }
BaseUniverseReify bindTo { case (c, Apply(TypeApply(_, List(tt)), List(expr))) => c.materializeExpr(c.prefix.tree, EmptyTree, expr) }
ReflectRuntimeCurrentMirror bindTo { case (c, _) => scala.reflect.runtime.Macros.currentMirror(c).tree }
StringContext_f bindTo { case (c, app@Apply(Select(Apply(_, parts), _), args)) => c.macro_StringInterpolation_f(parts, args, app.pos) }
diff --git a/src/library/scala/reflect/package.scala b/src/library/scala/reflect/package.scala
index 046491ae10..8b411d0dca 100644
--- a/src/library/scala/reflect/package.scala
+++ b/src/library/scala/reflect/package.scala
@@ -3,37 +3,37 @@ package scala
/**
* The base package of Scala's reflection library.
*
- * The reflection library is structured according to the 'cake pattern'. The base layer
+ * The reflection library is structured according to the 'cake pattern'. The base layer
* resides in package [[scala.reflect.base]] and defines an interface to the following main types:
- *
+ *
* - [[scala.reflect.base.Types#Type Types]] represent types
* - [[scala.reflect.base.Symbols#Symbol Symbols]] represent definitions
* - [[scala.reflect.base.Trees#Tree Trees]] represent abstract syntax trees
* - [[scala.reflect.base.Names#Name Names]] represent term and type names
* - [[scala.reflect.base.Annotations#Annotation Annotations]] represent annotations
* - [[scala.reflect.base.Positions#Position Positions]] represent source positions of tree nodes
- * - [[scala.reflect.base.FlagSets#FlagSet FlagSet]] represent sets of flags that apply to symbols and
+ * - [[scala.reflect.base.FlagSets#FlagSet FlagSet]] represent sets of flags that apply to symbols and
* definition trees
- * - [[scala.reflect.base.Constants#Constant Constants]] represent compile-time constants.
+ * - [[scala.reflect.base.Constants#Constant Constants]] represent compile-time constants.
*
- * Each of these types are defined in their own enclosing traits, which are ultimately all inherited by class
+ * Each of these types are defined in their own enclosing traits, which are ultimately all inherited by class
* [[scala.reflect.base.Universe Universe]]. The base universe defines a minimal interface to the above types.
- * Universes that provide additional functionality such as deeper introspection or runtime code generation,
+ * Universes that provide additional functionality such as deeper introspection or runtime code generation,
* are defined in packages [[scala.reflect.api]] and `scala.tools.reflect`.
*
- * The cake pattern employed here requires to write certain Scala idioms with more indirections that usual.
+ * The cake pattern employed here requires to write certain Scala idioms with more indirections that usual.
* What follows is a description of these indirections, which will help to navigate the Scaladocs easily.
*
- * For instance, consider the base type of all abstract syntax trees: [[scala.reflect.base.Trees#Tree]].
- * This type is not a class but is abstract and has an upper bound of [[scala.reflect.base.Trees#TreeBase]],
- * which is a class defining the minimal base interface for all trees.
+ * For instance, consider the base type of all abstract syntax trees: [[scala.reflect.base.Trees#Tree]].
+ * This type is not a class but is abstract and has an upper bound of [[scala.reflect.base.Trees#TreeBase]],
+ * which is a class defining the minimal base interface for all trees.
*
- * For a more interesting tree type, consider [[scala.reflect.base.Trees#If]] representing if-expressions.
- * It does not come with a class `IfBase`, since it does not add anything to the interface of its upper
- * bound `TermTree`. However, it is defined next to a value `If` of type [[scala.reflect.base.Trees#IfExtractor]].
- * This value serves as the companion object defining a factory method `apply` and a corresponding `unapply`
+ * For a more interesting tree type, consider [[scala.reflect.base.Trees#If]] representing if-expressions.
+ * It does not come with a class `IfBase`, since it does not add anything to the interface of its upper
+ * bound `TermTree`. However, it is defined next to a value `If` of type [[scala.reflect.base.Trees#IfExtractor]].
+ * This value serves as the companion object defining a factory method `apply` and a corresponding `unapply`
* for pattern matching.
- *
+ *
* {{{
* import scala.reflect.runtime.universe._
* val cond = reify{ condition }.tree // <- just some tree representing a condition
@@ -41,32 +41,32 @@ package scala
* val other = Literal(Constant(2))
* val iftree = If(cond,body,other)
* }}}
- *
+ *
* is equivalent to
- *
+ *
* {{{
* import scala.reflect.runtime.universe._
* val iftree = reify{ if( condition ) 1 else 2 }.tree
* }}}
*
* and can be pattern matched as
- *
+ *
* {{{
* iftree match { case If(cond,body,other) => ... }
* }}}
- *
- * Moreover, there is an implicit value [[scala.reflect.base.Trees#IfTag]] of type
+ *
+ * Moreover, there is an implicit value [[scala.reflect.base.Trees#IfTag]] of type
* `ClassTag[If]` that is used by the Scala compiler so that we can indeed pattern match on `If`:
* {{{
* iftree match { case _:If => ... }
- * }}}
+ * }}}
* Without the given implicit value, this pattern match would raise an "unchecked" warning at compile time
* since `If` is an abstract type that gets erased at runtime. See [[scala.reflect.ClassTag]] for details.
*
- * To summarize: each tree type `X` (and similarly for other types such as `Type` or `Symbol`) is represented
- * by an abstract type `X`, optionally together with a class `XBase` that defines `X`'s' interface.
- * `X`'s companion object, if it exists, is represented by a value `X` that is of type `XExtractor`.
- * Moreover, for each type `X`, there is a value `XTag` of type `ClassTag[X]` that allows to pattern match
+ * To summarize: each tree type `X` (and similarly for other types such as `Type` or `Symbol`) is represented
+ * by an abstract type `X`, optionally together with a class `XBase` that defines `X`'s' interface.
+ * `X`'s companion object, if it exists, is represented by a value `X` that is of type `XExtractor`.
+ * Moreover, for each type `X`, there is a value `XTag` of type `ClassTag[X]` that allows to pattern match
* on `X`.
*/
package object reflect {
@@ -113,6 +113,8 @@ package object reflect {
def classTag[T](implicit ctag: ClassTag[T]) = ctag
// typeTag incantation is defined inside scala.reflect.basis and scala.reflect.runtime.universe
+ private[scala] def materializeClassTag[T](u: base.Universe): ClassTag[T] = ??? // macro
+
// ClassTag class is defined in ClassTag.scala
type TypeTag[T] = scala.reflect.basis.TypeTag[T]
diff --git a/src/partest/scala/tools/partest/package.scala b/src/partest/scala/tools/partest/package.scala
index ebd3e46b7c..df1c296d47 100644
--- a/src/partest/scala/tools/partest/package.scala
+++ b/src/partest/scala/tools/partest/package.scala
@@ -93,11 +93,34 @@ package object partest {
import scala.reflect.macros.Context
def traceImpl[A: c.WeakTypeTag](c: Context)(a: c.Expr[A]): c.Expr[A] = {
import c.universe._
- val exprCode = c.literal(show(a.tree))
- val exprType = c.literal(show(a.actualType))
- reify {
- println(s"trace> ${exprCode.splice}\nres: ${exprType.splice} = ${a.splice}\n")
- a.splice
- }
+ import definitions._
+
+ // xeno.by: reify shouldn't be used explicitly before the final release of 2.10.0,
+ // because this impairs reflection refactorings
+ //
+ // val exprCode = c.literal(show(a.tree))
+ // val exprType = c.literal(show(a.actualType))
+ // reify {
+ // println(s"trace> ${exprCode.splice}\nres: ${exprType.splice} = ${a.splice}\n")
+ // a.splice
+ // }
+
+ c.Expr(Block(
+ List(Apply(
+ Select(Ident(PredefModule), newTermName("println")),
+ List(Apply(
+ Select(Apply(
+ Select(Ident(ScalaPackage), newTermName("StringContext")),
+ List(
+ Literal(Constant("trace> ")),
+ Literal(Constant("\\nres: ")),
+ Literal(Constant(" = ")),
+ Literal(Constant("\\n")))),
+ newTermName("s")),
+ List(
+ Literal(Constant(show(a.tree))),
+ Literal(Constant(show(a.actualType))),
+ a.tree))))),
+ a.tree))
}
}
diff --git a/src/reflect/scala/reflect/api/package.scala b/src/reflect/scala/reflect/api/package.scala
index d2fce7cf1d..5e31071e2d 100644
--- a/src/reflect/scala/reflect/api/package.scala
+++ b/src/reflect/scala/reflect/api/package.scala
@@ -9,4 +9,7 @@ package object api {
type Attachments = base.Attachments
type MirrorOf[U <: base.Universe with Singleton] = base.MirrorOf[U]
+
+ private[scala] def materializeWeakTypeTag[T](u: base.Universe): u.WeakTypeTag[T] = ??? // macro
+ private[scala] def materializeTypeTag[T](u: base.Universe): u.TypeTag[T] = ??? // macro
}
diff --git a/src/reflect/scala/reflect/internal/Definitions.scala b/src/reflect/scala/reflect/internal/Definitions.scala
index 48a658192b..08cf97673f 100644
--- a/src/reflect/scala/reflect/internal/Definitions.scala
+++ b/src/reflect/scala/reflect/internal/Definitions.scala
@@ -485,6 +485,7 @@ trait Definitions extends api.StandardDefinitions {
// scala.reflect
lazy val ReflectPackage = requiredModule[scala.reflect.`package`.type]
def ReflectBasis = getMemberValue(ReflectPackage, nme.basis)
+ lazy val ReflectApiPackage = getPackageObjectIfDefined("scala.reflect.api") // defined in scala-reflect.jar, so we need to be careful
lazy val ReflectRuntimePackage = getPackageObjectIfDefined("scala.reflect.runtime") // defined in scala-reflect.jar, so we need to be careful
def ReflectRuntimeUniverse = if (ReflectRuntimePackage != NoSymbol) getMemberValue(ReflectRuntimePackage, nme.universe) else NoSymbol
def ReflectRuntimeCurrentMirror = if (ReflectRuntimePackage != NoSymbol) getMemberMethod(ReflectRuntimePackage, nme.currentMirror) else NoSymbol
@@ -509,6 +510,9 @@ trait Definitions extends api.StandardDefinitions {
lazy val WeakTypeTagModule = getMemberModule(TypeTagsClass, nme.WeakTypeTag)
lazy val TypeTagClass = getMemberClass(TypeTagsClass, tpnme.TypeTag)
lazy val TypeTagModule = getMemberModule(TypeTagsClass, nme.TypeTag)
+ def materializeClassTag = getMemberMethod(ReflectPackage, nme.materializeClassTag)
+ def materializeWeakTypeTag = if (ReflectApiPackage != NoSymbol) getMemberMethod(ReflectApiPackage, nme.materializeWeakTypeTag) else NoSymbol
+ def materializeTypeTag = if (ReflectApiPackage != NoSymbol) getMemberMethod(ReflectApiPackage, nme.materializeTypeTag) else NoSymbol
lazy val BaseUniverseClass = requiredClass[scala.reflect.base.Universe]
def BaseUniverseReify = getMemberMethod(BaseUniverseClass, nme.reify)