From 9892f52adf76c1e39c6d129f8b35ee98802de188 Mon Sep 17 00:00:00 2001 From: Eugene Burmako Date: Tue, 24 Jul 2012 12:34:18 +0200 Subject: reflect.makro => reflect.macros (Step I) Builds a starr that uses stuff from scala.reflect.macros for macro activities. Crucial makro thingies (such as makro.Context or makro.internal.macroImpl) are temporarily left in place, because they are necessary for previous starr. Macro tests will be fixed in a dedicated commit, so that they don't pollute meaningful commits, making the life easy for reviewers and spelunkers. --- lib/scala-compiler-src.jar.desired.sha1 | 2 +- lib/scala-compiler.jar.desired.sha1 | 2 +- lib/scala-library-src.jar.desired.sha1 | 2 +- lib/scala-library.jar.desired.sha1 | 2 +- lib/scala-reflect-src.jar.desired.sha1 | 2 +- lib/scala-reflect.jar.desired.sha1 | 2 +- .../macros/runtime/AbortMacroException.scala | 6 ++ .../scala/reflect/macros/runtime/Aliases.scala | 26 +++++ .../reflect/macros/runtime/CapturedVariables.scala | 15 +++ .../scala/reflect/macros/runtime/Context.scala | 32 ++++++ .../scala/reflect/macros/runtime/Enclosures.scala | 23 +++++ .../scala/reflect/macros/runtime/Evals.scala | 18 ++++ .../scala/reflect/macros/runtime/ExprUtils.scala | 35 +++++++ .../scala/reflect/macros/runtime/Exprs.scala | 8 ++ .../scala/reflect/macros/runtime/FrontEnds.scala | 47 +++++++++ .../reflect/macros/runtime/Infrastructure.scala | 52 ++++++++++ .../scala/reflect/macros/runtime/Names.scala | 17 ++++ .../scala/reflect/macros/runtime/Parsers.scala | 25 +++++ .../scala/reflect/macros/runtime/Reifiers.scala | 79 +++++++++++++++ .../scala/reflect/macros/runtime/Settings.scala | 36 +++++++ .../scala/reflect/macros/runtime/Traces.scala | 8 ++ .../scala/reflect/macros/runtime/TypeTags.scala | 9 ++ .../scala/reflect/macros/runtime/Typers.scala | 68 +++++++++++++ .../scala/reflect/macros/util/Traces.scala | 18 ++++ .../makro/runtime/AbortMacroException.scala | 6 -- .../scala/reflect/makro/runtime/Aliases.scala | 26 ----- .../reflect/makro/runtime/CapturedVariables.scala | 15 --- .../scala/reflect/makro/runtime/Context.scala | 32 ------ .../scala/reflect/makro/runtime/Enclosures.scala | 23 ----- .../scala/reflect/makro/runtime/Evals.scala | 18 ---- .../scala/reflect/makro/runtime/ExprUtils.scala | 35 ------- .../scala/reflect/makro/runtime/Exprs.scala | 8 -- .../scala/reflect/makro/runtime/FrontEnds.scala | 47 --------- .../reflect/makro/runtime/Infrastructure.scala | 52 ---------- .../scala/reflect/makro/runtime/Names.scala | 17 ---- .../scala/reflect/makro/runtime/Parsers.scala | 25 ----- .../scala/reflect/makro/runtime/Reifiers.scala | 79 --------------- .../scala/reflect/makro/runtime/Settings.scala | 36 ------- .../scala/reflect/makro/runtime/Traces.scala | 8 -- .../scala/reflect/makro/runtime/TypeTags.scala | 9 -- .../scala/reflect/makro/runtime/Typers.scala | 68 ------------- src/compiler/scala/reflect/makro/util/Traces.scala | 18 ---- src/compiler/scala/reflect/reify/Errors.scala | 4 +- src/compiler/scala/reflect/reify/Reifier.scala | 4 +- src/compiler/scala/reflect/reify/Taggers.scala | 4 +- src/compiler/scala/reflect/reify/package.scala | 2 +- .../scala/tools/nsc/typechecker/Implicits.scala | 2 +- .../scala/tools/nsc/typechecker/Macros.scala | 10 +- .../tools/nsc/typechecker/StdAttachments.scala | 2 +- .../scala/tools/reflect/MacroImplementations.scala | 8 +- src/compiler/scala/tools/reflect/StdTags.scala | 2 +- src/compiler/scala/tools/util/PathResolver.scala | 2 +- .../scala/reflect/macros/internal/macroImpl.scala | 18 ++++ .../scala/reflect/macros/internal/package.scala | 15 +++ .../scala/reflect/makro/internal/macroImpl.scala | 18 ---- .../scala/reflect/makro/internal/package.scala | 6 +- .../scala/reflect/internal/Definitions.scala | 6 +- .../scala/reflect/internal/SymbolTable.scala | 2 +- src/reflect/scala/reflect/internal/TreeGen.scala | 2 +- src/reflect/scala/reflect/macros/Aliases.scala | 26 +++++ .../scala/reflect/macros/CapturedVariables.scala | 21 ++++ src/reflect/scala/reflect/macros/Context.scala | 34 +++++++ src/reflect/scala/reflect/macros/Enclosures.scala | 50 ++++++++++ src/reflect/scala/reflect/macros/Evals.scala | 9 ++ src/reflect/scala/reflect/macros/ExprUtils.scala | 32 ++++++ src/reflect/scala/reflect/macros/Exprs.scala | 8 ++ src/reflect/scala/reflect/macros/FrontEnds.scala | 42 ++++++++ .../scala/reflect/macros/Infrastructure.scala | 103 ++++++++++++++++++++ src/reflect/scala/reflect/macros/Names.scala | 15 +++ src/reflect/scala/reflect/macros/Parsers.scala | 18 ++++ src/reflect/scala/reflect/macros/Reifiers.scala | 91 +++++++++++++++++ src/reflect/scala/reflect/macros/Settings.scala | 40 ++++++++ src/reflect/scala/reflect/macros/TreeBuilder.scala | 60 ++++++++++++ src/reflect/scala/reflect/macros/TypeTags.scala | 9 ++ src/reflect/scala/reflect/macros/Typers.scala | 83 ++++++++++++++++ src/reflect/scala/reflect/macros/Universe.scala | 108 +++++++++++++++++++++ src/reflect/scala/reflect/macros/package.scala | 6 ++ src/reflect/scala/reflect/makro/Aliases.scala | 26 ----- .../scala/reflect/makro/CapturedVariables.scala | 21 ---- src/reflect/scala/reflect/makro/Context.scala | 34 ------- src/reflect/scala/reflect/makro/Enclosures.scala | 50 ---------- src/reflect/scala/reflect/makro/Evals.scala | 9 -- src/reflect/scala/reflect/makro/ExprUtils.scala | 32 ------ src/reflect/scala/reflect/makro/Exprs.scala | 8 -- src/reflect/scala/reflect/makro/FrontEnds.scala | 42 -------- .../scala/reflect/makro/Infrastructure.scala | 103 -------------------- src/reflect/scala/reflect/makro/Names.scala | 15 --- src/reflect/scala/reflect/makro/Parsers.scala | 18 ---- src/reflect/scala/reflect/makro/Reifiers.scala | 91 ----------------- src/reflect/scala/reflect/makro/Settings.scala | 40 -------- src/reflect/scala/reflect/makro/TreeBuilder.scala | 60 ------------ src/reflect/scala/reflect/makro/TypeTags.scala | 9 -- src/reflect/scala/reflect/makro/Typers.scala | 83 ---------------- src/reflect/scala/reflect/makro/Universe.scala | 108 --------------------- src/reflect/scala/reflect/makro/package.scala | 5 +- src/reflect/scala/reflect/runtime/package.scala | 2 +- 96 files changed, 1345 insertions(+), 1329 deletions(-) create mode 100644 src/compiler/scala/reflect/macros/runtime/AbortMacroException.scala create mode 100644 src/compiler/scala/reflect/macros/runtime/Aliases.scala create mode 100644 src/compiler/scala/reflect/macros/runtime/CapturedVariables.scala create mode 100644 src/compiler/scala/reflect/macros/runtime/Context.scala create mode 100644 src/compiler/scala/reflect/macros/runtime/Enclosures.scala create mode 100644 src/compiler/scala/reflect/macros/runtime/Evals.scala create mode 100644 src/compiler/scala/reflect/macros/runtime/ExprUtils.scala create mode 100644 src/compiler/scala/reflect/macros/runtime/Exprs.scala create mode 100644 src/compiler/scala/reflect/macros/runtime/FrontEnds.scala create mode 100644 src/compiler/scala/reflect/macros/runtime/Infrastructure.scala create mode 100644 src/compiler/scala/reflect/macros/runtime/Names.scala create mode 100644 src/compiler/scala/reflect/macros/runtime/Parsers.scala create mode 100644 src/compiler/scala/reflect/macros/runtime/Reifiers.scala create mode 100644 src/compiler/scala/reflect/macros/runtime/Settings.scala create mode 100644 src/compiler/scala/reflect/macros/runtime/Traces.scala create mode 100644 src/compiler/scala/reflect/macros/runtime/TypeTags.scala create mode 100644 src/compiler/scala/reflect/macros/runtime/Typers.scala create mode 100644 src/compiler/scala/reflect/macros/util/Traces.scala delete mode 100644 src/compiler/scala/reflect/makro/runtime/AbortMacroException.scala delete mode 100644 src/compiler/scala/reflect/makro/runtime/Aliases.scala delete mode 100644 src/compiler/scala/reflect/makro/runtime/CapturedVariables.scala delete mode 100644 src/compiler/scala/reflect/makro/runtime/Context.scala delete mode 100644 src/compiler/scala/reflect/makro/runtime/Enclosures.scala delete mode 100644 src/compiler/scala/reflect/makro/runtime/Evals.scala delete mode 100644 src/compiler/scala/reflect/makro/runtime/ExprUtils.scala delete mode 100644 src/compiler/scala/reflect/makro/runtime/Exprs.scala delete mode 100644 src/compiler/scala/reflect/makro/runtime/FrontEnds.scala delete mode 100644 src/compiler/scala/reflect/makro/runtime/Infrastructure.scala delete mode 100644 src/compiler/scala/reflect/makro/runtime/Names.scala delete mode 100644 src/compiler/scala/reflect/makro/runtime/Parsers.scala delete mode 100644 src/compiler/scala/reflect/makro/runtime/Reifiers.scala delete mode 100644 src/compiler/scala/reflect/makro/runtime/Settings.scala delete mode 100644 src/compiler/scala/reflect/makro/runtime/Traces.scala delete mode 100644 src/compiler/scala/reflect/makro/runtime/TypeTags.scala delete mode 100644 src/compiler/scala/reflect/makro/runtime/Typers.scala delete mode 100644 src/compiler/scala/reflect/makro/util/Traces.scala create mode 100644 src/library/scala/reflect/macros/internal/macroImpl.scala create mode 100644 src/library/scala/reflect/macros/internal/package.scala delete mode 100644 src/library/scala/reflect/makro/internal/macroImpl.scala create mode 100644 src/reflect/scala/reflect/macros/Aliases.scala create mode 100644 src/reflect/scala/reflect/macros/CapturedVariables.scala create mode 100644 src/reflect/scala/reflect/macros/Context.scala create mode 100644 src/reflect/scala/reflect/macros/Enclosures.scala create mode 100644 src/reflect/scala/reflect/macros/Evals.scala create mode 100644 src/reflect/scala/reflect/macros/ExprUtils.scala create mode 100644 src/reflect/scala/reflect/macros/Exprs.scala create mode 100644 src/reflect/scala/reflect/macros/FrontEnds.scala create mode 100644 src/reflect/scala/reflect/macros/Infrastructure.scala create mode 100644 src/reflect/scala/reflect/macros/Names.scala create mode 100644 src/reflect/scala/reflect/macros/Parsers.scala create mode 100644 src/reflect/scala/reflect/macros/Reifiers.scala create mode 100644 src/reflect/scala/reflect/macros/Settings.scala create mode 100644 src/reflect/scala/reflect/macros/TreeBuilder.scala create mode 100644 src/reflect/scala/reflect/macros/TypeTags.scala create mode 100644 src/reflect/scala/reflect/macros/Typers.scala create mode 100644 src/reflect/scala/reflect/macros/Universe.scala create mode 100644 src/reflect/scala/reflect/macros/package.scala delete mode 100644 src/reflect/scala/reflect/makro/Aliases.scala delete mode 100644 src/reflect/scala/reflect/makro/CapturedVariables.scala delete mode 100644 src/reflect/scala/reflect/makro/Context.scala delete mode 100644 src/reflect/scala/reflect/makro/Enclosures.scala delete mode 100644 src/reflect/scala/reflect/makro/Evals.scala delete mode 100644 src/reflect/scala/reflect/makro/ExprUtils.scala delete mode 100644 src/reflect/scala/reflect/makro/Exprs.scala delete mode 100644 src/reflect/scala/reflect/makro/FrontEnds.scala delete mode 100644 src/reflect/scala/reflect/makro/Infrastructure.scala delete mode 100644 src/reflect/scala/reflect/makro/Names.scala delete mode 100644 src/reflect/scala/reflect/makro/Parsers.scala delete mode 100644 src/reflect/scala/reflect/makro/Reifiers.scala delete mode 100644 src/reflect/scala/reflect/makro/Settings.scala delete mode 100644 src/reflect/scala/reflect/makro/TreeBuilder.scala delete mode 100644 src/reflect/scala/reflect/makro/TypeTags.scala delete mode 100644 src/reflect/scala/reflect/makro/Typers.scala delete mode 100644 src/reflect/scala/reflect/makro/Universe.scala diff --git a/lib/scala-compiler-src.jar.desired.sha1 b/lib/scala-compiler-src.jar.desired.sha1 index 91e1cab75e..de9d23e095 100644 --- a/lib/scala-compiler-src.jar.desired.sha1 +++ b/lib/scala-compiler-src.jar.desired.sha1 @@ -1 +1 @@ -86ef964dd57de5e52783afd5a2f44df36eab5bf7 ?scala-compiler-src.jar +a347985ce7eeb0fa4d595ec3b8d1ce5de7373a51 ?scala-compiler-src.jar diff --git a/lib/scala-compiler.jar.desired.sha1 b/lib/scala-compiler.jar.desired.sha1 index 99ef1d01f4..a950b22c0a 100644 --- a/lib/scala-compiler.jar.desired.sha1 +++ b/lib/scala-compiler.jar.desired.sha1 @@ -1 +1 @@ -517e3b70161190ba079e172d6d0dd388eb3d04e8 ?scala-compiler.jar +0948b18e2856642ebc8288a8db9e73bdee4346e7 ?scala-compiler.jar diff --git a/lib/scala-library-src.jar.desired.sha1 b/lib/scala-library-src.jar.desired.sha1 index 32639184cb..34014da4e2 100644 --- a/lib/scala-library-src.jar.desired.sha1 +++ b/lib/scala-library-src.jar.desired.sha1 @@ -1 +1 @@ -d131ccb45a18edbec545c37cccd22872d02d1133 ?scala-library-src.jar +9aa0e579043f34fa7e4115bb9887a26367671d53 ?scala-library-src.jar diff --git a/lib/scala-library.jar.desired.sha1 b/lib/scala-library.jar.desired.sha1 index 293ce830e7..18ad1875b4 100644 --- a/lib/scala-library.jar.desired.sha1 +++ b/lib/scala-library.jar.desired.sha1 @@ -1 +1 @@ -9e7f92776e0f7a89aef3613da79c6ee6bf544b60 ?scala-library.jar +f73be8b1a280799b17d0783efca65cf8e92cb98a ?scala-library.jar diff --git a/lib/scala-reflect-src.jar.desired.sha1 b/lib/scala-reflect-src.jar.desired.sha1 index 47285a18ff..f495ee2486 100644 --- a/lib/scala-reflect-src.jar.desired.sha1 +++ b/lib/scala-reflect-src.jar.desired.sha1 @@ -1 +1 @@ -cf388008bc4a3e387cbe193019f6d780d71746d1 ?scala-reflect-src.jar +b7395ea71371d3884679a3086094d7365653050b ?scala-reflect-src.jar diff --git a/lib/scala-reflect.jar.desired.sha1 b/lib/scala-reflect.jar.desired.sha1 index efa6bd01e6..a7ee10739e 100644 --- a/lib/scala-reflect.jar.desired.sha1 +++ b/lib/scala-reflect.jar.desired.sha1 @@ -1 +1 @@ -2fa8739de9cbc52198d88164d85185f4ae9d153c ?scala-reflect.jar +4b31182e09723af2ae83dbc6a5ee42ed74be601d ?scala-reflect.jar diff --git a/src/compiler/scala/reflect/macros/runtime/AbortMacroException.scala b/src/compiler/scala/reflect/macros/runtime/AbortMacroException.scala new file mode 100644 index 0000000000..f45dde8a85 --- /dev/null +++ b/src/compiler/scala/reflect/macros/runtime/AbortMacroException.scala @@ -0,0 +1,6 @@ +package scala.reflect.macros +package runtime + +import scala.reflect.internal.util.Position + +class AbortMacroException(val pos: Position, val msg: String) extends Throwable(msg) diff --git a/src/compiler/scala/reflect/macros/runtime/Aliases.scala b/src/compiler/scala/reflect/macros/runtime/Aliases.scala new file mode 100644 index 0000000000..8b742755cd --- /dev/null +++ b/src/compiler/scala/reflect/macros/runtime/Aliases.scala @@ -0,0 +1,26 @@ +package scala.reflect.macros +package runtime + +trait Aliases { + self: Context => + + override type Symbol = universe.Symbol + override type Type = universe.Type + override type Name = universe.Name + override type TermName = universe.TermName + override type TypeName = universe.TypeName + override type Tree = universe.Tree + // override type Position = universe.Position + override type Scope = universe.Scope + override type Modifiers = universe.Modifiers + + override type Expr[+T] = universe.Expr[T] + override val Expr = universe.Expr + + override type AbsTypeTag[T] = universe.AbsTypeTag[T] + override type TypeTag[T] = universe.TypeTag[T] + override val AbsTypeTag = universe.AbsTypeTag + override val TypeTag = universe.TypeTag + override def typeTag[T](implicit ttag: TypeTag[T]) = ttag + override def typeOf[T](implicit ttag: TypeTag[T]): Type = ttag.tpe +} \ No newline at end of file diff --git a/src/compiler/scala/reflect/macros/runtime/CapturedVariables.scala b/src/compiler/scala/reflect/macros/runtime/CapturedVariables.scala new file mode 100644 index 0000000000..78fb7100b0 --- /dev/null +++ b/src/compiler/scala/reflect/macros/runtime/CapturedVariables.scala @@ -0,0 +1,15 @@ +package scala.reflect.macros +package runtime + +trait CapturedVariables { + self: Context => + + import mirror._ + import universe._ + + def captureVariable(vble: Symbol): Unit = universe.captureVariable(vble) + + def referenceCapturedVariable(vble: Symbol): Tree = universe.referenceCapturedVariable(vble) + + def capturedVariableType(vble: Symbol): Type = universe.capturedVariableType(vble) +} \ No newline at end of file diff --git a/src/compiler/scala/reflect/macros/runtime/Context.scala b/src/compiler/scala/reflect/macros/runtime/Context.scala new file mode 100644 index 0000000000..8bbfef44a3 --- /dev/null +++ b/src/compiler/scala/reflect/macros/runtime/Context.scala @@ -0,0 +1,32 @@ +package scala.reflect.macros +package runtime + +import scala.tools.nsc.Global + +abstract class Context extends scala.reflect.macros.Context + with Aliases + with CapturedVariables + with Infrastructure + with Enclosures + with Names + with Reifiers + with FrontEnds + with Settings + with Typers + with Parsers + with Exprs + with TypeTags + with Evals + with ExprUtils + with Traces { + + val universe: Global + + val mirror: MirrorOf[universe.type] = universe.rootMirror + + val callsiteTyper: universe.analyzer.Typer + + val prefix: Expr[PrefixType] + + val expandee: Tree +} diff --git a/src/compiler/scala/reflect/macros/runtime/Enclosures.scala b/src/compiler/scala/reflect/macros/runtime/Enclosures.scala new file mode 100644 index 0000000000..ebde4447d7 --- /dev/null +++ b/src/compiler/scala/reflect/macros/runtime/Enclosures.scala @@ -0,0 +1,23 @@ +package scala.reflect.macros +package runtime + +trait Enclosures { + self: Context => + + import universe._ + import mirror._ + + private def site = callsiteTyper.context + private def enclTrees = site.enclosingContextChain map (_.tree) + private def enclPoses = enclosingMacros map (_.macroApplication.pos) filterNot (_ eq NoPosition) + + // vals are eager to simplify debugging + // after all we wouldn't save that much time by making them lazy + val macroApplication: Tree = expandee + val enclosingClass: Tree = site.enclClass.tree + val enclosingImplicits: List[(Type, Tree)] = site.openImplicits + val enclosingMacros: List[Context] = this :: universe.analyzer.openMacros // include self + val enclosingMethod: Tree = site.enclMethod.tree + val enclosingPosition: Position = if (enclPoses.isEmpty) NoPosition else enclPoses.head.pos + val enclosingUnit: CompilationUnit = currentRun.currentUnit +} diff --git a/src/compiler/scala/reflect/macros/runtime/Evals.scala b/src/compiler/scala/reflect/macros/runtime/Evals.scala new file mode 100644 index 0000000000..348e29cdd7 --- /dev/null +++ b/src/compiler/scala/reflect/macros/runtime/Evals.scala @@ -0,0 +1,18 @@ +package scala.reflect.macros +package runtime + +import scala.reflect.runtime.{universe => ru} +import scala.tools.reflect.ToolBox + +trait Evals { + self: Context => + + private lazy val evalMirror = ru.runtimeMirror(libraryClassLoader) + private lazy val evalToolBox = evalMirror.mkToolBox() + private lazy val evalImporter = ru.mkImporter(universe).asInstanceOf[ru.Importer { val from: universe.type }] + + def eval[T](expr: Expr[T]): T = { + val imported = evalImporter.importTree(expr.tree) + evalToolBox.runExpr(imported).asInstanceOf[T] + } +} \ No newline at end of file diff --git a/src/compiler/scala/reflect/macros/runtime/ExprUtils.scala b/src/compiler/scala/reflect/macros/runtime/ExprUtils.scala new file mode 100644 index 0000000000..672699f00e --- /dev/null +++ b/src/compiler/scala/reflect/macros/runtime/ExprUtils.scala @@ -0,0 +1,35 @@ +package scala.reflect.macros +package runtime + +trait ExprUtils { + self: Context => + + import universe._ + import mirror._ + + def literalNull = Expr[Null](Literal(Constant(null)))(TypeTag.Null) + + def literalUnit = Expr[Unit](Literal(Constant(())))(TypeTag.Unit) + + def literalTrue = Expr[Boolean](Literal(Constant(true)))(TypeTag.Boolean) + + def literalFalse = Expr[Boolean](Literal(Constant(false)))(TypeTag.Boolean) + + def literal(x: Boolean) = Expr[Boolean](Literal(Constant(x)))(TypeTag.Boolean) + + def literal(x: Byte) = Expr[Byte](Literal(Constant(x)))(TypeTag.Byte) + + def literal(x: Short) = Expr[Short](Literal(Constant(x)))(TypeTag.Short) + + def literal(x: Int) = Expr[Int](Literal(Constant(x)))(TypeTag.Int) + + def literal(x: Long) = Expr[Long](Literal(Constant(x)))(TypeTag.Long) + + def literal(x: Float) = Expr[Float](Literal(Constant(x)))(TypeTag.Float) + + def literal(x: Double) = Expr[Double](Literal(Constant(x)))(TypeTag.Double) + + def literal(x: String) = Expr[String](Literal(Constant(x)))(TypeTag[String](definitions.StringClass.toTypeConstructor)) + + def literal(x: Char) = Expr[Char](Literal(Constant(x)))(TypeTag.Char) +} diff --git a/src/compiler/scala/reflect/macros/runtime/Exprs.scala b/src/compiler/scala/reflect/macros/runtime/Exprs.scala new file mode 100644 index 0000000000..4217a6a404 --- /dev/null +++ b/src/compiler/scala/reflect/macros/runtime/Exprs.scala @@ -0,0 +1,8 @@ +package scala.reflect.macros +package runtime + +trait Exprs { + self: Context => + + def Expr[T: AbsTypeTag](tree: Tree): Expr[T] = universe.Expr[T](mirror, universe.FixedMirrorTreeCreator(mirror, tree)) +} diff --git a/src/compiler/scala/reflect/macros/runtime/FrontEnds.scala b/src/compiler/scala/reflect/macros/runtime/FrontEnds.scala new file mode 100644 index 0000000000..69fa416f8f --- /dev/null +++ b/src/compiler/scala/reflect/macros/runtime/FrontEnds.scala @@ -0,0 +1,47 @@ +package scala.reflect.macros +package runtime + +trait FrontEnds extends scala.tools.reflect.FrontEnds { + self: Context => + + import universe._ + import mirror._ + + override type Position = universe.Position + + def frontEnd: FrontEnd = wrapReporter(universe.reporter) + + def setFrontEnd(frontEnd: FrontEnd): this.type = { + universe.reporter = wrapFrontEnd(frontEnd) + this + } + + def withFrontEnd[T](frontEnd: FrontEnd)(op: => T): T = { + val old = universe.reporter + setFrontEnd(frontEnd) + try op + finally universe.reporter = old + } + + def echo(pos: Position, msg: String): Unit = universe.reporter.echo(pos, msg) + + def info(pos: Position, msg: String, force: Boolean): Unit = universe.reporter.info(pos, msg, force) + + def hasWarnings: Boolean = universe.reporter.hasErrors + + def hasErrors: Boolean = universe.reporter.hasErrors + + def warning(pos: Position, msg: String): Unit = callsiteTyper.context.warning(pos, msg) + + def error(pos: Position, msg: String): Unit = callsiteTyper.context.error(pos, msg) + + def abort(pos: Position, msg: String): Nothing = { + callsiteTyper.context.error(pos, msg) + throw new AbortMacroException(pos, msg) + } + + def interactive(): Unit = universe.reporter match { + case reporter: tools.nsc.reporters.AbstractReporter => reporter.displayPrompt() + case _ => () + } +} \ No newline at end of file diff --git a/src/compiler/scala/reflect/macros/runtime/Infrastructure.scala b/src/compiler/scala/reflect/macros/runtime/Infrastructure.scala new file mode 100644 index 0000000000..19fb03364e --- /dev/null +++ b/src/compiler/scala/reflect/macros/runtime/Infrastructure.scala @@ -0,0 +1,52 @@ +package scala.reflect.macros +package runtime + +import scala.tools.nsc.util.ScalaClassLoader + +trait Infrastructure { + self: Context => + + val forJVM: Boolean = universe.forJVM + + val forMSIL: Boolean = universe.forMSIL + + val forInteractive: Boolean = universe.forInteractive + + val forScaladoc: Boolean = universe.forScaladoc + + val currentRun: Run = universe.currentRun + + val libraryClassPath: List[java.net.URL] = universe.classPath.asURLs + + lazy val libraryClassLoader: ClassLoader = { + val classpath = libraryClassPath + var loader: ClassLoader = ScalaClassLoader.fromURLs(classpath, self.getClass.getClassLoader) + + // [Eugene] a heuristic to detect REPL + if (universe.settings.exposeEmptyPackage.value) { + import scala.tools.nsc.interpreter._ + val virtualDirectory = universe.settings.outputDirs.getSingleOutput.get + loader = new AbstractFileClassLoader(virtualDirectory, loader) {} + } + + loader + } + + type Run = universe.Run + + object Run extends RunExtractor { + def unapply(run: Run): Option[(CompilationUnit, List[CompilationUnit])] = Some(run.currentUnit, run.units.toList) + } + + type CompilationUnit = universe.CompilationUnit + + object CompilationUnit extends CompilationUnitExtractor { + def unapply(compilationUnit: CompilationUnit): Option[(java.io.File, Array[Char], Tree)] = Some(compilationUnit.source.file.file, compilationUnit.source.content, compilationUnit.body) + } + + val currentMacro: Symbol = expandee.symbol + + val globalCache: collection.mutable.Map[Any, Any] = universe.analyzer.globalMacroCache + + val cache: collection.mutable.Map[Any, Any] = universe.analyzer.perRunMacroCache.getOrElseUpdate(currentMacro, collection.mutable.Map[Any, Any]()) +} \ No newline at end of file diff --git a/src/compiler/scala/reflect/macros/runtime/Names.scala b/src/compiler/scala/reflect/macros/runtime/Names.scala new file mode 100644 index 0000000000..ee9f3a56d3 --- /dev/null +++ b/src/compiler/scala/reflect/macros/runtime/Names.scala @@ -0,0 +1,17 @@ +package scala.reflect.macros +package runtime + +trait Names { + self: Context => + + lazy val freshNameCreator = callsiteTyper.context.unit.fresh + + def fresh(): String = + freshNameCreator.newName() + + def fresh(name: String): String = + freshNameCreator.newName(name) + + def fresh[NameType <: Name](name: NameType): NameType = + name.mapName(freshNameCreator.newName(_)).asInstanceOf[NameType] +} \ No newline at end of file diff --git a/src/compiler/scala/reflect/macros/runtime/Parsers.scala b/src/compiler/scala/reflect/macros/runtime/Parsers.scala new file mode 100644 index 0000000000..6d89b71f39 --- /dev/null +++ b/src/compiler/scala/reflect/macros/runtime/Parsers.scala @@ -0,0 +1,25 @@ +package scala.reflect.macros +package runtime + +import language.existentials +import scala.tools.reflect.ToolBox +import scala.tools.reflect.ToolBoxError + +trait Parsers { + self: Context => + + def parse(code: String): Tree = + // todo. provide decent implementation + try { + import scala.reflect.runtime.{universe => ru} + val parsed = ru.rootMirror.mkToolBox().parseExpr(code) + val importer = universe.mkImporter(ru) + importer.importTree(parsed) + } catch { + case ToolBoxError(msg, cause) => + throw new ParseError(universe.NoPosition, msg) + } + + case class ParseError(val pos: Position, val msg: String) extends Throwable(msg) + object ParseError extends ParseErrorExtractor +} \ No newline at end of file diff --git a/src/compiler/scala/reflect/macros/runtime/Reifiers.scala b/src/compiler/scala/reflect/macros/runtime/Reifiers.scala new file mode 100644 index 0000000000..056549578a --- /dev/null +++ b/src/compiler/scala/reflect/macros/runtime/Reifiers.scala @@ -0,0 +1,79 @@ +/* NSC -- new Scala compiler + * Copyright 2005-2011 LAMP/EPFL + * @author Gilles Dubochet + */ + +package scala.reflect.macros +package runtime + +trait Reifiers { + self: Context => + + val global: universe.type = universe + import universe._ + import definitions._ + + lazy val basisUniverse: Tree = gen.mkBasisUniverseRef + + lazy val runtimeUniverse: Tree = gen.mkRuntimeUniverseRef + + def reifyTree(universe: Tree, mirror: Tree, tree: Tree): Tree = { + val result = scala.reflect.reify.`package`.reifyTree(self.universe)(callsiteTyper, universe, mirror, tree) + logFreeVars(enclosingPosition, result) + result + } + + def reifyType(universe: Tree, mirror: Tree, tpe: Type, concrete: Boolean = false): Tree = { + val result = scala.reflect.reify.`package`.reifyType(self.universe)(callsiteTyper, universe, mirror, tpe, concrete) + logFreeVars(enclosingPosition, result) + result + } + + def reifyRuntimeClass(tpe: Type, concrete: Boolean = true): Tree = + scala.reflect.reify.`package`.reifyRuntimeClass(universe)(callsiteTyper, tpe, concrete = concrete) + + def reifyEnclosingRuntimeClass: Tree = + scala.reflect.reify.`package`.reifyEnclosingRuntimeClass(universe)(callsiteTyper) + + def unreifyTree(tree: Tree): Tree = { + assert(ExprSplice != NoSymbol) + Select(tree, ExprSplice) + } + + // fixme: if I put utils here, then "global" from utils' early initialization syntax + // and "global" that comes from here conflict with each other when incrementally compiling + // the problem is that both are pickled with the same owner - trait Reifiers + // and this upsets the compiler, so that oftentimes it throws assertion failures + // Martin knows the details + // + // object utils extends { + // val global: self.global.type = self.global + // val typer: global.analyzer.Typer = self.callsiteTyper + // } with scala.reflect.reify.utils.Utils + // import utils._ + + private def logFreeVars(position: Position, reification: Tree): Unit = { + object utils extends { + val global: self.global.type = self.global + val typer: global.analyzer.Typer = self.callsiteTyper + } with scala.reflect.reify.utils.Utils + import utils._ + + def logFreeVars(symtab: SymbolTable): Unit = + // logging free vars only when they are untyped prevents avalanches of duplicate messages + symtab.syms map (sym => symtab.symDef(sym)) foreach { + case FreeTermDef(_, _, binding, _, origin) if universe.settings.logFreeTerms.value && binding.tpe == null => + reporter.echo(position, "free term: %s %s".format(showRaw(binding), origin)) + case FreeTypeDef(_, _, binding, _, origin) if universe.settings.logFreeTypes.value && binding.tpe == null => + reporter.echo(position, "free type: %s %s".format(showRaw(binding), origin)) + case _ => + // do nothing + } + + if (universe.settings.logFreeTerms.value || universe.settings.logFreeTypes.value) + reification match { + case ReifiedTree(_, _, symtab, _, _, _, _) => logFreeVars(symtab) + case ReifiedType(_, _, symtab, _, _, _) => logFreeVars(symtab) + } + } +} diff --git a/src/compiler/scala/reflect/macros/runtime/Settings.scala b/src/compiler/scala/reflect/macros/runtime/Settings.scala new file mode 100644 index 0000000000..b7dba665fa --- /dev/null +++ b/src/compiler/scala/reflect/macros/runtime/Settings.scala @@ -0,0 +1,36 @@ +package scala.reflect.macros +package runtime + +trait Settings { + self: Context => + + def settings: List[String] = { + val optionName = universe.settings.XmacroSettings.name + val settings = compilerSettings.find(opt => opt.startsWith(optionName)).map(opt => opt.substring(optionName.length + 1)).getOrElse("") + settings.split(",").toList + } + + def compilerSettings: List[String] = universe.settings.recreateArgs + + def setCompilerSettings(options: String): this.type = + // todo. is not going to work with quoted arguments with embedded whitespaces + setCompilerSettings(options.split(" ").toList) + + def setCompilerSettings(options: List[String]): this.type = { + val settings = new tools.nsc.Settings(_ => ()) + // [Eugene] what settings should we exclude? + settings.copyInto(universe.settings) + this + } + + def withCompilerSettings[T](options: String)(op: => T): T = + // todo. is not going to work with quoted arguments with embedded whitespaces + withCompilerSettings(options.split(" ").toList)(op) + + def withCompilerSettings[T](options: List[String])(op: => T): T = { + val old = options + setCompilerSettings(options) + try op + finally setCompilerSettings(old) + } +} \ No newline at end of file diff --git a/src/compiler/scala/reflect/macros/runtime/Traces.scala b/src/compiler/scala/reflect/macros/runtime/Traces.scala new file mode 100644 index 0000000000..0238e9f84e --- /dev/null +++ b/src/compiler/scala/reflect/macros/runtime/Traces.scala @@ -0,0 +1,8 @@ +package scala.reflect.macros +package runtime + +trait Traces extends util.Traces { + self: Context => + + def globalSettings = universe.settings +} diff --git a/src/compiler/scala/reflect/macros/runtime/TypeTags.scala b/src/compiler/scala/reflect/macros/runtime/TypeTags.scala new file mode 100644 index 0000000000..2bc2fe6384 --- /dev/null +++ b/src/compiler/scala/reflect/macros/runtime/TypeTags.scala @@ -0,0 +1,9 @@ +package scala.reflect.macros +package runtime + +trait TypeTags { + self: Context => + + def AbsTypeTag[T](tpe: Type): AbsTypeTag[T] = universe.AbsTypeTag[T](mirror, universe.FixedMirrorTypeCreator(mirror, tpe)) + def TypeTag[T](tpe: Type): TypeTag[T] = universe.TypeTag[T](mirror, universe.FixedMirrorTypeCreator(mirror, tpe)) +} diff --git a/src/compiler/scala/reflect/macros/runtime/Typers.scala b/src/compiler/scala/reflect/macros/runtime/Typers.scala new file mode 100644 index 0000000000..9fa8567ada --- /dev/null +++ b/src/compiler/scala/reflect/macros/runtime/Typers.scala @@ -0,0 +1,68 @@ +package scala.reflect.macros +package runtime + +trait Typers { + self: Context => + + def openMacros: List[Context] = this :: universe.analyzer.openMacros + + def openImplicits: List[(Type, Tree)] = callsiteTyper.context.openImplicits + + def typeCheck(tree: Tree, pt: Type = universe.WildcardType, silent: Boolean = false, withImplicitViewsDisabled: Boolean = false, withMacrosDisabled: Boolean = false): Tree = { + macroLogVerbose("typechecking %s with expected type %s, implicit views = %s, macros = %s".format(tree, pt, !withImplicitViewsDisabled, !withMacrosDisabled)) + val context = callsiteTyper.context + val wrapper1 = if (!withImplicitViewsDisabled) (context.withImplicitsEnabled[Tree] _) else (context.withImplicitsDisabled[Tree] _) + val wrapper2 = if (!withMacrosDisabled) (context.withMacrosEnabled[Tree] _) else (context.withMacrosDisabled[Tree] _) + def wrapper (tree: => Tree) = wrapper1(wrapper2(tree)) + // if you get a "silent mode is not available past typer" here + // don't rush to change the typecheck not to use the silent method when the silent parameter is false + // typechecking uses silent anyways (e.g. in typedSelect), so you'll only waste your time + // I'd advise fixing the root cause: finding why the context is not set to report errors + // (also see reflect.runtime.ToolBoxes.typeCheckExpr for a workaround that might work for you) + wrapper(callsiteTyper.silent(_.typed(tree, universe.analyzer.EXPRmode, pt)) match { + case universe.analyzer.SilentResultValue(result) => + macroLogVerbose(result) + result + case error @ universe.analyzer.SilentTypeError(_) => + macroLogVerbose(error.err.errMsg) + if (!silent) throw new universe.TypeError(error.err.errPos, error.err.errMsg) + universe.EmptyTree + }) + } + + def inferImplicitValue(pt: Type, silent: Boolean = true, withMacrosDisabled: Boolean = false, pos: Position = enclosingPosition): Tree = { + macroLogVerbose("inferring implicit value of type %s, macros = %s".format(pt, !withMacrosDisabled)) + inferImplicit(universe.EmptyTree, pt, isView = false, silent = silent, withMacrosDisabled = withMacrosDisabled, pos = pos) + } + + def inferImplicitView(tree: Tree, from: Type, to: Type, silent: Boolean = true, withMacrosDisabled: Boolean = false, pos: Position = enclosingPosition): Tree = { + macroLogVerbose("inferring implicit view from %s to %s for %s, macros = %s".format(from, to, tree, !withMacrosDisabled)) + val viewTpe = universe.appliedType(universe.definitions.FunctionClass(1).toTypeConstructor, List(from, to)) + inferImplicit(tree, viewTpe, isView = true, silent = silent, withMacrosDisabled = withMacrosDisabled, pos = pos) + } + + private def inferImplicit(tree: Tree, pt: Type, isView: Boolean, silent: Boolean, withMacrosDisabled: Boolean, pos: Position): Tree = { + import universe.analyzer.SearchResult + val context = callsiteTyper.context + val wrapper1 = if (!withMacrosDisabled) (context.withMacrosEnabled[SearchResult] _) else (context.withMacrosDisabled[SearchResult] _) + def wrapper (inference: => SearchResult) = wrapper1(inference) + wrapper(universe.analyzer.inferImplicit(tree, pt, reportAmbiguous = true, isView = isView, context = context, saveAmbiguousDivergent = !silent, pos = pos)) match { + case failure if failure.tree.isEmpty => + macroLogVerbose("implicit search has failed. to find out the reason, turn on -Xlog-implicits") + if (context.hasErrors) throw new universe.TypeError(context.errBuffer.head.errPos, context.errBuffer.head.errMsg) + universe.EmptyTree + case success => + success.tree + } + } + + type TypeError = universe.TypeError + + object TypeError extends TypeErrorExtractor { + def unapply(error: TypeError): Option[(Position, String)] = Some((error.pos, error.msg)) + } + + def resetAllAttrs(tree: Tree): Tree = universe.resetAllAttrs(tree) + + def resetLocalAttrs(tree: Tree): Tree = universe.resetLocalAttrs(tree) +} \ No newline at end of file diff --git a/src/compiler/scala/reflect/macros/util/Traces.scala b/src/compiler/scala/reflect/macros/util/Traces.scala new file mode 100644 index 0000000000..6c2f115994 --- /dev/null +++ b/src/compiler/scala/reflect/macros/util/Traces.scala @@ -0,0 +1,18 @@ +package scala.reflect.macros +package util + +trait Traces { + def globalSettings: tools.nsc.Settings + + // [Eugene] lots of ways to log: + // 1) trace(...) + // 2) log(...) + // 3) if (foo) { doStuff(); includingSomeLogs(); } + // what is the conventional way of unifying this? + val macroDebugLite = globalSettings.YmacrodebugLite.value + val macroDebugVerbose = globalSettings.YmacrodebugVerbose.value + val macroTraceLite = scala.tools.nsc.util.trace when (macroDebugLite || macroDebugVerbose) + val macroTraceVerbose = scala.tools.nsc.util.trace when macroDebugVerbose + @inline final def macroLogLite(msg: => Any) { if (macroDebugLite || macroDebugVerbose) println(msg) } + @inline final def macroLogVerbose(msg: => Any) { if (macroDebugVerbose) println(msg) } +} \ No newline at end of file diff --git a/src/compiler/scala/reflect/makro/runtime/AbortMacroException.scala b/src/compiler/scala/reflect/makro/runtime/AbortMacroException.scala deleted file mode 100644 index a68910859d..0000000000 --- a/src/compiler/scala/reflect/makro/runtime/AbortMacroException.scala +++ /dev/null @@ -1,6 +0,0 @@ -package scala.reflect.makro -package runtime - -import scala.reflect.internal.util.Position - -class AbortMacroException(val pos: Position, val msg: String) extends Throwable(msg) diff --git a/src/compiler/scala/reflect/makro/runtime/Aliases.scala b/src/compiler/scala/reflect/makro/runtime/Aliases.scala deleted file mode 100644 index 760f7fc54d..0000000000 --- a/src/compiler/scala/reflect/makro/runtime/Aliases.scala +++ /dev/null @@ -1,26 +0,0 @@ -package scala.reflect.makro -package runtime - -trait Aliases { - self: Context => - - override type Symbol = universe.Symbol - override type Type = universe.Type - override type Name = universe.Name - override type TermName = universe.TermName - override type TypeName = universe.TypeName - override type Tree = universe.Tree - // override type Position = universe.Position - override type Scope = universe.Scope - override type Modifiers = universe.Modifiers - - override type Expr[+T] = universe.Expr[T] - override val Expr = universe.Expr - - override type AbsTypeTag[T] = universe.AbsTypeTag[T] - override type TypeTag[T] = universe.TypeTag[T] - override val AbsTypeTag = universe.AbsTypeTag - override val TypeTag = universe.TypeTag - override def typeTag[T](implicit ttag: TypeTag[T]) = ttag - override def typeOf[T](implicit ttag: TypeTag[T]): Type = ttag.tpe -} \ No newline at end of file diff --git a/src/compiler/scala/reflect/makro/runtime/CapturedVariables.scala b/src/compiler/scala/reflect/makro/runtime/CapturedVariables.scala deleted file mode 100644 index 021b93ceee..0000000000 --- a/src/compiler/scala/reflect/makro/runtime/CapturedVariables.scala +++ /dev/null @@ -1,15 +0,0 @@ -package scala.reflect.makro -package runtime - -trait CapturedVariables { - self: Context => - - import mirror._ - import universe._ - - def captureVariable(vble: Symbol): Unit = universe.captureVariable(vble) - - def referenceCapturedVariable(vble: Symbol): Tree = universe.referenceCapturedVariable(vble) - - def capturedVariableType(vble: Symbol): Type = universe.capturedVariableType(vble) -} \ No newline at end of file diff --git a/src/compiler/scala/reflect/makro/runtime/Context.scala b/src/compiler/scala/reflect/makro/runtime/Context.scala deleted file mode 100644 index 68964b7abb..0000000000 --- a/src/compiler/scala/reflect/makro/runtime/Context.scala +++ /dev/null @@ -1,32 +0,0 @@ -package scala.reflect.makro -package runtime - -import scala.tools.nsc.Global - -abstract class Context extends scala.reflect.makro.Context - with Aliases - with CapturedVariables - with Infrastructure - with Enclosures - with Names - with Reifiers - with FrontEnds - with Settings - with Typers - with Parsers - with Exprs - with TypeTags - with Evals - with ExprUtils - with Traces { - - val universe: Global - - val mirror: MirrorOf[universe.type] = universe.rootMirror - - val callsiteTyper: universe.analyzer.Typer - - val prefix: Expr[PrefixType] - - val expandee: Tree -} diff --git a/src/compiler/scala/reflect/makro/runtime/Enclosures.scala b/src/compiler/scala/reflect/makro/runtime/Enclosures.scala deleted file mode 100644 index 360a4b8e8a..0000000000 --- a/src/compiler/scala/reflect/makro/runtime/Enclosures.scala +++ /dev/null @@ -1,23 +0,0 @@ -package scala.reflect.makro -package runtime - -trait Enclosures { - self: Context => - - import universe._ - import mirror._ - - private def site = callsiteTyper.context - private def enclTrees = site.enclosingContextChain map (_.tree) - private def enclPoses = enclosingMacros map (_.macroApplication.pos) filterNot (_ eq NoPosition) - - // vals are eager to simplify debugging - // after all we wouldn't save that much time by making them lazy - val macroApplication: Tree = expandee - val enclosingClass: Tree = site.enclClass.tree - val enclosingImplicits: List[(Type, Tree)] = site.openImplicits - val enclosingMacros: List[Context] = this :: universe.analyzer.openMacros // include self - val enclosingMethod: Tree = site.enclMethod.tree - val enclosingPosition: Position = if (enclPoses.isEmpty) NoPosition else enclPoses.head.pos - val enclosingUnit: CompilationUnit = currentRun.currentUnit -} diff --git a/src/compiler/scala/reflect/makro/runtime/Evals.scala b/src/compiler/scala/reflect/makro/runtime/Evals.scala deleted file mode 100644 index 0574359a19..0000000000 --- a/src/compiler/scala/reflect/makro/runtime/Evals.scala +++ /dev/null @@ -1,18 +0,0 @@ -package scala.reflect.makro -package runtime - -import scala.reflect.runtime.{universe => ru} -import scala.tools.reflect.ToolBox - -trait Evals { - self: Context => - - private lazy val evalMirror = ru.runtimeMirror(libraryClassLoader) - private lazy val evalToolBox = evalMirror.mkToolBox() - private lazy val evalImporter = ru.mkImporter(universe).asInstanceOf[ru.Importer { val from: universe.type }] - - def eval[T](expr: Expr[T]): T = { - val imported = evalImporter.importTree(expr.tree) - evalToolBox.runExpr(imported).asInstanceOf[T] - } -} \ No newline at end of file diff --git a/src/compiler/scala/reflect/makro/runtime/ExprUtils.scala b/src/compiler/scala/reflect/makro/runtime/ExprUtils.scala deleted file mode 100644 index c89606289f..0000000000 --- a/src/compiler/scala/reflect/makro/runtime/ExprUtils.scala +++ /dev/null @@ -1,35 +0,0 @@ -package scala.reflect.makro -package runtime - -trait ExprUtils { - self: Context => - - import universe._ - import mirror._ - - def literalNull = Expr[Null](Literal(Constant(null)))(TypeTag.Null) - - def literalUnit = Expr[Unit](Literal(Constant(())))(TypeTag.Unit) - - def literalTrue = Expr[Boolean](Literal(Constant(true)))(TypeTag.Boolean) - - def literalFalse = Expr[Boolean](Literal(Constant(false)))(TypeTag.Boolean) - - def literal(x: Boolean) = Expr[Boolean](Literal(Constant(x)))(TypeTag.Boolean) - - def literal(x: Byte) = Expr[Byte](Literal(Constant(x)))(TypeTag.Byte) - - def literal(x: Short) = Expr[Short](Literal(Constant(x)))(TypeTag.Short) - - def literal(x: Int) = Expr[Int](Literal(Constant(x)))(TypeTag.Int) - - def literal(x: Long) = Expr[Long](Literal(Constant(x)))(TypeTag.Long) - - def literal(x: Float) = Expr[Float](Literal(Constant(x)))(TypeTag.Float) - - def literal(x: Double) = Expr[Double](Literal(Constant(x)))(TypeTag.Double) - - def literal(x: String) = Expr[String](Literal(Constant(x)))(TypeTag[String](definitions.StringClass.toTypeConstructor)) - - def literal(x: Char) = Expr[Char](Literal(Constant(x)))(TypeTag.Char) -} diff --git a/src/compiler/scala/reflect/makro/runtime/Exprs.scala b/src/compiler/scala/reflect/makro/runtime/Exprs.scala deleted file mode 100644 index b680b56bab..0000000000 --- a/src/compiler/scala/reflect/makro/runtime/Exprs.scala +++ /dev/null @@ -1,8 +0,0 @@ -package scala.reflect.makro -package runtime - -trait Exprs { - self: Context => - - def Expr[T: AbsTypeTag](tree: Tree): Expr[T] = universe.Expr[T](mirror, universe.FixedMirrorTreeCreator(mirror, tree)) -} diff --git a/src/compiler/scala/reflect/makro/runtime/FrontEnds.scala b/src/compiler/scala/reflect/makro/runtime/FrontEnds.scala deleted file mode 100644 index 6644c579ac..0000000000 --- a/src/compiler/scala/reflect/makro/runtime/FrontEnds.scala +++ /dev/null @@ -1,47 +0,0 @@ -package scala.reflect.makro -package runtime - -trait FrontEnds extends scala.tools.reflect.FrontEnds { - self: Context => - - import universe._ - import mirror._ - - override type Position = universe.Position - - def frontEnd: FrontEnd = wrapReporter(universe.reporter) - - def setFrontEnd(frontEnd: FrontEnd): this.type = { - universe.reporter = wrapFrontEnd(frontEnd) - this - } - - def withFrontEnd[T](frontEnd: FrontEnd)(op: => T): T = { - val old = universe.reporter - setFrontEnd(frontEnd) - try op - finally universe.reporter = old - } - - def echo(pos: Position, msg: String): Unit = universe.reporter.echo(pos, msg) - - def info(pos: Position, msg: String, force: Boolean): Unit = universe.reporter.info(pos, msg, force) - - def hasWarnings: Boolean = universe.reporter.hasErrors - - def hasErrors: Boolean = universe.reporter.hasErrors - - def warning(pos: Position, msg: String): Unit = callsiteTyper.context.warning(pos, msg) - - def error(pos: Position, msg: String): Unit = callsiteTyper.context.error(pos, msg) - - def abort(pos: Position, msg: String): Nothing = { - callsiteTyper.context.error(pos, msg) - throw new AbortMacroException(pos, msg) - } - - def interactive(): Unit = universe.reporter match { - case reporter: tools.nsc.reporters.AbstractReporter => reporter.displayPrompt() - case _ => () - } -} \ No newline at end of file diff --git a/src/compiler/scala/reflect/makro/runtime/Infrastructure.scala b/src/compiler/scala/reflect/makro/runtime/Infrastructure.scala deleted file mode 100644 index 76c4b21731..0000000000 --- a/src/compiler/scala/reflect/makro/runtime/Infrastructure.scala +++ /dev/null @@ -1,52 +0,0 @@ -package scala.reflect.makro -package runtime - -import scala.tools.nsc.util.ScalaClassLoader - -trait Infrastructure { - self: Context => - - val forJVM: Boolean = universe.forJVM - - val forMSIL: Boolean = universe.forMSIL - - val forInteractive: Boolean = universe.forInteractive - - val forScaladoc: Boolean = universe.forScaladoc - - val currentRun: Run = universe.currentRun - - val libraryClassPath: List[java.net.URL] = universe.classPath.asURLs - - lazy val libraryClassLoader: ClassLoader = { - val classpath = libraryClassPath - var loader: ClassLoader = ScalaClassLoader.fromURLs(classpath, self.getClass.getClassLoader) - - // [Eugene] a heuristic to detect REPL - if (universe.settings.exposeEmptyPackage.value) { - import scala.tools.nsc.interpreter._ - val virtualDirectory = universe.settings.outputDirs.getSingleOutput.get - loader = new AbstractFileClassLoader(virtualDirectory, loader) {} - } - - loader - } - - type Run = universe.Run - - object Run extends RunExtractor { - def unapply(run: Run): Option[(CompilationUnit, List[CompilationUnit])] = Some(run.currentUnit, run.units.toList) - } - - type CompilationUnit = universe.CompilationUnit - - object CompilationUnit extends CompilationUnitExtractor { - def unapply(compilationUnit: CompilationUnit): Option[(java.io.File, Array[Char], Tree)] = Some(compilationUnit.source.file.file, compilationUnit.source.content, compilationUnit.body) - } - - val currentMacro: Symbol = expandee.symbol - - val globalCache: collection.mutable.Map[Any, Any] = universe.analyzer.globalMacroCache - - val cache: collection.mutable.Map[Any, Any] = universe.analyzer.perRunMacroCache.getOrElseUpdate(currentMacro, collection.mutable.Map[Any, Any]()) -} \ No newline at end of file diff --git a/src/compiler/scala/reflect/makro/runtime/Names.scala b/src/compiler/scala/reflect/makro/runtime/Names.scala deleted file mode 100644 index 3f43b15d90..0000000000 --- a/src/compiler/scala/reflect/makro/runtime/Names.scala +++ /dev/null @@ -1,17 +0,0 @@ -package scala.reflect.makro -package runtime - -trait Names { - self: Context => - - lazy val freshNameCreator = callsiteTyper.context.unit.fresh - - def fresh(): String = - freshNameCreator.newName() - - def fresh(name: String): String = - freshNameCreator.newName(name) - - def fresh[NameType <: Name](name: NameType): NameType = - name.mapName(freshNameCreator.newName(_)).asInstanceOf[NameType] -} \ No newline at end of file diff --git a/src/compiler/scala/reflect/makro/runtime/Parsers.scala b/src/compiler/scala/reflect/makro/runtime/Parsers.scala deleted file mode 100644 index ac8d09f592..0000000000 --- a/src/compiler/scala/reflect/makro/runtime/Parsers.scala +++ /dev/null @@ -1,25 +0,0 @@ -package scala.reflect.makro -package runtime - -import language.existentials -import scala.tools.reflect.ToolBox -import scala.tools.reflect.ToolBoxError - -trait Parsers { - self: Context => - - def parse(code: String): Tree = - // todo. provide decent implementation - try { - import scala.reflect.runtime.{universe => ru} - val parsed = ru.rootMirror.mkToolBox().parseExpr(code) - val importer = universe.mkImporter(ru) - importer.importTree(parsed) - } catch { - case ToolBoxError(msg, cause) => - throw new ParseError(universe.NoPosition, msg) - } - - case class ParseError(val pos: Position, val msg: String) extends Throwable(msg) - object ParseError extends ParseErrorExtractor -} \ No newline at end of file diff --git a/src/compiler/scala/reflect/makro/runtime/Reifiers.scala b/src/compiler/scala/reflect/makro/runtime/Reifiers.scala deleted file mode 100644 index 10b5ae5f42..0000000000 --- a/src/compiler/scala/reflect/makro/runtime/Reifiers.scala +++ /dev/null @@ -1,79 +0,0 @@ -/* NSC -- new Scala compiler - * Copyright 2005-2011 LAMP/EPFL - * @author Gilles Dubochet - */ - -package scala.reflect.makro -package runtime - -trait Reifiers { - self: Context => - - val global: universe.type = universe - import universe._ - import definitions._ - - lazy val basisUniverse: Tree = gen.mkBasisUniverseRef - - lazy val runtimeUniverse: Tree = gen.mkRuntimeUniverseRef - - def reifyTree(universe: Tree, mirror: Tree, tree: Tree): Tree = { - val result = scala.reflect.reify.`package`.reifyTree(self.universe)(callsiteTyper, universe, mirror, tree) - logFreeVars(enclosingPosition, result) - result - } - - def reifyType(universe: Tree, mirror: Tree, tpe: Type, concrete: Boolean = false): Tree = { - val result = scala.reflect.reify.`package`.reifyType(self.universe)(callsiteTyper, universe, mirror, tpe, concrete) - logFreeVars(enclosingPosition, result) - result - } - - def reifyRuntimeClass(tpe: Type, concrete: Boolean = true): Tree = - scala.reflect.reify.`package`.reifyRuntimeClass(universe)(callsiteTyper, tpe, concrete = concrete) - - def reifyEnclosingRuntimeClass: Tree = - scala.reflect.reify.`package`.reifyEnclosingRuntimeClass(universe)(callsiteTyper) - - def unreifyTree(tree: Tree): Tree = { - assert(ExprSplice != NoSymbol) - Select(tree, ExprSplice) - } - - // fixme: if I put utils here, then "global" from utils' early initialization syntax - // and "global" that comes from here conflict with each other when incrementally compiling - // the problem is that both are pickled with the same owner - trait Reifiers - // and this upsets the compiler, so that oftentimes it throws assertion failures - // Martin knows the details - // - // object utils extends { - // val global: self.global.type = self.global - // val typer: global.analyzer.Typer = self.callsiteTyper - // } with scala.reflect.reify.utils.Utils - // import utils._ - - private def logFreeVars(position: Position, reification: Tree): Unit = { - object utils extends { - val global: self.global.type = self.global - val typer: global.analyzer.Typer = self.callsiteTyper - } with scala.reflect.reify.utils.Utils - import utils._ - - def logFreeVars(symtab: SymbolTable): Unit = - // logging free vars only when they are untyped prevents avalanches of duplicate messages - symtab.syms map (sym => symtab.symDef(sym)) foreach { - case FreeTermDef(_, _, binding, _, origin) if universe.settings.logFreeTerms.value && binding.tpe == null => - reporter.echo(position, "free term: %s %s".format(showRaw(binding), origin)) - case FreeTypeDef(_, _, binding, _, origin) if universe.settings.logFreeTypes.value && binding.tpe == null => - reporter.echo(position, "free type: %s %s".format(showRaw(binding), origin)) - case _ => - // do nothing - } - - if (universe.settings.logFreeTerms.value || universe.settings.logFreeTypes.value) - reification match { - case ReifiedTree(_, _, symtab, _, _, _, _) => logFreeVars(symtab) - case ReifiedType(_, _, symtab, _, _, _) => logFreeVars(symtab) - } - } -} diff --git a/src/compiler/scala/reflect/makro/runtime/Settings.scala b/src/compiler/scala/reflect/makro/runtime/Settings.scala deleted file mode 100644 index 8288180b8d..0000000000 --- a/src/compiler/scala/reflect/makro/runtime/Settings.scala +++ /dev/null @@ -1,36 +0,0 @@ -package scala.reflect.makro -package runtime - -trait Settings { - self: Context => - - def settings: List[String] = { - val optionName = universe.settings.XmacroSettings.name - val settings = compilerSettings.find(opt => opt.startsWith(optionName)).map(opt => opt.substring(optionName.length + 1)).getOrElse("") - settings.split(",").toList - } - - def compilerSettings: List[String] = universe.settings.recreateArgs - - def setCompilerSettings(options: String): this.type = - // todo. is not going to work with quoted arguments with embedded whitespaces - setCompilerSettings(options.split(" ").toList) - - def setCompilerSettings(options: List[String]): this.type = { - val settings = new tools.nsc.Settings(_ => ()) - // [Eugene] what settings should we exclude? - settings.copyInto(universe.settings) - this - } - - def withCompilerSettings[T](options: String)(op: => T): T = - // todo. is not going to work with quoted arguments with embedded whitespaces - withCompilerSettings(options.split(" ").toList)(op) - - def withCompilerSettings[T](options: List[String])(op: => T): T = { - val old = options - setCompilerSettings(options) - try op - finally setCompilerSettings(old) - } -} \ No newline at end of file diff --git a/src/compiler/scala/reflect/makro/runtime/Traces.scala b/src/compiler/scala/reflect/makro/runtime/Traces.scala deleted file mode 100644 index 225ee1f62b..0000000000 --- a/src/compiler/scala/reflect/makro/runtime/Traces.scala +++ /dev/null @@ -1,8 +0,0 @@ -package scala.reflect.makro -package runtime - -trait Traces extends util.Traces { - self: Context => - - def globalSettings = universe.settings -} diff --git a/src/compiler/scala/reflect/makro/runtime/TypeTags.scala b/src/compiler/scala/reflect/makro/runtime/TypeTags.scala deleted file mode 100644 index 4f9b287674..0000000000 --- a/src/compiler/scala/reflect/makro/runtime/TypeTags.scala +++ /dev/null @@ -1,9 +0,0 @@ -package scala.reflect.makro -package runtime - -trait TypeTags { - self: Context => - - def AbsTypeTag[T](tpe: Type): AbsTypeTag[T] = universe.AbsTypeTag[T](mirror, universe.FixedMirrorTypeCreator(mirror, tpe)) - def TypeTag[T](tpe: Type): TypeTag[T] = universe.TypeTag[T](mirror, universe.FixedMirrorTypeCreator(mirror, tpe)) -} diff --git a/src/compiler/scala/reflect/makro/runtime/Typers.scala b/src/compiler/scala/reflect/makro/runtime/Typers.scala deleted file mode 100644 index 7e92c1e9ca..0000000000 --- a/src/compiler/scala/reflect/makro/runtime/Typers.scala +++ /dev/null @@ -1,68 +0,0 @@ -package scala.reflect.makro -package runtime - -trait Typers { - self: Context => - - def openMacros: List[Context] = this :: universe.analyzer.openMacros - - def openImplicits: List[(Type, Tree)] = callsiteTyper.context.openImplicits - - def typeCheck(tree: Tree, pt: Type = universe.WildcardType, silent: Boolean = false, withImplicitViewsDisabled: Boolean = false, withMacrosDisabled: Boolean = false): Tree = { - macroLogVerbose("typechecking %s with expected type %s, implicit views = %s, macros = %s".format(tree, pt, !withImplicitViewsDisabled, !withMacrosDisabled)) - val context = callsiteTyper.context - val wrapper1 = if (!withImplicitViewsDisabled) (context.withImplicitsEnabled[Tree] _) else (context.withImplicitsDisabled[Tree] _) - val wrapper2 = if (!withMacrosDisabled) (context.withMacrosEnabled[Tree] _) else (context.withMacrosDisabled[Tree] _) - def wrapper (tree: => Tree) = wrapper1(wrapper2(tree)) - // if you get a "silent mode is not available past typer" here - // don't rush to change the typecheck not to use the silent method when the silent parameter is false - // typechecking uses silent anyways (e.g. in typedSelect), so you'll only waste your time - // I'd advise fixing the root cause: finding why the context is not set to report errors - // (also see reflect.runtime.ToolBoxes.typeCheckExpr for a workaround that might work for you) - wrapper(callsiteTyper.silent(_.typed(tree, universe.analyzer.EXPRmode, pt)) match { - case universe.analyzer.SilentResultValue(result) => - macroLogVerbose(result) - result - case error @ universe.analyzer.SilentTypeError(_) => - macroLogVerbose(error.err.errMsg) - if (!silent) throw new universe.TypeError(error.err.errPos, error.err.errMsg) - universe.EmptyTree - }) - } - - def inferImplicitValue(pt: Type, silent: Boolean = true, withMacrosDisabled: Boolean = false, pos: Position = enclosingPosition): Tree = { - macroLogVerbose("inferring implicit value of type %s, macros = %s".format(pt, !withMacrosDisabled)) - inferImplicit(universe.EmptyTree, pt, isView = false, silent = silent, withMacrosDisabled = withMacrosDisabled, pos = pos) - } - - def inferImplicitView(tree: Tree, from: Type, to: Type, silent: Boolean = true, withMacrosDisabled: Boolean = false, pos: Position = enclosingPosition): Tree = { - macroLogVerbose("inferring implicit view from %s to %s for %s, macros = %s".format(from, to, tree, !withMacrosDisabled)) - val viewTpe = universe.appliedType(universe.definitions.FunctionClass(1).toTypeConstructor, List(from, to)) - inferImplicit(tree, viewTpe, isView = true, silent = silent, withMacrosDisabled = withMacrosDisabled, pos = pos) - } - - private def inferImplicit(tree: Tree, pt: Type, isView: Boolean, silent: Boolean, withMacrosDisabled: Boolean, pos: Position): Tree = { - import universe.analyzer.SearchResult - val context = callsiteTyper.context - val wrapper1 = if (!withMacrosDisabled) (context.withMacrosEnabled[SearchResult] _) else (context.withMacrosDisabled[SearchResult] _) - def wrapper (inference: => SearchResult) = wrapper1(inference) - wrapper(universe.analyzer.inferImplicit(tree, pt, reportAmbiguous = true, isView = isView, context = context, saveAmbiguousDivergent = !silent, pos = pos)) match { - case failure if failure.tree.isEmpty => - macroLogVerbose("implicit search has failed. to find out the reason, turn on -Xlog-implicits") - if (context.hasErrors) throw new universe.TypeError(context.errBuffer.head.errPos, context.errBuffer.head.errMsg) - universe.EmptyTree - case success => - success.tree - } - } - - type TypeError = universe.TypeError - - object TypeError extends TypeErrorExtractor { - def unapply(error: TypeError): Option[(Position, String)] = Some((error.pos, error.msg)) - } - - def resetAllAttrs(tree: Tree): Tree = universe.resetAllAttrs(tree) - - def resetLocalAttrs(tree: Tree): Tree = universe.resetLocalAttrs(tree) -} \ No newline at end of file diff --git a/src/compiler/scala/reflect/makro/util/Traces.scala b/src/compiler/scala/reflect/makro/util/Traces.scala deleted file mode 100644 index 2363cc4bac..0000000000 --- a/src/compiler/scala/reflect/makro/util/Traces.scala +++ /dev/null @@ -1,18 +0,0 @@ -package scala.reflect.makro -package util - -trait Traces { - def globalSettings: tools.nsc.Settings - - // [Eugene] lots of ways to log: - // 1) trace(...) - // 2) log(...) - // 3) if (foo) { doStuff(); includingSomeLogs(); } - // what is the conventional way of unifying this? - val macroDebugLite = globalSettings.YmacrodebugLite.value - val macroDebugVerbose = globalSettings.YmacrodebugVerbose.value - val macroTraceLite = scala.tools.nsc.util.trace when (macroDebugLite || macroDebugVerbose) - val macroTraceVerbose = scala.tools.nsc.util.trace when macroDebugVerbose - @inline final def macroLogLite(msg: => Any) { if (macroDebugLite || macroDebugVerbose) println(msg) } - @inline final def macroLogVerbose(msg: => Any) { if (macroDebugVerbose) println(msg) } -} \ No newline at end of file diff --git a/src/compiler/scala/reflect/reify/Errors.scala b/src/compiler/scala/reflect/reify/Errors.scala index 1b72b3075b..5e15c5ad3a 100644 --- a/src/compiler/scala/reflect/reify/Errors.scala +++ b/src/compiler/scala/reflect/reify/Errors.scala @@ -1,7 +1,7 @@ package scala.reflect.reify -import scala.reflect.makro.ReificationError -import scala.reflect.makro.UnexpectedReificationError +import scala.reflect.macros.ReificationError +import scala.reflect.macros.UnexpectedReificationError trait Errors { self: Reifier => diff --git a/src/compiler/scala/reflect/reify/Reifier.scala b/src/compiler/scala/reflect/reify/Reifier.scala index 8fba7274be..5503ff2977 100644 --- a/src/compiler/scala/reflect/reify/Reifier.scala +++ b/src/compiler/scala/reflect/reify/Reifier.scala @@ -1,8 +1,8 @@ package scala.reflect.reify import scala.tools.nsc.Global -import scala.reflect.makro.ReificationError -import scala.reflect.makro.UnexpectedReificationError +import scala.reflect.macros.ReificationError +import scala.reflect.macros.UnexpectedReificationError import scala.reflect.reify.utils.Utils /** Given a tree or a type, generate a tree that when executed at runtime produces the original tree or type. diff --git a/src/compiler/scala/reflect/reify/Taggers.scala b/src/compiler/scala/reflect/reify/Taggers.scala index 4e30d0acf8..a8523fe686 100644 --- a/src/compiler/scala/reflect/reify/Taggers.scala +++ b/src/compiler/scala/reflect/reify/Taggers.scala @@ -1,7 +1,7 @@ package scala.reflect.reify -import scala.reflect.makro.{ReificationError, UnexpectedReificationError} -import scala.reflect.makro.runtime.Context +import scala.reflect.macros.{ReificationError, UnexpectedReificationError} +import scala.reflect.macros.runtime.Context abstract class Taggers { val c: Context diff --git a/src/compiler/scala/reflect/reify/package.scala b/src/compiler/scala/reflect/reify/package.scala index bd17b2d5df..a253effc1c 100644 --- a/src/compiler/scala/reflect/reify/package.scala +++ b/src/compiler/scala/reflect/reify/package.scala @@ -2,7 +2,7 @@ package scala.reflect import language.implicitConversions import scala.reflect.base.{Universe => BaseUniverse} -import scala.reflect.makro.{Context, ReificationError, UnexpectedReificationError} +import scala.reflect.macros.{Context, ReificationError, UnexpectedReificationError} import scala.tools.nsc.Global package object reify { diff --git a/src/compiler/scala/tools/nsc/typechecker/Implicits.scala b/src/compiler/scala/tools/nsc/typechecker/Implicits.scala index 529f5408a2..b442d16b1c 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Implicits.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Implicits.scala @@ -1196,7 +1196,7 @@ trait Implicits { gen.mkAttributedThis(thisSym) case _ => // if ``pre'' is not a PDT, e.g. if someone wrote - // implicitly[scala.reflect.makro.Context#TypeTag[Int]] + // implicitly[scala.reflect.macros.Context#TypeTag[Int]] // then we need to fail, because we don't know the prefix to use during type reification // upd. we also need to fail silently, because this is a very common situation // e.g. quite often we're searching for BaseUniverse#TypeTag, e.g. for a type tag in any universe diff --git a/src/compiler/scala/tools/nsc/typechecker/Macros.scala b/src/compiler/scala/tools/nsc/typechecker/Macros.scala index 71176d6247..1381450970 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Macros.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Macros.scala @@ -8,7 +8,7 @@ import scala.reflect.runtime.ReflectionUtils import scala.collection.mutable.ListBuffer import scala.compat.Platform.EOL import reflect.internal.util.Statistics -import scala.reflect.makro.util._ +import scala.reflect.macros.util._ import java.lang.{Class => jClass} import java.lang.reflect.{Array => jArray, Method => jMethod} @@ -24,7 +24,7 @@ import java.lang.reflect.{Array => jArray, Method => jMethod} * Then fooBar needs to point to a static method of the following form: * * def fooBar[T: c.TypeTag] - * (c: scala.reflect.makro.Context) + * (c: scala.reflect.macros.Context) * (xs: c.Expr[List[T]]) * : c.Expr[T] = { * ... @@ -51,7 +51,7 @@ trait Macros extends scala.tools.reflect.FastTrack with Traces { /** A list of compatible macro implementation signatures. * * In the example above: - * (c: scala.reflect.makro.Context)(xs: c.Expr[List[T]]): c.Expr[T] + * (c: scala.reflect.macros.Context)(xs: c.Expr[List[T]]): c.Expr[T] * * @param macroDef The macro definition symbol * @param tparams The type parameters of the macro definition @@ -879,7 +879,7 @@ trait Macros extends scala.tools.reflect.FastTrack with Traces { } /** Keeps track of macros in-flight. - * See more informations in comments to ``openMacros'' in ``scala.reflect.makro.Context''. + * See more informations in comments to ``openMacros'' in ``scala.reflect.macros.Context''. */ var openMacros = List[MacroContext]() def enclosingMacroPosition = openMacros map (_.macroApplication.pos) find (_ ne NoPosition) getOrElse NoPosition @@ -1155,7 +1155,7 @@ trait Macros extends scala.tools.reflect.FastTrack with Traces { // [Eugene] any ideas about how to improve this one? val realex = ReflectionUtils.unwrapThrowable(ex) realex match { - case realex: reflect.makro.runtime.AbortMacroException => + case realex: reflect.macros.runtime.AbortMacroException => macroLogVerbose("macro expansion has failed: %s".format(realex.msg)) fail(typer, expandee) // error has been reported by abort case err: TypeError => diff --git a/src/compiler/scala/tools/nsc/typechecker/StdAttachments.scala b/src/compiler/scala/tools/nsc/typechecker/StdAttachments.scala index 190b18711c..64c5b41638 100644 --- a/src/compiler/scala/tools/nsc/typechecker/StdAttachments.scala +++ b/src/compiler/scala/tools/nsc/typechecker/StdAttachments.scala @@ -4,7 +4,7 @@ package typechecker trait StdAttachments { self: Analyzer => - type UnaffiliatedMacroContext = scala.reflect.makro.runtime.Context + type UnaffiliatedMacroContext = scala.reflect.macros.runtime.Context type MacroContext = UnaffiliatedMacroContext { val universe: self.global.type } case class MacroRuntimeAttachment(delayed: Boolean, typerContext: Context, macroContext: Option[MacroContext]) } \ No newline at end of file diff --git a/src/compiler/scala/tools/reflect/MacroImplementations.scala b/src/compiler/scala/tools/reflect/MacroImplementations.scala index e1b959cefa..40ceefcc70 100644 --- a/src/compiler/scala/tools/reflect/MacroImplementations.scala +++ b/src/compiler/scala/tools/reflect/MacroImplementations.scala @@ -1,7 +1,7 @@ package scala.tools.reflect -import scala.reflect.makro.{ReificationError, UnexpectedReificationError} -import scala.reflect.makro.runtime.Context +import scala.reflect.macros.{ReificationError, UnexpectedReificationError} +import scala.reflect.macros.runtime.Context import scala.collection.mutable.ListBuffer import scala.collection.mutable.Stack @@ -25,9 +25,9 @@ abstract class MacroImplementations { c.abort(args(parts.length-1).pos, "too many arguments for interpolated string") } - val stringParts = parts map { + val stringParts = parts map { case Literal(Constant(s: String)) => s; - case _ => throw new IllegalArgumentException("argument parts must be a list of string literals") + case _ => throw new IllegalArgumentException("argument parts must be a list of string literals") } val pi = stringParts.iterator diff --git a/src/compiler/scala/tools/reflect/StdTags.scala b/src/compiler/scala/tools/reflect/StdTags.scala index 30bded4f86..0704189ddc 100644 --- a/src/compiler/scala/tools/reflect/StdTags.scala +++ b/src/compiler/scala/tools/reflect/StdTags.scala @@ -52,7 +52,7 @@ object StdRuntimeTags extends StdTags { } abstract class StdContextTags extends StdTags { - val tc: scala.reflect.makro.Context + val tc: scala.reflect.macros.Context val u: tc.universe.type = tc.universe val m = tc.mirror } diff --git a/src/compiler/scala/tools/util/PathResolver.scala b/src/compiler/scala/tools/util/PathResolver.scala index 5f4e6d58c3..d89ebcb2a3 100644 --- a/src/compiler/scala/tools/util/PathResolver.scala +++ b/src/compiler/scala/tools/util/PathResolver.scala @@ -194,7 +194,7 @@ class PathResolver(settings: Settings, context: JavaContext) { def scalaBootClassPath = cmdLineOrElse("bootclasspath", Defaults.scalaBootClassPath) def scalaExtDirs = cmdLineOrElse("extdirs", Defaults.scalaExtDirs) /** Scaladoc doesn't need any bootstrapping, otherwise will create errors such as: - * [scaladoc] ../scala-trunk/src/reflect/scala/reflect/makro/Reifiers.scala:89: error: object api is not a member of package reflect + * [scaladoc] ../scala-trunk/src/reflect/scala/reflect/macros/Reifiers.scala:89: error: object api is not a member of package reflect * [scaladoc] case class ReificationError(val pos: reflect.api.PositionApi, val msg: String) extends Throwable(msg) * [scaladoc] ^ * because the bootstrapping will look at the sourcepath and create package "reflect" in "" diff --git a/src/library/scala/reflect/macros/internal/macroImpl.scala b/src/library/scala/reflect/macros/internal/macroImpl.scala new file mode 100644 index 0000000000..a7b2bf482c --- /dev/null +++ b/src/library/scala/reflect/macros/internal/macroImpl.scala @@ -0,0 +1,18 @@ +package scala.reflect.macros +package internal + +/** Links macro definitions with their implementation. + * This is necessary to preserve macro def -> macro impl links between compilation runs. + * + * More precisely, after typechecking right-hand side of a macro def + * `typedMacroBody` slaps `macroImpl` annotation onto the macro def + * with the result of typechecking as a sole parameter. + * + * As an unfortunate consequence, this annotation must be defined in scala-library.jar, + * because anyone (even those programmers who compile their programs with only scala-library on classpath) + * must be able to define macros. + * + * To lessen the weirdness we define this annotation as `private[scala]`. + * It will not prevent pickling, but it will prevent application developers (and scaladocs) from seeing the annotation. + */ +private[scala] class macroImpl(val referenceToMacroImpl: Any) extends annotation.StaticAnnotation diff --git a/src/library/scala/reflect/macros/internal/package.scala b/src/library/scala/reflect/macros/internal/package.scala new file mode 100644 index 0000000000..912db53ed4 --- /dev/null +++ b/src/library/scala/reflect/macros/internal/package.scala @@ -0,0 +1,15 @@ +package scala.reflect.macros + +import scala.reflect.base.{Universe => BaseUniverse} +import scala.reflect.ClassTag + +// anchors for materialization macros emitted during tag materialization in Implicits.scala +// implementation is magically hardwired into `scala.reflect.reify.Taggers` +// +// todo. once we have implicit macros for tag generation, we can remove these anchors +// [Eugene++] how do I hide this from scaladoc? +package object internal { + private[scala] def materializeClassTag[T](u: BaseUniverse): ClassTag[T] = ??? // macro + private[scala] def materializeAbsTypeTag[T](u: BaseUniverse): u.AbsTypeTag[T] = ??? // macro + private[scala] def materializeTypeTag[T](u: BaseUniverse): u.TypeTag[T] = ??? // macro +} diff --git a/src/library/scala/reflect/makro/internal/macroImpl.scala b/src/library/scala/reflect/makro/internal/macroImpl.scala deleted file mode 100644 index 0dfa8d1654..0000000000 --- a/src/library/scala/reflect/makro/internal/macroImpl.scala +++ /dev/null @@ -1,18 +0,0 @@ -package scala.reflect.makro -package internal - -/** Links macro definitions with their implementation. - * This is necessary to preserve macro def -> macro impl links between compilation runs. - * - * More precisely, after typechecking right-hand side of a macro def - * `typedMacroBody` slaps `macroImpl` annotation onto the macro def - * with the result of typechecking as a sole parameter. - * - * As an unfortunate consequence, this annotation must be defined in scala-library.jar, - * because anyone (even those programmers who compile their programs with only scala-library on classpath) - * must be able to define macros. - * - * To lessen the weirdness we define this annotation as `private[scala]`. - * It will not prevent pickling, but it will prevent application developers (and scaladocs) from seeing the annotation. - */ -private[scala] class macroImpl(val referenceToMacroImpl: Any) extends annotation.StaticAnnotation diff --git a/src/library/scala/reflect/makro/internal/package.scala b/src/library/scala/reflect/makro/internal/package.scala index f08448297c..b8097d84e3 100644 --- a/src/library/scala/reflect/makro/internal/package.scala +++ b/src/library/scala/reflect/makro/internal/package.scala @@ -3,12 +3,8 @@ package makro import scala.reflect.base.{Universe => BaseUniverse} -// anchors for materialization macros emitted during tag materialization in Implicits.scala -// implementation is magically hardwired into `scala.reflect.reify.Taggers` -// -// todo. once we have implicit macros for tag generation, we can remove these anchors -// [Eugene++] how do I hide this from scaladoc? package object internal { + private[scala] type macroImpl = scala.reflect.macros.internal.macroImpl private[scala] def materializeClassTag[T](u: BaseUniverse): ClassTag[T] = ??? // macro private[scala] def materializeAbsTypeTag[T](u: BaseUniverse): u.AbsTypeTag[T] = ??? // macro private[scala] def materializeTypeTag[T](u: BaseUniverse): u.TypeTag[T] = ??? // macro diff --git a/src/reflect/scala/reflect/internal/Definitions.scala b/src/reflect/scala/reflect/internal/Definitions.scala index 7248fac5fb..0fd86cdb3a 100644 --- a/src/reflect/scala/reflect/internal/Definitions.scala +++ b/src/reflect/scala/reflect/internal/Definitions.scala @@ -495,13 +495,13 @@ trait Definitions extends api.StandardDefinitions { lazy val TypeCreatorClass = requiredClass[scala.reflect.base.TypeCreator] lazy val TreeCreatorClass = requiredClass[scala.reflect.base.TreeCreator] - lazy val MacroContextClass = getClassIfDefined("scala.reflect.makro.Context") // defined in scala-reflect.jar, so we need to be careful + lazy val MacroContextClass = getClassIfDefined("scala.reflect.macros.Context") // defined in scala-reflect.jar, so we need to be careful def MacroContextPrefix = if (MacroContextClass != NoSymbol) getMemberMethod(MacroContextClass, nme.prefix) else NoSymbol def MacroContextPrefixType = if (MacroContextClass != NoSymbol) getMemberType(MacroContextClass, tpnme.PrefixType) else NoSymbol def MacroContextUniverse = if (MacroContextClass != NoSymbol) getMemberMethod(MacroContextClass, nme.universe) else NoSymbol def MacroContextMirror = if (MacroContextClass != NoSymbol) getMemberMethod(MacroContextClass, nme.mirror) else NoSymbol - lazy val MacroImplAnnotation = requiredClass[scala.reflect.makro.internal.macroImpl] - lazy val MacroInternalPackage = getPackageObject("scala.reflect.makro.internal") + lazy val MacroImplAnnotation = requiredClass[scala.reflect.macros.internal.macroImpl] + lazy val MacroInternalPackage = getPackageObject("scala.reflect.macros.internal") def MacroInternal_materializeClassTag = getMemberMethod(MacroInternalPackage, nme.materializeClassTag) def MacroInternal_materializeAbsTypeTag = getMemberMethod(MacroInternalPackage, nme.materializeAbsTypeTag) def MacroInternal_materializeTypeTag = getMemberMethod(MacroInternalPackage, nme.materializeTypeTag) diff --git a/src/reflect/scala/reflect/internal/SymbolTable.scala b/src/reflect/scala/reflect/internal/SymbolTable.scala index 5ae8f22c64..dfb434300d 100644 --- a/src/reflect/scala/reflect/internal/SymbolTable.scala +++ b/src/reflect/scala/reflect/internal/SymbolTable.scala @@ -9,7 +9,7 @@ package internal import scala.collection.{ mutable, immutable } import util._ -abstract class SymbolTable extends makro.Universe +abstract class SymbolTable extends macros.Universe with Collections with Names with Symbols diff --git a/src/reflect/scala/reflect/internal/TreeGen.scala b/src/reflect/scala/reflect/internal/TreeGen.scala index 285700f9ff..d160695e67 100644 --- a/src/reflect/scala/reflect/internal/TreeGen.scala +++ b/src/reflect/scala/reflect/internal/TreeGen.scala @@ -1,7 +1,7 @@ package scala.reflect package internal -abstract class TreeGen extends makro.TreeBuilder { +abstract class TreeGen extends macros.TreeBuilder { val global: SymbolTable import global._ diff --git a/src/reflect/scala/reflect/macros/Aliases.scala b/src/reflect/scala/reflect/macros/Aliases.scala new file mode 100644 index 0000000000..46b7066902 --- /dev/null +++ b/src/reflect/scala/reflect/macros/Aliases.scala @@ -0,0 +1,26 @@ +package scala.reflect +package macros + +trait Aliases { + self: Context => + + type Symbol = universe.Symbol + type Type = universe.Type + type Name = universe.Name + type TermName = universe.TermName + type TypeName = universe.TypeName + type Tree = universe.Tree + // type Position = universe.Position + type Scope = universe.Scope + type Modifiers = universe.Modifiers + + type Expr[+T] = universe.Expr[T] + val Expr = universe.Expr + + type AbsTypeTag[T] = universe.AbsTypeTag[T] + type TypeTag[T] = universe.TypeTag[T] + val AbsTypeTag = universe.AbsTypeTag + val TypeTag = universe.TypeTag + def typeTag[T](implicit ttag: TypeTag[T]) = ttag + def typeOf[T](implicit ttag: TypeTag[T]): Type = ttag.tpe +} diff --git a/src/reflect/scala/reflect/macros/CapturedVariables.scala b/src/reflect/scala/reflect/macros/CapturedVariables.scala new file mode 100644 index 0000000000..60ed6f5e7b --- /dev/null +++ b/src/reflect/scala/reflect/macros/CapturedVariables.scala @@ -0,0 +1,21 @@ +package scala.reflect +package macros + +trait CapturedVariables { + self: Context => + + import mirror._ + + /** Mark a variable as captured; i.e. force boxing in a *Ref type. + */ + def captureVariable(vble: Symbol): Unit + + /** Mark given identifier as a reference to a captured variable itself + * suppressing dereferencing with the `elem` field. + */ + def referenceCapturedVariable(vble: Symbol): Tree + + /** Convert type of a captured variable to *Ref type. + */ + def capturedVariableType(vble: Symbol): Type +} \ No newline at end of file diff --git a/src/reflect/scala/reflect/macros/Context.scala b/src/reflect/scala/reflect/macros/Context.scala new file mode 100644 index 0000000000..37c8f9057e --- /dev/null +++ b/src/reflect/scala/reflect/macros/Context.scala @@ -0,0 +1,34 @@ +package scala.reflect +package macros + +// todo. introduce context hierarchy +// the most lightweight context should just expose the stuff from the SIP +// the full context should include all traits from scala.reflect.macros (and probably reside in scala-compiler.jar) + +trait Context extends Aliases + with CapturedVariables + with Enclosures + with Infrastructure + with Names + with Reifiers + with FrontEnds + with Settings + with Typers + with Parsers + with Exprs + with TypeTags + with Evals + with ExprUtils { + + /** The compile-time universe */ + val universe: Universe + + /** The mirror of the compile-time universe */ + val mirror: MirrorOf[universe.type] + + /** The type of the prefix tree from which the macro is selected */ + type PrefixType + + /** The prefix tree from which the macro is selected */ + val prefix: Expr[PrefixType] +} diff --git a/src/reflect/scala/reflect/macros/Enclosures.scala b/src/reflect/scala/reflect/macros/Enclosures.scala new file mode 100644 index 0000000000..a07ff85a08 --- /dev/null +++ b/src/reflect/scala/reflect/macros/Enclosures.scala @@ -0,0 +1,50 @@ +package scala.reflect +package macros + +trait Enclosures { + self: Context => + + /** The tree that undergoes macro expansion. + * Can be useful to get an offset or a range position of the entire tree being processed. + */ + val macroApplication: Tree + + /** Contexts that represent macros in-flight, including the current one. Very much like a stack trace, but for macros only. + * Can be useful for interoperating with other macros and for imposing compiler-friendly limits on macro expansion. + * + * Is also priceless for emitting sane error messages for macros that are called by other macros on synthetic (i.e. position-less) trees. + * In that dire case navigate the ``enclosingMacros'' stack, and it will most likely contain at least one macro with a position-ful macro application. + * See ``enclosingPosition'' for a default implementation of this logic. + * + * Unlike `openMacros`, this is a val, which means that it gets initialized when the context is created + * and always stays the same regardless of whatever happens during macro expansion. + */ + val enclosingMacros: List[Context] + + /** Types along with corresponding trees for which implicit arguments are currently searched. + * Can be useful to get information about an application with an implicit parameter that is materialized during current macro expansion. + * + * Unlike `openImplicits`, this is a val, which means that it gets initialized when the context is created + * and always stays the same regardless of whatever happens during macro expansion. + */ + val enclosingImplicits: List[(Type, Tree)] + + /** Tries to guess a position for the enclosing application. + * But that is simple, right? Just dereference ``pos'' of ``macroApplication''? Not really. + * If we're in a synthetic macro expansion (no positions), we must do our best to infer the position of something that triggerd this expansion. + * Surprisingly, quite often we can do this by navigation the ``enclosingMacros'' stack. + */ + val enclosingPosition: Position + + /** Tree that corresponds to the enclosing method, or EmptyTree if not applicable. + */ + val enclosingMethod: Tree + + /** Tree that corresponds to the enclosing class, or EmptyTree if not applicable. + */ + val enclosingClass: Tree + + /** Compilation unit that contains this macro application. + */ + val enclosingUnit: CompilationUnit +} \ No newline at end of file diff --git a/src/reflect/scala/reflect/macros/Evals.scala b/src/reflect/scala/reflect/macros/Evals.scala new file mode 100644 index 0000000000..3837d749da --- /dev/null +++ b/src/reflect/scala/reflect/macros/Evals.scala @@ -0,0 +1,9 @@ +package scala.reflect +package macros + +trait Evals { + self: Context => + + /** .. */ + def eval[T](expr: Expr[T]): T +} \ No newline at end of file diff --git a/src/reflect/scala/reflect/macros/ExprUtils.scala b/src/reflect/scala/reflect/macros/ExprUtils.scala new file mode 100644 index 0000000000..adcdc78c78 --- /dev/null +++ b/src/reflect/scala/reflect/macros/ExprUtils.scala @@ -0,0 +1,32 @@ +package scala.reflect +package macros + +trait ExprUtils { + self: Context => + + def literalNull: Expr[Null] + + def literalUnit: Expr[Unit] + + def literalTrue: Expr[Boolean] + + def literalFalse: Expr[Boolean] + + def literal(x: Boolean): Expr[Boolean] + + def literal(x: Byte): Expr[Byte] + + def literal(x: Short): Expr[Short] + + def literal(x: Int): Expr[Int] + + def literal(x: Long): Expr[Long] + + def literal(x: Float): Expr[Float] + + def literal(x: Double): Expr[Double] + + def literal(x: String): Expr[String] + + def literal(x: Char): Expr[Char] +} diff --git a/src/reflect/scala/reflect/macros/Exprs.scala b/src/reflect/scala/reflect/macros/Exprs.scala new file mode 100644 index 0000000000..ceaab06d12 --- /dev/null +++ b/src/reflect/scala/reflect/macros/Exprs.scala @@ -0,0 +1,8 @@ +package scala.reflect +package macros + +trait Exprs { + self: Context => + + def Expr[T: AbsTypeTag](tree: Tree): Expr[T] +} diff --git a/src/reflect/scala/reflect/macros/FrontEnds.scala b/src/reflect/scala/reflect/macros/FrontEnds.scala new file mode 100644 index 0000000000..d15db0725f --- /dev/null +++ b/src/reflect/scala/reflect/macros/FrontEnds.scala @@ -0,0 +1,42 @@ +package scala.reflect +package macros + +trait FrontEnds extends scala.reflect.api.FrontEnds { + self: Context => + + import mirror._ + + type Position = universe.Position + + /** Exposes means to control the compiler UI */ + def frontEnd: FrontEnd + def setFrontEnd(frontEnd: FrontEnd): this.type + def withFrontEnd[T](frontEnd: FrontEnd)(op: => T): T + + /** For sending a message which should not be labeled as a warning/error, + * but also shouldn't require -verbose to be visible. + * Use ``enclosingPosition'' if you're in doubt what position to pass to ``pos''. + */ + def echo(pos: Position, msg: String): Unit + + /** Informational messages, suppressed unless -verbose or force=true. + * Use ``enclosingPosition'' if you're in doubt what position to pass to ``pos''. + */ + def info(pos: Position, msg: String, force: Boolean): Unit + + /** Warnings and errors. + * Use ``enclosingPosition'' if you're in doubt what position to pass to ``pos''. + */ + def hasWarnings: Boolean + def hasErrors: Boolean + def warning(pos: Position, msg: String): Unit + def error(pos: Position, msg: String): Unit + + /** Abruptly terminates current macro expansion leaving a note about what happened. + * Use ``enclosingPosition'' if you're in doubt what position to pass to ``pos''. + */ + def abort(pos: Position, msg: String): Nothing + + /** Drops into interactive mode if supported by the compiler UI */ + def interactive(): Unit +} \ No newline at end of file diff --git a/src/reflect/scala/reflect/macros/Infrastructure.scala b/src/reflect/scala/reflect/macros/Infrastructure.scala new file mode 100644 index 0000000000..1f1bd160a1 --- /dev/null +++ b/src/reflect/scala/reflect/macros/Infrastructure.scala @@ -0,0 +1,103 @@ +package scala.reflect +package macros + +trait Infrastructure { + self: Context => + + /** Determines whether the compiler expanding a macro targets JVM. + */ + val forJVM: Boolean + + /** Determines whether the compiler expanding a macro targets CLR. + */ + val forMSIL: Boolean + + /** Determines whether the compiler expanding a macro is a presentation compiler. + */ + val forInteractive: Boolean + + /** Determines whether the compiler expanding a macro is a Scaladoc compiler. + */ + val forScaladoc: Boolean + + /** Exposes current compilation run. + */ + val currentRun: Run + + /** Exposes library classpath. + */ + val libraryClassPath: List[java.net.URL] + + /** Exposes a classloader that corresponds to the library classpath. + * + * With this classloader you can perform on-the-fly evaluation of macro arguments. + * For example, consider this code snippet: + * + * def staticEval[T](x: T) = macro staticEval[T] + * + * def staticEval[T: c.TypeTag](c: Context)(x: c.Expr[T]) = { + * import scala.reflect.runtime.{universe => ru} + * val mirror = ru.runtimeMirror(c.libraryClassLoader) + * import scala.tools.reflect.ToolBox + * val toolBox = mirror.mkToolBox() + * val importer = ru.mkImporter(c.universe).asInstanceOf[ru.Importer { val from: c.universe.type }] + * val tree = c.resetAllAttrs(x.tree.duplicate) + * val imported = importer.importTree(tree) + * val valueOfX = toolBox.runExpr(imported).asInstanceOf[T] + * ... + * } + * + * // [Eugene++] using this guy will tremendously slow down the compilation + * // https://twitter.com/xeno_by/status/201248317831774208 + * // todo. we need to address this somehow + */ + def libraryClassLoader: ClassLoader + + /** As seen by macro API, compilation run is an opaque type that can be deconstructed into: + * 1) Current compilation unit + * 2) List of all compilation units that comprise the run + */ + type Run + + val Run: RunExtractor + + abstract class RunExtractor { + def unapply(run: Run): Option[(CompilationUnit, List[CompilationUnit])] + } + + /** As seen by macro API, compilation unit is an opaque type that can be deconstructed into: + * 1) File that corresponds to the unit (if not applicable, null) + * 2) Content of the file (if not applicable, empty array) + * 3) Body, i.e. the AST that represents the compilation unit + */ + type CompilationUnit + + val CompilationUnit: CompilationUnitExtractor + + abstract class CompilationUnitExtractor { + def unapply(compilationUnit: CompilationUnit): Option[(java.io.File, Array[Char], Tree)] + } + + /** Returns a macro definition which triggered this macro expansion. + */ + val currentMacro: Symbol + + // todo. redo caches as discussed on Reflecting Meeting 2012/03/29 + // https://docs.google.com/document/d/1oUZGQpdt2qwioTlJcSt8ZFQwVLTvpxn8xa67P8OGVpU/edit + + /** A cache shared by all invocations of all macros across all compilation runs. + * + * Needs to be used with extreme care, since memory leaks here will swiftly crash the presentation compiler. + * For example, Scala IDE typically launches a compiler run on every edit action so there might be hundreds of runs per minute. + */ + val globalCache: collection.mutable.Map[Any, Any] + + /** A cache shared by all invocations of the same macro within a single compilation run. + * + * This cache is cleared automatically after a compilation run is completed or abandoned. + * It is also specific to a particular macro definition. + * + * To share data between different macros and/or different compilation runs, use ``globalCache''. + */ + val cache: collection.mutable.Map[Any, Any] +} diff --git a/src/reflect/scala/reflect/macros/Names.scala b/src/reflect/scala/reflect/macros/Names.scala new file mode 100644 index 0000000000..fab9bbbca5 --- /dev/null +++ b/src/reflect/scala/reflect/macros/Names.scala @@ -0,0 +1,15 @@ +package scala.reflect +package macros + +trait Names { + self: Context => + + /** Creates a fresh string */ + def fresh(): String + + /** Creates a fresh string from the provided string */ + def fresh(name: String): String + + /** Creates a fresh name from the provided name */ + def fresh[NameType <: Name](name: NameType): NameType +} diff --git a/src/reflect/scala/reflect/macros/Parsers.scala b/src/reflect/scala/reflect/macros/Parsers.scala new file mode 100644 index 0000000000..ea87c5842e --- /dev/null +++ b/src/reflect/scala/reflect/macros/Parsers.scala @@ -0,0 +1,18 @@ +package scala.reflect +package macros + +trait Parsers { + self: Context => + + /** .. */ + // todo. distinguish between `parseExpr` and `parse` + def parse(code: String): Tree + + /** Represents an error during parsing + */ + type ParseError <: Throwable + val ParseError: ParseErrorExtractor + abstract class ParseErrorExtractor { + def unapply(error: ParseError): Option[(Position, String)] + } +} \ No newline at end of file diff --git a/src/reflect/scala/reflect/macros/Reifiers.scala b/src/reflect/scala/reflect/macros/Reifiers.scala new file mode 100644 index 0000000000..1bee17d548 --- /dev/null +++ b/src/reflect/scala/reflect/macros/Reifiers.scala @@ -0,0 +1,91 @@ +package scala.reflect +package macros + +trait Reifiers { + self: Context => + + /** Reification prefix that refers to the base reflexive universe, ``scala.reflect.basis''. + * Providing it for the ``prefix'' parameter of ``reifyTree'' or ``reifyType'' will create a tree that can be inspected at runtime. + */ + val basisUniverse: Tree + + /** Reification prefix that refers to the runtime reflexive universe, ``scala.reflect.runtime.universe''. + * Providing it for the ``prefix'' parameter of ``reifyTree'' or ``reifyType'' will create a full-fledged tree that can be inspected at runtime. + */ + val runtimeUniverse: Tree + + /** Given a tree, generate a tree that when compiled and executed produces the original tree. + * For more information and examples see the documentation for ``Universe.reify''. + * + * The produced tree will be bound to the specified ``universe'' and ``mirror''. + * Possible values for ``universe'' include ``basisUniverse'' and ``runtimeUniverse''. + * Possible values for ``mirror'' include ``EmptyTree'' (in that case the reifier will automatically pick an appropriate mirror). + * + * This function is deeply connected to ``Universe.reify'', a macro that reifies arbitrary expressions into runtime trees. + * They do very similar things (``Universe.reify'' calls ``Context.reifyTree'' to implement itself), but they operate on different metalevels (see below). + * + * Let's study the differences between ``Context.reifyTree'' and ``Universe.reify'' on an example of using them inside a ``fooMacro'' macro: + * + * * Since reify itself is a macro, it will be executed when fooMacro is being compiled (metalevel -1) + * and will produce a tree that when evaluated during macro expansion of fooMacro (metalevel 0) will recreate the input tree. + * + * This provides a facility analogous to quasi-quoting. Writing "reify{ expr }" will generate an AST that represents expr. + * Afterwards this AST (or its parts) can be used to construct the return value of fooMacro. + * + * * reifyTree is evaluated during macro expansion (metalevel 0) + * and will produce a tree that when evaluated during the runtime of the program (metalevel 1) will recreate the input tree. + * + * This provides a way to retain certain trees from macro expansion time to be inspected later, in the runtime. + * For example, DSL authors may find it useful to capture DSL snippets into ASTs that are then processed at runtime in a domain-specific way. + * + * Also note the difference between universes of the runtime trees produced by two reifies: + * + * * The result of compiling and running the result of reify will be bound to the Universe that called reify. + * This is possible because it's a macro, so it can generate whatever code it wishes. + * + * * The result of compiling and running the result of reifyTree will be the ``prefix'' that needs to be passed explicitly. + * This happens because the Universe of the evaluated result is from a different metalevel than the Context the called reify. + * + * Typical usage of this function is to retain some of the trees received/created by a macro + * into the form that can be inspected (via pattern matching) or compiled/run (by a reflective ToolBox) during the runtime. + */ + def reifyTree(universe: Tree, mirror: Tree, tree: Tree): Tree + + /** Given a type, generate a tree that when compiled and executed produces the original type. + * The produced tree will be bound to the specified ``universe'' and ``mirror''. + * For more information and examples see the documentation for ``Context.reifyTree'' and ``Universe.reify''. + */ + def reifyType(universe: Tree, mirror: Tree, tpe: Type, concrete: Boolean = false): Tree + + /** Given a type, generate a tree that when compiled and executed produces the runtime class of the original type. + * If ``concrete'' is true, then this function will bail on types, who refer to abstract types (like `ClassTag` does). + */ + def reifyRuntimeClass(tpe: Type, concrete: Boolean = true): Tree + + /** Given a type, generate a tree that when compiled and executed produces the runtime class of the enclosing class or module. + * Returns `EmptyTree` if there does not exist an enclosing class or module. + */ + def reifyEnclosingRuntimeClass: Tree + + /** Undoes reification of a tree. + * + * This reversion doesn't simply restore the original tree (that would lose the context of reification), + * but does something more involved that conforms to the following laws: + * + * 1) unreifyTree(reifyTree(tree)) != tree // unreified tree is tree + saved context + * // in current implementation, the result of unreify is opaque + * // i.e. there's no possibility to inspect underlying tree/context + * + * 2) reifyTree(unreifyTree(reifyTree(tree))) == reifyTree(tree) // the result of reifying a tree in its original context equals to + * // the result of reifying a tree along with its saved context + * + * 3) compileAndEval(unreifyTree(reifyTree(tree))) ~ compileAndEval(tree) // at runtime original and unreified trees are behaviorally equivalent + */ + def unreifyTree(tree: Tree): Tree +} + +// made these guys non path-dependent, otherwise exception handling quickly becomes a mess + +case class ReificationError(val pos: reflect.api.PositionApi, val msg: String) extends Throwable(msg) + +case class UnexpectedReificationError(val pos: reflect.api.PositionApi, val msg: String, val cause: Throwable = null) extends Throwable(msg, cause) diff --git a/src/reflect/scala/reflect/macros/Settings.scala b/src/reflect/scala/reflect/macros/Settings.scala new file mode 100644 index 0000000000..8d166056c3 --- /dev/null +++ b/src/reflect/scala/reflect/macros/Settings.scala @@ -0,0 +1,40 @@ +package scala.reflect +package macros + +trait Settings { + self: Context => + + /** Exposes macro-specific settings as a list of strings. + * These settings are passed to the compiler via the "-Xmacro-settings:setting1,setting2...,settingN" command-line option. + */ + def settings: List[String] + + /** Exposes current compiler settings as a list of options. + * Use `scalac -help`, `scalac -X` and `scalac -Y` to learn about currently supported options. + */ + // [Eugene] ugly? yes, but I don't really fancy copy/pasting all our settings here and keep it synchronized at all times + // why all settings? because macros need to be in full control of the stuff going on + // maybe later we can implement a gettable/settable list of important settings, but for now let's leave it like that + def compilerSettings: List[String] + + /** Updates current compiler settings with an option string. + * Use `scalac -help`, `scalac -X` and `scalac -Y` to learn about currently supported options. + * todo. http://groups.google.com/group/scala-internals/browse_thread/thread/07c18cff41f59203 + */ + def setCompilerSettings(options: String): this.type + + /** Updates current compiler settings with a list of options. + * Use `scalac -help`, `scalac -X` and `scalac -Y` to learn about currently supported options. + */ + def setCompilerSettings(options: List[String]): this.type + + /** Temporary sets compiler settings to a given option string and executes a given closure. + * Use `scalac -help`, `scalac -X` and `scalac -Y` to learn about currently supported options. + */ + def withCompilerSettings[T](options: String)(op: => T): T + + /** Temporary sets compiler settings to a given list of options and executes a given closure. + * Use `scalac -help`, `scalac -X` and `scalac -Y` to learn about currently supported options. + */ + def withCompilerSettings[T](options: List[String])(op: => T): T +} \ No newline at end of file diff --git a/src/reflect/scala/reflect/macros/TreeBuilder.scala b/src/reflect/scala/reflect/macros/TreeBuilder.scala new file mode 100644 index 0000000000..06f5caf68b --- /dev/null +++ b/src/reflect/scala/reflect/macros/TreeBuilder.scala @@ -0,0 +1,60 @@ +package scala.reflect +package macros + +// [Eugene] I added some stuff that was necessary for typetag materialization macros +// but we should think it over and pick other generally useful stuff +// same goes for tree traversers/transformers, type maps, etc +// and once we expose all that, there's another question: how do we stay in sync? +abstract class TreeBuilder { + val global: Universe + + import global._ + import definitions._ + + /** Builds a reference to value whose type is given stable prefix. + * The type must be suitable for this. For example, it + * must not be a TypeRef pointing to an abstract type variable. + */ + def mkAttributedQualifier(tpe: Type): Tree + + /** Builds a reference to value whose type is given stable prefix. + * If the type is unsuitable, e.g. it is a TypeRef for an + * abstract type variable, then an Ident will be made using + * termSym as the Ident's symbol. In that case, termSym must + * not be NoSymbol. + */ + def mkAttributedQualifier(tpe: Type, termSym: Symbol): Tree + + /** Builds a typed reference to given symbol with given stable prefix. */ + def mkAttributedRef(pre: Type, sym: Symbol): Tree + + /** Builds a typed reference to given symbol. */ + def mkAttributedRef(sym: Symbol): Tree + + /** Builds a typed This reference to given symbol. */ + def mkAttributedThis(sym: Symbol): Tree + + /** Builds a typed Ident with an underlying symbol. */ + def mkAttributedIdent(sym: Symbol): Tree + + /** Builds a typed Select with an underlying symbol. */ + def mkAttributedSelect(qual: Tree, sym: Symbol): Tree + + /** A creator for method calls, e.g. fn[T1, T2, ...](v1, v2, ...) + * There are a number of variations. + * + * @param receiver symbol of the method receiver + * @param methodName name of the method to call + * @param targs type arguments (if Nil, no TypeApply node will be generated) + * @param args value arguments + * @return the newly created trees. + */ + def mkMethodCall(receiver: Symbol, methodName: Name, targs: List[Type], args: List[Tree]): Tree + def mkMethodCall(method: Symbol, targs: List[Type], args: List[Tree]): Tree + def mkMethodCall(method: Symbol, args: List[Tree]): Tree + def mkMethodCall(target: Tree, args: List[Tree]): Tree + def mkMethodCall(receiver: Symbol, methodName: Name, args: List[Tree]): Tree + def mkMethodCall(receiver: Tree, method: Symbol, targs: List[Type], args: List[Tree]): Tree + def mkMethodCall(target: Tree, targs: List[Type], args: List[Tree]): Tree + def mkNullaryCall(method: Symbol, targs: List[Type]): Tree +} diff --git a/src/reflect/scala/reflect/macros/TypeTags.scala b/src/reflect/scala/reflect/macros/TypeTags.scala new file mode 100644 index 0000000000..8f590d1de4 --- /dev/null +++ b/src/reflect/scala/reflect/macros/TypeTags.scala @@ -0,0 +1,9 @@ +package scala.reflect +package macros + +trait TypeTags { + self: Context => + + def AbsTypeTag[T](tpe: Type): AbsTypeTag[T] + def TypeTag[T](tpe: Type): TypeTag[T] +} diff --git a/src/reflect/scala/reflect/macros/Typers.scala b/src/reflect/scala/reflect/macros/Typers.scala new file mode 100644 index 0000000000..eef6507418 --- /dev/null +++ b/src/reflect/scala/reflect/macros/Typers.scala @@ -0,0 +1,83 @@ +package scala.reflect +package macros + +trait Typers { + self: Context => + + import universe._ + + /** Contexts that represent macros in-flight, including the current one. Very much like a stack trace, but for macros only. + * Can be useful for interoperating with other macros and for imposing compiler-friendly limits on macro expansion. + * + * Is also priceless for emitting sane error messages for macros that are called by other macros on synthetic (i.e. position-less) trees. + * In that dire case navigate the `openMacros` stack, and it will most likely contain at least one macro with a position-ful macro application. + * See `enclosingPosition` for a default implementation of this logic. + * + * Unlike `enclosingMacros`, this is a def, which means that it gets recalculated on every invocation, + * so it might change depending on what is going on during macro expansion. + */ + def openMacros: List[Context] + + /** Types along with corresponding trees for which implicit arguments are currently searched. + * Can be useful to get information about an application with an implicit parameter that is materialized during current macro expansion. + * + * Unlike `enclosingImplicits`, this is a def, which means that it gets recalculated on every invocation, + * so it might change depending on what is going on during macro expansion. + */ + def openImplicits: List[(Type, Tree)] + + /** Typechecks the provided tree against the expected type `pt` in the macro callsite context. + * + * If `silent` is false, `TypeError` will be thrown in case of a typecheck error. + * If `silent` is true, the typecheck is silent and will return `EmptyTree` if an error occurs. + * Such errors don't vanish and can be inspected by turning on -Ymacro-debug-verbose. + * Unlike in `inferImplicitValue` and `inferImplicitView`, `silent` is false by default. + * + * Typechecking can be steered with the following optional parameters: + * `withImplicitViewsDisabled` recursively prohibits implicit views (though, implicit vals will still be looked up and filled in), default value is false + * `withMacrosDisabled` recursively prohibits macro expansions and macro-based implicits, default value is false + */ + def typeCheck(tree: Tree, pt: Type = WildcardType, silent: Boolean = false, withImplicitViewsDisabled: Boolean = false, withMacrosDisabled: Boolean = false): Tree + + /** Infers an implicit value of the expected type `pt` in the macro callsite context. + * Optional `pos` parameter provides a position that will be associated with the implicit search. + * + * If `silent` is false, `TypeError` will be thrown in case of an inference error. + * If `silent` is true, the typecheck is silent and will return `EmptyTree` if an error occurs. + * Such errors don't vanish and can be inspected by turning on -Xlog-implicits. + * Unlike in `typeCheck`, `silent` is true by default. + */ + def inferImplicitValue(pt: Type, silent: Boolean = true, withMacrosDisabled: Boolean = false, pos: Position = enclosingPosition): Tree + + /** Infers an implicit view from the provided tree `tree` of the type `from` to the type `to` in the macro callsite context. + * Optional `pos` parameter provides a position that will be associated with the implicit search. + * + * If `silent` is false, `TypeError` will be thrown in case of an inference error. + * If `silent` is true, the typecheck is silent and will return `EmptyTree` if an error occurs. + * Such errors don't vanish and can be inspected by turning on -Xlog-implicits. + * Unlike in `typeCheck`, `silent` is true by default. + */ + def inferImplicitView(tree: Tree, from: Type, to: Type, silent: Boolean = true, withMacrosDisabled: Boolean = false, pos: Position = enclosingPosition): Tree + + /** Recursively resets symbols and types in a given tree. + * + * Note that this does not revert the tree to its pre-typer shape. + * For more info, read up https://issues.scala-lang.org/browse/SI-5464. + */ + def resetAllAttrs(tree: Tree): Tree + + /** Recursively resets locally defined symbols and types in a given tree. + * + * Note that this does not revert the tree to its pre-typer shape. + * For more info, read up https://issues.scala-lang.org/browse/SI-5464. + */ + def resetLocalAttrs(tree: Tree): Tree + + /** Represents an error during typechecking + */ + type TypeError <: Throwable + val TypeError: TypeErrorExtractor + abstract class TypeErrorExtractor { + def unapply(error: TypeError): Option[(Position, String)] + } +} \ No newline at end of file diff --git a/src/reflect/scala/reflect/macros/Universe.scala b/src/reflect/scala/reflect/macros/Universe.scala new file mode 100644 index 0000000000..4074dd9e93 --- /dev/null +++ b/src/reflect/scala/reflect/macros/Universe.scala @@ -0,0 +1,108 @@ +package scala.reflect +package macros + +abstract class Universe extends scala.reflect.api.Universe { + + val treeBuild: TreeBuilder { val global: Universe.this.type } + + trait AttachableApi { + /** ... */ + def attachments: base.Attachments { type Pos = Position } + + /** ... */ + def addAttachment(attachment: Any): AttachableApi.this.type + + /** ... */ + def removeAttachment[T: ClassTag]: AttachableApi.this.type + } + + // Symbol extensions --------------------------------------------------------------- + + override type Symbol >: Null <: SymbolContextApi + + /** The extended API of symbols that's supported in macro context universes + */ + trait SymbolContextApi extends SymbolApi with AttachableApi { this: Symbol => + + def setFlags(flags: FlagSet): this.type + + def setTypeSignature(tpe: Type): this.type + + def setAnnotations(annots: AnnotationInfo*): this.type + + def setName(name: Name): this.type + + def setPrivateWithin(sym: Symbol): this.type + } + + // Tree extensions --------------------------------------------------------------- + + override type Tree >: Null <: TreeContextApi + + /** The extended API of trees that's supported in macro context universes + */ + trait TreeContextApi extends TreeApi with AttachableApi { this: Tree => + + /** ... */ + def pos_=(pos: Position): Unit + + /** ... */ + def setPos(newpos: Position): this.type + + /** ... */ + def tpe_=(t: Type): Unit + + /** Set tpe to give `tp` and return this. + */ + def setType(tp: Type): this.type + + /** Like `setType`, but if this is a previously empty TypeTree that + * fact is remembered so that resetAllAttrs will snap back. + * + * @PP: Attempting to elaborate on the above, I find: If defineType + * is called on a TypeTree whose type field is null or NoType, + * this is recorded as "wasEmpty = true". That value is used in + * ResetAttrsTraverser, which nulls out the type field of TypeTrees + * for which wasEmpty is true, leaving the others alone. + * + * resetAllAttrs is used in situations where some speculative + * typing of a tree takes place, fails, and the tree needs to be + * returned to its former state to try again. So according to me: + * using `defineType` instead of `setType` is how you communicate + * that the type being set does not depend on any previous state, + * and therefore should be abandoned if the current line of type + * inquiry doesn't work out. + */ + def defineType(tp: Type): this.type + + /** ... */ + def symbol_=(sym: Symbol): Unit + + /** ... */ + def setSymbol(sym: Symbol): this.type + } + + override type SymTree >: Null <: Tree with SymTreeContextApi + + /** The extended API of sym trees that's supported in macro context universes + */ + trait SymTreeContextApi extends SymTreeApi { this: SymTree => + var symbol: Symbol + } + + override type TypeTree >: Null <: TypTree with TypeTreeContextApi + + /** The extended API of sym trees that's supported in macro context universes + */ + trait TypeTreeContextApi extends TypeTreeApi { this: TypeTree => + def setOriginal(tree: Tree): this.type + } + + override type Ident >: Null <: RefTree with IdentContextApi + + /** The extended API of idents that's supported in macro context universes + */ + trait IdentContextApi extends IdentApi { this: Ident => + def isBackquoted: Boolean + } +} \ No newline at end of file diff --git a/src/reflect/scala/reflect/macros/package.scala b/src/reflect/scala/reflect/macros/package.scala new file mode 100644 index 0000000000..06ce0b3244 --- /dev/null +++ b/src/reflect/scala/reflect/macros/package.scala @@ -0,0 +1,6 @@ +package scala.reflect + +package object macros { + + type MirrorOf[U <: base.Universe with Singleton] = base.MirrorOf[U] +} diff --git a/src/reflect/scala/reflect/makro/Aliases.scala b/src/reflect/scala/reflect/makro/Aliases.scala deleted file mode 100644 index 4bd246572f..0000000000 --- a/src/reflect/scala/reflect/makro/Aliases.scala +++ /dev/null @@ -1,26 +0,0 @@ -package scala.reflect -package makro - -trait Aliases { - self: Context => - - type Symbol = universe.Symbol - type Type = universe.Type - type Name = universe.Name - type TermName = universe.TermName - type TypeName = universe.TypeName - type Tree = universe.Tree - // type Position = universe.Position - type Scope = universe.Scope - type Modifiers = universe.Modifiers - - type Expr[+T] = universe.Expr[T] - val Expr = universe.Expr - - type AbsTypeTag[T] = universe.AbsTypeTag[T] - type TypeTag[T] = universe.TypeTag[T] - val AbsTypeTag = universe.AbsTypeTag - val TypeTag = universe.TypeTag - def typeTag[T](implicit ttag: TypeTag[T]) = ttag - def typeOf[T](implicit ttag: TypeTag[T]): Type = ttag.tpe -} diff --git a/src/reflect/scala/reflect/makro/CapturedVariables.scala b/src/reflect/scala/reflect/makro/CapturedVariables.scala deleted file mode 100644 index 592e28b3b2..0000000000 --- a/src/reflect/scala/reflect/makro/CapturedVariables.scala +++ /dev/null @@ -1,21 +0,0 @@ -package scala.reflect -package makro - -trait CapturedVariables { - self: Context => - - import mirror._ - - /** Mark a variable as captured; i.e. force boxing in a *Ref type. - */ - def captureVariable(vble: Symbol): Unit - - /** Mark given identifier as a reference to a captured variable itself - * suppressing dereferencing with the `elem` field. - */ - def referenceCapturedVariable(vble: Symbol): Tree - - /** Convert type of a captured variable to *Ref type. - */ - def capturedVariableType(vble: Symbol): Type -} \ No newline at end of file diff --git a/src/reflect/scala/reflect/makro/Context.scala b/src/reflect/scala/reflect/makro/Context.scala deleted file mode 100644 index f3b1271a57..0000000000 --- a/src/reflect/scala/reflect/makro/Context.scala +++ /dev/null @@ -1,34 +0,0 @@ -package scala.reflect -package makro - -// todo. introduce context hierarchy -// the most lightweight context should just expose the stuff from the SIP -// the full context should include all traits from scala.reflect.makro (and probably reside in scala-compiler.jar) - -trait Context extends Aliases - with CapturedVariables - with Enclosures - with Infrastructure - with Names - with Reifiers - with FrontEnds - with Settings - with Typers - with Parsers - with Exprs - with TypeTags - with Evals - with ExprUtils { - - /** The compile-time universe */ - val universe: Universe - - /** The mirror of the compile-time universe */ - val mirror: MirrorOf[universe.type] - - /** The type of the prefix tree from which the macro is selected */ - type PrefixType - - /** The prefix tree from which the macro is selected */ - val prefix: Expr[PrefixType] -} diff --git a/src/reflect/scala/reflect/makro/Enclosures.scala b/src/reflect/scala/reflect/makro/Enclosures.scala deleted file mode 100644 index ff5c13a785..0000000000 --- a/src/reflect/scala/reflect/makro/Enclosures.scala +++ /dev/null @@ -1,50 +0,0 @@ -package scala.reflect -package makro - -trait Enclosures { - self: Context => - - /** The tree that undergoes macro expansion. - * Can be useful to get an offset or a range position of the entire tree being processed. - */ - val macroApplication: Tree - - /** Contexts that represent macros in-flight, including the current one. Very much like a stack trace, but for macros only. - * Can be useful for interoperating with other macros and for imposing compiler-friendly limits on macro expansion. - * - * Is also priceless for emitting sane error messages for macros that are called by other macros on synthetic (i.e. position-less) trees. - * In that dire case navigate the ``enclosingMacros'' stack, and it will most likely contain at least one macro with a position-ful macro application. - * See ``enclosingPosition'' for a default implementation of this logic. - * - * Unlike `openMacros`, this is a val, which means that it gets initialized when the context is created - * and always stays the same regardless of whatever happens during macro expansion. - */ - val enclosingMacros: List[Context] - - /** Types along with corresponding trees for which implicit arguments are currently searched. - * Can be useful to get information about an application with an implicit parameter that is materialized during current macro expansion. - * - * Unlike `openImplicits`, this is a val, which means that it gets initialized when the context is created - * and always stays the same regardless of whatever happens during macro expansion. - */ - val enclosingImplicits: List[(Type, Tree)] - - /** Tries to guess a position for the enclosing application. - * But that is simple, right? Just dereference ``pos'' of ``macroApplication''? Not really. - * If we're in a synthetic macro expansion (no positions), we must do our best to infer the position of something that triggerd this expansion. - * Surprisingly, quite often we can do this by navigation the ``enclosingMacros'' stack. - */ - val enclosingPosition: Position - - /** Tree that corresponds to the enclosing method, or EmptyTree if not applicable. - */ - val enclosingMethod: Tree - - /** Tree that corresponds to the enclosing class, or EmptyTree if not applicable. - */ - val enclosingClass: Tree - - /** Compilation unit that contains this macro application. - */ - val enclosingUnit: CompilationUnit -} \ No newline at end of file diff --git a/src/reflect/scala/reflect/makro/Evals.scala b/src/reflect/scala/reflect/makro/Evals.scala deleted file mode 100644 index 4e5fc2f97f..0000000000 --- a/src/reflect/scala/reflect/makro/Evals.scala +++ /dev/null @@ -1,9 +0,0 @@ -package scala.reflect -package makro - -trait Evals { - self: Context => - - /** .. */ - def eval[T](expr: Expr[T]): T -} \ No newline at end of file diff --git a/src/reflect/scala/reflect/makro/ExprUtils.scala b/src/reflect/scala/reflect/makro/ExprUtils.scala deleted file mode 100644 index c3e5cc6bc1..0000000000 --- a/src/reflect/scala/reflect/makro/ExprUtils.scala +++ /dev/null @@ -1,32 +0,0 @@ -package scala.reflect -package makro - -trait ExprUtils { - self: Context => - - def literalNull: Expr[Null] - - def literalUnit: Expr[Unit] - - def literalTrue: Expr[Boolean] - - def literalFalse: Expr[Boolean] - - def literal(x: Boolean): Expr[Boolean] - - def literal(x: Byte): Expr[Byte] - - def literal(x: Short): Expr[Short] - - def literal(x: Int): Expr[Int] - - def literal(x: Long): Expr[Long] - - def literal(x: Float): Expr[Float] - - def literal(x: Double): Expr[Double] - - def literal(x: String): Expr[String] - - def literal(x: Char): Expr[Char] -} diff --git a/src/reflect/scala/reflect/makro/Exprs.scala b/src/reflect/scala/reflect/makro/Exprs.scala deleted file mode 100644 index 91d3dafbf2..0000000000 --- a/src/reflect/scala/reflect/makro/Exprs.scala +++ /dev/null @@ -1,8 +0,0 @@ -package scala.reflect -package makro - -trait Exprs { - self: Context => - - def Expr[T: AbsTypeTag](tree: Tree): Expr[T] -} diff --git a/src/reflect/scala/reflect/makro/FrontEnds.scala b/src/reflect/scala/reflect/makro/FrontEnds.scala deleted file mode 100644 index 5087f90174..0000000000 --- a/src/reflect/scala/reflect/makro/FrontEnds.scala +++ /dev/null @@ -1,42 +0,0 @@ -package scala.reflect -package makro - -trait FrontEnds extends scala.reflect.api.FrontEnds { - self: Context => - - import mirror._ - - type Position = universe.Position - - /** Exposes means to control the compiler UI */ - def frontEnd: FrontEnd - def setFrontEnd(frontEnd: FrontEnd): this.type - def withFrontEnd[T](frontEnd: FrontEnd)(op: => T): T - - /** For sending a message which should not be labeled as a warning/error, - * but also shouldn't require -verbose to be visible. - * Use ``enclosingPosition'' if you're in doubt what position to pass to ``pos''. - */ - def echo(pos: Position, msg: String): Unit - - /** Informational messages, suppressed unless -verbose or force=true. - * Use ``enclosingPosition'' if you're in doubt what position to pass to ``pos''. - */ - def info(pos: Position, msg: String, force: Boolean): Unit - - /** Warnings and errors. - * Use ``enclosingPosition'' if you're in doubt what position to pass to ``pos''. - */ - def hasWarnings: Boolean - def hasErrors: Boolean - def warning(pos: Position, msg: String): Unit - def error(pos: Position, msg: String): Unit - - /** Abruptly terminates current macro expansion leaving a note about what happened. - * Use ``enclosingPosition'' if you're in doubt what position to pass to ``pos''. - */ - def abort(pos: Position, msg: String): Nothing - - /** Drops into interactive mode if supported by the compiler UI */ - def interactive(): Unit -} \ No newline at end of file diff --git a/src/reflect/scala/reflect/makro/Infrastructure.scala b/src/reflect/scala/reflect/makro/Infrastructure.scala deleted file mode 100644 index e6bfe33366..0000000000 --- a/src/reflect/scala/reflect/makro/Infrastructure.scala +++ /dev/null @@ -1,103 +0,0 @@ -package scala.reflect -package makro - -trait Infrastructure { - self: Context => - - /** Determines whether the compiler expanding a macro targets JVM. - */ - val forJVM: Boolean - - /** Determines whether the compiler expanding a macro targets CLR. - */ - val forMSIL: Boolean - - /** Determines whether the compiler expanding a macro is a presentation compiler. - */ - val forInteractive: Boolean - - /** Determines whether the compiler expanding a macro is a Scaladoc compiler. - */ - val forScaladoc: Boolean - - /** Exposes current compilation run. - */ - val currentRun: Run - - /** Exposes library classpath. - */ - val libraryClassPath: List[java.net.URL] - - /** Exposes a classloader that corresponds to the library classpath. - * - * With this classloader you can perform on-the-fly evaluation of macro arguments. - * For example, consider this code snippet: - * - * def staticEval[T](x: T) = macro staticEval[T] - * - * def staticEval[T: c.TypeTag](c: Context)(x: c.Expr[T]) = { - * import scala.reflect.runtime.{universe => ru} - * val mirror = ru.runtimeMirror(c.libraryClassLoader) - * import scala.tools.reflect.ToolBox - * val toolBox = mirror.mkToolBox() - * val importer = ru.mkImporter(c.universe).asInstanceOf[ru.Importer { val from: c.universe.type }] - * val tree = c.resetAllAttrs(x.tree.duplicate) - * val imported = importer.importTree(tree) - * val valueOfX = toolBox.runExpr(imported).asInstanceOf[T] - * ... - * } - * - * // [Eugene++] using this guy will tremendously slow down the compilation - * // https://twitter.com/xeno_by/status/201248317831774208 - * // todo. we need to address this somehow - */ - def libraryClassLoader: ClassLoader - - /** As seen by macro API, compilation run is an opaque type that can be deconstructed into: - * 1) Current compilation unit - * 2) List of all compilation units that comprise the run - */ - type Run - - val Run: RunExtractor - - abstract class RunExtractor { - def unapply(run: Run): Option[(CompilationUnit, List[CompilationUnit])] - } - - /** As seen by macro API, compilation unit is an opaque type that can be deconstructed into: - * 1) File that corresponds to the unit (if not applicable, null) - * 2) Content of the file (if not applicable, empty array) - * 3) Body, i.e. the AST that represents the compilation unit - */ - type CompilationUnit - - val CompilationUnit: CompilationUnitExtractor - - abstract class CompilationUnitExtractor { - def unapply(compilationUnit: CompilationUnit): Option[(java.io.File, Array[Char], Tree)] - } - - /** Returns a macro definition which triggered this macro expansion. - */ - val currentMacro: Symbol - - // todo. redo caches as discussed on Reflecting Meeting 2012/03/29 - // https://docs.google.com/document/d/1oUZGQpdt2qwioTlJcSt8ZFQwVLTvpxn8xa67P8OGVpU/edit - - /** A cache shared by all invocations of all macros across all compilation runs. - * - * Needs to be used with extreme care, since memory leaks here will swiftly crash the presentation compiler. - * For example, Scala IDE typically launches a compiler run on every edit action so there might be hundreds of runs per minute. - */ - val globalCache: collection.mutable.Map[Any, Any] - - /** A cache shared by all invocations of the same macro within a single compilation run. - * - * This cache is cleared automatically after a compilation run is completed or abandoned. - * It is also specific to a particular macro definition. - * - * To share data between different macros and/or different compilation runs, use ``globalCache''. - */ - val cache: collection.mutable.Map[Any, Any] -} diff --git a/src/reflect/scala/reflect/makro/Names.scala b/src/reflect/scala/reflect/makro/Names.scala deleted file mode 100644 index 909976d83c..0000000000 --- a/src/reflect/scala/reflect/makro/Names.scala +++ /dev/null @@ -1,15 +0,0 @@ -package scala.reflect -package makro - -trait Names { - self: Context => - - /** Creates a fresh string */ - def fresh(): String - - /** Creates a fresh string from the provided string */ - def fresh(name: String): String - - /** Creates a fresh name from the provided name */ - def fresh[NameType <: Name](name: NameType): NameType -} diff --git a/src/reflect/scala/reflect/makro/Parsers.scala b/src/reflect/scala/reflect/makro/Parsers.scala deleted file mode 100644 index 9866b7e491..0000000000 --- a/src/reflect/scala/reflect/makro/Parsers.scala +++ /dev/null @@ -1,18 +0,0 @@ -package scala.reflect -package makro - -trait Parsers { - self: Context => - - /** .. */ - // todo. distinguish between `parseExpr` and `parse` - def parse(code: String): Tree - - /** Represents an error during parsing - */ - type ParseError <: Throwable - val ParseError: ParseErrorExtractor - abstract class ParseErrorExtractor { - def unapply(error: ParseError): Option[(Position, String)] - } -} \ No newline at end of file diff --git a/src/reflect/scala/reflect/makro/Reifiers.scala b/src/reflect/scala/reflect/makro/Reifiers.scala deleted file mode 100644 index f39f56f935..0000000000 --- a/src/reflect/scala/reflect/makro/Reifiers.scala +++ /dev/null @@ -1,91 +0,0 @@ -package scala.reflect -package makro - -trait Reifiers { - self: Context => - - /** Reification prefix that refers to the base reflexive universe, ``scala.reflect.basis''. - * Providing it for the ``prefix'' parameter of ``reifyTree'' or ``reifyType'' will create a tree that can be inspected at runtime. - */ - val basisUniverse: Tree - - /** Reification prefix that refers to the runtime reflexive universe, ``scala.reflect.runtime.universe''. - * Providing it for the ``prefix'' parameter of ``reifyTree'' or ``reifyType'' will create a full-fledged tree that can be inspected at runtime. - */ - val runtimeUniverse: Tree - - /** Given a tree, generate a tree that when compiled and executed produces the original tree. - * For more information and examples see the documentation for ``Universe.reify''. - * - * The produced tree will be bound to the specified ``universe'' and ``mirror''. - * Possible values for ``universe'' include ``basisUniverse'' and ``runtimeUniverse''. - * Possible values for ``mirror'' include ``EmptyTree'' (in that case the reifier will automatically pick an appropriate mirror). - * - * This function is deeply connected to ``Universe.reify'', a macro that reifies arbitrary expressions into runtime trees. - * They do very similar things (``Universe.reify'' calls ``Context.reifyTree'' to implement itself), but they operate on different metalevels (see below). - * - * Let's study the differences between ``Context.reifyTree'' and ``Universe.reify'' on an example of using them inside a ``fooMacro'' macro: - * - * * Since reify itself is a macro, it will be executed when fooMacro is being compiled (metalevel -1) - * and will produce a tree that when evaluated during macro expansion of fooMacro (metalevel 0) will recreate the input tree. - * - * This provides a facility analogous to quasi-quoting. Writing "reify{ expr }" will generate an AST that represents expr. - * Afterwards this AST (or its parts) can be used to construct the return value of fooMacro. - * - * * reifyTree is evaluated during macro expansion (metalevel 0) - * and will produce a tree that when evaluated during the runtime of the program (metalevel 1) will recreate the input tree. - * - * This provides a way to retain certain trees from macro expansion time to be inspected later, in the runtime. - * For example, DSL authors may find it useful to capture DSL snippets into ASTs that are then processed at runtime in a domain-specific way. - * - * Also note the difference between universes of the runtime trees produced by two reifies: - * - * * The result of compiling and running the result of reify will be bound to the Universe that called reify. - * This is possible because it's a macro, so it can generate whatever code it wishes. - * - * * The result of compiling and running the result of reifyTree will be the ``prefix'' that needs to be passed explicitly. - * This happens because the Universe of the evaluated result is from a different metalevel than the Context the called reify. - * - * Typical usage of this function is to retain some of the trees received/created by a macro - * into the form that can be inspected (via pattern matching) or compiled/run (by a reflective ToolBox) during the runtime. - */ - def reifyTree(universe: Tree, mirror: Tree, tree: Tree): Tree - - /** Given a type, generate a tree that when compiled and executed produces the original type. - * The produced tree will be bound to the specified ``universe'' and ``mirror''. - * For more information and examples see the documentation for ``Context.reifyTree'' and ``Universe.reify''. - */ - def reifyType(universe: Tree, mirror: Tree, tpe: Type, concrete: Boolean = false): Tree - - /** Given a type, generate a tree that when compiled and executed produces the runtime class of the original type. - * If ``concrete'' is true, then this function will bail on types, who refer to abstract types (like `ClassTag` does). - */ - def reifyRuntimeClass(tpe: Type, concrete: Boolean = true): Tree - - /** Given a type, generate a tree that when compiled and executed produces the runtime class of the enclosing class or module. - * Returns `EmptyTree` if there does not exist an enclosing class or module. - */ - def reifyEnclosingRuntimeClass: Tree - - /** Undoes reification of a tree. - * - * This reversion doesn't simply restore the original tree (that would lose the context of reification), - * but does something more involved that conforms to the following laws: - * - * 1) unreifyTree(reifyTree(tree)) != tree // unreified tree is tree + saved context - * // in current implementation, the result of unreify is opaque - * // i.e. there's no possibility to inspect underlying tree/context - * - * 2) reifyTree(unreifyTree(reifyTree(tree))) == reifyTree(tree) // the result of reifying a tree in its original context equals to - * // the result of reifying a tree along with its saved context - * - * 3) compileAndEval(unreifyTree(reifyTree(tree))) ~ compileAndEval(tree) // at runtime original and unreified trees are behaviorally equivalent - */ - def unreifyTree(tree: Tree): Tree -} - -// made these guys non path-dependent, otherwise exception handling quickly becomes a mess - -case class ReificationError(val pos: reflect.api.PositionApi, val msg: String) extends Throwable(msg) - -case class UnexpectedReificationError(val pos: reflect.api.PositionApi, val msg: String, val cause: Throwable = null) extends Throwable(msg, cause) diff --git a/src/reflect/scala/reflect/makro/Settings.scala b/src/reflect/scala/reflect/makro/Settings.scala deleted file mode 100644 index c6c7e5870b..0000000000 --- a/src/reflect/scala/reflect/makro/Settings.scala +++ /dev/null @@ -1,40 +0,0 @@ -package scala.reflect -package makro - -trait Settings { - self: Context => - - /** Exposes macro-specific settings as a list of strings. - * These settings are passed to the compiler via the "-Xmacro-settings:setting1,setting2...,settingN" command-line option. - */ - def settings: List[String] - - /** Exposes current compiler settings as a list of options. - * Use `scalac -help`, `scalac -X` and `scalac -Y` to learn about currently supported options. - */ - // [Eugene] ugly? yes, but I don't really fancy copy/pasting all our settings here and keep it synchronized at all times - // why all settings? because macros need to be in full control of the stuff going on - // maybe later we can implement a gettable/settable list of important settings, but for now let's leave it like that - def compilerSettings: List[String] - - /** Updates current compiler settings with an option string. - * Use `scalac -help`, `scalac -X` and `scalac -Y` to learn about currently supported options. - * todo. http://groups.google.com/group/scala-internals/browse_thread/thread/07c18cff41f59203 - */ - def setCompilerSettings(options: String): this.type - - /** Updates current compiler settings with a list of options. - * Use `scalac -help`, `scalac -X` and `scalac -Y` to learn about currently supported options. - */ - def setCompilerSettings(options: List[String]): this.type - - /** Temporary sets compiler settings to a given option string and executes a given closure. - * Use `scalac -help`, `scalac -X` and `scalac -Y` to learn about currently supported options. - */ - def withCompilerSettings[T](options: String)(op: => T): T - - /** Temporary sets compiler settings to a given list of options and executes a given closure. - * Use `scalac -help`, `scalac -X` and `scalac -Y` to learn about currently supported options. - */ - def withCompilerSettings[T](options: List[String])(op: => T): T -} \ No newline at end of file diff --git a/src/reflect/scala/reflect/makro/TreeBuilder.scala b/src/reflect/scala/reflect/makro/TreeBuilder.scala deleted file mode 100644 index c4179b9c80..0000000000 --- a/src/reflect/scala/reflect/makro/TreeBuilder.scala +++ /dev/null @@ -1,60 +0,0 @@ -package scala.reflect -package makro - -// [Eugene] I added some stuff that was necessary for typetag materialization macros -// but we should think it over and pick other generally useful stuff -// same goes for tree traversers/transformers, type maps, etc -// and once we expose all that, there's another question: how do we stay in sync? -abstract class TreeBuilder { - val global: Universe - - import global._ - import definitions._ - - /** Builds a reference to value whose type is given stable prefix. - * The type must be suitable for this. For example, it - * must not be a TypeRef pointing to an abstract type variable. - */ - def mkAttributedQualifier(tpe: Type): Tree - - /** Builds a reference to value whose type is given stable prefix. - * If the type is unsuitable, e.g. it is a TypeRef for an - * abstract type variable, then an Ident will be made using - * termSym as the Ident's symbol. In that case, termSym must - * not be NoSymbol. - */ - def mkAttributedQualifier(tpe: Type, termSym: Symbol): Tree - - /** Builds a typed reference to given symbol with given stable prefix. */ - def mkAttributedRef(pre: Type, sym: Symbol): Tree - - /** Builds a typed reference to given symbol. */ - def mkAttributedRef(sym: Symbol): Tree - - /** Builds a typed This reference to given symbol. */ - def mkAttributedThis(sym: Symbol): Tree - - /** Builds a typed Ident with an underlying symbol. */ - def mkAttributedIdent(sym: Symbol): Tree - - /** Builds a typed Select with an underlying symbol. */ - def mkAttributedSelect(qual: Tree, sym: Symbol): Tree - - /** A creator for method calls, e.g. fn[T1, T2, ...](v1, v2, ...) - * There are a number of variations. - * - * @param receiver symbol of the method receiver - * @param methodName name of the method to call - * @param targs type arguments (if Nil, no TypeApply node will be generated) - * @param args value arguments - * @return the newly created trees. - */ - def mkMethodCall(receiver: Symbol, methodName: Name, targs: List[Type], args: List[Tree]): Tree - def mkMethodCall(method: Symbol, targs: List[Type], args: List[Tree]): Tree - def mkMethodCall(method: Symbol, args: List[Tree]): Tree - def mkMethodCall(target: Tree, args: List[Tree]): Tree - def mkMethodCall(receiver: Symbol, methodName: Name, args: List[Tree]): Tree - def mkMethodCall(receiver: Tree, method: Symbol, targs: List[Type], args: List[Tree]): Tree - def mkMethodCall(target: Tree, targs: List[Type], args: List[Tree]): Tree - def mkNullaryCall(method: Symbol, targs: List[Type]): Tree -} diff --git a/src/reflect/scala/reflect/makro/TypeTags.scala b/src/reflect/scala/reflect/makro/TypeTags.scala deleted file mode 100644 index 53a9b116e3..0000000000 --- a/src/reflect/scala/reflect/makro/TypeTags.scala +++ /dev/null @@ -1,9 +0,0 @@ -package scala.reflect -package makro - -trait TypeTags { - self: Context => - - def AbsTypeTag[T](tpe: Type): AbsTypeTag[T] - def TypeTag[T](tpe: Type): TypeTag[T] -} diff --git a/src/reflect/scala/reflect/makro/Typers.scala b/src/reflect/scala/reflect/makro/Typers.scala deleted file mode 100644 index 4176c184d0..0000000000 --- a/src/reflect/scala/reflect/makro/Typers.scala +++ /dev/null @@ -1,83 +0,0 @@ -package scala.reflect -package makro - -trait Typers { - self: Context => - - import universe._ - - /** Contexts that represent macros in-flight, including the current one. Very much like a stack trace, but for macros only. - * Can be useful for interoperating with other macros and for imposing compiler-friendly limits on macro expansion. - * - * Is also priceless for emitting sane error messages for macros that are called by other macros on synthetic (i.e. position-less) trees. - * In that dire case navigate the `openMacros` stack, and it will most likely contain at least one macro with a position-ful macro application. - * See `enclosingPosition` for a default implementation of this logic. - * - * Unlike `enclosingMacros`, this is a def, which means that it gets recalculated on every invocation, - * so it might change depending on what is going on during macro expansion. - */ - def openMacros: List[Context] - - /** Types along with corresponding trees for which implicit arguments are currently searched. - * Can be useful to get information about an application with an implicit parameter that is materialized during current macro expansion. - * - * Unlike `enclosingImplicits`, this is a def, which means that it gets recalculated on every invocation, - * so it might change depending on what is going on during macro expansion. - */ - def openImplicits: List[(Type, Tree)] - - /** Typechecks the provided tree against the expected type `pt` in the macro callsite context. - * - * If `silent` is false, `TypeError` will be thrown in case of a typecheck error. - * If `silent` is true, the typecheck is silent and will return `EmptyTree` if an error occurs. - * Such errors don't vanish and can be inspected by turning on -Ymacro-debug-verbose. - * Unlike in `inferImplicitValue` and `inferImplicitView`, `silent` is false by default. - * - * Typechecking can be steered with the following optional parameters: - * `withImplicitViewsDisabled` recursively prohibits implicit views (though, implicit vals will still be looked up and filled in), default value is false - * `withMacrosDisabled` recursively prohibits macro expansions and macro-based implicits, default value is false - */ - def typeCheck(tree: Tree, pt: Type = WildcardType, silent: Boolean = false, withImplicitViewsDisabled: Boolean = false, withMacrosDisabled: Boolean = false): Tree - - /** Infers an implicit value of the expected type `pt` in the macro callsite context. - * Optional `pos` parameter provides a position that will be associated with the implicit search. - * - * If `silent` is false, `TypeError` will be thrown in case of an inference error. - * If `silent` is true, the typecheck is silent and will return `EmptyTree` if an error occurs. - * Such errors don't vanish and can be inspected by turning on -Xlog-implicits. - * Unlike in `typeCheck`, `silent` is true by default. - */ - def inferImplicitValue(pt: Type, silent: Boolean = true, withMacrosDisabled: Boolean = false, pos: Position = enclosingPosition): Tree - - /** Infers an implicit view from the provided tree `tree` of the type `from` to the type `to` in the macro callsite context. - * Optional `pos` parameter provides a position that will be associated with the implicit search. - * - * If `silent` is false, `TypeError` will be thrown in case of an inference error. - * If `silent` is true, the typecheck is silent and will return `EmptyTree` if an error occurs. - * Such errors don't vanish and can be inspected by turning on -Xlog-implicits. - * Unlike in `typeCheck`, `silent` is true by default. - */ - def inferImplicitView(tree: Tree, from: Type, to: Type, silent: Boolean = true, withMacrosDisabled: Boolean = false, pos: Position = enclosingPosition): Tree - - /** Recursively resets symbols and types in a given tree. - * - * Note that this does not revert the tree to its pre-typer shape. - * For more info, read up https://issues.scala-lang.org/browse/SI-5464. - */ - def resetAllAttrs(tree: Tree): Tree - - /** Recursively resets locally defined symbols and types in a given tree. - * - * Note that this does not revert the tree to its pre-typer shape. - * For more info, read up https://issues.scala-lang.org/browse/SI-5464. - */ - def resetLocalAttrs(tree: Tree): Tree - - /** Represents an error during typechecking - */ - type TypeError <: Throwable - val TypeError: TypeErrorExtractor - abstract class TypeErrorExtractor { - def unapply(error: TypeError): Option[(Position, String)] - } -} \ No newline at end of file diff --git a/src/reflect/scala/reflect/makro/Universe.scala b/src/reflect/scala/reflect/makro/Universe.scala deleted file mode 100644 index d88e7e0bb8..0000000000 --- a/src/reflect/scala/reflect/makro/Universe.scala +++ /dev/null @@ -1,108 +0,0 @@ -package scala.reflect -package makro - -abstract class Universe extends scala.reflect.api.Universe { - - val treeBuild: TreeBuilder { val global: Universe.this.type } - - trait AttachableApi { - /** ... */ - def attachments: base.Attachments { type Pos = Position } - - /** ... */ - def addAttachment(attachment: Any): AttachableApi.this.type - - /** ... */ - def removeAttachment[T: ClassTag]: AttachableApi.this.type - } - - // Symbol extensions --------------------------------------------------------------- - - override type Symbol >: Null <: SymbolContextApi - - /** The extended API of symbols that's supported in macro context universes - */ - trait SymbolContextApi extends SymbolApi with AttachableApi { this: Symbol => - - def setFlags(flags: FlagSet): this.type - - def setTypeSignature(tpe: Type): this.type - - def setAnnotations(annots: AnnotationInfo*): this.type - - def setName(name: Name): this.type - - def setPrivateWithin(sym: Symbol): this.type - } - - // Tree extensions --------------------------------------------------------------- - - override type Tree >: Null <: TreeContextApi - - /** The extended API of trees that's supported in macro context universes - */ - trait TreeContextApi extends TreeApi with AttachableApi { this: Tree => - - /** ... */ - def pos_=(pos: Position): Unit - - /** ... */ - def setPos(newpos: Position): this.type - - /** ... */ - def tpe_=(t: Type): Unit - - /** Set tpe to give `tp` and return this. - */ - def setType(tp: Type): this.type - - /** Like `setType`, but if this is a previously empty TypeTree that - * fact is remembered so that resetAllAttrs will snap back. - * - * @PP: Attempting to elaborate on the above, I find: If defineType - * is called on a TypeTree whose type field is null or NoType, - * this is recorded as "wasEmpty = true". That value is used in - * ResetAttrsTraverser, which nulls out the type field of TypeTrees - * for which wasEmpty is true, leaving the others alone. - * - * resetAllAttrs is used in situations where some speculative - * typing of a tree takes place, fails, and the tree needs to be - * returned to its former state to try again. So according to me: - * using `defineType` instead of `setType` is how you communicate - * that the type being set does not depend on any previous state, - * and therefore should be abandoned if the current line of type - * inquiry doesn't work out. - */ - def defineType(tp: Type): this.type - - /** ... */ - def symbol_=(sym: Symbol): Unit - - /** ... */ - def setSymbol(sym: Symbol): this.type - } - - override type SymTree >: Null <: Tree with SymTreeContextApi - - /** The extended API of sym trees that's supported in macro context universes - */ - trait SymTreeContextApi extends SymTreeApi { this: SymTree => - var symbol: Symbol - } - - override type TypeTree >: Null <: TypTree with TypeTreeContextApi - - /** The extended API of sym trees that's supported in macro context universes - */ - trait TypeTreeContextApi extends TypeTreeApi { this: TypeTree => - def setOriginal(tree: Tree): this.type - } - - override type Ident >: Null <: RefTree with IdentContextApi - - /** The extended API of idents that's supported in macro context universes - */ - trait IdentContextApi extends IdentApi { this: Ident => - def isBackquoted: Boolean - } -} \ No newline at end of file diff --git a/src/reflect/scala/reflect/makro/package.scala b/src/reflect/scala/reflect/makro/package.scala index 3c0e51030e..f5868eab18 100644 --- a/src/reflect/scala/reflect/makro/package.scala +++ b/src/reflect/scala/reflect/makro/package.scala @@ -1,6 +1,5 @@ package scala.reflect package object makro { - - type MirrorOf[U <: base.Universe with Singleton] = base.MirrorOf[U] -} + type Context = scala.reflect.macros.Context +} \ No newline at end of file diff --git a/src/reflect/scala/reflect/runtime/package.scala b/src/reflect/scala/reflect/runtime/package.scala index 2d48b9a5bf..2cb72d3824 100644 --- a/src/reflect/scala/reflect/runtime/package.scala +++ b/src/reflect/scala/reflect/runtime/package.scala @@ -13,7 +13,7 @@ package object runtime { package runtime { object Macros { - def currentMirror(c: scala.reflect.makro.Context): c.Expr[universe.Mirror] = { + def currentMirror(c: scala.reflect.macros.Context): c.Expr[universe.Mirror] = { import c.universe._ val runtimeClass = c.reifyEnclosingRuntimeClass if (runtimeClass.isEmpty) c.abort(c.enclosingPosition, "call site does not have an enclosing class") -- cgit v1.2.3