From 814cf34fb00f9ccb001249f4b3445ebc4f9942c9 Mon Sep 17 00:00:00 2001 From: Eugene Burmako Date: Thu, 12 Apr 2012 01:59:46 +0200 Subject: Next generation of macros Implements SIP 16: Self-cleaning macros: http://bit.ly/wjjXTZ Features: * Macro defs * Reification * Type tags * Manifests aliased to type tags * Extended reflection API * Several hundred tests * 1111 changed files Not yet implemented: * Reification of refined types * Expr.value splicing * Named and default macro expansions * Intricacies of interaction between macros and implicits * Emission of debug information for macros (compliant with JSR-45) Dedicated to Yuri Alekseyevich Gagarin --- test/files/neg/t3507.check | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'test/files/neg/t3507.check') diff --git a/test/files/neg/t3507.check b/test/files/neg/t3507.check index 8e538e4a8b..6b6df6ba76 100644 --- a/test/files/neg/t3507.check +++ b/test/files/neg/t3507.check @@ -1,4 +1,4 @@ -t3507.scala:13: error: No Manifest available for _1.b.c.type. - mani/*[object _1.b.c]*/(c) // kaboom in manifestOfType / TreeGen.mkAttributedQualifier - ^ -one error found +t3507.scala:13: error: No GroundTypeTag available for _1.b.c.type + mani/*[object _1.b.c]*/(c) // kaboom in manifestOfType / TreeGen.mkAttributedQualifier + ^ +one error found -- cgit v1.2.3 From 46d0d73f66111d5d31b9fd593972970d7e9056bb Mon Sep 17 00:00:00 2001 From: Eugene Burmako Date: Thu, 12 Apr 2012 11:32:31 +0200 Subject: GroundTypeTag => ConcreteTypeTag --- lib/scala-compiler.jar.desired.sha1 | 2 +- lib/scala-library.jar.desired.sha1 | 2 +- .../scala/reflect/internal/Definitions.scala | 22 +-- src/compiler/scala/reflect/internal/StdNames.scala | 4 +- .../scala/reflect/makro/runtime/Reifiers.scala | 8 +- src/compiler/scala/reflect/reify/Errors.scala | 4 +- src/compiler/scala/reflect/reify/Reifiers.scala | 6 +- .../scala/reflect/reify/codegen/Types.scala | 20 +-- src/compiler/scala/reflect/reify/package.scala | 6 +- .../scala/tools/nsc/typechecker/Implicits.scala | 4 +- .../scala/tools/nsc/typechecker/Macros.scala | 2 +- .../scala/tools/nsc/typechecker/Typers.scala | 2 +- src/library/scala/Predef.scala | 26 ++-- src/library/scala/reflect/ClassTags.scala | 15 +- src/library/scala/reflect/TagMaterialization.scala | 42 +++--- .../scala/reflect/api/StandardDefinitions.scala | 4 +- src/library/scala/reflect/api/TypeTags.scala | 153 +++++++++++---------- src/library/scala/reflect/makro/Aliases.scala | 4 +- src/library/scala/reflect/makro/Reifiers.scala | 2 +- .../scala/reflect/makro/internal/typeTagImpl.scala | 18 +-- src/library/scala/reflect/package.scala | 16 +-- ...o-reify-groundtypetag-hktypeparams-notags.check | 8 +- .../Test.scala | 4 +- ...cro-reify-groundtypetag-typeparams-notags.check | 8 +- .../Test.scala | 4 +- .../neg/macro-reify-groundtypetag-usetypetag.check | 8 +- .../Test.scala | 4 +- test/files/neg/t3507.check | 2 +- test/files/neg/t3692.check | 4 +- test/files/run/groundtypetags_core.check | 30 ++-- test/files/run/groundtypetags_core.scala | 60 ++++---- test/files/run/macro-expand-nullary-generic.check | 10 +- test/files/run/macro-expand-tparams-explicit.check | 2 +- test/files/run/macro-expand-tparams-implicit.check | 4 +- test/files/run/macro-expand-tparams-prefix-a.check | 8 +- test/files/run/macro-expand-tparams-prefix-b.check | 4 +- .../files/run/macro-expand-tparams-prefix-c1.check | 6 +- .../files/run/macro-expand-tparams-prefix-c2.check | 6 +- .../files/run/macro-expand-tparams-prefix-d1.check | 2 +- .../macro-reify-groundtypetag-notypeparams.check | 4 +- .../Test.scala | 4 +- ...macro-reify-groundtypetag-typeparams-tags.check | 4 +- .../Test.scala | 6 +- .../run/macro-reify-typetag-notypeparams.check | 4 +- .../macro-reify-typetag-typeparams-notags.check | 4 +- .../run/macro-reify-typetag-typeparams-tags.check | 4 +- .../run/macro-reify-typetag-usegroundtypetag.check | 4 +- .../Test.scala | 2 +- .../files/run/macro-typecheck-macrosdisabled.check | 2 +- test/files/run/macro-undetparams-consfromsls.check | 6 +- test/files/run/macro-undetparams-implicitval.check | 2 +- test/files/run/macro-undetparams-macroitself.check | 4 +- test/files/run/primitive-sigs-2.check | 2 +- test/files/run/reify_newimpl_25.check | 2 +- test/files/run/reify_newimpl_26.check | 2 +- .../run/toolbox_typecheck_macrosdisabled.check | 2 +- test/files/run/typetags_core.check | 30 ++-- .../Test.scala | 6 +- 58 files changed, 320 insertions(+), 310 deletions(-) (limited to 'test/files/neg/t3507.check') diff --git a/lib/scala-compiler.jar.desired.sha1 b/lib/scala-compiler.jar.desired.sha1 index d74b6353d9..3f94b85db9 100644 --- a/lib/scala-compiler.jar.desired.sha1 +++ b/lib/scala-compiler.jar.desired.sha1 @@ -1 +1 @@ -d2808836aef2cbee506f9b0b0e346c749cac9ad8 ?scala-compiler.jar +82af2cfc6a81ae12f39c55c9cf684c5ec01971d3 ?scala-compiler.jar diff --git a/lib/scala-library.jar.desired.sha1 b/lib/scala-library.jar.desired.sha1 index 78e9f0b593..bf1f4829f2 100644 --- a/lib/scala-library.jar.desired.sha1 +++ b/lib/scala-library.jar.desired.sha1 @@ -1 +1 @@ -752baeeb4a01c7c50ac0dc6e0f59f5598696a223 ?scala-library.jar +6a58ca2e4398623145c179f4ce215bfb86a065c4 ?scala-library.jar diff --git a/src/compiler/scala/reflect/internal/Definitions.scala b/src/compiler/scala/reflect/internal/Definitions.scala index b1c822ed97..12b083b4f6 100644 --- a/src/compiler/scala/reflect/internal/Definitions.scala +++ b/src/compiler/scala/reflect/internal/Definitions.scala @@ -477,16 +477,16 @@ trait Definitions extends reflect.api.StandardDefinitions { def ExprValue = getMember(ExprClass, nme.value) lazy val ExprModule = getMember(getRequiredClass("scala.reflect.api.Exprs"), nme.Expr) - lazy val ClassTagClass = getRequiredClass("scala.reflect.ClassTag") - def ClassTagErasure = getMember(ClassTagClass, nme.erasure) - def ClassTagTpe = getMember(ClassTagClass, nme.tpe) - lazy val ClassTagModule = getRequiredModule("scala.reflect.ClassTag") - lazy val TypeTagsClass = getRequiredClass("scala.reflect.api.TypeTags") - lazy val TypeTagClass = getMember(TypeTagsClass, tpnme.TypeTag) - def TypeTagTpe = getMember(TypeTagClass, nme.tpe) - lazy val TypeTagModule = getMember(TypeTagsClass, nme.TypeTag) - lazy val GroundTypeTagClass = getMember(TypeTagsClass, tpnme.GroundTypeTag) - lazy val GroundTypeTagModule = getMember(TypeTagsClass, nme.GroundTypeTag) + lazy val ClassTagClass = getRequiredClass("scala.reflect.ClassTag") + def ClassTagErasure = getMember(ClassTagClass, nme.erasure) + def ClassTagTpe = getMember(ClassTagClass, nme.tpe) + lazy val ClassTagModule = getRequiredModule("scala.reflect.ClassTag") + lazy val TypeTagsClass = getRequiredClass("scala.reflect.api.TypeTags") + lazy val TypeTagClass = getMember(TypeTagsClass, tpnme.TypeTag) + def TypeTagTpe = getMember(TypeTagClass, nme.tpe) + lazy val TypeTagModule = getMember(TypeTagsClass, nme.TypeTag) + lazy val ConcreteTypeTagClass = getMember(TypeTagsClass, tpnme.ConcreteTypeTag) + lazy val ConcreteTypeTagModule = getMember(TypeTagsClass, nme.ConcreteTypeTag) lazy val MacroContextClass = getRequiredClass("scala.reflect.makro.Context") def MacroContextPrefix = getMember(MacroContextClass, nme.prefix) @@ -497,7 +497,7 @@ trait Definitions extends reflect.api.StandardDefinitions { lazy val MacroInternalPackage = getPackageObject("scala.reflect.makro.internal") def MacroInternal_materializeClassTag = getMember(MacroInternalPackage, nme.materializeClassTag) def MacroInternal_materializeTypeTag = getMember(MacroInternalPackage, nme.materializeTypeTag) - def MacroInternal_materializeGroundTypeTag = getMember(MacroInternalPackage, nme.materializeGroundTypeTag) + def MacroInternal_materializeConcreteTypeTag = getMember(MacroInternalPackage, nme.materializeConcreteTypeTag) lazy val ScalaSignatureAnnotation = getRequiredClass("scala.reflect.ScalaSignature") lazy val ScalaLongSignatureAnnotation = getRequiredClass("scala.reflect.ScalaLongSignature") diff --git a/src/compiler/scala/reflect/internal/StdNames.scala b/src/compiler/scala/reflect/internal/StdNames.scala index b72610f1e0..1666887133 100644 --- a/src/compiler/scala/reflect/internal/StdNames.scala +++ b/src/compiler/scala/reflect/internal/StdNames.scala @@ -126,7 +126,7 @@ trait StdNames extends NameManglers { self: SymbolTable => final val Symbol: NameType = "Symbol" final val ClassTag: NameType = "ClassTag" final val TypeTag : NameType = "TypeTag" - final val GroundTypeTag: NameType = "GroundTypeTag" + final val ConcreteTypeTag: NameType = "ConcreteTypeTag" // fictions we use as both types and terms final val ERROR: NameType = "" @@ -396,7 +396,7 @@ trait StdNames extends NameManglers { self: SymbolTable => val map: NameType = "map" val materializeClassTag: NameType = "materializeClassTag" val materializeTypeTag: NameType = "materializeTypeTag" - val materializeGroundTypeTag: NameType = "materializeGroundTypeTag" + val materializeConcreteTypeTag: NameType = "materializeConcreteTypeTag" val mirror : NameType = "mirror" val moduleClass : NameType = "moduleClass" val name: NameType = "name" diff --git a/src/compiler/scala/reflect/makro/runtime/Reifiers.scala b/src/compiler/scala/reflect/makro/runtime/Reifiers.scala index 826fa7153f..2488b06d6c 100644 --- a/src/compiler/scala/reflect/makro/runtime/Reifiers.scala +++ b/src/compiler/scala/reflect/makro/runtime/Reifiers.scala @@ -21,16 +21,16 @@ trait Reifiers { def reifyTree(prefix: Tree, tree: Tree): Tree = reifyTopLevel(prefix, tree) - def reifyType(prefix: Tree, tpe: Type, dontSpliceAtTopLevel: Boolean = false, noTypeVariablesInResult: Boolean = false): Tree = - reifyTopLevel(prefix, tpe, dontSpliceAtTopLevel, noTypeVariablesInResult) + def reifyType(prefix: Tree, tpe: Type, dontSpliceAtTopLevel: Boolean = false, requireConcreteTypeTag: Boolean = false): Tree = + reifyTopLevel(prefix, tpe, dontSpliceAtTopLevel, requireConcreteTypeTag) def unreifyTree(tree: Tree): Tree = Select(tree, definitions.ExprEval) - def reifyTopLevel(prefix: Tree, reifee: Any, dontSpliceAtTopLevel: Boolean = false, requireGroundTypeTag: Boolean = false): Tree = { + def reifyTopLevel(prefix: Tree, reifee: Any, dontSpliceAtTopLevel: Boolean = false, requireConcreteTypeTag: Boolean = false): Tree = { // [Eugene] the plumbing is not very pretty, but anyways factoring out the reifier seems like a necessary step to me import scala.reflect.reify._ - val reifier = mkReifier(mirror)(callsiteTyper, prefix, reifee, dontSpliceAtTopLevel, requireGroundTypeTag) + val reifier = mkReifier(mirror)(callsiteTyper, prefix, reifee, dontSpliceAtTopLevel, requireConcreteTypeTag) try { val result = reifier.reified diff --git a/src/compiler/scala/reflect/reify/Errors.scala b/src/compiler/scala/reflect/reify/Errors.scala index 8bfe64621b..30c6c06c7b 100644 --- a/src/compiler/scala/reflect/reify/Errors.scala +++ b/src/compiler/scala/reflect/reify/Errors.scala @@ -33,8 +33,8 @@ trait Errors { throw new ReificationError(defaultErrorPosition, msg) } - def CannotReifyGroundTypeTagHavingUnresolvedTypeParameters(tpe: Type) = { - val msg = "cannot reify GroundTypeTag having unresolved type parameter %s".format(tpe) + def CannotReifyConcreteTypeTagHavingUnresolvedTypeParameters(tpe: Type) = { + val msg = "cannot reify ConcreteTypeTag having unresolved type parameter %s".format(tpe) throw new ReificationError(defaultErrorPosition, msg) } diff --git a/src/compiler/scala/reflect/reify/Reifiers.scala b/src/compiler/scala/reflect/reify/Reifiers.scala index 6854710949..16c26734b2 100644 --- a/src/compiler/scala/reflect/reify/Reifiers.scala +++ b/src/compiler/scala/reflect/reify/Reifiers.scala @@ -21,7 +21,7 @@ abstract class Reifier extends Phases val prefix: Tree val reifee: Any val dontSpliceAtTopLevel: Boolean - val requireGroundTypeTag: Boolean + val requireConcreteTypeTag: Boolean /** * For ``reifee'' and other reification parameters, generate a tree of the form @@ -74,7 +74,7 @@ abstract class Reifier extends Phases val manifestedType = typer.packedType(tree, NoSymbol) val manifestedRtype = reifyType(manifestedType) - val tagModule = if (definitelyGround) GroundTypeTagModule else TypeTagModule + val tagModule = if (definitelyConcrete) ConcreteTypeTagModule else TypeTagModule var typeTagCtor = TypeApply(Select(Ident(nme.MIRROR_SHORT), tagModule.name), List(TypeTree(manifestedType))) var exprCtor = TypeApply(Select(Ident(nme.MIRROR_SHORT), ExprModule.name), List(TypeTree(manifestedType))) Apply(Apply(exprCtor, List(rtree)), List(Apply(typeTagCtor, List(manifestedRtype)))) @@ -85,7 +85,7 @@ abstract class Reifier extends Phases val rtree = reify(tpe) val manifestedType = tpe - var tagModule = if (definitelyGround) GroundTypeTagModule else TypeTagModule + var tagModule = if (definitelyConcrete) ConcreteTypeTagModule else TypeTagModule var ctor = TypeApply(Select(Ident(nme.MIRROR_SHORT), tagModule.name), List(TypeTree(manifestedType))) Apply(ctor, List(rtree)) diff --git a/src/compiler/scala/reflect/reify/codegen/Types.scala b/src/compiler/scala/reflect/reify/codegen/Types.scala index 6f3a60a076..9bc113e8a4 100644 --- a/src/compiler/scala/reflect/reify/codegen/Types.scala +++ b/src/compiler/scala/reflect/reify/codegen/Types.scala @@ -67,8 +67,8 @@ trait Types { private var spliceTypesEnabled = !dontSpliceAtTopLevel /** Keeps track of whether this reification contains abstract type parameters */ - var maybeGround = true - var definitelyGround = true + var maybeConcrete = true + var definitelyConcrete = true def eligibleForSplicing(tpe: Type): Boolean = { // [Eugene] is this comprehensive? @@ -88,7 +88,7 @@ trait Types { if (reifyDebug) println("splicing " + tpe) if (spliceTypesEnabled) { - var tagClass = if (requireGroundTypeTag) GroundTypeTagClass else TypeTagClass + var tagClass = if (requireConcreteTypeTag) ConcreteTypeTagClass else TypeTagClass val tagTpe = singleType(prefix.tpe, prefix.tpe member tagClass.name) // [Eugene] this should be enough for an abstract type, right? @@ -99,16 +99,16 @@ trait Types { // to find out the whereabouts of the error run scalac with -Ydebug if (reifyDebug) println("launching implicit search for %s.%s[%s]".format(prefix, tagClass.name, tpe)) val positionBearer = mirror.analyzer.openMacros.find(c => c.macroApplication.pos != NoPosition).map(_.macroApplication).getOrElse(EmptyTree).asInstanceOf[Tree] - typer.resolveTypeTag(positionBearer, prefix.tpe, tpe, requireGroundTypeTag) match { + typer.resolveTypeTag(positionBearer, prefix.tpe, tpe, requireConcreteTypeTag) match { case failure if failure.isEmpty => if (reifyDebug) println("implicit search was fruitless") - definitelyGround &= false - maybeGround &= false + definitelyConcrete &= false + maybeConcrete &= false EmptyTree case success => if (reifyDebug) println("implicit search has produced a result: " + success) - definitelyGround |= requireGroundTypeTag - maybeGround |= true + definitelyConcrete |= requireConcreteTypeTag + maybeConcrete |= true var splice = Select(success, nme.tpe) splice match { case InlinedTypeSplice(_, inlinedSymbolTable, tpe) => @@ -126,8 +126,8 @@ trait Types { if (reifyDebug) println("splicing has been cancelled: spliceTypesEnabled = false") } - if (requireGroundTypeTag) - CannotReifyGroundTypeTagHavingUnresolvedTypeParameters(tpe) + if (requireConcreteTypeTag) + CannotReifyConcreteTypeTagHavingUnresolvedTypeParameters(tpe) } spliceTypesEnabled = true diff --git a/src/compiler/scala/reflect/reify/package.scala b/src/compiler/scala/reflect/reify/package.scala index 7041fbf6ed..85cf92fe2f 100644 --- a/src/compiler/scala/reflect/reify/package.scala +++ b/src/compiler/scala/reflect/reify/package.scala @@ -3,12 +3,12 @@ package scala.reflect import scala.tools.nsc.Global package object reify { - def mkReifier(global: Global)(typer: global.analyzer.Typer, prefix: global.Tree, reifee: Any, dontSpliceAtTopLevel: Boolean = false, requireGroundTypeTag: Boolean = false): Reifier { val mirror: global.type } = { + def mkReifier(global: Global)(typer: global.analyzer.Typer, prefix: global.Tree, reifee: Any, dontSpliceAtTopLevel: Boolean = false, requireConcreteTypeTag: Boolean = false): Reifier { val mirror: global.type } = { val typer1: typer.type = typer val prefix1: prefix.type = prefix val reifee1 = reifee val dontSpliceAtTopLevel1 = dontSpliceAtTopLevel - val requireGroundTypeTag1 = requireGroundTypeTag + val requireConcreteTypeTag1 = requireConcreteTypeTag new { val mirror: global.type = global @@ -16,7 +16,7 @@ package object reify { val prefix = prefix1 val reifee = reifee1 val dontSpliceAtTopLevel = dontSpliceAtTopLevel1 - val requireGroundTypeTag = requireGroundTypeTag1 + val requireConcreteTypeTag = requireConcreteTypeTag1 } with Reifier } } diff --git a/src/compiler/scala/tools/nsc/typechecker/Implicits.scala b/src/compiler/scala/tools/nsc/typechecker/Implicits.scala index 8aa257983a..3a789b83b6 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Implicits.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Implicits.scala @@ -1099,11 +1099,11 @@ trait Implicits { } // these should be lazy, otherwise we wouldn't be able to compile scala-library with starr - private val TagSymbols = Set(ClassTagClass, TypeTagClass, GroundTypeTagClass) + private val TagSymbols = Set(ClassTagClass, TypeTagClass, ConcreteTypeTagClass) private val TagMaterializers = Map( ClassTagClass -> MacroInternal_materializeClassTag, TypeTagClass -> MacroInternal_materializeTypeTag, - GroundTypeTagClass -> MacroInternal_materializeGroundTypeTag + ConcreteTypeTagClass -> MacroInternal_materializeConcreteTypeTag ) def tagOfType(pre: Type, tp: Type, tagClass: Symbol): SearchResult = { diff --git a/src/compiler/scala/tools/nsc/typechecker/Macros.scala b/src/compiler/scala/tools/nsc/typechecker/Macros.scala index 3b270a92ad..9608108a0d 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Macros.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Macros.scala @@ -877,7 +877,7 @@ trait Macros { self: Analyzer => tpe }) map (tpe => { val ttag = TypeTag(tpe) - if (ttag.isGround) ttag.toGround else ttag + if (ttag.isConcrete) ttag.toConcrete else ttag }) argss = argss.dropRight(1) :+ (evidences ++ argss.last) diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index 1b508a96fe..5d9b8ae94a 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -5020,7 +5020,7 @@ trait Typers extends Modes with Adaptations with PatMatVirtualiser { def resolveTypeTag(tree: Tree, pre: Type, tp: Type, full: Boolean): Tree = beforeTyper { inferImplicit( EmptyTree, - appliedType(singleType(pre, pre member (if (full) GroundTypeTagClass else TypeTagClass).name), List(tp)), + appliedType(singleType(pre, pre member (if (full) ConcreteTypeTagClass else TypeTagClass).name), List(tp)), /*reportAmbiguous =*/ true, /*isView =*/ false, /*context =*/ context, diff --git a/src/library/scala/Predef.scala b/src/library/scala/Predef.scala index d241d2ddc0..837ce96baa 100644 --- a/src/library/scala/Predef.scala +++ b/src/library/scala/Predef.scala @@ -103,12 +103,12 @@ object Predef extends LowPriorityImplicits { type ClassManifest[T] = scala.reflect.ClassManifest[T] @deprecated("OptManifest is no longer supported and using it may lead to incorrect results, use `@scala.reflect.TypeTag` instead", "2.10.0") type OptManifest[T] = scala.reflect.OptManifest[T] - @deprecated("Use `@scala.reflect.GroundTypeTag` instead", "2.10.0") + @deprecated("Use `@scala.reflect.ConcreteTypeTag` instead", "2.10.0") type Manifest[T] = scala.reflect.Manifest[T] @deprecated("Use `@scala.reflect.ClassTag` instead", "2.10.0") val ClassManifest = scala.reflect.ClassManifest // [Paul to Eugene] No lazy vals in Predef. Too expensive. Have to work harder on breaking initialization dependencies. - @deprecated("Use `@scala.reflect.GroundTypeTag` instead", "2.10.0") + @deprecated("Use `@scala.reflect.ConcreteTypeTag` instead", "2.10.0") lazy val Manifest = scala.reflect.Manifest // needs to be lazy, because requires scala.reflect.mirror instance @deprecated("NoManifest is no longer supported and using it may lead to incorrect results, use `@scala.reflect.TypeTag` instead", "2.10.0") lazy val NoManifest = scala.reflect.NoManifest // needs to be lazy, because requires scala.reflect.mirror instance @@ -118,20 +118,20 @@ object Predef extends LowPriorityImplicits { def optManifest[T](implicit m: OptManifest[T]) = m // Tag types and companions, and incantations for summoning - type ClassTag[T] = scala.reflect.ClassTag[T] - type TypeTag[T] = scala.reflect.TypeTag[T] - type GroundTypeTag[T] = scala.reflect.GroundTypeTag[T] - val ClassTag = scala.reflect.ClassTag // doesn't need to be lazy, because it's not a path-dependent type + type ClassTag[T] = scala.reflect.ClassTag[T] + type TypeTag[T] = scala.reflect.TypeTag[T] + type ConcreteTypeTag[T] = scala.reflect.ConcreteTypeTag[T] + val ClassTag = scala.reflect.ClassTag // doesn't need to be lazy, because it's not a path-dependent type // [Paul to Eugene] No lazy vals in Predef. Too expensive. Have to work harder on breaking initialization dependencies. - lazy val TypeTag = scala.reflect.TypeTag // needs to be lazy, because requires scala.reflect.mirror instance - lazy val GroundTypeTag = scala.reflect.GroundTypeTag + lazy val TypeTag = scala.reflect.TypeTag // needs to be lazy, because requires scala.reflect.mirror instance + lazy val ConcreteTypeTag = scala.reflect.ConcreteTypeTag // [Eugene to Martin] it's really tedious to type "implicitly[...]" all the time, so I'm reintroducing these shortcuts - def classTag[T](implicit ctag: ClassTag[T]) = ctag - def tag[T](implicit ttag: TypeTag[T]) = ttag - def typeTag[T](implicit ttag: TypeTag[T]) = ttag - def groundTag[T](implicit gttag: GroundTypeTag[T]) = gttag - def groundTypeTag[T](implicit gttag: GroundTypeTag[T]) = gttag + def classTag[T](implicit ctag: ClassTag[T]) = ctag + def tag[T](implicit ttag: TypeTag[T]) = ttag + def typeTag[T](implicit ttag: TypeTag[T]) = ttag + def concreteTag[T](implicit cttag: ConcreteTypeTag[T]) = cttag + def concreteTypeTag[T](implicit cttag: ConcreteTypeTag[T]) = cttag // Minor variations on identity functions def identity[A](x: A): A = x // @see `conforms` for the implicit version diff --git a/src/library/scala/reflect/ClassTags.scala b/src/library/scala/reflect/ClassTags.scala index 2833e7cc8e..cde6da5539 100644 --- a/src/library/scala/reflect/ClassTags.scala +++ b/src/library/scala/reflect/ClassTags.scala @@ -4,11 +4,20 @@ import java.lang.{ Class => jClass } import scala.reflect.{ mirror => rm } /** A `ClassTag[T]` wraps a Java class, which can be accessed via the `erasure` method. + * * This is useful in itself, but also enables very important use case. * Having this knowledge ClassTag can instantiate `Arrays` * in those cases where the element type is unknown at compile time. * Hence, ClassTag[T] conforms to the ArrayTag[T] trait. - */ + * + * If an implicit value of type u.ClassTag[T] is required, the compiler will make one up on demand. + * The implicitly created value contains in its erasure field the Java class that is the result of erasing type T. + * In that value, any occurrences of type parameters or abstract types U which come themselves with a ClassTag + * or a reflect.mirror.ConcreteTypeTag are represented by the type referenced by that tag. + * If the type T contains unresolved references to type parameters or abstract types, a static error results. + * + * A ConcreteTypeTag member of the reflect.mirror object is convertible to a ClassTag via an implicit conversion + * (this is not possible to do in all reflection universes because an operation that converts a type to a Java class might not be available). */ // please, don't add any APIs here, like it was with `newWrappedArray` and `newArrayBuilder` // class tags, and all tags in general, should be as minimalistic as possible @annotation.implicitNotFound(msg = "No ClassTag available for ${T}") @@ -20,7 +29,7 @@ abstract case class ClassTag[T](erasure: jClass[_]) extends ArrayTag[T] { /** A Scala reflection type representing T. * For ClassTags this representation is lossy (in their case tpe is retrospectively constructed from erasure). - * For TypeTags and GroundTypeTags the representation is almost precise, because it uses reification + * For TypeTags and ConcreteTypeTags the representation is almost precise, because they use reification * (information is lost only when T refers to non-locatable symbols, which are then reified as free variables). */ def tpe: rm.Type = rm.classToType(erasure) @@ -153,6 +162,6 @@ class DeprecatedClassManifestApis[T](ctag: ClassTag[T]) { @deprecated("Use `@scala.collection.mutable.ArrayBuilder` object instead", "2.10.0") def newArrayBuilder(): ArrayBuilder[T] = ArrayBuilder.make[T]()(ctag) - @deprecated("`typeArguments` is no longer supported, and will always return an empty list. Use `@scala.reflect.TypeTag` or `@scala.reflect.GroundTypeTag` to capture and analyze type arguments", "2.10.0") + @deprecated("`typeArguments` is no longer supported, and will always return an empty list. Use `@scala.reflect.TypeTag` or `@scala.reflect.ConcreteTypeTag` to capture and analyze type arguments", "2.10.0") def typeArguments: List[OptManifest[_]] = List() } \ No newline at end of file diff --git a/src/library/scala/reflect/TagMaterialization.scala b/src/library/scala/reflect/TagMaterialization.scala index 991feb3bac..5918b6effc 100644 --- a/src/library/scala/reflect/TagMaterialization.scala +++ b/src/library/scala/reflect/TagMaterialization.scala @@ -18,13 +18,13 @@ object TagMaterialization { def materializeTypeTag[T: c.TypeTag](c: Context { type PrefixType = Universe }): c.Expr[c.prefix.value.TypeTag[T]] = { import c.mirror._ val tpe = implicitly[c.TypeTag[T]].tpe - c.materializeTypeTag(tpe, requireGroundTypeTag = false) + c.materializeTypeTag(tpe, requireConcreteTypeTag = false) } - def materializeGroundTypeTag[T: c.TypeTag](c: Context { type PrefixType = Universe }): c.Expr[c.prefix.value.GroundTypeTag[T]] = { + def materializeConcreteTypeTag[T: c.TypeTag](c: Context { type PrefixType = Universe }): c.Expr[c.prefix.value.ConcreteTypeTag[T]] = { import c.mirror._ val tpe = implicitly[c.TypeTag[T]].tpe - c.materializeTypeTag(tpe, requireGroundTypeTag = true) + c.materializeTypeTag(tpe, requireConcreteTypeTag = true) } private implicit def context2utils(c0: Context) : Utils { val c: c0.type } = new { val c: c0.type = c0 } with Utils @@ -52,17 +52,17 @@ object TagMaterialization { NothingClass.asType -> newTermName("Nothing"), NullClass.asType -> newTermName("Null")) - val ReflectPackage = staticModule("scala.reflect.package") - val Reflect_mirror = selectTerm(ReflectPackage, "mirror") - val ClassTagClass = staticClass("scala.reflect.ClassTag") - val ClassTagErasure = selectTerm(ClassTagClass, "erasure") - val ClassTagModule = staticModule("scala.reflect.ClassTag") - val TypeTagsClass = staticClass("scala.reflect.api.TypeTags") - val TypeTagClass = selectType(TypeTagsClass, "TypeTag") - val TypeTagTpe = selectTerm(TypeTagClass, "tpe") - val TypeTagModule = selectTerm(TypeTagsClass, "TypeTag") - val GroundTypeTagClass = selectType(TypeTagsClass, "GroundTypeTag") - val GroundTypeTagModule = selectTerm(TypeTagsClass, "GroundTypeTag") + val ReflectPackage = staticModule("scala.reflect.package") + val Reflect_mirror = selectTerm(ReflectPackage, "mirror") + val ClassTagClass = staticClass("scala.reflect.ClassTag") + val ClassTagErasure = selectTerm(ClassTagClass, "erasure") + val ClassTagModule = staticModule("scala.reflect.ClassTag") + val TypeTagsClass = staticClass("scala.reflect.api.TypeTags") + val TypeTagClass = selectType(TypeTagsClass, "TypeTag") + val TypeTagTpe = selectTerm(TypeTagClass, "tpe") + val TypeTagModule = selectTerm(TypeTagsClass, "TypeTag") + val ConcreteTypeTagClass = selectType(TypeTagsClass, "ConcreteTypeTag") + val ConcreteTypeTagModule = selectTerm(TypeTagsClass, "ConcreteTypeTag") def materializeClassTag(tpe: Type): Tree = { val prefix = gen.mkAttributedRef(Reflect_mirror) setType singleType(Reflect_mirror.owner.thisPrefix, Reflect_mirror) @@ -70,8 +70,8 @@ object TagMaterialization { } def materializeClassTag(prefix: Tree, tpe: Type): Tree = { - val typetagInScope = c.inferImplicitValue(appliedType(typeRef(prefix.tpe, TypeTagClass, Nil), List(tpe))) - def typetagIsSynthetic(tree: Tree) = tree.isInstanceOf[Block] || (tree exists (sub => sub.symbol == TypeTagModule || sub.symbol == GroundTypeTagModule)) + val typetagInScope = c.inferImplicitValue(appliedType(typeRef(prefix.tpe, ConcreteTypeTagClass, Nil), List(tpe))) + def typetagIsSynthetic(tree: Tree) = tree.isInstanceOf[Block] || (tree exists (sub => sub.symbol == TypeTagModule || sub.symbol == ConcreteTypeTagModule)) typetagInScope match { case success if !success.isEmpty && !typetagIsSynthetic(success) => val factory = TypeApply(Select(Ident(ClassTagModule), newTermName("apply")), List(TypeTree(tpe))) @@ -104,19 +104,19 @@ object TagMaterialization { } } - def materializeTypeTag(tpe: Type, requireGroundTypeTag: Boolean): Tree = { + def materializeTypeTag(tpe: Type, requireConcreteTypeTag: Boolean): Tree = { def prefix: Tree = ??? // todo. needs to be synthesized from c.prefix - materializeTypeTag(prefix, tpe, requireGroundTypeTag) + materializeTypeTag(prefix, tpe, requireConcreteTypeTag) } - def materializeTypeTag(prefix: Tree, tpe: Type, requireGroundTypeTag: Boolean): Tree = { - val tagModule = if (requireGroundTypeTag) GroundTypeTagModule else TypeTagModule + def materializeTypeTag(prefix: Tree, tpe: Type, requireConcreteTypeTag: Boolean): Tree = { + val tagModule = if (requireConcreteTypeTag) ConcreteTypeTagModule else TypeTagModule val result = tpe match { case coreTpe if coreTags contains coreTpe => Select(Select(prefix, tagModule.name), coreTags(coreTpe)) case _ => - try c.reifyType(prefix, tpe, dontSpliceAtTopLevel = true, requireGroundTypeTag = requireGroundTypeTag) + try c.reifyType(prefix, tpe, dontSpliceAtTopLevel = true, requireConcreteTypeTag = requireConcreteTypeTag) catch { case ex: Throwable => // [Eugene] cannot pattern match on an abstract type, so had to do this diff --git a/src/library/scala/reflect/api/StandardDefinitions.scala b/src/library/scala/reflect/api/StandardDefinitions.scala index b4fedbe055..e457bb73e0 100755 --- a/src/library/scala/reflect/api/StandardDefinitions.scala +++ b/src/library/scala/reflect/api/StandardDefinitions.scala @@ -113,8 +113,8 @@ trait StandardDefinitions { self: Universe => def ClassTagModule: Symbol def TypeTagClass: Symbol def TypeTagModule: Symbol - def GroundTypeTagClass: Symbol - def GroundTypeTagModule: Symbol + def ConcreteTypeTagClass: Symbol + def ConcreteTypeTagModule: Symbol /** Given a type T, returns the type corresponding to the VM's * representation: ClassClass's type constructor applied to `arg`. diff --git a/src/library/scala/reflect/api/TypeTags.scala b/src/library/scala/reflect/api/TypeTags.scala index a38c21a9d4..ed47620e13 100644 --- a/src/library/scala/reflect/api/TypeTags.scala +++ b/src/library/scala/reflect/api/TypeTags.scala @@ -14,14 +14,16 @@ import scala.reflect.{ mirror => rm } * TypeTags are much better integrated with reflection than manifests are, and are consequently much simpler. * * Type tags are organized in a hierarchy of two classes: - * [[scala.reflect.ClassTag]], [[scala.reflect.api.Universe#TypeTag]] and [[scala.reflect.api.Universe#GroundTypeTag]]. - * A [[scala.reflect.ClassTag]] value wraps a Java class, which can be accessed via the erasure method. + * [[scala.reflect.api.Universe#TypeTag]] and [[scala.reflect.api.Universe#ConcreteTypeTag]]. * A [[scala.reflect.api.Universe#TypeTag]] value wraps a full Scala type in its tpe field. - * A [[scala.reflect.api.Universe#GroundTypeTag]] value is a type tag that is guaranteed not to contain any references to type parameters or abstract types. + * A [[scala.reflect.api.Universe#ConcreteTypeTag]] value is a type tag that is guaranteed not to contain any references to type parameters or abstract types. + * + * It is also possible to capture Java classes by using a different kind of tag. + * A [[scala.reflect.ClassTag]] value wraps a Java class, which can be accessed via the erasure method. * * TypeTags correspond loosely to Manifests. More precisely: * The previous notion of a [[scala.reflect.ClassManifest]] corresponds to a scala.reflect.ClassTag, - * The previous notion of a [[scala.reflect.Manifest]] corresponds to scala.reflect.mirror.GroundTypeTag, + * The previous notion of a [[scala.reflect.Manifest]] corresponds to scala.reflect.mirror.ConcreteTypeTag, * Whereas scala.reflect.mirror.TypeTag is approximated by the previous notion of [[scala.reflect.OptManifest]]. * * Implicit in the contract for all Tag classes is that the reified type tpe represents the type parameter T. @@ -59,38 +61,34 @@ trait TypeTags { self: Universe => def sym = tpe.typeSymbol - def isGround = !isNotGround - def isNotGround = tpe exists (_.typeSymbol.isAbstractType) - - def toGround: GroundTypeTag[T] = { - assert(isGround, tpe) - GroundTypeTag[T](tpe) - } + def isConcrete = !isNotConcrete + def isNotConcrete = tpe exists (_.typeSymbol.isAbstractType) + def toConcrete: ConcreteTypeTag[T] = ConcreteTypeTag[T](tpe) override def toString = { - var prefix = if (isGround) "GroundTypeTag" else "TypeTag" + var prefix = if (isConcrete) "ConcreteTypeTag" else "TypeTag" if (prefix != this.productPrefix) prefix = "*" + prefix prefix + "[" + tpe + "]" } } object TypeTag { - val Byte : TypeTag[scala.Byte] = GroundTypeTag.Byte - val Short : TypeTag[scala.Short] = GroundTypeTag.Short - val Char : TypeTag[scala.Char] = GroundTypeTag.Char - val Int : TypeTag[scala.Int] = GroundTypeTag.Int - val Long : TypeTag[scala.Long] = GroundTypeTag.Long - val Float : TypeTag[scala.Float] = GroundTypeTag.Float - val Double : TypeTag[scala.Double] = GroundTypeTag.Double - val Boolean : TypeTag[scala.Boolean] = GroundTypeTag.Boolean - val Unit : TypeTag[scala.Unit] = GroundTypeTag.Unit - val Any : TypeTag[scala.Any] = GroundTypeTag.Any - val Object : TypeTag[java.lang.Object] = GroundTypeTag.Object - val AnyVal : TypeTag[scala.AnyVal] = GroundTypeTag.AnyVal - val AnyRef : TypeTag[scala.AnyRef] = GroundTypeTag.AnyRef - val Nothing : TypeTag[scala.Nothing] = GroundTypeTag.Nothing - val Null : TypeTag[scala.Null] = GroundTypeTag.Null - val String : TypeTag[java.lang.String] = GroundTypeTag.String + val Byte : TypeTag[scala.Byte] = ConcreteTypeTag.Byte + val Short : TypeTag[scala.Short] = ConcreteTypeTag.Short + val Char : TypeTag[scala.Char] = ConcreteTypeTag.Char + val Int : TypeTag[scala.Int] = ConcreteTypeTag.Int + val Long : TypeTag[scala.Long] = ConcreteTypeTag.Long + val Float : TypeTag[scala.Float] = ConcreteTypeTag.Float + val Double : TypeTag[scala.Double] = ConcreteTypeTag.Double + val Boolean : TypeTag[scala.Boolean] = ConcreteTypeTag.Boolean + val Unit : TypeTag[scala.Unit] = ConcreteTypeTag.Unit + val Any : TypeTag[scala.Any] = ConcreteTypeTag.Any + val Object : TypeTag[java.lang.Object] = ConcreteTypeTag.Object + val AnyVal : TypeTag[scala.AnyVal] = ConcreteTypeTag.AnyVal + val AnyRef : TypeTag[scala.AnyRef] = ConcreteTypeTag.AnyRef + val Nothing : TypeTag[scala.Nothing] = ConcreteTypeTag.Nothing + val Null : TypeTag[scala.Null] = ConcreteTypeTag.Null + val String : TypeTag[java.lang.String] = ConcreteTypeTag.String def apply[T](tpe: Type): TypeTag[T] = tpe match { @@ -115,64 +113,67 @@ trait TypeTags { self: Universe => } /** - * If an implicit value of type u.GroundTypeTag[T] is required, the compiler will make one up on demand following the same procedure as for TypeTags. + * If an implicit value of type u.ConcreteTypeTag[T] is required, the compiler will make one up on demand following the same procedure as for TypeTags. * However, if the resulting type still contains references to type parameters or abstract types, a static error results. * * @see [[scala.reflect.api.TypeTags]] */ - @annotation.implicitNotFound(msg = "No GroundTypeTag available for ${T}") - class GroundTypeTag[T](tpe: Type) extends TypeTag[T](tpe) { - assert(isGround, tpe) - override def productPrefix = "GroundTypeTag" + @annotation.implicitNotFound(msg = "No ConcreteTypeTag available for ${T}") + class ConcreteTypeTag[T](tpe: Type) extends TypeTag[T](tpe) { + // it's unsafe to use assert here, because we might run into deadlocks with Predef + // also see comments in ClassTags.scala + //assert(isConcrete, tpe) + if (isNotConcrete) throw new Error("%s (%s) is not concrete and cannot be used to construct a concrete type tag".format(tpe, tpe.kind)) + override def productPrefix = "ConcreteTypeTag" } - object GroundTypeTag { - val Byte : GroundTypeTag[scala.Byte] = new GroundTypeTag[scala.Byte](ByteTpe) { private def readResolve() = GroundTypeTag.Byte } - val Short : GroundTypeTag[scala.Short] = new GroundTypeTag[scala.Short](ShortTpe) { private def readResolve() = GroundTypeTag.Short } - val Char : GroundTypeTag[scala.Char] = new GroundTypeTag[scala.Char](CharTpe) { private def readResolve() = GroundTypeTag.Char } - val Int : GroundTypeTag[scala.Int] = new GroundTypeTag[scala.Int](IntTpe) { private def readResolve() = GroundTypeTag.Int } - val Long : GroundTypeTag[scala.Long] = new GroundTypeTag[scala.Long](LongTpe) { private def readResolve() = GroundTypeTag.Long } - val Float : GroundTypeTag[scala.Float] = new GroundTypeTag[scala.Float](FloatTpe) { private def readResolve() = GroundTypeTag.Float } - val Double : GroundTypeTag[scala.Double] = new GroundTypeTag[scala.Double](DoubleTpe) { private def readResolve() = GroundTypeTag.Double } - val Boolean : GroundTypeTag[scala.Boolean] = new GroundTypeTag[scala.Boolean](BooleanTpe) { private def readResolve() = GroundTypeTag.Boolean } - val Unit : GroundTypeTag[scala.Unit] = new GroundTypeTag[scala.Unit](UnitTpe) { private def readResolve() = GroundTypeTag.Unit } - val Any : GroundTypeTag[scala.Any] = new GroundTypeTag[scala.Any](AnyTpe) { private def readResolve() = GroundTypeTag.Any } - val Object : GroundTypeTag[java.lang.Object] = new GroundTypeTag[java.lang.Object](ObjectTpe) { private def readResolve() = GroundTypeTag.Object } - val AnyVal : GroundTypeTag[scala.AnyVal] = new GroundTypeTag[scala.AnyVal](AnyValTpe) { private def readResolve() = GroundTypeTag.AnyVal } - val AnyRef : GroundTypeTag[scala.AnyRef] = new GroundTypeTag[scala.AnyRef](AnyRefTpe) { private def readResolve() = GroundTypeTag.AnyRef } - val Nothing : GroundTypeTag[scala.Nothing] = new GroundTypeTag[scala.Nothing](NothingTpe) { private def readResolve() = GroundTypeTag.Nothing } - val Null : GroundTypeTag[scala.Null] = new GroundTypeTag[scala.Null](NullTpe) { private def readResolve() = GroundTypeTag.Null } - val String : GroundTypeTag[java.lang.String] = new GroundTypeTag[java.lang.String](StringTpe) { private def readResolve() = GroundTypeTag.String } - - def apply[T](tpe: Type): GroundTypeTag[T] = + object ConcreteTypeTag { + val Byte : ConcreteTypeTag[scala.Byte] = new ConcreteTypeTag[scala.Byte](ByteTpe) { private def readResolve() = ConcreteTypeTag.Byte } + val Short : ConcreteTypeTag[scala.Short] = new ConcreteTypeTag[scala.Short](ShortTpe) { private def readResolve() = ConcreteTypeTag.Short } + val Char : ConcreteTypeTag[scala.Char] = new ConcreteTypeTag[scala.Char](CharTpe) { private def readResolve() = ConcreteTypeTag.Char } + val Int : ConcreteTypeTag[scala.Int] = new ConcreteTypeTag[scala.Int](IntTpe) { private def readResolve() = ConcreteTypeTag.Int } + val Long : ConcreteTypeTag[scala.Long] = new ConcreteTypeTag[scala.Long](LongTpe) { private def readResolve() = ConcreteTypeTag.Long } + val Float : ConcreteTypeTag[scala.Float] = new ConcreteTypeTag[scala.Float](FloatTpe) { private def readResolve() = ConcreteTypeTag.Float } + val Double : ConcreteTypeTag[scala.Double] = new ConcreteTypeTag[scala.Double](DoubleTpe) { private def readResolve() = ConcreteTypeTag.Double } + val Boolean : ConcreteTypeTag[scala.Boolean] = new ConcreteTypeTag[scala.Boolean](BooleanTpe) { private def readResolve() = ConcreteTypeTag.Boolean } + val Unit : ConcreteTypeTag[scala.Unit] = new ConcreteTypeTag[scala.Unit](UnitTpe) { private def readResolve() = ConcreteTypeTag.Unit } + val Any : ConcreteTypeTag[scala.Any] = new ConcreteTypeTag[scala.Any](AnyTpe) { private def readResolve() = ConcreteTypeTag.Any } + val Object : ConcreteTypeTag[java.lang.Object] = new ConcreteTypeTag[java.lang.Object](ObjectTpe) { private def readResolve() = ConcreteTypeTag.Object } + val AnyVal : ConcreteTypeTag[scala.AnyVal] = new ConcreteTypeTag[scala.AnyVal](AnyValTpe) { private def readResolve() = ConcreteTypeTag.AnyVal } + val AnyRef : ConcreteTypeTag[scala.AnyRef] = new ConcreteTypeTag[scala.AnyRef](AnyRefTpe) { private def readResolve() = ConcreteTypeTag.AnyRef } + val Nothing : ConcreteTypeTag[scala.Nothing] = new ConcreteTypeTag[scala.Nothing](NothingTpe) { private def readResolve() = ConcreteTypeTag.Nothing } + val Null : ConcreteTypeTag[scala.Null] = new ConcreteTypeTag[scala.Null](NullTpe) { private def readResolve() = ConcreteTypeTag.Null } + val String : ConcreteTypeTag[java.lang.String] = new ConcreteTypeTag[java.lang.String](StringTpe) { private def readResolve() = ConcreteTypeTag.String } + + def apply[T](tpe: Type): ConcreteTypeTag[T] = tpe match { - case ByteTpe => GroundTypeTag.Byte.asInstanceOf[GroundTypeTag[T]] - case ShortTpe => GroundTypeTag.Short.asInstanceOf[GroundTypeTag[T]] - case CharTpe => GroundTypeTag.Char.asInstanceOf[GroundTypeTag[T]] - case IntTpe => GroundTypeTag.Int.asInstanceOf[GroundTypeTag[T]] - case LongTpe => GroundTypeTag.Long.asInstanceOf[GroundTypeTag[T]] - case FloatTpe => GroundTypeTag.Float.asInstanceOf[GroundTypeTag[T]] - case DoubleTpe => GroundTypeTag.Double.asInstanceOf[GroundTypeTag[T]] - case BooleanTpe => GroundTypeTag.Boolean.asInstanceOf[GroundTypeTag[T]] - case UnitTpe => GroundTypeTag.Unit.asInstanceOf[GroundTypeTag[T]] - case AnyTpe => GroundTypeTag.Any.asInstanceOf[GroundTypeTag[T]] - case ObjectTpe => GroundTypeTag.Object.asInstanceOf[GroundTypeTag[T]] - case AnyValTpe => GroundTypeTag.AnyVal.asInstanceOf[GroundTypeTag[T]] - case AnyRefTpe => GroundTypeTag.AnyRef.asInstanceOf[GroundTypeTag[T]] - case NothingTpe => GroundTypeTag.Nothing.asInstanceOf[GroundTypeTag[T]] - case NullTpe => GroundTypeTag.Null.asInstanceOf[GroundTypeTag[T]] - case StringTpe => GroundTypeTag.String.asInstanceOf[GroundTypeTag[T]] - case _ => new GroundTypeTag[T](tpe) {} + case ByteTpe => ConcreteTypeTag.Byte.asInstanceOf[ConcreteTypeTag[T]] + case ShortTpe => ConcreteTypeTag.Short.asInstanceOf[ConcreteTypeTag[T]] + case CharTpe => ConcreteTypeTag.Char.asInstanceOf[ConcreteTypeTag[T]] + case IntTpe => ConcreteTypeTag.Int.asInstanceOf[ConcreteTypeTag[T]] + case LongTpe => ConcreteTypeTag.Long.asInstanceOf[ConcreteTypeTag[T]] + case FloatTpe => ConcreteTypeTag.Float.asInstanceOf[ConcreteTypeTag[T]] + case DoubleTpe => ConcreteTypeTag.Double.asInstanceOf[ConcreteTypeTag[T]] + case BooleanTpe => ConcreteTypeTag.Boolean.asInstanceOf[ConcreteTypeTag[T]] + case UnitTpe => ConcreteTypeTag.Unit.asInstanceOf[ConcreteTypeTag[T]] + case AnyTpe => ConcreteTypeTag.Any.asInstanceOf[ConcreteTypeTag[T]] + case ObjectTpe => ConcreteTypeTag.Object.asInstanceOf[ConcreteTypeTag[T]] + case AnyValTpe => ConcreteTypeTag.AnyVal.asInstanceOf[ConcreteTypeTag[T]] + case AnyRefTpe => ConcreteTypeTag.AnyRef.asInstanceOf[ConcreteTypeTag[T]] + case NothingTpe => ConcreteTypeTag.Nothing.asInstanceOf[ConcreteTypeTag[T]] + case NullTpe => ConcreteTypeTag.Null.asInstanceOf[ConcreteTypeTag[T]] + case StringTpe => ConcreteTypeTag.String.asInstanceOf[ConcreteTypeTag[T]] + case _ => new ConcreteTypeTag[T](tpe) {} } - def unapply[T](ttag: TypeTag[T]): Option[Type] = if (ttag.isGround) Some(ttag.tpe) else None + def unapply[T](ttag: TypeTag[T]): Option[Type] = if (ttag.isConcrete) Some(ttag.tpe) else None - implicit def toClassTag[T](ttag: rm.GroundTypeTag[T]): ClassTag[T] = ClassTag[T](rm.typeToClass(ttag.tpe.erasure)) + implicit def toClassTag[T](ttag: rm.ConcreteTypeTag[T]): ClassTag[T] = ClassTag[T](rm.typeToClass(ttag.tpe.erasure)) - implicit def toDeprecatedManifestApis[T](ttag: rm.GroundTypeTag[T]): DeprecatedManifestApis[T] = new DeprecatedManifestApis[T](ttag) + implicit def toDeprecatedManifestApis[T](ttag: rm.ConcreteTypeTag[T]): DeprecatedManifestApis[T] = new DeprecatedManifestApis[T](ttag) // this class should not be used directly in client code - class DeprecatedManifestApis[T](ttag: rm.GroundTypeTag[T]) extends DeprecatedClassManifestApis[T](toClassTag(ttag)) { + class DeprecatedManifestApis[T](ttag: rm.ConcreteTypeTag[T]) extends DeprecatedClassManifestApis[T](toClassTag(ttag)) { @deprecated("Use `tpe` to analyze the underlying type", "2.10.0") def <:<(that: Manifest[_]): Boolean = ttag.tpe <:< that.tpe @@ -180,7 +181,7 @@ trait TypeTags { self: Universe => def >:>(that: Manifest[_]): Boolean = that <:< ttag @deprecated("Use `tpe` to analyze the type arguments", "2.10.0") - override def typeArguments: List[Manifest[_]] = ttag.tpe.typeArguments map (targ => rm.GroundTypeTag(targ)) + override def typeArguments: List[Manifest[_]] = ttag.tpe.typeArguments map (targ => rm.ConcreteTypeTag(targ)) } } @@ -188,6 +189,6 @@ trait TypeTags { self: Universe => // moved to Context, since rm.tags have their own incantations in Predef, and these guys are only useful in macros // def tag[T](implicit ttag: TypeTag[T]) = ttag // def typeTag[T](implicit ttag: TypeTag[T]) = ttag -// def groundTag[T](implicit gttag: GroundTypeTag[T]) = gttag -// def groundTypeTag[T](implicit gttag: GroundTypeTag[T]) = gttag +// def concreteTag[T](implicit gttag: ConcreteTypeTag[T]) = cttag +// def concreteTypeTag[T](implicit gttag: ConcreteTypeTag[T]) = cttag } \ No newline at end of file diff --git a/src/library/scala/reflect/makro/Aliases.scala b/src/library/scala/reflect/makro/Aliases.scala index e8b847600c..38b1065a40 100644 --- a/src/library/scala/reflect/makro/Aliases.scala +++ b/src/library/scala/reflect/makro/Aliases.scala @@ -21,6 +21,6 @@ trait Aliases { /** incantations for summoning tags */ def tag[T](implicit ttag: TypeTag[T]) = ttag def typeTag[T](implicit ttag: TypeTag[T]) = ttag - def groundTag[T](implicit gttag: GroundTypeTag[T]) = gttag - def groundTypeTag[T](implicit gttag: GroundTypeTag[T]) = gttag + def concreteTag[T](implicit cttag: ConcreteTypeTag[T]) = cttag + def concreteTypeTag[T](implicit cttag: ConcreteTypeTag[T]) = cttag } diff --git a/src/library/scala/reflect/makro/Reifiers.scala b/src/library/scala/reflect/makro/Reifiers.scala index 9bd25cf0f8..d690df6aee 100644 --- a/src/library/scala/reflect/makro/Reifiers.scala +++ b/src/library/scala/reflect/makro/Reifiers.scala @@ -46,7 +46,7 @@ trait Reifiers { * The produced tree will be bound to the mirror specified by ``prefix'' (also see ``reflectMirrorPrefix''). * For more information and examples see the documentation for ``Context.reifyTree'' and ``Universe.reify''. */ - def reifyType(prefix: Tree, tpe: Type, dontSpliceAtTopLevel: Boolean = false, requireGroundTypeTag: Boolean = false): Tree + def reifyType(prefix: Tree, tpe: Type, dontSpliceAtTopLevel: Boolean = false, requireConcreteTypeTag: Boolean = false): Tree /** Undoes reification of a tree. * diff --git a/src/library/scala/reflect/makro/internal/typeTagImpl.scala b/src/library/scala/reflect/makro/internal/typeTagImpl.scala index 6c49ef45de..de404ff39f 100644 --- a/src/library/scala/reflect/makro/internal/typeTagImpl.scala +++ b/src/library/scala/reflect/makro/internal/typeTagImpl.scala @@ -16,14 +16,14 @@ package object internal { /** This method is required by the compiler and should not be used in client code. */ def materializeTypeTag_impl[T: c.TypeTag](c: Context)(u: c.Expr[Universe]): c.Expr[u.value.TypeTag[T]] = - c.Expr[Nothing](c.materializeTypeTag(u.tree, implicitly[c.TypeTag[T]].tpe, requireGroundTypeTag = false))(c.TypeTag.Nothing) + c.Expr[Nothing](c.materializeTypeTag(u.tree, implicitly[c.TypeTag[T]].tpe, requireConcreteTypeTag = false))(c.TypeTag.Nothing) /** This method is required by the compiler and should not be used in client code. */ - def materializeGroundTypeTag[T](u: Universe): u.GroundTypeTag[T] = macro materializeGroundTypeTag_impl[T] + def materializeConcreteTypeTag[T](u: Universe): u.ConcreteTypeTag[T] = macro materializeConcreteTypeTag_impl[T] /** This method is required by the compiler and should not be used in client code. */ - def materializeGroundTypeTag_impl[T: c.TypeTag](c: Context)(u: c.Expr[Universe]): c.Expr[u.value.GroundTypeTag[T]] = - c.Expr[Nothing](c.materializeTypeTag(u.tree, implicitly[c.TypeTag[T]].tpe, requireGroundTypeTag = true))(c.TypeTag.Nothing) + def materializeConcreteTypeTag_impl[T: c.TypeTag](c: Context)(u: c.Expr[Universe]): c.Expr[u.value.ConcreteTypeTag[T]] = + c.Expr[Nothing](c.materializeTypeTag(u.tree, implicitly[c.TypeTag[T]].tpe, requireConcreteTypeTag = true))(c.TypeTag.Nothing) /** This method is required by the compiler and should not be used in client code. */ private[scala] implicit def context2utils(c0: Context) : Utils { val c: c0.type } = new { val c: c0.type = c0 } with Utils @@ -54,8 +54,8 @@ package internal { NullClass.asType -> newTermName("Null")) def materializeClassTag(prefix: Tree, tpe: Type): Tree = { - val typetagInScope = c.inferImplicitValue(appliedType(typeRef(prefix.tpe, TypeTagClass, Nil), List(tpe))) - def typetagIsSynthetic(tree: Tree) = tree.isInstanceOf[Block] || (tree exists (sub => sub.symbol == TypeTagModule || sub.symbol == GroundTypeTagModule)) + val typetagInScope = c.inferImplicitValue(appliedType(typeRef(prefix.tpe, ConcreteTypeTagClass, Nil), List(tpe))) + def typetagIsSynthetic(tree: Tree) = tree.isInstanceOf[Block] || (tree exists (sub => sub.symbol == TypeTagModule || sub.symbol == ConcreteTypeTagModule)) typetagInScope match { case success if !success.isEmpty && !typetagIsSynthetic(success) => val factory = TypeApply(Select(Ident(ClassTagModule), newTermName("apply")), List(TypeTree(tpe))) @@ -88,14 +88,14 @@ package internal { } } - def materializeTypeTag(prefix: Tree, tpe: Type, requireGroundTypeTag: Boolean): Tree = { - val tagModule = if (requireGroundTypeTag) GroundTypeTagModule else TypeTagModule + def materializeTypeTag(prefix: Tree, tpe: Type, requireConcreteTypeTag: Boolean): Tree = { + val tagModule = if (requireConcreteTypeTag) ConcreteTypeTagModule else TypeTagModule val result = tpe match { case coreTpe if coreTags contains coreTpe => Select(Select(prefix, tagModule.name), coreTags(coreTpe)) case _ => - try c.reifyType(prefix, tpe, dontSpliceAtTopLevel = true, requireGroundTypeTag = requireGroundTypeTag) + try c.reifyType(prefix, tpe, dontSpliceAtTopLevel = true, requireConcreteTypeTag = requireConcreteTypeTag) catch { case ex: Throwable => // [Eugene] cannot pattern match on an abstract type, so had to do this diff --git a/src/library/scala/reflect/package.scala b/src/library/scala/reflect/package.scala index 7a8267e689..1738642932 100644 --- a/src/library/scala/reflect/package.scala +++ b/src/library/scala/reflect/package.scala @@ -43,21 +43,21 @@ package object reflect { type ClassManifest[T] = ClassTag[T] @deprecated("OptManifest is no longer supported, and using it may lead to incorrect results, Use `@scala.reflect.TypeTag` instead", "2.10.0") type OptManifest[T] = TypeTag[T] - @deprecated("Use `@scala.reflect.GroundTypeTag` instead", "2.10.0") - type Manifest[T] = GroundTypeTag[T] + @deprecated("Use `@scala.reflect.ConcreteTypeTag` instead", "2.10.0") + type Manifest[T] = ConcreteTypeTag[T] @deprecated("Use `@scala.reflect.ClassTag` instead", "2.10.0") val ClassManifest = ClassTag - @deprecated("Use `@scala.reflect.GroundTypeTag` instead", "2.10.0") - lazy val Manifest = GroundTypeTag + @deprecated("Use `@scala.reflect.ConcreteTypeTag` instead", "2.10.0") + lazy val Manifest = ConcreteTypeTag @deprecated("NoManifest is no longer supported, and using it may lead to incorrect results, Use `@scala.reflect.TypeTag` instead", "2.10.0") object NoManifest extends OptManifest[Nothing](scala.reflect.mirror.definitions.NothingClass.asType) with Serializable // ClassTag class is defined separately from the mirror - type TypeTag[T] = scala.reflect.mirror.TypeTag[T] - type GroundTypeTag[T] = scala.reflect.mirror.GroundTypeTag[T] + type TypeTag[T] = scala.reflect.mirror.TypeTag[T] + type ConcreteTypeTag[T] = scala.reflect.mirror.ConcreteTypeTag[T] // ClassTag object is defined separately from the mirror - lazy val TypeTag = scala.reflect.mirror.TypeTag - lazy val GroundTypeTag = scala.reflect.mirror.GroundTypeTag + lazy val TypeTag = scala.reflect.mirror.TypeTag + lazy val ConcreteTypeTag = scala.reflect.mirror.ConcreteTypeTag } diff --git a/test/files/neg/macro-reify-groundtypetag-hktypeparams-notags.check b/test/files/neg/macro-reify-groundtypetag-hktypeparams-notags.check index d9c390ba25..39e90f827e 100644 --- a/test/files/neg/macro-reify-groundtypetag-hktypeparams-notags.check +++ b/test/files/neg/macro-reify-groundtypetag-hktypeparams-notags.check @@ -1,7 +1,7 @@ -Test.scala:5: error: No GroundTypeTag available for C[T] - println(implicitly[GroundTypeTag[C[T]]]) +Test.scala:5: error: No ConcreteTypeTag available for C[T] + println(implicitly[ConcreteTypeTag[C[T]]]) ^ -Test.scala:6: error: No GroundTypeTag available for List[C[T]] - println(implicitly[GroundTypeTag[List[C[T]]]]) +Test.scala:6: error: No ConcreteTypeTag available for List[C[T]] + println(implicitly[ConcreteTypeTag[List[C[T]]]]) ^ two errors found diff --git a/test/files/neg/macro-reify-groundtypetag-hktypeparams-notags/Test.scala b/test/files/neg/macro-reify-groundtypetag-hktypeparams-notags/Test.scala index d5ee61b91d..1302999da6 100644 --- a/test/files/neg/macro-reify-groundtypetag-hktypeparams-notags/Test.scala +++ b/test/files/neg/macro-reify-groundtypetag-hktypeparams-notags/Test.scala @@ -2,8 +2,8 @@ import scala.reflect.mirror._ object Test extends App { def fooNoTypeTagHK[C[_], T] = { - println(implicitly[GroundTypeTag[C[T]]]) - println(implicitly[GroundTypeTag[List[C[T]]]]) + println(implicitly[ConcreteTypeTag[C[T]]]) + println(implicitly[ConcreteTypeTag[List[C[T]]]]) } fooNoTypeTagHK[List, Int] } \ No newline at end of file diff --git a/test/files/neg/macro-reify-groundtypetag-typeparams-notags.check b/test/files/neg/macro-reify-groundtypetag-typeparams-notags.check index c678a2a313..164ca3543f 100644 --- a/test/files/neg/macro-reify-groundtypetag-typeparams-notags.check +++ b/test/files/neg/macro-reify-groundtypetag-typeparams-notags.check @@ -1,7 +1,7 @@ -Test.scala:5: error: No GroundTypeTag available for T - println(implicitly[GroundTypeTag[T]]) +Test.scala:5: error: No ConcreteTypeTag available for T + println(implicitly[ConcreteTypeTag[T]]) ^ -Test.scala:6: error: No GroundTypeTag available for List[T] - println(implicitly[GroundTypeTag[List[T]]]) +Test.scala:6: error: No ConcreteTypeTag available for List[T] + println(implicitly[ConcreteTypeTag[List[T]]]) ^ two errors found diff --git a/test/files/neg/macro-reify-groundtypetag-typeparams-notags/Test.scala b/test/files/neg/macro-reify-groundtypetag-typeparams-notags/Test.scala index 98bdf6d67f..d2276ce333 100644 --- a/test/files/neg/macro-reify-groundtypetag-typeparams-notags/Test.scala +++ b/test/files/neg/macro-reify-groundtypetag-typeparams-notags/Test.scala @@ -2,8 +2,8 @@ import scala.reflect.mirror._ object Test extends App { def fooNoTypeTag[T] = { - println(implicitly[GroundTypeTag[T]]) - println(implicitly[GroundTypeTag[List[T]]]) + println(implicitly[ConcreteTypeTag[T]]) + println(implicitly[ConcreteTypeTag[List[T]]]) } fooNoTypeTag[Int] } \ No newline at end of file diff --git a/test/files/neg/macro-reify-groundtypetag-usetypetag.check b/test/files/neg/macro-reify-groundtypetag-usetypetag.check index c678a2a313..164ca3543f 100644 --- a/test/files/neg/macro-reify-groundtypetag-usetypetag.check +++ b/test/files/neg/macro-reify-groundtypetag-usetypetag.check @@ -1,7 +1,7 @@ -Test.scala:5: error: No GroundTypeTag available for T - println(implicitly[GroundTypeTag[T]]) +Test.scala:5: error: No ConcreteTypeTag available for T + println(implicitly[ConcreteTypeTag[T]]) ^ -Test.scala:6: error: No GroundTypeTag available for List[T] - println(implicitly[GroundTypeTag[List[T]]]) +Test.scala:6: error: No ConcreteTypeTag available for List[T] + println(implicitly[ConcreteTypeTag[List[T]]]) ^ two errors found diff --git a/test/files/neg/macro-reify-groundtypetag-usetypetag/Test.scala b/test/files/neg/macro-reify-groundtypetag-usetypetag/Test.scala index 507d03a390..d82cdc33e9 100644 --- a/test/files/neg/macro-reify-groundtypetag-usetypetag/Test.scala +++ b/test/files/neg/macro-reify-groundtypetag-usetypetag/Test.scala @@ -2,8 +2,8 @@ import scala.reflect.mirror._ object Test extends App { def fooTypeTag[T: TypeTag] = { - println(implicitly[GroundTypeTag[T]]) - println(implicitly[GroundTypeTag[List[T]]]) + println(implicitly[ConcreteTypeTag[T]]) + println(implicitly[ConcreteTypeTag[List[T]]]) } fooTypeTag[Int] } \ No newline at end of file diff --git a/test/files/neg/t3507.check b/test/files/neg/t3507.check index 6b6df6ba76..71bf295039 100644 --- a/test/files/neg/t3507.check +++ b/test/files/neg/t3507.check @@ -1,4 +1,4 @@ -t3507.scala:13: error: No GroundTypeTag available for _1.b.c.type +t3507.scala:13: error: No ConcreteTypeTag available for _1.b.c.type mani/*[object _1.b.c]*/(c) // kaboom in manifestOfType / TreeGen.mkAttributedQualifier ^ one error found diff --git a/test/files/neg/t3692.check b/test/files/neg/t3692.check index ec67e76bb4..d83abd31e2 100644 --- a/test/files/neg/t3692.check +++ b/test/files/neg/t3692.check @@ -1,7 +1,7 @@ -t3692.scala:11: warning: type Manifest in object Predef is deprecated: Use `@scala.reflect.GroundTypeTag` instead +t3692.scala:11: warning: type Manifest in object Predef is deprecated: Use `@scala.reflect.ConcreteTypeTag` instead private final def toJavaMap[T, V](map: Map[T, V])(implicit m1: Manifest[T], m2: Manifest[V]): java.util.Map[_, _] = { ^ -t3692.scala:11: warning: type Manifest in object Predef is deprecated: Use `@scala.reflect.GroundTypeTag` instead +t3692.scala:11: warning: type Manifest in object Predef is deprecated: Use `@scala.reflect.ConcreteTypeTag` instead private final def toJavaMap[T, V](map: Map[T, V])(implicit m1: Manifest[T], m2: Manifest[V]): java.util.Map[_, _] = { ^ t3692.scala:15: error: unreachable code diff --git a/test/files/run/groundtypetags_core.check b/test/files/run/groundtypetags_core.check index d1b71f0926..62fcb481ae 100644 --- a/test/files/run/groundtypetags_core.check +++ b/test/files/run/groundtypetags_core.check @@ -1,30 +1,30 @@ true -GroundTypeTag[Byte] +ConcreteTypeTag[Byte] true -GroundTypeTag[Short] +ConcreteTypeTag[Short] true -GroundTypeTag[Char] +ConcreteTypeTag[Char] true -GroundTypeTag[Int] +ConcreteTypeTag[Int] true -GroundTypeTag[Long] +ConcreteTypeTag[Long] true -GroundTypeTag[Float] +ConcreteTypeTag[Float] true -GroundTypeTag[Double] +ConcreteTypeTag[Double] true -GroundTypeTag[Boolean] +ConcreteTypeTag[Boolean] true -GroundTypeTag[Unit] +ConcreteTypeTag[Unit] true -GroundTypeTag[Any] +ConcreteTypeTag[Any] true -GroundTypeTag[Object] +ConcreteTypeTag[Object] true -GroundTypeTag[AnyVal] +ConcreteTypeTag[AnyVal] true -GroundTypeTag[AnyRef] +ConcreteTypeTag[AnyRef] true -GroundTypeTag[Null] +ConcreteTypeTag[Null] true -GroundTypeTag[Nothing] +ConcreteTypeTag[Nothing] diff --git a/test/files/run/groundtypetags_core.scala b/test/files/run/groundtypetags_core.scala index d779e3fc7e..8b81a0c795 100644 --- a/test/files/run/groundtypetags_core.scala +++ b/test/files/run/groundtypetags_core.scala @@ -1,32 +1,32 @@ object Test extends App { - println(implicitly[GroundTypeTag[Byte]] eq GroundTypeTag.Byte) - println(implicitly[GroundTypeTag[Byte]]) - println(implicitly[GroundTypeTag[Short]] eq GroundTypeTag.Short) - println(implicitly[GroundTypeTag[Short]]) - println(implicitly[GroundTypeTag[Char]] eq GroundTypeTag.Char) - println(implicitly[GroundTypeTag[Char]]) - println(implicitly[GroundTypeTag[Int]] eq GroundTypeTag.Int) - println(implicitly[GroundTypeTag[Int]]) - println(implicitly[GroundTypeTag[Long]] eq GroundTypeTag.Long) - println(implicitly[GroundTypeTag[Long]]) - println(implicitly[GroundTypeTag[Float]] eq GroundTypeTag.Float) - println(implicitly[GroundTypeTag[Float]]) - println(implicitly[GroundTypeTag[Double]] eq GroundTypeTag.Double) - println(implicitly[GroundTypeTag[Double]]) - println(implicitly[GroundTypeTag[Boolean]] eq GroundTypeTag.Boolean) - println(implicitly[GroundTypeTag[Boolean]]) - println(implicitly[GroundTypeTag[Unit]] eq GroundTypeTag.Unit) - println(implicitly[GroundTypeTag[Unit]]) - println(implicitly[GroundTypeTag[Any]] eq GroundTypeTag.Any) - println(implicitly[GroundTypeTag[Any]]) - println(implicitly[GroundTypeTag[Object]] eq GroundTypeTag.Object) - println(implicitly[GroundTypeTag[Object]]) - println(implicitly[GroundTypeTag[AnyVal]] eq GroundTypeTag.AnyVal) - println(implicitly[GroundTypeTag[AnyVal]]) - println(implicitly[GroundTypeTag[AnyRef]] eq GroundTypeTag.AnyRef) - println(implicitly[GroundTypeTag[AnyRef]]) - println(implicitly[GroundTypeTag[Null]] eq GroundTypeTag.Null) - println(implicitly[GroundTypeTag[Null]]) - println(implicitly[GroundTypeTag[Nothing]] eq GroundTypeTag.Nothing) - println(implicitly[GroundTypeTag[Nothing]]) + println(implicitly[ConcreteTypeTag[Byte]] eq ConcreteTypeTag.Byte) + println(implicitly[ConcreteTypeTag[Byte]]) + println(implicitly[ConcreteTypeTag[Short]] eq ConcreteTypeTag.Short) + println(implicitly[ConcreteTypeTag[Short]]) + println(implicitly[ConcreteTypeTag[Char]] eq ConcreteTypeTag.Char) + println(implicitly[ConcreteTypeTag[Char]]) + println(implicitly[ConcreteTypeTag[Int]] eq ConcreteTypeTag.Int) + println(implicitly[ConcreteTypeTag[Int]]) + println(implicitly[ConcreteTypeTag[Long]] eq ConcreteTypeTag.Long) + println(implicitly[ConcreteTypeTag[Long]]) + println(implicitly[ConcreteTypeTag[Float]] eq ConcreteTypeTag.Float) + println(implicitly[ConcreteTypeTag[Float]]) + println(implicitly[ConcreteTypeTag[Double]] eq ConcreteTypeTag.Double) + println(implicitly[ConcreteTypeTag[Double]]) + println(implicitly[ConcreteTypeTag[Boolean]] eq ConcreteTypeTag.Boolean) + println(implicitly[ConcreteTypeTag[Boolean]]) + println(implicitly[ConcreteTypeTag[Unit]] eq ConcreteTypeTag.Unit) + println(implicitly[ConcreteTypeTag[Unit]]) + println(implicitly[ConcreteTypeTag[Any]] eq ConcreteTypeTag.Any) + println(implicitly[ConcreteTypeTag[Any]]) + println(implicitly[ConcreteTypeTag[Object]] eq ConcreteTypeTag.Object) + println(implicitly[ConcreteTypeTag[Object]]) + println(implicitly[ConcreteTypeTag[AnyVal]] eq ConcreteTypeTag.AnyVal) + println(implicitly[ConcreteTypeTag[AnyVal]]) + println(implicitly[ConcreteTypeTag[AnyRef]] eq ConcreteTypeTag.AnyRef) + println(implicitly[ConcreteTypeTag[AnyRef]]) + println(implicitly[ConcreteTypeTag[Null]] eq ConcreteTypeTag.Null) + println(implicitly[ConcreteTypeTag[Null]]) + println(implicitly[ConcreteTypeTag[Nothing]] eq ConcreteTypeTag.Nothing) + println(implicitly[ConcreteTypeTag[Nothing]]) } \ No newline at end of file diff --git a/test/files/run/macro-expand-nullary-generic.check b/test/files/run/macro-expand-nullary-generic.check index 34a453cd3a..6dfe04af12 100644 --- a/test/files/run/macro-expand-nullary-generic.check +++ b/test/files/run/macro-expand-nullary-generic.check @@ -1,6 +1,6 @@ -it works GroundTypeTag[Int] -it works GroundTypeTag[Int] -it works GroundTypeTag[Int] -it works GroundTypeTag[Int] -it works GroundTypeTag[Int] +it works ConcreteTypeTag[Int] +it works ConcreteTypeTag[Int] +it works ConcreteTypeTag[Int] +it works ConcreteTypeTag[Int] +it works ConcreteTypeTag[Int] kkthxbai diff --git a/test/files/run/macro-expand-tparams-explicit.check b/test/files/run/macro-expand-tparams-explicit.check index 54da026aa8..5670e27c4e 100644 --- a/test/files/run/macro-expand-tparams-explicit.check +++ b/test/files/run/macro-expand-tparams-explicit.check @@ -1 +1 @@ -GroundTypeTag[Int] +ConcreteTypeTag[Int] diff --git a/test/files/run/macro-expand-tparams-implicit.check b/test/files/run/macro-expand-tparams-implicit.check index 60c021a35b..e57fc1217b 100644 --- a/test/files/run/macro-expand-tparams-implicit.check +++ b/test/files/run/macro-expand-tparams-implicit.check @@ -1,2 +1,2 @@ -GroundTypeTag[Int] -GroundTypeTag[String] +ConcreteTypeTag[Int] +ConcreteTypeTag[String] diff --git a/test/files/run/macro-expand-tparams-prefix-a.check b/test/files/run/macro-expand-tparams-prefix-a.check index 1447c2478f..922be1a6dd 100644 --- a/test/files/run/macro-expand-tparams-prefix-a.check +++ b/test/files/run/macro-expand-tparams-prefix-a.check @@ -1,4 +1,4 @@ -GroundTypeTag[Int] -GroundTypeTag[Int] -GroundTypeTag[String] -GroundTypeTag[Boolean] +ConcreteTypeTag[Int] +ConcreteTypeTag[Int] +ConcreteTypeTag[String] +ConcreteTypeTag[Boolean] diff --git a/test/files/run/macro-expand-tparams-prefix-b.check b/test/files/run/macro-expand-tparams-prefix-b.check index c7ec594b92..a336bb51ec 100644 --- a/test/files/run/macro-expand-tparams-prefix-b.check +++ b/test/files/run/macro-expand-tparams-prefix-b.check @@ -1,2 +1,2 @@ -GroundTypeTag[Boolean] GroundTypeTag[Int] -GroundTypeTag[Boolean] GroundTypeTag[String] +ConcreteTypeTag[Boolean] ConcreteTypeTag[Int] +ConcreteTypeTag[Boolean] ConcreteTypeTag[String] diff --git a/test/files/run/macro-expand-tparams-prefix-c1.check b/test/files/run/macro-expand-tparams-prefix-c1.check index fac58e9516..87f295aa49 100644 --- a/test/files/run/macro-expand-tparams-prefix-c1.check +++ b/test/files/run/macro-expand-tparams-prefix-c1.check @@ -1,3 +1,3 @@ -GroundTypeTag[Int] -GroundTypeTag[String] -GroundTypeTag[Boolean] +ConcreteTypeTag[Int] +ConcreteTypeTag[String] +ConcreteTypeTag[Boolean] diff --git a/test/files/run/macro-expand-tparams-prefix-c2.check b/test/files/run/macro-expand-tparams-prefix-c2.check index fac58e9516..87f295aa49 100644 --- a/test/files/run/macro-expand-tparams-prefix-c2.check +++ b/test/files/run/macro-expand-tparams-prefix-c2.check @@ -1,3 +1,3 @@ -GroundTypeTag[Int] -GroundTypeTag[String] -GroundTypeTag[Boolean] +ConcreteTypeTag[Int] +ConcreteTypeTag[String] +ConcreteTypeTag[Boolean] diff --git a/test/files/run/macro-expand-tparams-prefix-d1.check b/test/files/run/macro-expand-tparams-prefix-d1.check index f78ddea4f3..ca7a220475 100644 --- a/test/files/run/macro-expand-tparams-prefix-d1.check +++ b/test/files/run/macro-expand-tparams-prefix-d1.check @@ -1,3 +1,3 @@ TypeTag[T] TypeTag[U] -GroundTypeTag[Boolean] +ConcreteTypeTag[Boolean] diff --git a/test/files/run/macro-reify-groundtypetag-notypeparams.check b/test/files/run/macro-reify-groundtypetag-notypeparams.check index 24612cd4b7..d75b3c72b2 100644 --- a/test/files/run/macro-reify-groundtypetag-notypeparams.check +++ b/test/files/run/macro-reify-groundtypetag-notypeparams.check @@ -1,2 +1,2 @@ -GroundTypeTag[Int] -GroundTypeTag[List[Int]] +ConcreteTypeTag[Int] +ConcreteTypeTag[List[Int]] diff --git a/test/files/run/macro-reify-groundtypetag-notypeparams/Test.scala b/test/files/run/macro-reify-groundtypetag-notypeparams/Test.scala index 3aa40251ec..d2f8fab5ec 100644 --- a/test/files/run/macro-reify-groundtypetag-notypeparams/Test.scala +++ b/test/files/run/macro-reify-groundtypetag-notypeparams/Test.scala @@ -1,6 +1,6 @@ import scala.reflect.mirror._ object Test extends App { - println(implicitly[GroundTypeTag[Int]]) - println(implicitly[GroundTypeTag[List[Int]]]) + println(implicitly[ConcreteTypeTag[Int]]) + println(implicitly[ConcreteTypeTag[List[Int]]]) } \ No newline at end of file diff --git a/test/files/run/macro-reify-groundtypetag-typeparams-tags.check b/test/files/run/macro-reify-groundtypetag-typeparams-tags.check index 24612cd4b7..d75b3c72b2 100644 --- a/test/files/run/macro-reify-groundtypetag-typeparams-tags.check +++ b/test/files/run/macro-reify-groundtypetag-typeparams-tags.check @@ -1,2 +1,2 @@ -GroundTypeTag[Int] -GroundTypeTag[List[Int]] +ConcreteTypeTag[Int] +ConcreteTypeTag[List[Int]] diff --git a/test/files/run/macro-reify-groundtypetag-typeparams-tags/Test.scala b/test/files/run/macro-reify-groundtypetag-typeparams-tags/Test.scala index 21735c10d5..6d7eab5f9a 100644 --- a/test/files/run/macro-reify-groundtypetag-typeparams-tags/Test.scala +++ b/test/files/run/macro-reify-groundtypetag-typeparams-tags/Test.scala @@ -1,9 +1,9 @@ import scala.reflect.mirror._ object Test extends App { - def fooTypeTag[T: GroundTypeTag] = { - println(implicitly[GroundTypeTag[T]]) - println(implicitly[GroundTypeTag[List[T]]]) + def fooTypeTag[T: ConcreteTypeTag] = { + println(implicitly[ConcreteTypeTag[T]]) + println(implicitly[ConcreteTypeTag[List[T]]]) } fooTypeTag[Int] } \ No newline at end of file diff --git a/test/files/run/macro-reify-typetag-notypeparams.check b/test/files/run/macro-reify-typetag-notypeparams.check index 24612cd4b7..d75b3c72b2 100644 --- a/test/files/run/macro-reify-typetag-notypeparams.check +++ b/test/files/run/macro-reify-typetag-notypeparams.check @@ -1,2 +1,2 @@ -GroundTypeTag[Int] -GroundTypeTag[List[Int]] +ConcreteTypeTag[Int] +ConcreteTypeTag[List[Int]] diff --git a/test/files/run/macro-reify-typetag-typeparams-notags.check b/test/files/run/macro-reify-typetag-typeparams-notags.check index 3da30c71ba..af4877e205 100644 --- a/test/files/run/macro-reify-typetag-typeparams-notags.check +++ b/test/files/run/macro-reify-typetag-typeparams-notags.check @@ -1,2 +1,2 @@ -GroundTypeTag[T] -GroundTypeTag[List[T]] +ConcreteTypeTag[T] +ConcreteTypeTag[List[T]] diff --git a/test/files/run/macro-reify-typetag-typeparams-tags.check b/test/files/run/macro-reify-typetag-typeparams-tags.check index 24612cd4b7..d75b3c72b2 100644 --- a/test/files/run/macro-reify-typetag-typeparams-tags.check +++ b/test/files/run/macro-reify-typetag-typeparams-tags.check @@ -1,2 +1,2 @@ -GroundTypeTag[Int] -GroundTypeTag[List[Int]] +ConcreteTypeTag[Int] +ConcreteTypeTag[List[Int]] diff --git a/test/files/run/macro-reify-typetag-usegroundtypetag.check b/test/files/run/macro-reify-typetag-usegroundtypetag.check index 24612cd4b7..d75b3c72b2 100644 --- a/test/files/run/macro-reify-typetag-usegroundtypetag.check +++ b/test/files/run/macro-reify-typetag-usegroundtypetag.check @@ -1,2 +1,2 @@ -GroundTypeTag[Int] -GroundTypeTag[List[Int]] +ConcreteTypeTag[Int] +ConcreteTypeTag[List[Int]] diff --git a/test/files/run/macro-reify-typetag-usegroundtypetag/Test.scala b/test/files/run/macro-reify-typetag-usegroundtypetag/Test.scala index c9b210f35a..de235f51cc 100644 --- a/test/files/run/macro-reify-typetag-usegroundtypetag/Test.scala +++ b/test/files/run/macro-reify-typetag-usegroundtypetag/Test.scala @@ -1,7 +1,7 @@ import scala.reflect.mirror._ object Test extends App { - def fooTypeTag[T: GroundTypeTag] = { + def fooTypeTag[T: ConcreteTypeTag] = { println(implicitly[TypeTag[T]]) println(implicitly[TypeTag[List[T]]]) } diff --git a/test/files/run/macro-typecheck-macrosdisabled.check b/test/files/run/macro-typecheck-macrosdisabled.check index 9760c117a7..b432a539fc 100644 --- a/test/files/run/macro-typecheck-macrosdisabled.check +++ b/test/files/run/macro-typecheck-macrosdisabled.check @@ -1,5 +1,5 @@ { val $mr: reflect.mirror.type = scala.reflect.`package`.mirror; - $mr.Expr.apply[Int(2)]($mr.Literal.apply($mr.Constant.apply(2)))($mr.GroundTypeTag.apply[Int(2)]($mr.ConstantType.apply($mr.Constant.apply(2)))) + $mr.Expr.apply[Int(2)]($mr.Literal.apply($mr.Constant.apply(2)))($mr.ConcreteTypeTag.apply[Int(2)]($mr.ConstantType.apply($mr.Constant.apply(2)))) } mr.reify[Int](2) diff --git a/test/files/run/macro-undetparams-consfromsls.check b/test/files/run/macro-undetparams-consfromsls.check index 6bf9bcca5a..49e9140d5a 100644 --- a/test/files/run/macro-undetparams-consfromsls.check +++ b/test/files/run/macro-undetparams-consfromsls.check @@ -1,5 +1,5 @@ -A = GroundTypeTag[Int] -B = GroundTypeTag[Nothing] +A = ConcreteTypeTag[Int] +B = ConcreteTypeTag[Nothing] List(1) -A = GroundTypeTag[Any] +A = ConcreteTypeTag[Any] List(abc, 1) diff --git a/test/files/run/macro-undetparams-implicitval.check b/test/files/run/macro-undetparams-implicitval.check index 352a2e6480..6c2b601aa5 100644 --- a/test/files/run/macro-undetparams-implicitval.check +++ b/test/files/run/macro-undetparams-implicitval.check @@ -1 +1 @@ -GroundTypeTag[Nothing] +ConcreteTypeTag[Nothing] diff --git a/test/files/run/macro-undetparams-macroitself.check b/test/files/run/macro-undetparams-macroitself.check index 60c021a35b..e57fc1217b 100644 --- a/test/files/run/macro-undetparams-macroitself.check +++ b/test/files/run/macro-undetparams-macroitself.check @@ -1,2 +1,2 @@ -GroundTypeTag[Int] -GroundTypeTag[String] +ConcreteTypeTag[Int] +ConcreteTypeTag[String] diff --git a/test/files/run/primitive-sigs-2.check b/test/files/run/primitive-sigs-2.check index 761aa1ca72..1b6e24ed20 100644 --- a/test/files/run/primitive-sigs-2.check +++ b/test/files/run/primitive-sigs-2.check @@ -1,7 +1,7 @@ T List(A, char, class java.lang.Object) a -public java.lang.Object Arr.arr4(java.lang.Object[],scala.reflect.api.TypeTags.scala.reflect.api.TypeTags$GroundTypeTag) +public java.lang.Object Arr.arr4(java.lang.Object[],scala.reflect.api.TypeTags.scala.reflect.api.TypeTags$ConcreteTypeTag) public float[] Arr.arr3(float[][]) public scala.collection.immutable.List Arr.arr2(java.lang.Character[]) public scala.collection.immutable.List Arr.arr1(int[]) diff --git a/test/files/run/reify_newimpl_25.check b/test/files/run/reify_newimpl_25.check index 31ece627e1..37ff83c9ee 100644 --- a/test/files/run/reify_newimpl_25.check +++ b/test/files/run/reify_newimpl_25.check @@ -14,7 +14,7 @@ scala> { :13: free term: Ident(newTermName("x")) defined by res0 in :12:21 val tt = implicitly[TypeTag[x.type]] ^ -GroundTypeTag[x.type] +ConcreteTypeTag[x.type] scala> diff --git a/test/files/run/reify_newimpl_26.check b/test/files/run/reify_newimpl_26.check index 68b0ee8c99..bfbf1d653d 100644 --- a/test/files/run/reify_newimpl_26.check +++ b/test/files/run/reify_newimpl_26.check @@ -16,7 +16,7 @@ scala> def foo[T]{ foo: [T]=> Unit scala> foo[Int] -GroundTypeTag[List[T]] +ConcreteTypeTag[List[T]] scala> diff --git a/test/files/run/toolbox_typecheck_macrosdisabled.check b/test/files/run/toolbox_typecheck_macrosdisabled.check index fe2323ea06..cf2420bc17 100644 --- a/test/files/run/toolbox_typecheck_macrosdisabled.check +++ b/test/files/run/toolbox_typecheck_macrosdisabled.check @@ -1,5 +1,5 @@ { val $mr: mr.type = mr; - $mr.Expr.apply[Int(2)]($mr.Literal.apply($mr.Constant.apply(2)))($mr.GroundTypeTag.apply[Int(2)]($mr.ConstantType.apply($mr.Constant.apply(2)))) + $mr.Expr.apply[Int(2)]($mr.Literal.apply($mr.Constant.apply(2)))($mr.ConcreteTypeTag.apply[Int(2)]($mr.ConstantType.apply($mr.Constant.apply(2)))) } mr.reify[Int](2) diff --git a/test/files/run/typetags_core.check b/test/files/run/typetags_core.check index d1b71f0926..62fcb481ae 100644 --- a/test/files/run/typetags_core.check +++ b/test/files/run/typetags_core.check @@ -1,30 +1,30 @@ true -GroundTypeTag[Byte] +ConcreteTypeTag[Byte] true -GroundTypeTag[Short] +ConcreteTypeTag[Short] true -GroundTypeTag[Char] +ConcreteTypeTag[Char] true -GroundTypeTag[Int] +ConcreteTypeTag[Int] true -GroundTypeTag[Long] +ConcreteTypeTag[Long] true -GroundTypeTag[Float] +ConcreteTypeTag[Float] true -GroundTypeTag[Double] +ConcreteTypeTag[Double] true -GroundTypeTag[Boolean] +ConcreteTypeTag[Boolean] true -GroundTypeTag[Unit] +ConcreteTypeTag[Unit] true -GroundTypeTag[Any] +ConcreteTypeTag[Any] true -GroundTypeTag[Object] +ConcreteTypeTag[Object] true -GroundTypeTag[AnyVal] +ConcreteTypeTag[AnyVal] true -GroundTypeTag[AnyRef] +ConcreteTypeTag[AnyRef] true -GroundTypeTag[Null] +ConcreteTypeTag[Null] true -GroundTypeTag[Nothing] +ConcreteTypeTag[Nothing] diff --git a/test/pending/run/macro-reify-groundtypetag-hktypeparams-tags/Test.scala b/test/pending/run/macro-reify-groundtypetag-hktypeparams-tags/Test.scala index 4b264d83af..ef70a66f1a 100644 --- a/test/pending/run/macro-reify-groundtypetag-hktypeparams-tags/Test.scala +++ b/test/pending/run/macro-reify-groundtypetag-hktypeparams-tags/Test.scala @@ -1,9 +1,9 @@ import scala.reflect.mirror._ object Test extends App { - def fooTypeTagHK[C[_]: GroundTypeTag, T: GroundTypeTag] = { - println(implicitly[GroundTypeTag[C[T]]]) - println(implicitly[GroundTypeTag[List[C[T]]]]) + def fooTypeTagHK[C[_]: ConcreteTypeTag, T: ConcreteTypeTag] = { + println(implicitly[ConcreteTypeTag[C[T]]]) + println(implicitly[ConcreteTypeTag[List[C[T]]]]) } fooTypeTagHK[List, Int] } \ No newline at end of file -- cgit v1.2.3 From 5e4c47f33b8e25feb59ab4599231b1b8d3150de8 Mon Sep 17 00:00:00 2001 From: Eugene Burmako Date: Sat, 14 Apr 2012 21:11:37 +0200 Subject: implements reification of tough types --- src/compiler/scala/reflect/internal/StdNames.scala | 1 + src/compiler/scala/reflect/internal/Symbols.scala | 4 +- src/compiler/scala/reflect/internal/TreeInfo.scala | 16 +-- src/compiler/scala/reflect/internal/Types.scala | 33 ++++- .../reflect/reify/codegen/AnnotationInfos.scala | 56 ++++++++ .../scala/reflect/reify/codegen/Symbols.scala | 114 +++++++++++++---- .../scala/reflect/reify/codegen/Trees.scala | 20 ++- .../scala/reflect/reify/codegen/Types.scala | 141 ++++++--------------- .../scala/reflect/reify/phases/Metalevels.scala | 2 + .../scala/reflect/reify/phases/Reify.scala | 4 + src/compiler/scala/tools/nsc/util/Position.scala | 10 +- src/library/scala/reflect/api/Attachment.scala | 10 +- src/library/scala/reflect/api/StandardNames.scala | 1 + src/library/scala/reflect/api/Symbols.scala | 5 + src/library/scala/reflect/api/Trees.scala | 18 ++- src/library/scala/reflect/api/TypeTags.scala | 7 +- src/library/scala/reflect/api/Types.scala | 4 + test/files/jvm/manifests.check | 56 ++++++++ .../files/jvm/manifests.check.temporarily.disabled | 55 -------- test/files/jvm/manifests.scala | 112 ++++++++++++++++ .../files/jvm/manifests.scala.temporarily.disabled | 109 ---------------- test/files/neg/t3507.check | 4 - test/files/neg/t3507.scala | 15 --- test/files/pos/implicits.scala | 89 +++++++++++++ .../files/pos/implicits.scala.temporarily.disabled | 89 ------------- test/files/pos/manifest1.scala | 21 +++ .../files/pos/manifest1.scala.temporarily.disabled | 21 --- test/files/run/existentials3.check | 24 ++++ .../run/existentials3.check.temporarily.disabled | 22 ---- test/files/run/existentials3.scala | 79 ++++++++++++ .../run/existentials3.scala.temporarily.disabled | 73 ----------- test/files/run/t1195.check | 6 + test/files/run/t1195.check.temporarily.disabled | 6 - test/files/run/t1195.scala | 26 ++++ test/files/run/t1195.scala.temporarily.disabled | 26 ---- test/files/run/t3507.check | 1 + test/files/run/t3507.scala | 15 +++ test/files/run/t4110.check | 2 + test/files/run/t4110.check.temporarily.disabled | 2 - test/files/run/t4110.scala | 11 ++ test/files/run/t4110.scala.temporarily.disabled | 11 -- test/files/run/treePrint.check | 5 + .../files/run/treePrint.check.temporarily.disabled | 5 - test/files/run/treePrint.scala | 43 +++++++ .../files/run/treePrint.scala.temporarily.disabled | 42 ------ 45 files changed, 786 insertions(+), 630 deletions(-) create mode 100644 src/compiler/scala/reflect/reify/codegen/AnnotationInfos.scala create mode 100644 test/files/jvm/manifests.check delete mode 100644 test/files/jvm/manifests.check.temporarily.disabled create mode 100644 test/files/jvm/manifests.scala delete mode 100644 test/files/jvm/manifests.scala.temporarily.disabled delete mode 100644 test/files/neg/t3507.check delete mode 100644 test/files/neg/t3507.scala create mode 100644 test/files/pos/implicits.scala delete mode 100644 test/files/pos/implicits.scala.temporarily.disabled create mode 100644 test/files/pos/manifest1.scala delete mode 100644 test/files/pos/manifest1.scala.temporarily.disabled create mode 100644 test/files/run/existentials3.check delete mode 100644 test/files/run/existentials3.check.temporarily.disabled create mode 100644 test/files/run/existentials3.scala delete mode 100644 test/files/run/existentials3.scala.temporarily.disabled create mode 100644 test/files/run/t1195.check delete mode 100644 test/files/run/t1195.check.temporarily.disabled create mode 100644 test/files/run/t1195.scala delete mode 100644 test/files/run/t1195.scala.temporarily.disabled create mode 100644 test/files/run/t3507.check create mode 100644 test/files/run/t3507.scala create mode 100644 test/files/run/t4110.check delete mode 100644 test/files/run/t4110.check.temporarily.disabled create mode 100644 test/files/run/t4110.scala delete mode 100644 test/files/run/t4110.scala.temporarily.disabled create mode 100644 test/files/run/treePrint.check delete mode 100644 test/files/run/treePrint.check.temporarily.disabled create mode 100644 test/files/run/treePrint.scala delete mode 100644 test/files/run/treePrint.scala.temporarily.disabled (limited to 'test/files/neg/t3507.check') diff --git a/src/compiler/scala/reflect/internal/StdNames.scala b/src/compiler/scala/reflect/internal/StdNames.scala index ac2cf178bf..bf468affe6 100644 --- a/src/compiler/scala/reflect/internal/StdNames.scala +++ b/src/compiler/scala/reflect/internal/StdNames.scala @@ -206,6 +206,7 @@ trait StdNames extends NameManglers { self: SymbolTable => val MIRROR_FREE_PREFIX: NameType = "free$" val MIRROR_FREE_THIS_SUFFIX: NameType = "$this" val MIRROR_FREE_VALUE_SUFFIX: NameType = "$value" + val MIRROR_SYMDEF_PREFIX: NameType = "symdef$" val MIXIN_CONSTRUCTOR: NameType = "$init$" val MODULE_INSTANCE_FIELD: NameType = NameTransformer.MODULE_INSTANCE_NAME // "MODULE$" val OUTER: NameType = "$outer" diff --git a/src/compiler/scala/reflect/internal/Symbols.scala b/src/compiler/scala/reflect/internal/Symbols.scala index 3bb57cea04..c9947c3c09 100644 --- a/src/compiler/scala/reflect/internal/Symbols.scala +++ b/src/compiler/scala/reflect/internal/Symbols.scala @@ -64,6 +64,7 @@ trait Symbols extends api.Symbols { self: SymbolTable => this: Symbol => def kind: String = kindString + def isExistential: Boolean = this.isExistentiallyBound def newNestedSymbol(name: Name, pos: Position, newFlags: Long, isClass: Boolean): Symbol = name match { case n: TermName => newTermSymbol(n, pos, newFlags) @@ -897,8 +898,10 @@ trait Symbols extends api.Symbols { self: SymbolTable => if (!owner.isLocatable) return false if (owner.isTerm) return false + if (isLocalDummy) return false if (isType && isNonClassType) return false + if (isRefinementClass) return false return true } @@ -2965,7 +2968,6 @@ trait Symbols extends api.Symbols { self: SymbolTable => override def isFreeTerm = true } - // [Eugene] the NoSymbol origin works for type parameters. what about existential free types? class FreeType(name0: TypeName, value0: => Any, val origin: String) extends TypeSkolem(NoSymbol, NoPosition, name0, NoSymbol) { def value = value0 override def isFreeType = true diff --git a/src/compiler/scala/reflect/internal/TreeInfo.scala b/src/compiler/scala/reflect/internal/TreeInfo.scala index a8cca1625f..039c8e557a 100644 --- a/src/compiler/scala/reflect/internal/TreeInfo.scala +++ b/src/compiler/scala/reflect/internal/TreeInfo.scala @@ -590,7 +590,7 @@ abstract class TreeInfo { } object Reified { - def unapply(tree: Tree): Option[(Tree, List[ValDef], Tree)] = tree match { + def unapply(tree: Tree): Option[(Tree, List[Tree], Tree)] = tree match { case ReifiedTree(reifee, symbolTable, reified, _) => Some(reifee, symbolTable, reified) case ReifiedType(reifee, symbolTable, reified) => @@ -601,16 +601,16 @@ abstract class TreeInfo { } object ReifiedTree { - def unapply(tree: Tree): Option[(Tree, List[ValDef], Tree, Tree)] = tree match { + def unapply(tree: Tree): Option[(Tree, List[Tree], Tree, Tree)] = tree match { case reifee @ Block((mrDef @ ValDef(_, _, _, _)) :: symbolTable, Apply(Apply(_, List(tree)), List(Apply(_, List(tpe))))) if mrDef.name == nme.MIRROR_SHORT => - Some(reifee, symbolTable map (_.asInstanceOf[ValDef]), tree, tpe) + Some(reifee, symbolTable, tree, tpe) case _ => None } } object InlineableTreeSplice { - def unapply(tree: Tree): Option[(Tree, List[ValDef], Tree, Tree, Symbol)] = tree match { + def unapply(tree: Tree): Option[(Tree, List[Tree], Tree, Tree, Symbol)] = tree match { case select @ Select(ReifiedTree(splicee, symbolTable, tree, tpe), _) if select.symbol == ExprEval || select.symbol == ExprValue => Some(splicee, symbolTable, tree, tpe, select.symbol) case _ => @@ -619,7 +619,7 @@ abstract class TreeInfo { } object InlinedTreeSplice { - def unapply(tree: Tree): Option[(Tree, List[ValDef], Tree, Tree)] = tree match { + def unapply(tree: Tree): Option[(Tree, List[Tree], Tree, Tree)] = tree match { case Select(ReifiedTree(splicee, symbolTable, tree, tpe), name) if name == ExprTree.name => Some(splicee, symbolTable, tree, tpe) case _ => @@ -628,16 +628,16 @@ abstract class TreeInfo { } object ReifiedType { - def unapply(tree: Tree): Option[(Tree, List[ValDef], Tree)] = tree match { + def unapply(tree: Tree): Option[(Tree, List[Tree], Tree)] = tree match { case reifee @ Block((mrDef @ ValDef(_, _, _, _)) :: symbolTable, Apply(_, List(tpe))) if mrDef.name == nme.MIRROR_SHORT => - Some(reifee, symbolTable map (_.asInstanceOf[ValDef]), tpe) + Some(reifee, symbolTable, tpe) case _ => None } } object InlinedTypeSplice { - def unapply(tree: Tree): Option[(Tree, List[ValDef], Tree)] = tree match { + def unapply(tree: Tree): Option[(Tree, List[Tree], Tree)] = tree match { case Select(ReifiedType(splicee, symbolTable, tpe), name) if name == TypeTagTpe.name => Some(splicee, symbolTable, tpe) case _ => diff --git a/src/compiler/scala/reflect/internal/Types.scala b/src/compiler/scala/reflect/internal/Types.scala index 3efbe4b4df..d7c90d597c 100644 --- a/src/compiler/scala/reflect/internal/Types.scala +++ b/src/compiler/scala/reflect/internal/Types.scala @@ -266,6 +266,35 @@ trait Types extends api.Types { self: SymbolTable => def typeArguments = typeArgs def erasure = transformedType(this) def substituteTypes(from: List[Symbol], to: List[Type]): Type = subst(from, to) + + // [Eugene] to be discussed and refactored + def isConcrete = { + def notConcreteSym(sym: Symbol) = + sym.isAbstractType && !sym.isExistential + + def notConcreteTpe(tpe: Type): Boolean = tpe match { + case ThisType(_) => false + case SuperType(_, _) => false + case SingleType(pre, sym) => notConcreteSym(sym) + case ConstantType(_) => false + case TypeRef(_, sym, _) => notConcreteSym(sym) + case RefinedType(_, _) => false + case ExistentialType(_, _) => false + case AnnotatedType(_, tp, _) => notConcreteTpe(tp) + case _ => true + } + + !notConcreteTpe(this) + } + + // [Eugene] is this comprehensive? + // the only thingies that we want to splice are: 1) type parameters, 2) type members + // the thingies that we don't want to splice are: 1) concrete types (obviously), 2) existential skolems + // this check seems to cover them all, right? + // todo. after we discuss this, move the check to subclasses + def isSpliceable = { + this.isInstanceOf[TypeRef] && typeSymbol.isAbstractType && !typeSymbol.isExistential + } } /** The base class for all types */ @@ -2147,7 +2176,7 @@ trait Types extends api.Types { self: SymbolTable => sym.isPackageClass || pre.isGround && args.forall(_.isGround) ) - + def etaExpand: Type = { // must initialise symbol, see test/files/pos/ticket0137.scala val tpars = initializedTypeParams @@ -2763,7 +2792,7 @@ trait Types extends api.Types { self: SymbolTable => zippedArgs map { case (p, a) => p.name + "=" + a } mkString (origin + "[", ", ", "]") ) } - + trait UntouchableTypeVar extends TypeVar { override def untouchable = true override def isGround = true diff --git a/src/compiler/scala/reflect/reify/codegen/AnnotationInfos.scala b/src/compiler/scala/reflect/reify/codegen/AnnotationInfos.scala new file mode 100644 index 0000000000..1d218317dc --- /dev/null +++ b/src/compiler/scala/reflect/reify/codegen/AnnotationInfos.scala @@ -0,0 +1,56 @@ +package scala.reflect.reify +package codegen + +trait AnnotationInfos { + self: Reifier => + + import mirror._ + import definitions._ + import treeInfo._ + + // usually annotations are reified as their originals from Modifiers + // however, when reifying free and tough types, we're forced to reify annotation infos as is + // why is that bad? take a look inside + def reifyAnnotationInfo(ann: AnnotationInfo): Tree = { + val reifiedArgs = ann.args map { arg => + val saved1 = reifyTreeSymbols + val saved2 = reifyTreeTypes + + try { + // one more quirk of reifying annotations + // + // when reifying AnnotatedTypes we need to reify all the types and symbols of inner ASTs + // that's because a lot of logic expects post-typer trees to have non-null tpes + // + // Q: reified trees are pre-typer, so there's shouldn't be a problem. + // reflective typechecker will fill in missing symbols and types, right? + // A: actually, no. annotation ASTs live inside AnnotatedTypes, + // and insides of the types is the place where typechecker doesn't look. + reifyTreeSymbols = true + reifyTreeTypes = true + + // todo. every AnnotationInfo is an island, entire of itself + // no regular Traverser or Transformer can reach it + // hence we need to run its contents through the entire reification pipeline + // e.g. to apply reshaping or to check metalevels + reify(arg) + } finally { + reifyTreeSymbols = saved1 + reifyTreeTypes = saved2 + } + } + + def reifyClassfileAnnotArg(arg: ClassfileAnnotArg): Tree = arg match { + case LiteralAnnotArg(const) => + mirrorFactoryCall(nme.LiteralAnnotArg, reifyProduct(const)) + case ArrayAnnotArg(args) => + mirrorFactoryCall(nme.ArrayAnnotArg, scalaFactoryCall(nme.Array, args map reifyClassfileAnnotArg: _*)) + case NestedAnnotArg(ann) => + mirrorFactoryCall(nme.NestedAnnotArg, reifyAnnotationInfo(ann)) + } + + // if you reify originals of anns, you get SO when trying to reify AnnotatedTypes, so screw it - after all, it's not that important + val reifiedAssocs = ann.assocs map (assoc => scalaFactoryCall(nme.Tuple2, reify(assoc._1), reifyClassfileAnnotArg(assoc._2))) + mirrorFactoryCall(nme.AnnotationInfo, reify(ann.atp), mkList(reifiedArgs), mkList(reifiedAssocs)) + } +} \ No newline at end of file diff --git a/src/compiler/scala/reflect/reify/codegen/Symbols.scala b/src/compiler/scala/reflect/reify/codegen/Symbols.scala index 3328f5e402..2fc0002838 100644 --- a/src/compiler/scala/reflect/reify/codegen/Symbols.scala +++ b/src/compiler/scala/reflect/reify/codegen/Symbols.scala @@ -46,13 +46,8 @@ trait Symbols { } } else { // todo. make sure that free methods and free local defs work correctly - if (sym.isTerm) { - if (reifyDebug) println("Free term" + (if (sym.isCapturedVariable) " (captured)" else "") + ": " + sym) - reifyFreeTerm(sym, Ident(sym)) - } else { - if (reifyDebug) println("Free type: " + sym) - reifyFreeType(sym, Ident(sym)) - } + if (sym.isTerm) reifyFreeTerm(sym, Ident(sym)) + else reifyFreeType(sym, Ident(sym)) } } @@ -61,13 +56,16 @@ trait Symbols { case Some(reified) => reified case None => + if (reifyDebug) println("Free term" + (if (sym.isCapturedVariable) " (captured)" else "") + ": " + sym + "(" + sym.accurateKindString + ")") + var name = newTermName(nme.MIRROR_FREE_PREFIX + sym.name) + if (sym.isType) name = name.append(nme.MIRROR_FREE_THIS_SUFFIX) if (sym.isCapturedVariable) { assert(value.isInstanceOf[Ident], showRaw(value)) val capturedTpe = capturedVariableType(sym) val capturedValue = referenceCapturedVariable(sym) - locallyReify(sym, mirrorCall(nme.newFreeTerm, reify(sym.name.toString), reify(capturedTpe), capturedValue, reify(origin(sym)))) + locallyReify(sym, name, mirrorCall(nme.newFreeTerm, reify(sym.name.toString), reify(capturedTpe), capturedValue, reify(origin(sym)))) } else { - locallyReify(sym, mirrorCall(nme.newFreeTerm, reify(sym.name.toString), reify(sym.tpe), value, reify(origin(sym)))) + locallyReify(sym, name, mirrorCall(nme.newFreeTerm, reify(sym.name.toString), reify(sym.tpe), value, reify(origin(sym)))) } } @@ -76,36 +74,104 @@ trait Symbols { case Some(reified) => reified case None => + if (reifyDebug) println("Free type: %s (%s)".format(sym, sym.accurateKindString)) + var name = newTermName(nme.MIRROR_FREE_PREFIX + sym.name) val phantomTypeTag = Apply(TypeApply(Select(Ident(nme.MIRROR_SHORT), nme.TypeTag), List(value)), List(Literal(Constant(null)))) // todo. implement info reification for free types: type bounds, HK-arity, whatever else that can be useful - locallyReify(sym, mirrorCall(nme.newFreeType, reify(sym.name.toString), reify(sym.info), phantomTypeTag, reify(origin(sym)))) + locallyReify(sym, name, mirrorCall(nme.newFreeType, reify(sym.name.toString), reify(sym.info), phantomTypeTag, reify(origin(sym)))) + } + + def reifySymDef(sym: Symbol): Tree = + locallyReified get sym match { + case Some(reified) => + reified + case None => + if (reifyDebug) println("Sym def: %s (%s)".format(sym, sym.accurateKindString)) + assert(!sym.isLocatable, sym) // if this assertion fires, then tough type reification needs to be rethought + sym.owner.ownersIterator find (!_.isLocatable) foreach reifySymDef + var name = newTermName(nme.MIRROR_SYMDEF_PREFIX + sym.name) + locallyReify(sym, name, Apply(Select(reify(sym.owner), nme.newNestedSymbol), List(reify(sym.name), reify(sym.pos), reify(sym.flags), reify(sym.isClass)))) } + // todo. very brittle abstraction, needs encapsulation import scala.collection.mutable._ - private val localReifications = ArrayBuffer[ValDef]() + private val localReifications = ArrayBuffer[Tree]() private val locallyReified = Map[Symbol, Tree]() - def symbolTable: List[ValDef] = localReifications.toList - def symbolTable_=(newSymbolTable: List[ValDef]): Unit = { + private var filledIn = false + def symbolTable: List[Tree] = { fillInSymbolTable(); localReifications.toList } + def symbolTable_=(newSymbolTable: List[Tree]): Unit = { localReifications.clear() locallyReified.clear() + filledIn = false newSymbolTable foreach { - case freedef @ FreeDef(_, name, binding, _) => - if (!(locallyReified contains binding.symbol)) { - localReifications += freedef - locallyReified(binding.symbol) = Ident(name) + case entry => + val att = entry.attachment + att match { + case sym: Symbol => + // don't duplicate reified symbols when merging inlined reifee + if (!(locallyReified contains sym)) { + val ValDef(_, name, _, _) = entry + localReifications += entry + locallyReified(sym) = Ident(name) + } + case other => + // do nothing => symbol table fill-ins will be repopulated later } } } - private def locallyReify(sym: Symbol, reificode: => Tree): Tree = { + private def localName(name0: TermName): TermName = { + var name = name0.toString + name = name.replace(".type", "$type") + name = name.replace(" ", "$") + val fresh = typer.context.unit.fresh + newTermName(fresh.newName(name)) + } + + private def locallyReify(sym: Symbol, name0: TermName, reificode: => Tree): Tree = { val reified = reificode - val Apply(Select(_, flavor), _) = reified - // [Eugene] name clashes are impossible, right? - var name = newTermName(nme.MIRROR_FREE_PREFIX + sym.name) - if (flavor == nme.newFreeTerm && sym.isType) name = name.append(nme.MIRROR_FREE_THIS_SUFFIX); - // todo. also reify annotations for free vars - localReifications += ValDef(NoMods, name, TypeTree(), reified) + val name = localName(name0) + // todo. tried to declare a private class here to carry an attachment, but it's path-dependent + // so got troubles with exchanging free variables between nested and enclosing quasiquotes + // attaching just Symbol isn't good either, so we need to think of a principled solution + val local = ValDef(NoMods, name, TypeTree(), reified) setAttachment sym + localReifications += local + filledIn = false locallyReified(sym) = Ident(name) locallyReified(sym) } + + /** Sets type signatures and annotations for locally reified symbols */ + private def fillInSymbolTable() = { + if (!filledIn) { + val fillIns = new ArrayBuffer[Tree] + var i = 0 + while (i < localReifications.length) { + // fillInSymbol might create new locallyReified symbols, that's why this is done iteratively + val reified = localReifications(i) + reified.attachment match { + case sym: Symbol => fillIns += fillInSymbol(sym) + case other => // do nothing + } + i += 1 + } + + filledIn = true + localReifications ++= fillIns.toList + } + } + + /** Generate code to add type and annotation info to a reified symbol */ + private def fillInSymbol(sym: Symbol): Tree = { + if (reifyDebug) println("Filling in: %s (%s)".format(sym, sym.accurateKindString)) + val isFree = locallyReified(sym) match { case Ident(name) => name startsWith nme.MIRROR_FREE_PREFIX } + if (isFree) { + if (sym.annotations.isEmpty) EmptyTree + else Apply(Select(locallyReified(sym), nme.setAnnotations), List(reify(sym.annotations))) + } else { + val rset = Apply(Select(locallyReified(sym), nme.setTypeSignature), List(reifyType(sym.info))) + if (sym.annotations.isEmpty) rset + else Apply(Select(rset, nme.setAnnotations), List(reify(sym.annotations))) + } + } } \ No newline at end of file diff --git a/src/compiler/scala/reflect/reify/codegen/Trees.scala b/src/compiler/scala/reflect/reify/codegen/Trees.scala index 22f42aea49..5ad53c0009 100644 --- a/src/compiler/scala/reflect/reify/codegen/Trees.scala +++ b/src/compiler/scala/reflect/reify/codegen/Trees.scala @@ -8,6 +8,11 @@ trait Trees { import definitions._ import treeInfo._ + // unfortunately, these are necessary to reify AnnotatedTypes + // I'd gladly got rid of them, but I don't fancy making a metaprogramming API that doesn't work with annotated types + var reifyTreeSymbols = false + var reifyTreeTypes = false + /** * Reify a tree. * For internal use only, use ``reified'' instead. @@ -59,6 +64,17 @@ trait Trees { reifyProduct(tree) } + // usually we don't reify symbols/types, because they can be re-inferred during subsequent reflective compilation + // however, reification of AnnotatedTypes is special. see ``reifyType'' to find out why. + if (reifyTreeSymbols && tree.hasSymbol) { + if (reifyDebug) println("reifying symbol %s for tree %s".format(tree.symbol, tree)) + rtree = Apply(Select(rtree, nme.setSymbol), List(reifySymRef(tree.symbol))) + } + if (reifyTreeTypes && tree.tpe != null) { + if (reifyDebug) println("reifying type %s for tree %s".format(tree.tpe, tree)) + rtree = Apply(Select(rtree, nme.setType), List(reifyType(tree.tpe))) + } + rtree } @@ -82,7 +98,7 @@ trait Trees { case InlinedTreeSplice(_, inlinedSymbolTable, tree, _) => if (reifyDebug) println("inlining the splicee") // all free vars local to the enclosing reifee should've already been inlined by ``Metalevels'' - inlinedSymbolTable foreach { case freedef @ FreeDef(_, _, binding, _) => assert(!binding.symbol.isLocalToReifee, freedef) } + inlinedSymbolTable collect { case freedef @ FreeDef(_, _, binding, _) if binding.symbol.isLocalToReifee => assert(false, freedef) } symbolTable ++= inlinedSymbolTable tree case tree => @@ -152,7 +168,7 @@ trait Trees { val tpe = tpe0.dealias if (reifyDebug) println("reifying bound type %s (underlying type is %s, dealiased is %s)".format(sym0, tpe0, tpe)) - if (eligibleForSplicing(tpe)) { + if (tpe.isSpliceable) { val spliced = spliceType(tpe) if (spliced == EmptyTree) { if (reifyDebug) println("splicing failed: reify as is") diff --git a/src/compiler/scala/reflect/reify/codegen/Types.scala b/src/compiler/scala/reflect/reify/codegen/Types.scala index 9bc113e8a4..948728088e 100644 --- a/src/compiler/scala/reflect/reify/codegen/Types.scala +++ b/src/compiler/scala/reflect/reify/codegen/Types.scala @@ -55,11 +55,9 @@ trait Types { case tpe @ NullaryMethodType(restpe) => reifyProduct(tpe) case tpe @ AnnotatedType(anns, underlying, selfsym) => -// reifyAnnotatedType(tpe) - CannotReifyType(tpe) + reifyAnnotatedType(tpe) case _ => -// reifyToughType(tpe) - CannotReifyType(tpe) + reifyToughType(tpe) } } @@ -70,13 +68,6 @@ trait Types { var maybeConcrete = true var definitelyConcrete = true - def eligibleForSplicing(tpe: Type): Boolean = { - // [Eugene] is this comprehensive? - // the only thingies that we want to splice are: 1) type parameters, 2) type members - // this check seems to cover them all, right? - tpe.isInstanceOf[TypeRef] && tpe.typeSymbol.isAbstractType - } - private type SpliceCacheKey = (Symbol, Symbol) private lazy val spliceCache: collection.mutable.Map[SpliceCacheKey, Tree] = { val cache = analyzer.perRunMacroCache.getOrElseUpdate(MacroContextReify, collection.mutable.Map[Any, Any]()) @@ -84,7 +75,7 @@ trait Types { } def spliceType(tpe: Type): Tree = { - if (eligibleForSplicing(tpe)) { + if (tpe.isSpliceable) { if (reifyDebug) println("splicing " + tpe) if (spliceTypesEnabled) { @@ -113,7 +104,7 @@ trait Types { splice match { case InlinedTypeSplice(_, inlinedSymbolTable, tpe) => // all free vars local to the enclosing reifee should've already been inlined by ``Metalevels'' - inlinedSymbolTable foreach { case freedef @ FreeDef(_, _, binding, _) => assert(!binding.symbol.isLocalToReifee, freedef) } + inlinedSymbolTable collect { case freedef @ FreeDef(_, _, binding, _) if binding.symbol.isLocalToReifee => assert(false, freedef) } symbolTable ++= inlinedSymbolTable reifyTrace("inlined the splicee: ")(tpe) case tpe => @@ -134,93 +125,39 @@ trait Types { EmptyTree } - // yet another thingie disabled for simplicity - // in principle, we could retain and reify AnnotatedTypes - // but that'd require reifying every type and symbol inside ann.args - // however, since we've given up on tough types for the moment, the former would be problematic -// private def reifyAnnotatedType(tpe: AnnotatedType): Tree = { -// // ``Reshaper'' transforms annotation infos from symbols back into Modifier.annotations, which are trees -// // so the only place on Earth that can lead to reification of AnnotationInfos is the Ay Tee Land -// // therefore this function is as local as possible, don't move it out of this scope -// def reifyAnnotationInfo(ann: AnnotationInfo): Tree = { -// val reifiedArgs = ann.args map { arg => -// val saved1 = reifyTreeSymbols -// val saved2 = reifyTreeTypes -// -// try { -// // one more quirk of reifying annotations -// // -// // when reifying AnnotatedTypes we need to reify all the types and symbols of inner ASTs -// // that's because a lot of logic expects post-typer trees to have non-null tpes -// // -// // Q: reified trees are pre-typer, so there's shouldn't be a problem. -// // reflective typechecker will fill in missing symbols and types, right? -// // A: actually, no. annotation ASTs live inside AnnotatedTypes, -// // and insides of the types is the place where typechecker doesn't look. -// reifyTreeSymbols = true -// reifyTreeTypes = true -// -// // todo. every AnnotationInfo is an island, entire of itself -// // no regular Traverser or Transformer can reach it -// // hence we need to run its contents through the entire reification pipeline -// // e.g. to apply reshaping or to check metalevels -// reify(arg) -// } finally { -// reifyTreeSymbols = saved1 -// reifyTreeTypes = saved2 -// } -// } -// -// def reifyClassfileAnnotArg(arg: ClassfileAnnotArg): Tree = arg match { -// case LiteralAnnotArg(const) => -// mirrorFactoryCall(nme.LiteralAnnotArg, reifyProduct(const)) -// case ArrayAnnotArg(args) => -// mirrorFactoryCall(nme.ArrayAnnotArg, scalaFactoryCall(nme.Array, args map reifyClassfileAnnotArg: _*)) -// case NestedAnnotArg(ann) => -// mirrorFactoryCall(nme.NestedAnnotArg, reifyAnnotationInfo(ann)) -// } -// -// // if you reify originals of anns, you get SO when trying to reify AnnotatedTypes, so screw it - after all, it's not that important -// val reifiedAssocs = ann.assocs map (assoc => scalaFactoryCall(nme.Tuple2, reify(assoc._1), reifyClassfileAnnotArg(assoc._2))) -// mirrorFactoryCall(nme.AnnotationInfo, reify(ann.atp), mkList(reifiedArgs), mkList(reifiedAssocs)) -// } -// -// val AnnotatedType(anns, underlying, selfsym) = tpe -// mirrorFactoryCall(nme.AnnotatedType, mkList(anns map reifyAnnotationInfo), reify(underlying), reify(selfsym)) -// } - - // previous solution to reifying tough types involved creating dummy symbols (see ``registerReifiableSymbol'' calls below) - // however such symbols lost all the connections with their origins and became almost useless, except for typechecking - // hence this approach was replaced by less powerful, but more principled one based on ``reifyFreeType'' - // it's possible that later on we will revise and revive ``reifyToughType'', but for now it's disabled under an implementation restriction -// /** Reify a tough type, i.e. the one that leads to creation of auxiliary symbols */ -// // This is the uncharted territory in the reifier -// private def reifyToughType(tpe: Type): Tree = { -// if (reifyDebug) println("tough type: %s (%s)".format(tpe, tpe.kind)) -// -// def reifyScope(scope: Scope): Tree = { -// scope foreach registerReifiableSymbol -// mirrorCall(nme.newScopeWith, scope.toList map reify: _*) -// } -// -// tpe match { -// case tpe @ RefinedType(parents, decls) => -// registerReifiableSymbol(tpe.typeSymbol) -// mirrorFactoryCall(tpe, reify(parents), reifyScope(decls), reify(tpe.typeSymbol)) -// case tpe @ ExistentialType(tparams, underlying) => -// tparams foreach registerReifiableSymbol -// mirrorFactoryCall(tpe, reify(tparams), reify(underlying)) -// case tpe @ ClassInfoType(parents, decls, clazz) => -// registerReifiableSymbol(clazz) -// mirrorFactoryCall(tpe, reify(parents), reifyScope(decls), reify(tpe.typeSymbol)) -// case tpe @ MethodType(params, restpe) => -// params foreach registerReifiableSymbol -// mirrorFactoryCall(tpe, reify(params), reify(restpe)) -// case tpe @ PolyType(tparams, underlying) => -// tparams foreach registerReifiableSymbol -// mirrorFactoryCall(tpe, reify(tparams), reify(underlying)) -// case _ => -// throw new Error("internal error: %s (%s) is not supported".format(tpe, tpe.kind)) -// } -// } + /** Reify an annotated type, i.e. the one that makes us deal with AnnotationInfos */ + private def reifyAnnotatedType(tpe: AnnotatedType): Tree = { + val AnnotatedType(anns, underlying, selfsym) = tpe + mirrorFactoryCall(nme.AnnotatedType, mkList(anns map reifyAnnotationInfo), reify(underlying), reify(selfsym)) + } + + /** Reify a tough type, i.e. the one that leads to creation of auxiliary symbols */ + private def reifyToughType(tpe: Type): Tree = { + if (reifyDebug) println("tough type: %s (%s)".format(tpe, tpe.kind)) + + def reifyScope(scope: Scope): Tree = { + scope foreach reifySymDef + mirrorCall(nme.newScopeWith, scope.toList map reify: _*) + } + + tpe match { + case tpe @ RefinedType(parents, decls) => + reifySymDef(tpe.typeSymbol) + mirrorFactoryCall(tpe, reify(parents), reifyScope(decls), reify(tpe.typeSymbol)) + case tpe @ ExistentialType(tparams, underlying) => + tparams foreach reifySymDef + mirrorFactoryCall(tpe, reify(tparams), reify(underlying)) + case tpe @ ClassInfoType(parents, decls, clazz) => + reifySymDef(clazz) + mirrorFactoryCall(tpe, reify(parents), reifyScope(decls), reify(tpe.typeSymbol)) + case tpe @ MethodType(params, restpe) => + params foreach reifySymDef + mirrorFactoryCall(tpe, reify(params), reify(restpe)) + case tpe @ PolyType(tparams, underlying) => + tparams foreach reifySymDef + mirrorFactoryCall(tpe, reify(tparams), reify(underlying)) + case _ => + throw new Error("internal error: %s (%s) is not supported".format(tpe, tpe.kind)) + } + } } \ No newline at end of file diff --git a/src/compiler/scala/reflect/reify/phases/Metalevels.scala b/src/compiler/scala/reflect/reify/phases/Metalevels.scala index a329a1043d..bb0b8ac138 100644 --- a/src/compiler/scala/reflect/reify/phases/Metalevels.scala +++ b/src/compiler/scala/reflect/reify/phases/Metalevels.scala @@ -134,6 +134,8 @@ trait Metalevels { // FreeRef(_, _) check won't work, because metalevels of symbol table and body are different, hence, freerefs in symbol table look different from freerefs in body // todo. also perform garbage collection on local symbols // so that local symbols used only in type signatures of free vars get removed + // todo. same goes for auxiliary symbol defs reified to support tough types + // some of them need to be rebuilt, some of them need to be removed, because they're no longer necessary case FreeRef(mr, name) if freedefsToInline contains name => if (reifyDebug) println("inlineable free ref: %s in %s".format(name, showRaw(tree))) val freedef @ FreeDef(_, _, binding, _) = freedefsToInline(name) diff --git a/src/compiler/scala/reflect/reify/phases/Reify.scala b/src/compiler/scala/reflect/reify/phases/Reify.scala index f6d6423605..02a96987ed 100644 --- a/src/compiler/scala/reflect/reify/phases/Reify.scala +++ b/src/compiler/scala/reflect/reify/phases/Reify.scala @@ -9,6 +9,7 @@ trait Reify extends Symbols with Types with Names with Trees + with AnnotationInfos with Positions with Util { @@ -30,6 +31,9 @@ trait Reify extends Symbols case tpe: Type => reifyType(tpe) case name: Name => reifyName(name) case tree: Tree => reifyTree(tree) + // disabled because this is a very special case that I plan to remove later + // why do I dislike annotations? see comments to `reifyAnnotationInfo` +// case ann: AnnotationInfo => reifyAnnotationInfo(ann) case pos: Position => reifyPosition(pos) case mods: mirror.Modifiers => reifyModifiers(mods) case xs: List[_] => reifyList(xs) diff --git a/src/compiler/scala/tools/nsc/util/Position.scala b/src/compiler/scala/tools/nsc/util/Position.scala index 573f7bc7b2..208cd5703a 100644 --- a/src/compiler/scala/tools/nsc/util/Position.scala +++ b/src/compiler/scala/tools/nsc/util/Position.scala @@ -40,7 +40,15 @@ trait Position extends scala.reflect.api.Position with scala.reflect.api.Attachm /** A bit weird method that is necessary to safely update positions without destroying custom attachments */ // necessary for conformance with Attachment - def withPos(pos: scala.reflect.api.Position) = pos + def withPos(newPos: scala.reflect.api.Position): scala.reflect.api.Attachment = newPos + + /** Exposes itself as payload of Attachment */ + // necessary for conformance with Attachment + def payload: Position = this + + /** A bit weird method that is necessary to safely update positions without destroying custom attachments */ + // necessary for conformance with Attachment + def withPayload(newPos: Any): scala.reflect.api.Attachment = newPos.asInstanceOf[Position] /** Java file corresponding to the source file of this position. */ diff --git a/src/library/scala/reflect/api/Attachment.scala b/src/library/scala/reflect/api/Attachment.scala index dfd362ebe0..9fa5ceb0fb 100644 --- a/src/library/scala/reflect/api/Attachment.scala +++ b/src/library/scala/reflect/api/Attachment.scala @@ -7,10 +7,18 @@ package api * Attachments have to carry positions, because we don't want to introduce even a single additional field in Tree * imposing an unnecessary memory tax because of something that will not be used in most cases. */ +// [Eugene] with the introduction of `attach` and `payload[T]` users don't need to create custom attachments anymore +// however, we cannot move attachments to scala.reflect.internal, because they are used in Trees, which are implemented completely in scala.reflect.api trait Attachment { /** Gets the underlying position */ def pos: Position /** Creates a copy of this attachment with its position updated */ - def withPos(pos: Position): Attachment + def withPos(newPos: Position): Attachment + + /** Gets the underlying payload */ + def payload: Any + + /** Creates a copy of this attachment with its payload updated */ + def withPayload(newPayload: Any): Attachment } diff --git a/src/library/scala/reflect/api/StandardNames.scala b/src/library/scala/reflect/api/StandardNames.scala index d2110ede75..d39d44dd86 100644 --- a/src/library/scala/reflect/api/StandardNames.scala +++ b/src/library/scala/reflect/api/StandardNames.scala @@ -44,6 +44,7 @@ trait StandardNames { self: Universe => val MIRROR_FREE_PREFIX: TermName val MIRROR_FREE_THIS_SUFFIX: TermName val MIRROR_FREE_VALUE_SUFFIX: TermName + val MIRROR_SYMDEF_PREFIX: TermName val MIXIN_CONSTRUCTOR: TermName val MODULE_INSTANCE_FIELD: TermName val OUTER: TermName diff --git a/src/library/scala/reflect/api/Symbols.scala b/src/library/scala/reflect/api/Symbols.scala index a154e5f7a0..e47bc7216e 100755 --- a/src/library/scala/reflect/api/Symbols.scala +++ b/src/library/scala/reflect/api/Symbols.scala @@ -173,6 +173,11 @@ trait Symbols { self: Universe => */ def isSkolem : Boolean + /** Does this symbol represent an existentially bound type? + * If yes, `isType` is also guaranteed to be true. + */ + def isExistential : Boolean + /** Does this symbol represent a free type captured by reification? */ // needed for ones who wish to inspect reified trees diff --git a/src/library/scala/reflect/api/Trees.scala b/src/library/scala/reflect/api/Trees.scala index 6ddb2ea673..5ef73cba0c 100644 --- a/src/library/scala/reflect/api/Trees.scala +++ b/src/library/scala/reflect/api/Trees.scala @@ -85,10 +85,18 @@ trait Trees { self: Universe => def pos_=(pos: Position): Unit = rawatt = (rawatt withPos pos) // the "withPos" part is crucial to robustness def setPos(newpos: Position): this.type = { pos = newpos; this } - private[this] var rawatt: Attachment = NoPosition - def attachment: Attachment = rawatt - def attachment_=(att: Attachment): Unit = rawatt = att - def setAttachment(att: Attachment): this.type = { rawatt = att; this } + private var rawatt: Attachment = NoPosition + private case class NontrivialAttachment(pos: api.Position, payload: Any) extends Attachment { + def withPos(newPos: api.Position) = copy(pos = newPos, payload = payload) + def withPayload(newPayload: Any) = copy(pos = pos, payload = newPayload) + } + // todo. annotate T with ClassTag and make pattern matcher use it + // todo. support multiple attachments, and remove the assignment. only leave attach/detach +// def attachment[T]: T = rawatt.payload.asInstanceOf[T] +// def attachmentOpt[T]: Option[T] = try { Some(rawatt.payload.asInstanceOf[T]) } catch { case _: Throwable => None } + def attachment: Any = rawatt.payload + def attachment_=(att: Any): Unit = rawatt = NontrivialAttachment(pos, att) + def setAttachment(att: Any): this.type = { attachment = att; this } private[this] var rawtpe: Type = _ @@ -238,7 +246,7 @@ trait Trees { self: Universe => duplicateTree(this).asInstanceOf[this.type] private[scala] def copyAttrs(tree: Tree): this.type = { - attachment = tree.attachment + rawatt = tree.rawatt tpe = tree.tpe if (hasSymbol) symbol = tree.symbol this diff --git a/src/library/scala/reflect/api/TypeTags.scala b/src/library/scala/reflect/api/TypeTags.scala index 4ffabe1c36..59a7c87f44 100644 --- a/src/library/scala/reflect/api/TypeTags.scala +++ b/src/library/scala/reflect/api/TypeTags.scala @@ -61,9 +61,8 @@ trait TypeTags { self: Universe => // assert(tpe != null) def sym = tpe.typeSymbol - - def isConcrete = !isNotConcrete - def isNotConcrete = tpe exists (_.typeSymbol.isAbstractType) + def isConcrete = tpe.isConcrete + def notConcrete = !isConcrete def toConcrete: ConcreteTypeTag[T] = ConcreteTypeTag[T](tpe) override def toString = { @@ -124,7 +123,7 @@ trait TypeTags { self: Universe => // it's unsafe to use assert here, because we might run into deadlocks with Predef // also see comments in ClassTags.scala //assert(isConcrete, tpe) - if (isNotConcrete) throw new Error("%s (%s) is not concrete and cannot be used to construct a concrete type tag".format(tpe, tpe.kind)) + if (notConcrete) throw new Error("%s (%s) is not concrete and cannot be used to construct a concrete type tag".format(tpe, tpe.kind)) override def productPrefix = "ConcreteTypeTag" } diff --git a/src/library/scala/reflect/api/Types.scala b/src/library/scala/reflect/api/Types.scala index 12aad453b1..5e1c1af2fe 100755 --- a/src/library/scala/reflect/api/Types.scala +++ b/src/library/scala/reflect/api/Types.scala @@ -57,6 +57,10 @@ trait Types { self: Universe => */ def isHigherKinded: Boolean // !!! This should be called "isTypeConstructor", no? + /** Does this type refer to abstract types or is an abstract type? + */ + def isConcrete: Boolean + /** * Expands type aliases and converts higher-kinded TypeRefs to PolyTypes. * Functions on types are also implemented as PolyTypes. diff --git a/test/files/jvm/manifests.check b/test/files/jvm/manifests.check new file mode 100644 index 0000000000..be8ec2bb5b --- /dev/null +++ b/test/files/jvm/manifests.check @@ -0,0 +1,56 @@ +x=(), m=ConcreteTypeTag[Unit], k=TypeRef, s=class Unit +x=true, m=ConcreteTypeTag[Boolean], k=TypeRef, s=class Boolean +x=a, m=ConcreteTypeTag[Char], k=TypeRef, s=class Char +x=1, m=ConcreteTypeTag[Int], k=TypeRef, s=class Int +x=abc, m=ConcreteTypeTag[String], k=TypeRef, s=class String +x='abc, m=ConcreteTypeTag[Symbol], k=TypeRef, s=class Symbol + +x=List(()), m=ConcreteTypeTag[List[Unit]], k=TypeRef, s=class List +x=List(true), m=ConcreteTypeTag[List[Boolean]], k=TypeRef, s=class List +x=List(1), m=ConcreteTypeTag[List[Int]], k=TypeRef, s=class List +x=List(abc), m=ConcreteTypeTag[List[String]], k=TypeRef, s=class List +x=List('abc), m=ConcreteTypeTag[List[Symbol]], k=TypeRef, s=class List + +x=[Z, m=ConcreteTypeTag[Array[Boolean]], k=TypeRef, s=class Array +x=[C, m=ConcreteTypeTag[Array[Char]], k=TypeRef, s=class Array +x=[I, m=ConcreteTypeTag[Array[Int]], k=TypeRef, s=class Array +x=[Ljava.lang.String;, m=ConcreteTypeTag[Array[String]], k=TypeRef, s=class Array +x=[Lscala.Symbol;, m=ConcreteTypeTag[Array[Symbol]], k=TypeRef, s=class Array + +x=((),()), m=ConcreteTypeTag[(Unit, Unit)], k=TypeRef, s=class Tuple2 +x=(true,false), m=ConcreteTypeTag[(Boolean, Boolean)], k=TypeRef, s=class Tuple2 +x=(1,2), m=ConcreteTypeTag[(Int, Int)], k=TypeRef, s=class Tuple2 +x=(abc,xyz), m=ConcreteTypeTag[(String, String)], k=TypeRef, s=class Tuple2 +x=('abc,'xyz), m=ConcreteTypeTag[(Symbol, Symbol)], k=TypeRef, s=class Tuple2 + + +x=Foo, m=ConcreteTypeTag[Foo[Int]], k=TypeRef, s=class Foo +x=Foo, m=ConcreteTypeTag[Foo[List[Int]]], k=TypeRef, s=class Foo +x=Foo, m=ConcreteTypeTag[Foo[Foo[Int]]], k=TypeRef, s=class Foo +x=Foo, m=ConcreteTypeTag[Foo[List[Foo[Int]]]], k=TypeRef, s=class Foo + +x=Test1$$anon$1, m=ConcreteTypeTag[Bar[String]], k=RefinedType, s= +x=Test1$$anon$2, m=ConcreteTypeTag[Bar[String]], k=RefinedType, s= + +()=() +true=true +a=a +1=1 +'abc='abc + +List(())=List(()) +List(true)=List(true) +List('abc)=List('abc) + +Array()=Array() +Array(true)=Array(true) +Array(a)=Array(a) +Array(1)=Array(1) + +((),())=((),()) +(true,false)=(true,false) + +List(List(1), List(2))=List(List(1), List(2)) + +Array(Array(1), Array(2))=Array(Array(1), Array(2)) + diff --git a/test/files/jvm/manifests.check.temporarily.disabled b/test/files/jvm/manifests.check.temporarily.disabled deleted file mode 100644 index 54f504b929..0000000000 --- a/test/files/jvm/manifests.check.temporarily.disabled +++ /dev/null @@ -1,55 +0,0 @@ -x=(), m=Unit -x=true, m=Boolean -x=a, m=Char -x=1, m=Int -x=abc, m=java.lang.String -x='abc, m=scala.Symbol - -x=List(()), m=scala.collection.immutable.List[Unit] -x=List(true), m=scala.collection.immutable.List[Boolean] -x=List(1), m=scala.collection.immutable.List[Int] -x=List(abc), m=scala.collection.immutable.List[java.lang.String] -x=List('abc), m=scala.collection.immutable.List[scala.Symbol] - -x=[Z, m=Array[Boolean] -x=[C, m=Array[Char] -x=[I, m=Array[Int] -x=[Ljava.lang.String;, m=Array[java.lang.String] -x=[Lscala.Symbol;, m=Array[scala.Symbol] - -x=((),()), m=scala.Tuple2[Unit, Unit] -x=(true,false), m=scala.Tuple2[Boolean, Boolean] -x=(1,2), m=scala.Tuple2[Int, Int] -x=(abc,xyz), m=scala.Tuple2[java.lang.String, java.lang.String] -x=('abc,'xyz), m=scala.Tuple2[scala.Symbol, scala.Symbol] - - -x=Foo, m=Foo[Int] -x=Foo, m=Foo[scala.collection.immutable.List[Int]] -x=Foo, m=Foo[Foo[Int]] -x=Foo, m=Foo[scala.collection.immutable.List[Foo[Int]]] - -x=Test1$$anon$1, m=Object with Bar[java.lang.String] - -()=() -true=true -a=a -1=1 -'abc='abc - -List(())=List(()) -List(true)=List(true) -List('abc)=List('abc) - -Array()=Array() -Array(true)=Array(true) -Array(a)=Array(a) -Array(1)=Array(1) - -((),())=((),()) -(true,false)=(true,false) - -List(List(1), List(2))=List(List(1), List(2)) - -Array(Array(1), Array(2))=Array(Array(1), Array(2)) - diff --git a/test/files/jvm/manifests.scala b/test/files/jvm/manifests.scala new file mode 100644 index 0000000000..935427f5d4 --- /dev/null +++ b/test/files/jvm/manifests.scala @@ -0,0 +1,112 @@ +object Test extends App { + Test1 + Test2 +} + +class Foo[T](x: T) +trait Bar[T] { def f: T } + +object Test1 extends TestUtil { + print(()) + print(true) + print('a') + print(1) + print("abc") + print('abc) + println() + + print(List(())) + print(List(true)) + print(List(1)) + print(List("abc")) + print(List('abc)) + println() + + //print(Array(())) //Illegal class name "[V" in class file Test$ + print(Array(true)) + print(Array('a')) + print(Array(1)) + print(Array("abc")) + print(Array('abc)) + println() + + print(((), ())) + print((true, false)) + print((1, 2)) + print(("abc", "xyz")) + print(('abc, 'xyz)) + println() + + // Disabled: should these work? changing the inference for objects from + // "object Test" to "Test.type" drags in a singleton manifest which for + // some reason leads to serialization failure. + // print(Test) + // print(List) + println() + + print(new Foo(2)) + print(new Foo(List(2))) + print(new Foo(new Foo(2))) + print(new Foo(List(new Foo(2)))) + println() + + print(new Bar[String] { def f = "abc" }); + {print(new Bar[String] { def f = "abc" })} + println() +} + +object Test2 { + import scala.util.Marshal._ + println("()="+load[Unit](dump(()))) + println("true="+load[Boolean](dump(true))) + println("a="+load[Char](dump('a'))) + println("1="+load[Int](dump(1))) + println("'abc="+load[Symbol](dump('abc))) + println() + + println("List(())="+load[List[Unit]](dump(List(())))) + println("List(true)="+load[List[Boolean]](dump(List(true)))) + println("List('abc)="+load[List[Symbol]](dump(List('abc)))) + println() + + def loadArray[T](x: Array[Byte])(implicit m: reflect.Manifest[Array[T]]) = + load[Array[T]](x)(m).deep.toString + println("Array()="+loadArray[Int](dump(Array(): Array[Int]))) + println("Array(true)="+loadArray[Boolean](dump(Array(true)))) + println("Array(a)="+loadArray[Char](dump(Array('a')))) + println("Array(1)="+loadArray[Int](dump(Array(1)))) + println() + + println("((),())="+load[(Unit, Unit)](dump(((), ())))) + println("(true,false)="+load[(Boolean, Boolean)](dump((true, false)))) + println() + + println("List(List(1), List(2))="+load[List[List[Int]]](dump(List(List(1), List(2))))) + println() + + println("Array(Array(1), Array(2))="+loadArray[Array[Int]](dump(Array(Array(1), Array(2))))) + println() +} + +trait TestUtil { + import java.io._ + def write[A](o: A): Array[Byte] = { + val ba = new ByteArrayOutputStream(512) + val out = new ObjectOutputStream(ba) + out.writeObject(o) + out.close() + ba.toByteArray() + } + def read[A](buffer: Array[Byte]): A = { + val in = new ObjectInputStream(new ByteArrayInputStream(buffer)) + in.readObject().asInstanceOf[A] + } + import scala.reflect._ + def print[T](x: T)(implicit m: Manifest[T]) { + // manifests are no longer serializable +// val m1: Manifest[T] = read(write(m)) + val m1: Manifest[T] = m + val x1 = x.toString.replaceAll("@[0-9a-z]+$", "") + println("x="+x1+", m="+m1+", k="+m1.tpe.kind+", s="+m1.sym.toString) + } +} diff --git a/test/files/jvm/manifests.scala.temporarily.disabled b/test/files/jvm/manifests.scala.temporarily.disabled deleted file mode 100644 index 241966fd9d..0000000000 --- a/test/files/jvm/manifests.scala.temporarily.disabled +++ /dev/null @@ -1,109 +0,0 @@ -object Test extends App { - Test1 - Test2 -} - -class Foo[T](x: T) -trait Bar[T] { def f: T } - -object Test1 extends TestUtil { - print(()) - print(true) - print('a') - print(1) - print("abc") - print('abc) - println() - - print(List(())) - print(List(true)) - print(List(1)) - print(List("abc")) - print(List('abc)) - println() - - //print(Array(())) //Illegal class name "[V" in class file Test$ - print(Array(true)) - print(Array('a')) - print(Array(1)) - print(Array("abc")) - print(Array('abc)) - println() - - print(((), ())) - print((true, false)) - print((1, 2)) - print(("abc", "xyz")) - print(('abc, 'xyz)) - println() - - // Disabled: should these work? changing the inference for objects from - // "object Test" to "Test.type" drags in a singleton manifest which for - // some reason leads to serialization failure. - // print(Test) - // print(List) - println() - - print(new Foo(2)) - print(new Foo(List(2))) - print(new Foo(new Foo(2))) - print(new Foo(List(new Foo(2)))) - println() - - print(new Bar[String] { def f = "abc" }) - println() -} - -object Test2 { - import scala.util.Marshal._ - println("()="+load[Unit](dump(()))) - println("true="+load[Boolean](dump(true))) - println("a="+load[Char](dump('a'))) - println("1="+load[Int](dump(1))) - println("'abc="+load[Symbol](dump('abc))) - println() - - println("List(())="+load[List[Unit]](dump(List(())))) - println("List(true)="+load[List[Boolean]](dump(List(true)))) - println("List('abc)="+load[List[Symbol]](dump(List('abc)))) - println() - - def loadArray[T](x: Array[Byte])(implicit m: reflect.Manifest[Array[T]]) = - load[Array[T]](x)(m).deep.toString - println("Array()="+loadArray[Int](dump(Array(): Array[Int]))) - println("Array(true)="+loadArray[Boolean](dump(Array(true)))) - println("Array(a)="+loadArray[Char](dump(Array('a')))) - println("Array(1)="+loadArray[Int](dump(Array(1)))) - println() - - println("((),())="+load[(Unit, Unit)](dump(((), ())))) - println("(true,false)="+load[(Boolean, Boolean)](dump((true, false)))) - println() - - println("List(List(1), List(2))="+load[List[List[Int]]](dump(List(List(1), List(2))))) - println() - - println("Array(Array(1), Array(2))="+loadArray[Array[Int]](dump(Array(Array(1), Array(2))))) - println() -} - -trait TestUtil { - import java.io._ - def write[A](o: A): Array[Byte] = { - val ba = new ByteArrayOutputStream(512) - val out = new ObjectOutputStream(ba) - out.writeObject(o) - out.close() - ba.toByteArray() - } - def read[A](buffer: Array[Byte]): A = { - val in = new ObjectInputStream(new ByteArrayInputStream(buffer)) - in.readObject().asInstanceOf[A] - } - import scala.reflect._ - def print[T](x: T)(implicit m: Manifest[T]) { - val m1: Manifest[T] = read(write(m)) - val x1 = x.toString.replaceAll("@[0-9a-z]+$", "") - println("x="+x1+", m="+m1) - } -} diff --git a/test/files/neg/t3507.check b/test/files/neg/t3507.check deleted file mode 100644 index 71bf295039..0000000000 --- a/test/files/neg/t3507.check +++ /dev/null @@ -1,4 +0,0 @@ -t3507.scala:13: error: No ConcreteTypeTag available for _1.b.c.type - mani/*[object _1.b.c]*/(c) // kaboom in manifestOfType / TreeGen.mkAttributedQualifier - ^ -one error found diff --git a/test/files/neg/t3507.scala b/test/files/neg/t3507.scala deleted file mode 100644 index 32688d3934..0000000000 --- a/test/files/neg/t3507.scala +++ /dev/null @@ -1,15 +0,0 @@ -class A { - object b { - object c - } - def m = b.c -} - -object Test { - var a: A = new A // mutable - val c /*: object _1.b.c forSome { val _1: A } */ = a.m // widening using existential - - def mani[T: Manifest](x: T) = () - mani/*[object _1.b.c]*/(c) // kaboom in manifestOfType / TreeGen.mkAttributedQualifier - // --> _1 is not in scope here -} \ No newline at end of file diff --git a/test/files/pos/implicits.scala b/test/files/pos/implicits.scala new file mode 100644 index 0000000000..2c01dd0ba8 --- /dev/null +++ b/test/files/pos/implicits.scala @@ -0,0 +1,89 @@ +// #1435 +object t1435 { + implicit def a(s:String):String = error("") + implicit def a(i:Int):String = error("") + implicit def b(i:Int):String = error("") +} + +class C1435 { + val v:String = { + import t1435.a + 2 + } +} + +// #1492 +class C1492 { + + class X + + def foo(x: X => X) {} + + foo ( implicit x => implicitly[X] ) + foo { implicit x => implicitly[X] } +} + +// #1579 +object Test1579 { + class Column + class Query[E](val value: E) + class Invoker(q: Any) { val foo = null } + + implicit def unwrap[C](q: Query[C]) = q.value + implicit def invoker(q: Query[Column]) = new Invoker(q) + + val q = new Query(new Column) + q.foo +} +// #1625 +object Test1625 { + + class Wrapped(x:Any) { + def unwrap() = x + } + + implicit def byName[A](x: =>A) = new Wrapped(x) + + implicit def byVal[A](x: A) = x + + def main(args: Array[String]) = { + +// val res:Wrapped = 7 // works + + val res = 7.unwrap() // doesn't work + + println("=> result: " + res) + } +} + +object Test2188 { + implicit def toJavaList[A: ClassManifest](t:collection.Seq[A]):java.util.List[A] = java.util.Arrays.asList(t.toArray:_*) + + val x: java.util.List[String] = List("foo") +} + +object TestNumericWidening { + val y = 1 + val x: java.lang.Long = y +} + +// #2709 +package foo2709 { + class A + class B + + package object bar { + implicit def a2b(a: A): B = new B + } + + package bar { + object test { + new A: B + } + } +} + +// Problem with specs +object specsProblem { + println(implicitly[Manifest[Class[_]]]) +} diff --git a/test/files/pos/implicits.scala.temporarily.disabled b/test/files/pos/implicits.scala.temporarily.disabled deleted file mode 100644 index 2c01dd0ba8..0000000000 --- a/test/files/pos/implicits.scala.temporarily.disabled +++ /dev/null @@ -1,89 +0,0 @@ -// #1435 -object t1435 { - implicit def a(s:String):String = error("") - implicit def a(i:Int):String = error("") - implicit def b(i:Int):String = error("") -} - -class C1435 { - val v:String = { - import t1435.a - 2 - } -} - -// #1492 -class C1492 { - - class X - - def foo(x: X => X) {} - - foo ( implicit x => implicitly[X] ) - foo { implicit x => implicitly[X] } -} - -// #1579 -object Test1579 { - class Column - class Query[E](val value: E) - class Invoker(q: Any) { val foo = null } - - implicit def unwrap[C](q: Query[C]) = q.value - implicit def invoker(q: Query[Column]) = new Invoker(q) - - val q = new Query(new Column) - q.foo -} -// #1625 -object Test1625 { - - class Wrapped(x:Any) { - def unwrap() = x - } - - implicit def byName[A](x: =>A) = new Wrapped(x) - - implicit def byVal[A](x: A) = x - - def main(args: Array[String]) = { - -// val res:Wrapped = 7 // works - - val res = 7.unwrap() // doesn't work - - println("=> result: " + res) - } -} - -object Test2188 { - implicit def toJavaList[A: ClassManifest](t:collection.Seq[A]):java.util.List[A] = java.util.Arrays.asList(t.toArray:_*) - - val x: java.util.List[String] = List("foo") -} - -object TestNumericWidening { - val y = 1 - val x: java.lang.Long = y -} - -// #2709 -package foo2709 { - class A - class B - - package object bar { - implicit def a2b(a: A): B = new B - } - - package bar { - object test { - new A: B - } - } -} - -// Problem with specs -object specsProblem { - println(implicitly[Manifest[Class[_]]]) -} diff --git a/test/files/pos/manifest1.scala b/test/files/pos/manifest1.scala new file mode 100644 index 0000000000..8901aa7437 --- /dev/null +++ b/test/files/pos/manifest1.scala @@ -0,0 +1,21 @@ +import scala.reflect.Manifest + +object Test { + def foo[T](x: T)(implicit m: Manifest[T]) { + foo(List(x)) + } + foo(1) + foo("abc") + foo(List(1, 2, 3)) + val x: List[Int] with Ordered[List[Int]] = null + foo(x) + foo[x.type](x) + abstract class C { type T = String; val x: T } + val c = new C { val x = "abc" } + foo(c.x) + abstract class D { type T; implicit val m: Manifest[T]; val x: T } + val stringm = implicitly[Manifest[String]] + val d: D = new D { type T = String; val m = stringm; val x = "x" } + import d.m + foo(d.x) +} diff --git a/test/files/pos/manifest1.scala.temporarily.disabled b/test/files/pos/manifest1.scala.temporarily.disabled deleted file mode 100644 index 8901aa7437..0000000000 --- a/test/files/pos/manifest1.scala.temporarily.disabled +++ /dev/null @@ -1,21 +0,0 @@ -import scala.reflect.Manifest - -object Test { - def foo[T](x: T)(implicit m: Manifest[T]) { - foo(List(x)) - } - foo(1) - foo("abc") - foo(List(1, 2, 3)) - val x: List[Int] with Ordered[List[Int]] = null - foo(x) - foo[x.type](x) - abstract class C { type T = String; val x: T } - val c = new C { val x = "abc" } - foo(c.x) - abstract class D { type T; implicit val m: Manifest[T]; val x: T } - val stringm = implicitly[Manifest[String]] - val d: D = new D { type T = String; val m = stringm; val x = "x" } - import d.m - foo(d.x) -} diff --git a/test/files/run/existentials3.check b/test/files/run/existentials3.check new file mode 100644 index 0000000000..8227d77909 --- /dev/null +++ b/test/files/run/existentials3.check @@ -0,0 +1,24 @@ +ConcreteTypeTag[Bar.type], t=TypeRef, s= <: scala.runtime.AbstractFunction0[Bar] with Serializable{case def unapply(x$0: Bar): Boolean} with Singleton +ConcreteTypeTag[Bar], t=TypeRef, s= <: Test.ToS with Product with Serializable{def copy(): Bar} +ConcreteTypeTag[Test.ToS], t=RefinedType, s=f3 +ConcreteTypeTag[Test.ToS], t=RefinedType, s=f4 +ConcreteTypeTag[Test.ToS], t=RefinedType, s=f5 +ConcreteTypeTag[() => Test.ToS], t=TypeRef, s=class Function0 +ConcreteTypeTag[() => Test.ToS], t=TypeRef, s=class Function0 +ConcreteTypeTag[$anon], t=TypeRef, s= <: B with Test.ToS +ConcreteTypeTag[$anon], t=TypeRef, s= <: B with A with Test.ToS +ConcreteTypeTag[List[Object{type T1}#T1]], t=TypeRef, s=class List +ConcreteTypeTag[List[Seq[Int]]], t=TypeRef, s=class List +ConcreteTypeTag[List[Seq[U forSome { type U <: Int }]]], t=TypeRef, s=class List +ConcreteTypeTag[Bar.type], t=TypeRef, s= <: scala.runtime.AbstractFunction0[Bar] with Serializable{case def unapply(x$0: Bar): Boolean} with Singleton +ConcreteTypeTag[Bar], t=TypeRef, s= <: Test.ToS with Product with Serializable{def copy(): Bar} +ConcreteTypeTag[Test.ToS], t=RefinedType, s=g3 +ConcreteTypeTag[Test.ToS], t=RefinedType, s=g4 +ConcreteTypeTag[Test.ToS], t=RefinedType, s=g5 +ConcreteTypeTag[() => Test.ToS], t=TypeRef, s=class Function0 +ConcreteTypeTag[() => Test.ToS], t=TypeRef, s=class Function0 +ConcreteTypeTag[$anon], t=TypeRef, s= <: B with Test.ToS +ConcreteTypeTag[$anon], t=TypeRef, s= <: B with A with Test.ToS +ConcreteTypeTag[List[Object{type T1}#T1]], t=TypeRef, s=class List +ConcreteTypeTag[List[Seq[Int]]], t=TypeRef, s=class List +ConcreteTypeTag[List[Seq[U forSome { type U <: Int }]]], t=TypeRef, s=class List diff --git a/test/files/run/existentials3.check.temporarily.disabled b/test/files/run/existentials3.check.temporarily.disabled deleted file mode 100644 index 36a458dacc..0000000000 --- a/test/files/run/existentials3.check.temporarily.disabled +++ /dev/null @@ -1,22 +0,0 @@ -_ <: scala.runtime.AbstractFunction0[_ <: Object with Test$ToS with scala.Product with scala.Serializable] with scala.Serializable with java.lang.Object -_ <: Object with Test$ToS with scala.Product with scala.Serializable -Object with Test$ToS -Object with Test$ToS -Object with Test$ToS -scala.Function0[Object with Test$ToS] -scala.Function0[Object with Test$ToS] -_ <: Object with _ <: Object with Object with Test$ToS -_ <: Object with _ <: Object with _ <: Object with Test$ToS -scala.collection.immutable.List[Object with scala.collection.Seq[Int]] -scala.collection.immutable.List[Object with scala.collection.Seq[_ <: Int]] -_ <: scala.runtime.AbstractFunction0[_ <: Object with Test$ToS with scala.Product with scala.Serializable] with scala.Serializable with java.lang.Object -_ <: Object with Test$ToS with scala.Product with scala.Serializable -Object with Test$ToS -Object with Test$ToS -Object with Test$ToS -scala.Function0[Object with Test$ToS] -scala.Function0[Object with Test$ToS] -_ <: Object with _ <: Object with Object with Test$ToS -_ <: Object with _ <: Object with _ <: Object with Test$ToS -scala.collection.immutable.List[Object with scala.collection.Seq[Int]] -scala.collection.immutable.List[Object with scala.collection.Seq[_ <: Int]] diff --git a/test/files/run/existentials3.scala b/test/files/run/existentials3.scala new file mode 100644 index 0000000000..d6d5612687 --- /dev/null +++ b/test/files/run/existentials3.scala @@ -0,0 +1,79 @@ +object Test { + trait ToS { final override def toString = getClass.getName } + + def f1 = { case class Bar() extends ToS; Bar } + def f2 = { case class Bar() extends ToS; Bar() } + def f3 = { class Bar() extends ToS; object Bar extends ToS; Bar } + def f4 = { class Bar() extends ToS; new Bar() } + def f5 = { object Bar extends ToS; Bar } + def f6 = { () => { object Bar extends ToS ; Bar } } + def f7 = { val f = { () => { object Bar extends ToS ; Bar } } ; f } + + def f8 = { trait A ; trait B extends A ; class C extends B with ToS; new C { } } + def f9 = { trait A ; trait B ; class C extends B with A with ToS; new C { } } + + def f10 = { class A { type T1 } ; List[A#T1]() } + def f11 = { abstract class A extends Seq[Int] ; List[A]() } + def f12 = { abstract class A extends Seq[U forSome { type U <: Int }] ; List[A]() } + + val g1 = { case class Bar() extends ToS; Bar } + val g2 = { case class Bar() extends ToS; Bar() } + val g3 = { class Bar() extends ToS; object Bar extends ToS; Bar } + val g4 = { class Bar() extends ToS; new Bar() } + val g5 = { object Bar extends ToS; Bar } + val g6 = { () => { object Bar extends ToS ; Bar } } + val g7 = { val f = { () => { object Bar extends ToS ; Bar } } ; f } + + val g8 = { trait A ; trait B extends A ; class C extends B with ToS; new C { } } + val g9 = { trait A ; trait B ; class C extends B with A with ToS; new C { } } + + val g10 = { class A { type T1 } ; List[A#T1]() } + val g11 = { abstract class A extends Seq[Int] ; List[A]() } + val g12 = { abstract class A extends Seq[U forSome { type U <: Int }] ; List[A]() } + + def printTag(t: TypeTag[_]) = { + val s = if (t.sym.isFreeType) t.sym.typeSignature.toString else t.sym.toString + println("%s, t=%s, s=%s".format(t, t.tpe.kind, s)) + } + def m[T: ConcreteTypeTag](x: T) = printTag(concreteTypeTag[T]) + def m2[T: TypeTag](x: T) = printTag(typeTag[T]) + + // manifests don't work for f10/g10 + // oh, they do now :) + def main(args: Array[String]): Unit = { + m(f1) + m(f2) + m(f3) + m(f4) + m(f5) + m(f6) + m(f7) + m(f8) + m(f9) + m2(f10) + m(f11) + m(f12) + m(g1) + m(g2) + m(g3) + m(g4) + m(g5) + m(g6) + m(g7) + m(g8) + m(g9) + m2(g10) + m(g11) + m(g12) + } +} + +object Misc { + trait Bippy { def bippy = "I'm Bippy!" } + object o1 { + def f1 = { trait A extends Seq[U forSome { type U <: Bippy }] ; abstract class B extends A ; trait C extends B ; (null: C) } + def f2 = f1.head.bippy + } + def g1 = o1.f1 _ + def g2 = o1.f2 _ +} diff --git a/test/files/run/existentials3.scala.temporarily.disabled b/test/files/run/existentials3.scala.temporarily.disabled deleted file mode 100644 index bb80d366cc..0000000000 --- a/test/files/run/existentials3.scala.temporarily.disabled +++ /dev/null @@ -1,73 +0,0 @@ -object Test { - trait ToS { final override def toString = getClass.getName } - - def f1 = { case class Bar() extends ToS; Bar } - def f2 = { case class Bar() extends ToS; Bar() } - def f3 = { class Bar() extends ToS; object Bar extends ToS; Bar } - def f4 = { class Bar() extends ToS; new Bar() } - def f5 = { object Bar extends ToS; Bar } - def f6 = { () => { object Bar extends ToS ; Bar } } - def f7 = { val f = { () => { object Bar extends ToS ; Bar } } ; f } - - def f8 = { trait A ; trait B extends A ; class C extends B with ToS; new C { } } - def f9 = { trait A ; trait B ; class C extends B with A with ToS; new C { } } - - def f10 = { class A { type T1 } ; List[A#T1]() } - def f11 = { abstract class A extends Seq[Int] ; List[A]() } - def f12 = { abstract class A extends Seq[U forSome { type U <: Int }] ; List[A]() } - - val g1 = { case class Bar() extends ToS; Bar } - val g2 = { case class Bar() extends ToS; Bar() } - val g3 = { class Bar() extends ToS; object Bar extends ToS; Bar } - val g4 = { class Bar() extends ToS; new Bar() } - val g5 = { object Bar extends ToS; Bar } - val g6 = { () => { object Bar extends ToS ; Bar } } - val g7 = { val f = { () => { object Bar extends ToS ; Bar } } ; f } - - val g8 = { trait A ; trait B extends A ; class C extends B with ToS; new C { } } - val g9 = { trait A ; trait B ; class C extends B with A with ToS; new C { } } - - val g10 = { class A { type T1 } ; List[A#T1]() } - val g11 = { abstract class A extends Seq[Int] ; List[A]() } - val g12 = { abstract class A extends Seq[U forSome { type U <: Int }] ; List[A]() } - - def m[T: Manifest](x: T) = println(manifest[T]) - - // manifests don't work for f10/g10 - def main(args: Array[String]): Unit = { - m(f1) - m(f2) - m(f3) - m(f4) - m(f5) - m(f6) - m(f7) - m(f8) - m(f9) - // m(f10) - m(f11) - m(f12) - m(g1) - m(g2) - m(g3) - m(g4) - m(g5) - m(g6) - m(g7) - m(g8) - m(g9) - // m(g10) - m(g11) - m(g12) - } -} - -object Misc { - trait Bippy { def bippy = "I'm Bippy!" } - object o1 { - def f1 = { trait A extends Seq[U forSome { type U <: Bippy }] ; abstract class B extends A ; trait C extends B ; (null: C) } - def f2 = f1.head.bippy - } - def g1 = o1.f1 _ - def g2 = o1.f2 _ -} diff --git a/test/files/run/t1195.check b/test/files/run/t1195.check new file mode 100644 index 0000000000..554e3fd03d --- /dev/null +++ b/test/files/run/t1195.check @@ -0,0 +1,6 @@ +ConcreteTypeTag[Bar.type], underlying = <: scala.runtime.AbstractFunction1[Int,Bar] with Serializable{case def unapply(x$0: Bar): Option[Int]} with Singleton +ConcreteTypeTag[Bar], underlying = <: Product with Serializable{val x: Int; def copy(x: Int): Bar; def copy$default$1: Int; def _1: Int} +ConcreteTypeTag[Product with Serializable], underlying = Product with Serializable +ConcreteTypeTag[Bar.type], underlying = <: scala.runtime.AbstractFunction1[Int,Bar] with Serializable{case def unapply(x$0: Bar): Option[Int]} with Singleton +ConcreteTypeTag[Bar], underlying = <: Product with Serializable{val x: Int; def copy(x: Int): Bar; def copy$default$1: Int; def _1: Int} +ConcreteTypeTag[Product with Serializable], underlying = Product with Serializable diff --git a/test/files/run/t1195.check.temporarily.disabled b/test/files/run/t1195.check.temporarily.disabled deleted file mode 100644 index d023bc91f7..0000000000 --- a/test/files/run/t1195.check.temporarily.disabled +++ /dev/null @@ -1,6 +0,0 @@ -_ <: scala.runtime.AbstractFunction1[Int, _ <: Object with scala.Product with scala.Serializable] with scala.Serializable with java.lang.Object -_ <: Object with scala.Product with scala.Serializable -Object with scala.Product with scala.Serializable -_ <: scala.runtime.AbstractFunction1[Int, _ <: Object with scala.Product with scala.Serializable] with scala.Serializable with java.lang.Object -_ <: Object with scala.Product with scala.Serializable -Object with scala.Product with scala.Serializable diff --git a/test/files/run/t1195.scala b/test/files/run/t1195.scala new file mode 100644 index 0000000000..93b1dcbd07 --- /dev/null +++ b/test/files/run/t1195.scala @@ -0,0 +1,26 @@ +object Test { + def f() = { case class Bar(x: Int); Bar } + def g() = { case class Bar(x: Int); Bar(5) } + def h() = { case object Bar ; Bar } + + val f1 = f() + val g1 = g() + val h1 = h() + + def m[T: Manifest](x: T) = println(manifest[T] + ", underlying = " + manifest[T].sym.typeSignature) + + def main(args: Array[String]): Unit = { + m(f) + m(g) + m(h) + m(f1) + m(g1) + m(h1) + } +} + +class A1[T] { + class B1[U] { + def f = { case class D(x: Int) extends A1[String] ; new D(5) } + } +} diff --git a/test/files/run/t1195.scala.temporarily.disabled b/test/files/run/t1195.scala.temporarily.disabled deleted file mode 100644 index 81ef5bdb0e..0000000000 --- a/test/files/run/t1195.scala.temporarily.disabled +++ /dev/null @@ -1,26 +0,0 @@ -object Test { - def f() = { case class Bar(x: Int); Bar } - def g() = { case class Bar(x: Int); Bar(5) } - def h() = { case object Bar ; Bar } - - val f1 = f() - val g1 = g() - val h1 = h() - - def m[T: Manifest](x: T) = println(manifest[T]) - - def main(args: Array[String]): Unit = { - m(f) - m(g) - m(h) - m(f1) - m(g1) - m(h1) - } -} - -class A1[T] { - class B1[U] { - def f = { case class D(x: Int) extends A1[String] ; new D(5) } - } -} diff --git a/test/files/run/t3507.check b/test/files/run/t3507.check new file mode 100644 index 0000000000..50ab029592 --- /dev/null +++ b/test/files/run/t3507.check @@ -0,0 +1 @@ +ConcreteTypeTag[_1.type#b.c.type] diff --git a/test/files/run/t3507.scala b/test/files/run/t3507.scala new file mode 100644 index 0000000000..3cdd40a881 --- /dev/null +++ b/test/files/run/t3507.scala @@ -0,0 +1,15 @@ +class A { + object b { + object c + } + def m = b.c +} + +object Test extends App { + var a: A = new A // mutable + val c /*: object _1.b.c forSome { val _1: A } */ = a.m // widening using existential + + def mani[T: Manifest](x: T) = println(manifest[T]) + mani/*[object _1.b.c]*/(c) // kaboom in manifestOfType / TreeGen.mkAttributedQualifier + // --> _1 is not in scope here +} \ No newline at end of file diff --git a/test/files/run/t4110.check b/test/files/run/t4110.check new file mode 100644 index 0000000000..28f220e1fe --- /dev/null +++ b/test/files/run/t4110.check @@ -0,0 +1,2 @@ +ConcreteTypeTag[Test.A with Test.B] +ConcreteTypeTag[Test.A with Test.B] diff --git a/test/files/run/t4110.check.temporarily.disabled b/test/files/run/t4110.check.temporarily.disabled deleted file mode 100644 index 8b005989de..0000000000 --- a/test/files/run/t4110.check.temporarily.disabled +++ /dev/null @@ -1,2 +0,0 @@ -Object with Test$A with Test$B -Object with Test$A with Test$B diff --git a/test/files/run/t4110.scala b/test/files/run/t4110.scala new file mode 100644 index 0000000000..4bd377b73e --- /dev/null +++ b/test/files/run/t4110.scala @@ -0,0 +1,11 @@ +object Test extends App { + def inferredType[T : Manifest](v : T) = println(manifest[T]) + + trait A + trait B + + inferredType(new A with B) + + val name = new A with B + inferredType(name) +} \ No newline at end of file diff --git a/test/files/run/t4110.scala.temporarily.disabled b/test/files/run/t4110.scala.temporarily.disabled deleted file mode 100644 index 4bd377b73e..0000000000 --- a/test/files/run/t4110.scala.temporarily.disabled +++ /dev/null @@ -1,11 +0,0 @@ -object Test extends App { - def inferredType[T : Manifest](v : T) = println(manifest[T]) - - trait A - trait B - - inferredType(new A with B) - - val name = new A with B - inferredType(name) -} \ No newline at end of file diff --git a/test/files/run/treePrint.check b/test/files/run/treePrint.check new file mode 100644 index 0000000000..3360815ac1 --- /dev/null +++ b/test/files/run/treePrint.check @@ -0,0 +1,5 @@ +def foo = { + var q: Boolean = false; + val x = 5; + ((x == 5) || (!q)) || (true) +} diff --git a/test/files/run/treePrint.check.temporarily.disabled b/test/files/run/treePrint.check.temporarily.disabled deleted file mode 100644 index 3360815ac1..0000000000 --- a/test/files/run/treePrint.check.temporarily.disabled +++ /dev/null @@ -1,5 +0,0 @@ -def foo = { - var q: Boolean = false; - val x = 5; - ((x == 5) || (!q)) || (true) -} diff --git a/test/files/run/treePrint.scala b/test/files/run/treePrint.scala new file mode 100644 index 0000000000..4a80e2824d --- /dev/null +++ b/test/files/run/treePrint.scala @@ -0,0 +1,43 @@ +/** Testing compact tree printers. + */ +object Test { + import scala.tools.nsc._ + import interpreter._ + import java.io.{ OutputStream, BufferedReader, StringReader, PrintWriter, Writer, OutputStreamWriter} + + val code = """ + def foo = { + var q: Boolean = false + val x = if (true) { + if (true) { + if (true) { + 5 + } + else if (true) { + 5 + } else { + 10 + } + } + else 20 + } + else 30 + + (x == 5) || !q || true + } + """ + + class NullOutputStream extends OutputStream { def write(b: Int) { } } + + def main(args: Array[String]) { + val settings = new Settings + settings.classpath.value = System.getProperty("java.class.path") + settings.Ycompacttrees.value = true + + val intp = new IMain(settings, new PrintWriter(new NullOutputStream)) + val vals = new ReplVals { } + val power = new Power(intp, vals) + intp.interpret("""def initialize = "Have to interpret something or we get errors." """) + power trees code foreach println + } +} diff --git a/test/files/run/treePrint.scala.temporarily.disabled b/test/files/run/treePrint.scala.temporarily.disabled deleted file mode 100644 index e0332a705f..0000000000 --- a/test/files/run/treePrint.scala.temporarily.disabled +++ /dev/null @@ -1,42 +0,0 @@ -/** Testing compact tree printers. - */ -object Test { - import scala.tools.nsc._ - import interpreter._ - import java.io.{ OutputStream, BufferedReader, StringReader, PrintWriter, Writer, OutputStreamWriter} - - val code = """ - def foo = { - var q: Boolean = false - val x = if (true) { - if (true) { - if (true) { - 5 - } - else if (true) { - 5 - } else { - 10 - } - } - else 20 - } - else 30 - - (x == 5) || !q || true - } - """ - - class NullOutputStream extends OutputStream { def write(b: Int) { } } - - def main(args: Array[String]) { - val settings = new Settings - settings.classpath.value = System.getProperty("java.class.path") - settings.Ycompacttrees.value = true - - val intp = new IMain(settings, new PrintWriter(new NullOutputStream)) - val power = new Power(intp, new ReplVals { }) - intp.interpret("""def initialize = "Have to interpret something or we get errors." """) - power trees code foreach println - } -} -- cgit v1.2.3