summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools
diff options
context:
space:
mode:
authorEugene Burmako <xeno.by@gmail.com>2014-01-30 10:01:31 +0300
committerEugene Burmako <xeno.by@gmail.com>2014-02-14 23:51:22 +0100
commit114c99691674873393223a11a9aa9168c3f41d77 (patch)
treed855c67a565faf4dbe414cc8f1a1aaff68a8df79 /src/compiler/scala/tools
parent27805570cbf130260eab04fe1491e58fa95e8108 (diff)
downloadscala-114c99691674873393223a11a9aa9168c3f41d77.tar.gz
scala-114c99691674873393223a11a9aa9168c3f41d77.tar.bz2
scala-114c99691674873393223a11a9aa9168c3f41d77.zip
establishes scala.reflect.api#internal
Reflection API exhibits a tension inherent to experimental things: on the one hand we want it to grow into a beautiful and robust API, but on the other hand we have to deal with immaturity of underlying mechanisms by providing not very pretty solutions to enable important use cases. In Scala 2.10, which was our first stab at reflection API, we didn't have a systematic approach to dealing with this tension, sometimes exposing too much of internals (e.g. Symbol.deSkolemize) and sometimes exposing too little (e.g. there's still no facility to change owners, to do typing transformations, etc). This resulted in certain confusion with some internal APIs living among public ones, scaring the newcomers, and some internal APIs only available via casting, which requires intimate knowledge of the compiler and breaks compatibility guarantees. This led to creation of the `internal` API module for the reflection API, which provides advanced APIs necessary for macros that push boundaries of the state of the art, clearly demarcating them from the more or less straightforward rest and providing compatibility guarantees on par with the rest of the reflection API. This commit does break source compatibility with reflection API in 2.10, but the next commit is going to introduce a strategy of dealing with that.
Diffstat (limited to 'src/compiler/scala/tools')
-rw-r--r--src/compiler/scala/tools/nsc/Global.scala6
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Implicits.scala3
-rw-r--r--src/compiler/scala/tools/reflect/StdTags.scala3
-rw-r--r--src/compiler/scala/tools/reflect/ToolBoxFactory.scala2
-rw-r--r--src/compiler/scala/tools/reflect/quasiquotes/Holes.scala10
-rw-r--r--src/compiler/scala/tools/reflect/quasiquotes/Reifiers.scala6
6 files changed, 14 insertions, 16 deletions
diff --git a/src/compiler/scala/tools/nsc/Global.scala b/src/compiler/scala/tools/nsc/Global.scala
index 5ce0238b3b..03b76ed99e 100644
--- a/src/compiler/scala/tools/nsc/Global.scala
+++ b/src/compiler/scala/tools/nsc/Global.scala
@@ -34,6 +34,7 @@ import backend.jvm.GenASM
import backend.opt.{ Inliners, InlineExceptionHandlers, ConstantOptimization, ClosureElimination, DeadCodeElimination }
import backend.icode.analysis._
import scala.language.postfixOps
+import scala.tools.nsc.ast.{TreeGen => AstTreeGen}
class Global(var currentSettings: Settings, var reporter: Reporter)
extends SymbolTable
@@ -105,13 +106,10 @@ class Global(var currentSettings: Settings, var reporter: Reporter)
// sub-components --------------------------------------------------
- /** Generate ASTs */
- type TreeGen = scala.tools.nsc.ast.TreeGen
-
/** Tree generation, usually based on existing symbols. */
override object gen extends {
val global: Global.this.type = Global.this
- } with TreeGen {
+ } with AstTreeGen {
def mkAttributedCast(tree: Tree, pt: Type): Tree =
typer.typed(mkCast(tree, pt))
}
diff --git a/src/compiler/scala/tools/nsc/typechecker/Implicits.scala b/src/compiler/scala/tools/nsc/typechecker/Implicits.scala
index d3b5564f60..2bb874a8aa 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Implicits.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Implicits.scala
@@ -1271,7 +1271,8 @@ trait Implicits {
return SearchFailure
}
val cm = typed(Ident(ReflectRuntimeCurrentMirror))
- val interop = gen.mkMethodCall(ReflectRuntimeUniverse, nme.typeTagToManifest, List(tp), List(cm, tagInScope))
+ val internal = gen.mkAttributedSelect(gen.mkAttributedRef(ReflectRuntimeUniverse), UniverseInternal)
+ val interop = gen.mkMethodCall(Select(internal, nme.typeTagToManifest), List(tp), List(cm, tagInScope))
wrapResult(interop)
}
} else {
diff --git a/src/compiler/scala/tools/reflect/StdTags.scala b/src/compiler/scala/tools/reflect/StdTags.scala
index 5c53c81e8b..ee352c5e02 100644
--- a/src/compiler/scala/tools/reflect/StdTags.scala
+++ b/src/compiler/scala/tools/reflect/StdTags.scala
@@ -18,8 +18,7 @@ trait StdTags {
new TypeCreator {
def apply[U <: ApiUniverse with Singleton](m: Mirror[U]): U # Type = {
val u = m.universe
- val pre = u.ThisType(m.staticPackage("scala.collection.immutable").moduleClass.asInstanceOf[u.Symbol])
- u.TypeRef(pre, u.definitions.ListClass, List(u.definitions.StringClass.toTypeConstructor))
+ u.appliedType(u.definitions.ListClass.toType, List(u.definitions.StringClass.toType))
}
})
diff --git a/src/compiler/scala/tools/reflect/ToolBoxFactory.scala b/src/compiler/scala/tools/reflect/ToolBoxFactory.scala
index b43b4653eb..ce6382bec8 100644
--- a/src/compiler/scala/tools/reflect/ToolBoxFactory.scala
+++ b/src/compiler/scala/tools/reflect/ToolBoxFactory.scala
@@ -217,7 +217,7 @@ abstract class ToolBoxFactory[U <: JavaUniverse](val u: U) { factorySelf =>
val (expr, freeTerms) = extractFreeTerms(expr0, wrapFreeTermRefs = true)
val (obj, _) = rootMirror.EmptyPackageClass.newModuleAndClassSymbol(
- nextWrapperModuleName())
+ nextWrapperModuleName(), NoPosition, NoFlags)
val minfo = ClassInfoType(List(ObjectTpe), newScope, obj.moduleClass)
obj.moduleClass setInfo minfo
diff --git a/src/compiler/scala/tools/reflect/quasiquotes/Holes.scala b/src/compiler/scala/tools/reflect/quasiquotes/Holes.scala
index 2027d43264..c2f1bf430d 100644
--- a/src/compiler/scala/tools/reflect/quasiquotes/Holes.scala
+++ b/src/compiler/scala/tools/reflect/quasiquotes/Holes.scala
@@ -120,8 +120,8 @@ trait Holes { self: Quasiquotes =>
}
private def toStats(tree: Tree): Tree =
- // q"$u.build.toStats($tree)"
- Apply(Select(Select(u, nme.build), nme.toStats), tree :: Nil)
+ // q"$u.internal.reificationSupport.toStats($tree)"
+ Apply(Select(Select(Select(u, nme.internal), nme.reificationSupport), nme.toStats), tree :: Nil)
private def toList(tree: Tree, tpe: Type): Tree =
if (isListType(tpe)) tree
@@ -234,10 +234,10 @@ trait Holes { self: Quasiquotes =>
}
val lifter = inferUnliftable(tpe)
assert(helperName.isTermName)
- // q"val $name: $u.build.${helperName.toTypeName} = $u.build.$helperName($lifter)"
+ // q"val $name: $u.internal.reificationSupport.${helperName.toTypeName} = $u.internal.reificationSupport.$helperName($lifter)"
ValDef(NoMods, name,
- AppliedTypeTree(Select(Select(u, nme.build), helperName.toTypeName), List(TypeTree(tpe))),
- Apply(Select(Select(u, nme.build), helperName), lifter :: Nil))
+ AppliedTypeTree(Select(Select(Select(u, nme.internal), nme.reificationSupport), helperName.toTypeName), List(TypeTree(tpe))),
+ Apply(Select(Select(Select(u, nme.internal), nme.reificationSupport), helperName), lifter :: Nil))
}
}
}
diff --git a/src/compiler/scala/tools/reflect/quasiquotes/Reifiers.scala b/src/compiler/scala/tools/reflect/quasiquotes/Reifiers.scala
index 017e966f63..9078228314 100644
--- a/src/compiler/scala/tools/reflect/quasiquotes/Reifiers.scala
+++ b/src/compiler/scala/tools/reflect/quasiquotes/Reifiers.scala
@@ -64,9 +64,9 @@ trait Reifiers { self: Quasiquotes =>
val FreshName(prefix) = origname
val nameTypeName = if (origname.isTermName) tpnme.TermName else tpnme.TypeName
val freshName = if (origname.isTermName) nme.freshTermName else nme.freshTypeName
- // q"val ${names.head}: $u.$nameTypeName = $u.build.$freshName($prefix)"
+ // q"val ${names.head}: $u.$nameTypeName = $u.internal.reificationSupport.$freshName($prefix)"
ValDef(NoMods, names.head, Select(u, nameTypeName),
- Apply(Select(Select(u, nme.build), freshName), Literal(Constant(prefix)) :: Nil))
+ Apply(Select(Select(Select(u, nme.internal), nme.reificationSupport), freshName), Literal(Constant(prefix)) :: Nil))
}.toList
// q"..$freshdefs; $tree"
SyntacticBlock(freshdefs :+ tree)
@@ -358,7 +358,7 @@ trait Reifiers { self: Quasiquotes =>
Apply(Select(universe, name), args.toList)
override def mirrorBuildCall(name: TermName, args: Tree*): Tree =
- Apply(Select(Select(universe, nme.build), name), args.toList)
+ Apply(Select(Select(Select(universe, nme.internal), nme.reificationSupport), name), args.toList)
override def scalaFactoryCall(name: String, args: Tree*): Tree =
call("scala." + name, args: _*)