From 504b5f3b157de639633c962ea21f7e89152da77f Mon Sep 17 00:00:00 2001 From: Vlad Ureche Date: Mon, 8 Jul 2013 13:32:40 +0200 Subject: SI-7638 Superaccessor lookup after specialization The crash was caused by a symbol lookup to rewire the super calls, done after pickler, but specialization added new traits and new members, thus making the super rewiring impossible. To avoid such problems, this patch moves symbol lookup after specialization, so the changes done by specialization (and miniboxing) become visible to mixin. NOTE: This patch will be followed by a similar patch to master. Review by @adriaanm or @retronym. --- test/files/pos/SI-7638.scala | 51 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 test/files/pos/SI-7638.scala (limited to 'test/files/pos') diff --git a/test/files/pos/SI-7638.scala b/test/files/pos/SI-7638.scala new file mode 100644 index 0000000000..da16e0bd2c --- /dev/null +++ b/test/files/pos/SI-7638.scala @@ -0,0 +1,51 @@ +package miniboxing.tests.compile + +trait Ordering[@specialized(Int) A] { + def eqv(x: Array[A], y: Array[A]): Boolean = false +} + +trait ArrayVectorOrder[@specialized(Int) A] extends Ordering[A] { + override def eqv(x: Array[A], y: Array[A]): Boolean = super.eqv(x, y) +} + +object vectorOrder { + implicit def arrayOrder[@specialized(Int) A]() = + /* + * Before applying patch: + * + * while compiling: SI-7638.scala + * during phase: mixin + * library version: version 2.10.3-20130625-164027-d22e8d282c + * compiler version: version 2.10.3-20130627-153946-54cb6af7db + * reconstructed args: + * + * last tree to typer: TypeTree(class Array) + * symbol: class Array in package scala (flags: final) + * symbol definition: final class Array[T >: ? <: ?] extends Object + * tpe: Array[Int] + * symbol owners: class Array -> package scala + * context owners: anonymous class anon$1 -> package compile + * + * == Expanded type of tree == + * + * TypeRef( + * TypeSymbol(final class Array[T >: ? <: ?] extends Object) + * args = List(TypeRef(TypeSymbol(final abstract class Int extends ))) + * ) + * + * unhandled exception while transforming SI-7638.scala + * error: uncaught exception during compilation: java.lang.UnsupportedOperationException + * error: java.lang.UnsupportedOperationException: tail of empty list + * at scala.collection.immutable.Nil$.tail(List.scala:339) + * at scala.collection.immutable.Nil$.tail(List.scala:334) + * at scala.tools.nsc.transform.Mixin$$anonfun$scala$tools$nsc$transform$Mixin$$rebindSuper$1.apply(Mixin.scala:123) + * at scala.tools.nsc.transform.Mixin$$anonfun$scala$tools$nsc$transform$Mixin$$rebindSuper$1.apply(Mixin.scala:122) + * at scala.reflect.internal.SymbolTable.atPhase(SymbolTable.scala:207) + * at scala.reflect.internal.SymbolTable.afterPhase(SymbolTable.scala:216) + * at scala.tools.nsc.Global.afterPickler(Global.scala:1104) + * at scala.tools.nsc.transform.Mixin.scala$tools$nsc$transform$Mixin$$rebindSuper(Mixin.scala:122) + * at scala.tools.nsc.transform.Mixin$$anonfun$scala$tools$nsc$transform$Mixin$$mixinTraitMembers$1$1.apply(Mixin.scala:339) + * at scala.tools.nsc.transform.Mixin$$anonfun$scala$tools$nsc$transform$Mixin$$mixinTraitMembers$1$1.apply(Mixin.scala:292) + */ + new ArrayVectorOrder[A] { } +} -- cgit v1.2.3 From 6368ae7218c0af651f74a566f718a8b03a547ba2 Mon Sep 17 00:00:00 2001 From: Jason Zaugg Date: Thu, 11 Jul 2013 12:15:35 +1000 Subject: SI-7649 Fix positions for reshaped tag materializers Calls to `materializeClassTag[T]` are replaced during reification with `implicitly[ClassTag[T]]` in the `reify` macro. This is done to avoid referring to symbols in scala-compiler.jar. Class- and Type-Tag materialization is treated in the same way. This commit positions the replacement trees to avoid triggering assertions under -Yrangepos. --- .../scala/reflect/reify/phases/Reshape.scala | 16 ++++++++-------- test/files/pos/t7649.flags | 1 + test/files/pos/t7649.scala | 20 ++++++++++++++++++++ 3 files changed, 29 insertions(+), 8 deletions(-) create mode 100644 test/files/pos/t7649.flags create mode 100644 test/files/pos/t7649.scala (limited to 'test/files/pos') diff --git a/src/compiler/scala/reflect/reify/phases/Reshape.scala b/src/compiler/scala/reflect/reify/phases/Reshape.scala index a320718084..535a933c73 100644 --- a/src/compiler/scala/reflect/reify/phases/Reshape.scala +++ b/src/compiler/scala/reflect/reify/phases/Reshape.scala @@ -91,20 +91,20 @@ trait Reshape { private def undoMacroExpansion(tree: Tree): Tree = tree.attachments.get[MacroExpansionAttachment] match { case Some(MacroExpansionAttachment(original)) => + def mkImplicitly(tp: Type) = atPos(tree.pos)( + gen.mkNullaryCall(Predef_implicitly, List(tp)) + ) + val sym = original.symbol original match { // this hack is necessary until I fix implicit macros // so far tag materialization is implemented by sneaky macros hidden in scala-compiler.jar // hence we cannot reify references to them, because noone will be able to see them later // when implicit macros are fixed, these sneaky macros will move to corresponding companion objects // of, say, ClassTag or TypeTag - case Apply(TypeApply(_, List(tt)), _) if original.symbol == materializeClassTag => - gen.mkNullaryCall(Predef_implicitly, List(appliedType(ClassTagClass, tt.tpe))) - case Apply(TypeApply(_, List(tt)), List(pre)) if original.symbol == materializeWeakTypeTag => - gen.mkNullaryCall(Predef_implicitly, List(typeRef(pre.tpe, WeakTypeTagClass, List(tt.tpe)))) - case Apply(TypeApply(_, List(tt)), List(pre)) if original.symbol == materializeTypeTag => - gen.mkNullaryCall(Predef_implicitly, List(typeRef(pre.tpe, TypeTagClass, List(tt.tpe)))) - case _ => - original + case Apply(TypeApply(_, List(tt)), _) if sym == materializeClassTag => mkImplicitly(appliedType(ClassTagClass, tt.tpe)) + case Apply(TypeApply(_, List(tt)), List(pre)) if sym == materializeWeakTypeTag => mkImplicitly(typeRef(pre.tpe, WeakTypeTagClass, List(tt.tpe))) + case Apply(TypeApply(_, List(tt)), List(pre)) if sym == materializeTypeTag => mkImplicitly(typeRef(pre.tpe, TypeTagClass, List(tt.tpe))) + case _ => original } case _ => tree } diff --git a/test/files/pos/t7649.flags b/test/files/pos/t7649.flags new file mode 100644 index 0000000000..fcf951d907 --- /dev/null +++ b/test/files/pos/t7649.flags @@ -0,0 +1 @@ +-Yrangepos \ No newline at end of file diff --git a/test/files/pos/t7649.scala b/test/files/pos/t7649.scala new file mode 100644 index 0000000000..a1b02f63f1 --- /dev/null +++ b/test/files/pos/t7649.scala @@ -0,0 +1,20 @@ +object Test { + val c: reflect.macros.Context = ??? + import c.universe._ + reify { + // The lookup of the implicit WeakTypeTag[Any] + // was triggering an unpositioned tree. + c.Expr[Any](Literal(Constant(0))).splice + } + + import scala.reflect.ClassTag + def ct[A: ClassTag]: Expr[A] = ??? + def tt[A: TypeTag]: Expr[A] = ??? + def wtt[A: WeakTypeTag]: Expr[A] = ??? + + reify { + ct[String].splice + tt[String].splice + wtt[String].splice + } +} -- cgit v1.2.3