From 46d57d47e81c8794a9a3594e080576788cc92324 Mon Sep 17 00:00:00 2001 From: Eugene Burmako Date: Wed, 15 Aug 2012 13:37:26 +0200 Subject: cleanup of reflection- and macro-related stuff mostly removes [Eugene] marks that I left back then and reviews related code some of those tokens got left in place, because I don't know to how fix them without imposing risks on 2.10.0 --- src/library/scala/reflect/ScalaLongSignature.java | 3 -- src/library/scala/reflect/ScalaSignature.java | 2 - src/library/scala/reflect/base/Base.scala | 35 +++++++------- src/library/scala/reflect/base/BuildUtils.scala | 8 ++-- src/library/scala/reflect/base/Exprs.scala | 5 +- src/library/scala/reflect/base/MirrorOf.scala | 2 - src/library/scala/reflect/base/Positions.scala | 5 -- .../scala/reflect/base/StandardDefinitions.scala | 54 +++++++++++----------- src/library/scala/reflect/base/Symbols.scala | 5 +- src/library/scala/reflect/base/TagInterop.scala | 5 +- src/library/scala/reflect/base/Trees.scala | 6 --- src/library/scala/reflect/base/TypeTags.scala | 5 +- src/library/scala/reflect/base/Types.scala | 2 +- .../scala/reflect/macros/internal/package.scala | 2 - src/library/scala/util/Marshal.scala | 2 - 15 files changed, 53 insertions(+), 88 deletions(-) (limited to 'src/library') diff --git a/src/library/scala/reflect/ScalaLongSignature.java b/src/library/scala/reflect/ScalaLongSignature.java index fce58207f1..5b6d78f446 100644 --- a/src/library/scala/reflect/ScalaLongSignature.java +++ b/src/library/scala/reflect/ScalaLongSignature.java @@ -5,9 +5,6 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; -/** - * [Martin to Eugene++] Todo: Move to somewhere else? -*/ @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) public @interface ScalaLongSignature { diff --git a/src/library/scala/reflect/ScalaSignature.java b/src/library/scala/reflect/ScalaSignature.java index f0df99fe79..a8af554d2b 100644 --- a/src/library/scala/reflect/ScalaSignature.java +++ b/src/library/scala/reflect/ScalaSignature.java @@ -5,8 +5,6 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; -/** * [Martin to Eugene++] Todo: Move to somewhere else? - */ @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) public @interface ScalaSignature { diff --git a/src/library/scala/reflect/base/Base.scala b/src/library/scala/reflect/base/Base.scala index 714fd365ef..798e257d1e 100644 --- a/src/library/scala/reflect/base/Base.scala +++ b/src/library/scala/reflect/base/Base.scala @@ -279,8 +279,6 @@ class Base extends Universe { self => val NoPosition = new Position - def atPos[T <: Tree](pos: Position)(tree: T): T = tree - private val generated = new mutable.HashMap[String, WeakReference[Symbol]] private def cached(name: String)(symExpr: => Symbol): Symbol = @@ -411,6 +409,22 @@ class Base extends Universe { self => lazy val ListClass = staticClass("scala.List") lazy val PredefModule = staticModule("scala.Predef") + + lazy val ByteTpe = TypeRef(ScalaPrefix, ByteClass, Nil) + lazy val ShortTpe = TypeRef(ScalaPrefix, ShortClass, Nil) + lazy val CharTpe = TypeRef(ScalaPrefix, CharClass, Nil) + lazy val IntTpe = TypeRef(ScalaPrefix, IntClass, Nil) + lazy val LongTpe = TypeRef(ScalaPrefix, LongClass, Nil) + lazy val FloatTpe = TypeRef(ScalaPrefix, FloatClass, Nil) + lazy val DoubleTpe = TypeRef(ScalaPrefix, DoubleClass, Nil) + lazy val BooleanTpe = TypeRef(ScalaPrefix, BooleanClass, Nil) + lazy val UnitTpe = TypeRef(ScalaPrefix, UnitClass, Nil) + lazy val AnyTpe = TypeRef(ScalaPrefix, AnyClass, Nil) + lazy val AnyValTpe = TypeRef(ScalaPrefix, AnyValClass, Nil) + lazy val NothingTpe = TypeRef(ScalaPrefix, NothingClass, Nil) + lazy val NullTpe = TypeRef(ScalaPrefix, NullClass, Nil) + lazy val ObjectTpe = TypeRef(JavaLangPrefix, ObjectClass, Nil) + lazy val AnyRefTpe = ObjectTpe } import definitions._ @@ -419,22 +433,6 @@ class Base extends Universe { self => private lazy val ScalaPrefix = thisModuleType("scala") private lazy val JavaLangPrefix = thisModuleType("java.lang") - lazy val ByteTpe = TypeRef(ScalaPrefix, ByteClass, Nil) - lazy val ShortTpe = TypeRef(ScalaPrefix, ShortClass, Nil) - lazy val CharTpe = TypeRef(ScalaPrefix, CharClass, Nil) - lazy val IntTpe = TypeRef(ScalaPrefix, IntClass, Nil) - lazy val LongTpe = TypeRef(ScalaPrefix, LongClass, Nil) - lazy val FloatTpe = TypeRef(ScalaPrefix, FloatClass, Nil) - lazy val DoubleTpe = TypeRef(ScalaPrefix, DoubleClass, Nil) - lazy val BooleanTpe = TypeRef(ScalaPrefix, BooleanClass, Nil) - lazy val UnitTpe = TypeRef(ScalaPrefix, UnitClass, Nil) - lazy val AnyTpe = TypeRef(ScalaPrefix, AnyClass, Nil) - lazy val AnyValTpe = TypeRef(ScalaPrefix, AnyValClass, Nil) - lazy val NothingTpe = TypeRef(ScalaPrefix, NothingClass, Nil) - lazy val NullTpe = TypeRef(ScalaPrefix, NullClass, Nil) - lazy val ObjectTpe = TypeRef(JavaLangPrefix, ObjectClass, Nil) - lazy val AnyRefTpe = ObjectTpe - private var nodeCount = 0 // not synchronized abstract class Tree extends TreeBase with Product { @@ -745,7 +743,6 @@ class Base extends Universe { self => implicit val ExistentialTypeTreeTag = ClassTag[ExistentialTypeTree](classOf[ExistentialTypeTree]) implicit val TypeTreeTag = ClassTag[TypeTree](classOf[TypeTree]) - // [Eugene++] to be removed after SI-5863 is fixed def ClassDef(sym: Symbol, impl: Template): ClassDef = ??? def ModuleDef(sym: Symbol, impl: Template): ModuleDef = ??? def ValDef(sym: Symbol, rhs: Tree): ValDef = ??? diff --git a/src/library/scala/reflect/base/BuildUtils.scala b/src/library/scala/reflect/base/BuildUtils.scala index eaba0ec2b7..98f32231ad 100644 --- a/src/library/scala/reflect/base/BuildUtils.scala +++ b/src/library/scala/reflect/base/BuildUtils.scala @@ -5,6 +5,10 @@ trait BuildUtils { self: Universe => val build: BuildBase + // this API abstracts away the functionality necessary for reification + // it's too gimmicky and unstructured to be exposed directly in the universe + // but we need it in a publicly available place for reification to work + abstract class BuildBase { /** Selects type symbol with given simple name `name` from the defined members of `owner`. */ @@ -53,7 +57,6 @@ trait BuildUtils { self: Universe => * the only usage for it is preserving the captured symbol for compile-time analysis * @param flags (optional) flags of the free variable * @param origin (optional) debug information that tells where this symbol comes from - * [Martin to Eugene: why needed?] */ def newFreeExistential(name: String, info: Type, value: => Any, flags: FlagSet = NoFlags, origin: String = null): FreeTypeSymbol @@ -68,9 +71,6 @@ trait BuildUtils { self: Universe => def flagsFromBits(bits: Long): FlagSet - // [Eugene++ to Martin] these are necessary for reification - // on a second thought, I added them to BuildUtils instead of base - def emptyValDef: ValDef def This(sym: Symbol): Tree diff --git a/src/library/scala/reflect/base/Exprs.scala b/src/library/scala/reflect/base/Exprs.scala index 47af4f3a9d..10c222722a 100644 --- a/src/library/scala/reflect/base/Exprs.scala +++ b/src/library/scala/reflect/base/Exprs.scala @@ -39,10 +39,7 @@ trait Exprs { self: Universe => otherMirror.universe.Expr[T](otherMirror1, treec)(tag1) } - lazy val tree: Tree = treec[Exprs.this.type](mirror) - // [Eugene++] this is important - // !!! remove when we have improved type inference for singletons - // search for .type] to find other instances + lazy val tree: Tree = treec(mirror) lazy val staticType: Type = implicitly[AbsTypeTag[T]].tpe def actualType: Type = treeType(tree) diff --git a/src/library/scala/reflect/base/MirrorOf.scala b/src/library/scala/reflect/base/MirrorOf.scala index 6dc8090eee..1e9619d062 100644 --- a/src/library/scala/reflect/base/MirrorOf.scala +++ b/src/library/scala/reflect/base/MirrorOf.scala @@ -1,8 +1,6 @@ package scala.reflect package base -// [Eugene++ to Martin] why was this a member of `scala.reflect`, but not `scala.reflect.base`? - abstract class MirrorOf[U <: base.Universe with Singleton] { /** .. */ val universe: U diff --git a/src/library/scala/reflect/base/Positions.scala b/src/library/scala/reflect/base/Positions.scala index cefeb51c9a..76a7382e9e 100644 --- a/src/library/scala/reflect/base/Positions.scala +++ b/src/library/scala/reflect/base/Positions.scala @@ -14,9 +14,4 @@ trait Positions { /** .. */ val NoPosition: Position - - /** Assigns a given position to all position-less nodes of a given AST. - */ - def atPos[T <: Tree](pos: Position)(tree: T): T - // [Eugene++] why do we have this in base? } diff --git a/src/library/scala/reflect/base/StandardDefinitions.scala b/src/library/scala/reflect/base/StandardDefinitions.scala index fe32fdb4c2..8f1c96ea3f 100644 --- a/src/library/scala/reflect/base/StandardDefinitions.scala +++ b/src/library/scala/reflect/base/StandardDefinitions.scala @@ -6,37 +6,12 @@ package scala.reflect package base -// [Eugene++] not sure whether we need this in the top level of the universe -trait StandardTypes { - self: Universe => - - val ByteTpe: Type - val ShortTpe: Type - val CharTpe: Type - val IntTpe: Type - val LongTpe: Type - val FloatTpe: Type - val DoubleTpe: Type - val BooleanTpe: Type - val UnitTpe: Type - - val AnyTpe: Type - val AnyValTpe: Type - val AnyRefTpe: Type - val ObjectTpe: Type - - val NothingTpe: Type - val NullTpe: Type -} - -trait StandardDefinitions extends StandardTypes { +trait StandardDefinitions { self: Universe => val definitions: DefinitionsBase - // [Eugene] todo. shortcut to these fields if possible when generating tags - // todo. also shortcut to StandardTypes, of course - trait DefinitionsBase { + trait DefinitionsBase extends StandardTypes { // packages def ScalaPackageClass: ClassSymbol def ScalaPackage: ModuleSymbol @@ -66,9 +41,32 @@ trait StandardDefinitions extends StandardTypes { def StringClass : ClassSymbol def ClassClass : ClassSymbol def ArrayClass : ClassSymbol - def ListClass : ClassSymbol // [Eugene] I'd say List has earned its right to be here + def ListClass : ClassSymbol // the Predef object def PredefModule: ModuleSymbol } + + trait StandardTypes { + // the scala value classes + val UnitTpe: Type + val ByteTpe: Type + val ShortTpe: Type + val CharTpe: Type + val IntTpe: Type + val LongTpe: Type + val FloatTpe: Type + val DoubleTpe: Type + val BooleanTpe: Type + + // top types + val AnyTpe: Type + val AnyValTpe: Type + val AnyRefTpe: Type + val ObjectTpe: Type + + // bottom types + val NothingTpe: Type + val NullTpe: Type + } } diff --git a/src/library/scala/reflect/base/Symbols.scala b/src/library/scala/reflect/base/Symbols.scala index fe857c540f..294fa19d62 100644 --- a/src/library/scala/reflect/base/Symbols.scala +++ b/src/library/scala/reflect/base/Symbols.scala @@ -3,9 +3,6 @@ package base trait Symbols { self: Universe => - // [Eugene++ to Martin] why is Symbol >: Null, whereas all other symbol types are not nullable? - // same question goes for Types - /** The abstract type of symbols representing declarations */ type Symbol >: Null <: SymbolBase @@ -266,7 +263,7 @@ trait Symbols { self: Universe => * by inspecting its `selfType.termSymbol`. */ def moduleClass: Symbol // needed for tree traversals - // [Eugene++] when this becomes `moduleClass: ClassSymbol`, it will be the happiest day in my life + // when this becomes `moduleClass: ClassSymbol`, it will be the happiest day in my life final override def isModule = true final override def asModule = this diff --git a/src/library/scala/reflect/base/TagInterop.scala b/src/library/scala/reflect/base/TagInterop.scala index a9f0b60fd2..ec054106eb 100644 --- a/src/library/scala/reflect/base/TagInterop.scala +++ b/src/library/scala/reflect/base/TagInterop.scala @@ -4,12 +4,9 @@ package base import scala.runtime.ScalaRunTime._ trait TagInterop { self: Universe => - // [Eugene++] `mirror` parameters are now of type `Any`, because I can't make these path-dependent types work + // todo. `mirror` parameters are now of type `Any`, because I can't make these path-dependent types work // if you're brave enough, replace `Any` with `Mirror`, recompile and run interop_typetags_are_manifests.scala - // [Eugene++] would be great if we could approximate the interop without any mirrors - // todo. think how to implement that - def typeTagToManifest[T: ClassTag](mirror: Any, tag: base.Universe # TypeTag[T]): Manifest[T] = throw new UnsupportedOperationException("This universe does not support tag -> manifest conversions. Use scala.reflect.runtime.universe from scala-reflect.jar.") diff --git a/src/library/scala/reflect/base/Trees.scala b/src/library/scala/reflect/base/Trees.scala index 70993fd77f..224965a2b7 100644 --- a/src/library/scala/reflect/base/Trees.scala +++ b/src/library/scala/reflect/base/Trees.scala @@ -5,10 +5,6 @@ package scala.reflect package base -// [Eugene++] of all reflection APIs, this one is in the biggest need of review and documentation - -// Syncnote: Trees are currently not thread-safe. -// [Eugene++] now when trees are finally abstract types, can we do something for this? trait Trees { self: Universe => /** The base API that all trees support */ @@ -81,7 +77,6 @@ trait Trees { self: Universe => * example is Parens, which is eliminated during parsing. */ type Tree >: Null <: TreeBase - // [Eugene++] todo. discuss nullability of abstract types /** A tag that preserves the identity of the `Tree` abstract type from erasure. * Can be used for pattern matching, instance tests, serialization and likes. @@ -1381,7 +1376,6 @@ trait Trees { self: Universe => /** ... */ lazy val NoMods = Modifiers() - // [Eugene++] temporarily moved here until SI-5863 is fixed // ---------------------- factories ---------------------------------------------- /** @param sym the class symbol diff --git a/src/library/scala/reflect/base/TypeTags.scala b/src/library/scala/reflect/base/TypeTags.scala index b673122d00..c9d1ccf5bc 100644 --- a/src/library/scala/reflect/base/TypeTags.scala +++ b/src/library/scala/reflect/base/TypeTags.scala @@ -99,9 +99,10 @@ import language.implicitConversions * 4) Certain manifest functions (such as `<:<`, `>:>` and `typeArguments`) weren't included in the tag API. * Consider using reflection API provided by Java (for classes) and Scala (for types) instead. */ -// [Eugene++] implement serialization for typetags trait TypeTags { self: Universe => + import definitions._ + /** * If an implicit value of type u.AbsTypeTag[T] is required, the compiler will make one up on demand. * The implicitly created value contains in its tpe field a value of type u.Type that is a reflective representation of T. @@ -164,7 +165,7 @@ trait TypeTags { self: Universe => } private class AbsTypeTagImpl[T](val mirror: Mirror, val tpec: TypeCreator) extends AbsTypeTag[T] { - lazy val tpe: Type = tpec[self.type](mirror) + lazy val tpe: Type = tpec(mirror) def in[U <: Universe with Singleton](otherMirror: MirrorOf[U]): U # AbsTypeTag[T] = { val otherMirror1 = otherMirror.asInstanceOf[MirrorOf[otherMirror.universe.type]] otherMirror.universe.AbsTypeTag[T](otherMirror1, tpec) diff --git a/src/library/scala/reflect/base/Types.scala b/src/library/scala/reflect/base/Types.scala index 28aaf2d04d..b016b77f36 100644 --- a/src/library/scala/reflect/base/Types.scala +++ b/src/library/scala/reflect/base/Types.scala @@ -14,7 +14,7 @@ trait Types { self: Universe => /** A tag that preserves the identity of the `Type` abstract type from erasure. * Can be used for pattern matching, instance tests, serialization and likes. */ - implicit val TypeTagg: ClassTag[Type] // [Eugene++] rename! + implicit val TypeTagg: ClassTag[Type] /** This constant is used as a special value that indicates that no meaningful type exists. */ diff --git a/src/library/scala/reflect/macros/internal/package.scala b/src/library/scala/reflect/macros/internal/package.scala index 912db53ed4..0a0e6c5b51 100644 --- a/src/library/scala/reflect/macros/internal/package.scala +++ b/src/library/scala/reflect/macros/internal/package.scala @@ -5,9 +5,7 @@ import scala.reflect.ClassTag // anchors for materialization macros emitted during tag materialization in Implicits.scala // implementation is magically hardwired into `scala.reflect.reify.Taggers` -// // todo. once we have implicit macros for tag generation, we can remove these anchors -// [Eugene++] how do I hide this from scaladoc? package object internal { private[scala] def materializeClassTag[T](u: BaseUniverse): ClassTag[T] = ??? // macro private[scala] def materializeAbsTypeTag[T](u: BaseUniverse): u.AbsTypeTag[T] = ??? // macro diff --git a/src/library/scala/util/Marshal.scala b/src/library/scala/util/Marshal.scala index 2d3f54a95e..79476bdc16 100644 --- a/src/library/scala/util/Marshal.scala +++ b/src/library/scala/util/Marshal.scala @@ -37,8 +37,6 @@ object Marshal { val in = new ObjectInputStream(new ByteArrayInputStream(buffer)) val found = in.readObject.asInstanceOf[ClassTag[_]] try { - // [Eugene] needs review - // previously was: found <:< expected found.runtimeClass.asSubclass(expected.runtimeClass) in.readObject.asInstanceOf[A] } catch { -- cgit v1.2.3