diff options
author | Paul Phillips <paulp@improving.org> | 2013-06-07 16:38:13 -0700 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2013-06-07 16:38:13 -0700 |
commit | aefdbd3f923826c6efe87d6f5dbaa84095c090ce (patch) | |
tree | 5fda90b3f75949b5d947ceaef5f017e78f776bc2 /src/compiler | |
parent | 5312d6305530eb14d369d0f4acaf7ca4e278ea72 (diff) | |
parent | a45d3e5658a1ccb57d3b420eb36d84f7170404b5 (diff) | |
download | scala-aefdbd3f923826c6efe87d6f5dbaa84095c090ce.tar.gz scala-aefdbd3f923826c6efe87d6f5dbaa84095c090ce.tar.bz2 scala-aefdbd3f923826c6efe87d6f5dbaa84095c090ce.zip |
Merge pull request #2622 from scalamacros/pullrequest/paradise
Backport from paradise/macros
Diffstat (limited to 'src/compiler')
3 files changed, 21 insertions, 14 deletions
diff --git a/src/compiler/scala/reflect/macros/util/Helpers.scala b/src/compiler/scala/reflect/macros/util/Helpers.scala index ada8efa833..9b7680717e 100644 --- a/src/compiler/scala/reflect/macros/util/Helpers.scala +++ b/src/compiler/scala/reflect/macros/util/Helpers.scala @@ -54,7 +54,7 @@ trait Helpers { * * @see Metalevels.scala for more information and examples about metalevels */ - def increaseMetalevel(pre: Type, tp: Type): Type = dealiasAndRewrap(tp) { + def increaseMetalevel(pre: Type, tp: Type): Type = transparentShallowTransform(RepeatedParamClass, tp) { case tp => typeRef(pre, MacroContextExprClass, List(tp)) } @@ -64,8 +64,8 @@ trait Helpers { * * @see Metalevels.scala for more information and examples about metalevels */ - def decreaseMetalevel(tp: Type): Type = dealiasAndRewrap(tp) { + def decreaseMetalevel(tp: Type): Type = transparentShallowTransform(RepeatedParamClass, tp) { case ExprClassOf(runtimeType) => runtimeType - case _ => AnyClass.tpe // so that macro impls with rhs = ??? don't screw up our inference + case _ => AnyTpe // so that macro impls with rhs = ??? don't screw up our inference } }
\ No newline at end of file diff --git a/src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala b/src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala index fe1607c631..7fa199afaf 100644 --- a/src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala +++ b/src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala @@ -782,7 +782,7 @@ trait ContextErrors { } def MacroExpansionHasInvalidTypeError(expandee: Tree, expanded: Any) = { - val expected = "expr" + val expected = "expr or tree" val isPathMismatch = expanded != null && expanded.isInstanceOf[scala.reflect.api.Exprs#Expr[_]] macroExpansionError(expandee, s"macro must return a compiler-specific $expected; returned value is " + ( diff --git a/src/compiler/scala/tools/nsc/typechecker/Macros.scala b/src/compiler/scala/tools/nsc/typechecker/Macros.scala index 6c4d1e20aa..86ba3d2164 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Macros.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Macros.scala @@ -92,11 +92,12 @@ trait Macros extends FastTrack with MacroRuntimes with Traces with Helpers { methName: String, // flattens the macro impl's parameter lists having symbols replaced with their fingerprints // currently fingerprints are calculated solely from types of the symbols: - // * c.Expr[T] => IMPLPARAM_EXPR - // * c.WeakTypeTag[T] => index of the type parameter corresponding to that type tag - // * everything else (e.g. scala.reflect.macros.Context) => IMPLPARAM_OTHER + // * c.Expr[T] => LiftedTyped + // * c.Tree => LiftedUntyped + // * c.WeakTypeTag[T] => Tagged(index of the type parameter corresponding to that type tag) + // * everything else (e.g. scala.reflect.macros.Context) => Other // f.ex. for: def impl[T: WeakTypeTag, U, V: WeakTypeTag](c: Context)(x: c.Expr[T], y: c.Tree): (U, V) = ??? - // `signature` will be equal to List(List(Other), List(Lifted, Other), List(Tagged(0), Tagged(2))) + // `signature` will be equal to List(List(Other), List(LiftedTyped, LiftedUntyped), List(Tagged(0), Tagged(2))) signature: List[List[Fingerprint]], // type arguments part of a macro impl ref (the right-hand side of a macro definition) // these trees don't refer to a macro impl, so we can pickle them as is @@ -124,7 +125,7 @@ trait Macros extends FastTrack with MacroRuntimes with Traces with Helpers { * "className" = "Macros$")) */ object MacroImplBinding { - val versionFormat = 4.0 + val versionFormat = 5.0 def pickleAtom(obj: Any): Tree = obj match { @@ -164,7 +165,8 @@ trait Macros extends FastTrack with MacroRuntimes with Traces with Helpers { def signature: List[List[Fingerprint]] = { def fingerprint(tpe: Type): Fingerprint = tpe.dealiasWiden match { case TypeRef(_, RepeatedParamClass, underlying :: Nil) => fingerprint(underlying) - case ExprClassOf(_) => Lifted + case ExprClassOf(_) => LiftedTyped + case TreeType() => LiftedUntyped case _ => Other } @@ -388,7 +390,8 @@ trait Macros extends FastTrack with MacroRuntimes with Traces with Helpers { val wrappedArgs = mapWithIndex(args)((arg, j) => { val fingerprint = implParams(min(j, implParams.length - 1)) fingerprint match { - case Lifted => context.Expr[Nothing](arg)(TypeTag.Nothing) // TODO: SI-5752 + case LiftedTyped => context.Expr[Nothing](arg)(TypeTag.Nothing) // TODO: SI-5752 + case LiftedUntyped => arg case _ => abort(s"unexpected fingerprint $fingerprint in $binding with paramss being $paramss " + s"corresponding to arg $arg in $argss") } @@ -690,6 +693,7 @@ trait Macros extends FastTrack with MacroRuntimes with Traces with Helpers { } expanded match { case expanded: Expr[_] if expandee.symbol.isTermMacro => validateResultingTree(expanded.tree) + case expanded: Tree if expandee.symbol.isTermMacro => validateResultingTree(expanded) case _ => MacroExpansionHasInvalidTypeError(expandee, expanded) } } catch { @@ -804,10 +808,12 @@ class Fingerprint(val value: Int) extends AnyVal { def paramPos = { assert(isTag, this); value } def isTag = value >= 0 def isOther = this == Other - def isExpr = this == Lifted + def isExpr = this == LiftedTyped + def isTree = this == LiftedUntyped override def toString = this match { case Other => "Other" - case Lifted => "Expr" + case LiftedTyped => "Expr" + case LiftedUntyped => "Tree" case _ => s"Tag($value)" } } @@ -815,5 +821,6 @@ class Fingerprint(val value: Int) extends AnyVal { object Fingerprint { def Tagged(tparamPos: Int) = new Fingerprint(tparamPos) val Other = new Fingerprint(-1) - val Lifted = new Fingerprint(-2) + val LiftedTyped = new Fingerprint(-2) + val LiftedUntyped = new Fingerprint(-3) } |