diff options
author | Eugene Burmako <xeno.by@gmail.com> | 2013-09-26 15:05:36 +0200 |
---|---|---|
committer | Eugene Burmako <xeno.by@gmail.com> | 2013-09-26 16:39:19 +0200 |
commit | 7122560063b4cbe1e8012decbc842bf610e55863 (patch) | |
tree | b73e4804208e752248e6d60bfcbf96ece52a3987 /src | |
parent | bda48577d022811be58ce2b7f9e46890543ad45b (diff) | |
download | scala-7122560063b4cbe1e8012decbc842bf610e55863.tar.gz scala-7122560063b4cbe1e8012decbc842bf610e55863.tar.bz2 scala-7122560063b4cbe1e8012decbc842bf610e55863.zip |
transformers no longer ignore UnApply.fun
Second time's the charm. I remember trying to do exactly the same somewhen
around 2.10.0-M4, but then some continuations tests were failing.
Luckily, today everything went smoothly.
Please note that this fix changes the way that SI-5465 manifests itself.
Previously it produced type errors, now it simply crashes the compiler.
Therefore I had to attach the try/catch FatalError clause to invocations
of toolbox methods, so that compiler crashes get caught and translated to
ToolBoxErrors.
Also fixes SI-7871, and that clears the way for implementing quasiquotes
with conventional macros rather than relying on a special case in typer.
Diffstat (limited to 'src')
-rw-r--r-- | src/compiler/scala/tools/reflect/ToolBoxFactory.scala | 61 | ||||
-rw-r--r-- | src/reflect/scala/reflect/internal/Trees.scala | 2 |
2 files changed, 37 insertions, 26 deletions
diff --git a/src/compiler/scala/tools/reflect/ToolBoxFactory.scala b/src/compiler/scala/tools/reflect/ToolBoxFactory.scala index 2d905d5436..52b2f0800d 100644 --- a/src/compiler/scala/tools/reflect/ToolBoxFactory.scala +++ b/src/compiler/scala/tools/reflect/ToolBoxFactory.scala @@ -13,6 +13,7 @@ import scala.compat.Platform.EOL import scala.reflect.NameTransformer import scala.reflect.api.JavaUniverse import scala.reflect.io.NoAbstractFile +import scala.reflect.internal.FatalError abstract class ToolBoxFactory[U <: JavaUniverse](val u: U) { factorySelf => @@ -59,6 +60,10 @@ abstract class ToolBoxFactory[U <: JavaUniverse](val u: U) { factorySelf => try body finally cleanupCaches() + def wrappingFatalErrors[T](body: => T): T = + try body + catch { case ex: FatalError => throw ToolBoxError(s"fatal compiler error", ex) } + def verify(expr: Tree): Unit = { // Previously toolboxes used to typecheck their inputs before compiling. // Actually, the initial demo by Martin first typechecked the reified tree, @@ -333,16 +338,19 @@ abstract class ToolBoxFactory[U <: JavaUniverse](val u: U) { factorySelf => lazy val importer = compiler.mkImporter(u) lazy val exporter = importer.reverse - def typeCheck(tree: u.Tree, expectedType: u.Type, silent: Boolean = false, withImplicitViewsDisabled: Boolean = false, withMacrosDisabled: Boolean = false): u.Tree = compiler.withCleanupCaches { - if (compiler.settings.verbose) println("importing "+tree+", expectedType = "+expectedType) - val ctree: compiler.Tree = importer.importTree(tree) - val cexpectedType: compiler.Type = importer.importType(expectedType) - - if (compiler.settings.verbose) println("typing "+ctree+", expectedType = "+expectedType) - val ttree: compiler.Tree = compiler.typeCheck(ctree, cexpectedType, silent = silent, withImplicitViewsDisabled = withImplicitViewsDisabled, withMacrosDisabled = withMacrosDisabled) - val uttree = exporter.importTree(ttree) - uttree - } + def typeCheck(tree: u.Tree, expectedType: u.Type, silent: Boolean = false, withImplicitViewsDisabled: Boolean = false, withMacrosDisabled: Boolean = false): u.Tree = + compiler.wrappingFatalErrors { + compiler.withCleanupCaches { + if (compiler.settings.verbose) println("importing "+tree+", expectedType = "+expectedType) + val ctree: compiler.Tree = importer.importTree(tree) + val cexpectedType: compiler.Type = importer.importType(expectedType) + + if (compiler.settings.verbose) println("typing "+ctree+", expectedType = "+expectedType) + val ttree: compiler.Tree = compiler.typeCheck(ctree, cexpectedType, silent = silent, withImplicitViewsDisabled = withImplicitViewsDisabled, withMacrosDisabled = withMacrosDisabled) + val uttree = exporter.importTree(ttree) + uttree + } + } def inferImplicitValue(pt: u.Type, silent: Boolean = true, withMacrosDisabled: Boolean = false, pos: u.Position = u.NoPosition): u.Tree = { inferImplicit(u.EmptyTree, pt, isView = false, silent = silent, withMacrosDisabled = withMacrosDisabled, pos = pos) @@ -354,40 +362,43 @@ abstract class ToolBoxFactory[U <: JavaUniverse](val u: U) { factorySelf => inferImplicit(tree, viewTpe, isView = true, silent = silent, withMacrosDisabled = withMacrosDisabled, pos = pos) } - private def inferImplicit(tree: u.Tree, pt: u.Type, isView: Boolean, silent: Boolean, withMacrosDisabled: Boolean, pos: u.Position): u.Tree = compiler.withCleanupCaches { - if (compiler.settings.verbose) println(s"importing pt=$pt, tree=$tree, pos=$pos") - val ctree: compiler.Tree = importer.importTree(tree) - val cpt: compiler.Type = importer.importType(pt) - val cpos: compiler.Position = importer.importPosition(pos) - - if (compiler.settings.verbose) println("inferring implicit %s of type %s, macros = %s".format(if (isView) "view" else "value", pt, !withMacrosDisabled)) - val itree: compiler.Tree = compiler.inferImplicit(ctree, cpt, isView = isView, silent = silent, withMacrosDisabled = withMacrosDisabled, pos = cpos) - val uitree = exporter.importTree(itree) - uitree - } + private def inferImplicit(tree: u.Tree, pt: u.Type, isView: Boolean, silent: Boolean, withMacrosDisabled: Boolean, pos: u.Position): u.Tree = + compiler.wrappingFatalErrors { + compiler.withCleanupCaches { + if (compiler.settings.verbose) println(s"importing pt=$pt, tree=$tree, pos=$pos") + val ctree: compiler.Tree = importer.importTree(tree) + val cpt: compiler.Type = importer.importType(pt) + val cpos: compiler.Position = importer.importPosition(pos) + + if (compiler.settings.verbose) println("inferring implicit %s of type %s, macros = %s".format(if (isView) "view" else "value", pt, !withMacrosDisabled)) + val itree: compiler.Tree = compiler.inferImplicit(ctree, cpt, isView = isView, silent = silent, withMacrosDisabled = withMacrosDisabled, pos = cpos) + val uitree = exporter.importTree(itree) + uitree + } + } - def resetAllAttrs(tree: u.Tree): u.Tree = { + def resetAllAttrs(tree: u.Tree): u.Tree = compiler.wrappingFatalErrors { val ctree: compiler.Tree = importer.importTree(tree) val ttree: compiler.Tree = compiler.resetAllAttrs(ctree) val uttree = exporter.importTree(ttree) uttree } - def resetLocalAttrs(tree: u.Tree): u.Tree = { + def resetLocalAttrs(tree: u.Tree): u.Tree = compiler.wrappingFatalErrors { val ctree: compiler.Tree = importer.importTree(tree) val ttree: compiler.Tree = compiler.resetLocalAttrs(ctree) val uttree = exporter.importTree(ttree) uttree } - def parse(code: String): u.Tree = { + def parse(code: String): u.Tree = compiler.wrappingFatalErrors { if (compiler.settings.verbose) println("parsing "+code) val ctree: compiler.Tree = compiler.parse(code) val utree = exporter.importTree(ctree) utree } - def compile(tree: u.Tree): () => Any = { + def compile(tree: u.Tree): () => Any = compiler.wrappingFatalErrors { if (compiler.settings.verbose) println("importing "+tree) val ctree: compiler.Tree = importer.importTree(tree) diff --git a/src/reflect/scala/reflect/internal/Trees.scala b/src/reflect/scala/reflect/internal/Trees.scala index 2163a26b84..9138a1c7bb 100644 --- a/src/reflect/scala/reflect/internal/Trees.scala +++ b/src/reflect/scala/reflect/internal/Trees.scala @@ -1381,7 +1381,7 @@ trait Trees extends api.Trees { self: SymbolTable => case Star(elem) => treeCopy.Star(tree, transform(elem)) case UnApply(fun, args) => - treeCopy.UnApply(tree, fun, transformTrees(args)) // bq: see test/.../unapplyContexts2.scala + treeCopy.UnApply(tree, transform(fun), transformTrees(args)) // bq: see test/.../unapplyContexts2.scala case ArrayValue(elemtpt, trees) => treeCopy.ArrayValue(tree, transform(elemtpt), transformTrees(trees)) case ApplyDynamic(qual, args) => |