diff options
author | Paul Phillips <paulp@improving.org> | 2013-09-18 12:09:33 -0700 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2013-09-18 12:09:33 -0700 |
commit | 7f3a7a4e39642f03f3fc32467c14ea718036cf6c (patch) | |
tree | ceeb866f8e4fec486ab4d06735920ed1246ef833 /src/reflect | |
parent | c5fdc815c30f0565a80a3837f368717a4e81e04d (diff) | |
parent | 2b03ac41c0f53d7a411e7f232d6814d7d51051a3 (diff) | |
download | scala-7f3a7a4e39642f03f3fc32467c14ea718036cf6c.tar.gz scala-7f3a7a4e39642f03f3fc32467c14ea718036cf6c.tar.bz2 scala-7f3a7a4e39642f03f3fc32467c14ea718036cf6c.zip |
Merge pull request #2959 from paulp/pr/basic-type-housekeeping
Type housekeeping.
Diffstat (limited to 'src/reflect')
7 files changed, 38 insertions, 26 deletions
diff --git a/src/reflect/scala/reflect/internal/BuildUtils.scala b/src/reflect/scala/reflect/internal/BuildUtils.scala index 2584dcb117..de24b88397 100644 --- a/src/reflect/scala/reflect/internal/BuildUtils.scala +++ b/src/reflect/scala/reflect/internal/BuildUtils.scala @@ -3,6 +3,7 @@ package reflect package internal import Flags._ +import util._ trait BuildUtils { self: SymbolTable => import definitions.{TupleClass, FunctionClass, ScalaPackage, UnitClass} @@ -364,7 +365,7 @@ trait BuildUtils { self: SymbolTable => def unapply(tree: Tree): Option[(List[Tree], List[Tree], ValDef, List[Tree])] = tree match { case SyntacticApplied(Select(New(SyntacticTypeApplied(ident, targs)), nme.CONSTRUCTOR), argss) => Some((Nil, SyntacticApplied(SyntacticTypeApplied(ident, targs), argss) :: Nil, emptyValDef, Nil)) - case SyntacticBlock(SyntacticClassDef(_, tpnme.ANON_CLASS_NAME, Nil, _, List(Nil), earlyDefs, parents, selfdef, body) :: + case SyntacticBlock(SyntacticClassDef(_, tpnme.ANON_CLASS_NAME, Nil, _, ListOfNil, earlyDefs, parents, selfdef, body) :: Apply(Select(New(Ident(tpnme.ANON_CLASS_NAME)), nme.CONSTRUCTOR), Nil) :: Nil) => Some((earlyDefs, parents, selfdef, body)) case _ => diff --git a/src/reflect/scala/reflect/internal/Definitions.scala b/src/reflect/scala/reflect/internal/Definitions.scala index ed1c3f1044..f8af4f155d 100644 --- a/src/reflect/scala/reflect/internal/Definitions.scala +++ b/src/reflect/scala/reflect/internal/Definitions.scala @@ -285,6 +285,10 @@ trait Definitions extends api.StandardDefinitions { lazy val StringTpe = StringClass.tpe lazy val ThrowableTpe = ThrowableClass.tpe + lazy val ConstantTrue = ConstantType(Constant(true)) + lazy val ConstantFalse = ConstantType(Constant(false)) + lazy val ConstantNull = ConstantType(Constant(null)) + // Note: this is not the type alias AnyRef, it's a companion-like // object used by the @specialize annotation. lazy val AnyRefModule = getMemberModule(ScalaPackageClass, nme.AnyRef) diff --git a/src/reflect/scala/reflect/internal/TreeGen.scala b/src/reflect/scala/reflect/internal/TreeGen.scala index 26adf20c52..72e1ee107b 100644 --- a/src/reflect/scala/reflect/internal/TreeGen.scala +++ b/src/reflect/scala/reflect/internal/TreeGen.scala @@ -3,6 +3,7 @@ package reflect package internal import Flags._ +import util._ abstract class TreeGen extends macros.TreeBuilder { val global: SymbolTable @@ -355,8 +356,9 @@ abstract class TreeGen extends macros.TreeBuilder { if (body forall treeInfo.isInterfaceMember) None else Some( atPos(wrappingPos(superPos, lvdefs)) ( - DefDef(NoMods, nme.MIXIN_CONSTRUCTOR, List(), List(Nil), TypeTree(), Block(lvdefs, Literal(Constant()))))) - } else { + DefDef(NoMods, nme.MIXIN_CONSTRUCTOR, Nil, ListOfNil, TypeTree(), Block(lvdefs, Literal(Constant()))))) + } + else { // convert (implicit ... ) to ()(implicit ... ) if its the only parameter section if (vparamss1.isEmpty || !vparamss1.head.isEmpty && vparamss1.head.head.mods.isImplicit) vparamss1 = List() :: vparamss1 @@ -416,7 +418,7 @@ abstract class TreeGen extends macros.TreeBuilder { atPos(cpos) { ClassDef( Modifiers(FINAL), x, Nil, - mkTemplate(parents, self, NoMods, List(Nil), stats, cpos.focus)) + mkTemplate(parents, self, NoMods, ListOfNil, stats, cpos.focus)) }), atPos(npos) { New( diff --git a/src/reflect/scala/reflect/internal/TypeDebugging.scala b/src/reflect/scala/reflect/internal/TypeDebugging.scala index fd64d98ca2..b70d3bd970 100644 --- a/src/reflect/scala/reflect/internal/TypeDebugging.scala +++ b/src/reflect/scala/reflect/internal/TypeDebugging.scala @@ -7,7 +7,7 @@ package scala package reflect package internal -import util.shortClassOfInstance +import util._ trait TypeDebugging { self: SymbolTable => @@ -39,17 +39,17 @@ trait TypeDebugging { def skipType(tpe: Type): Boolean = (tpe eq null) || skipSym(tpe.typeSymbolDirect) def skip(t: Tree): Boolean = t match { - case EmptyTree => true - case PackageDef(_, _) => true - case t: RefTree => skipRefTree(t) - case TypeBoundsTree(lo, hi) => skip(lo) && skip(hi) - case Block(Nil, expr) => skip(expr) - case Apply(fn, Nil) => skip(fn) - case Block(stmt :: Nil, expr) => skip(stmt) && skip(expr) - case DefDef(_, nme.CONSTRUCTOR, Nil, Nil :: Nil, _, rhs) => skip(rhs) - case Literal(Constant(())) => true - case tt @ TypeTree() => skipType(tt.tpe) - case _ => skipSym(t.symbol) + case EmptyTree => true + case PackageDef(_, _) => true + case t: RefTree => skipRefTree(t) + case TypeBoundsTree(lo, hi) => skip(lo) && skip(hi) + case Block(Nil, expr) => skip(expr) + case Apply(fn, Nil) => skip(fn) + case Block(stmt :: Nil, expr) => skip(stmt) && skip(expr) + case DefDef(_, nme.CONSTRUCTOR, Nil, ListOfNil, _, rhs) => skip(rhs) + case Literal(Constant(())) => true + case tt @ TypeTree() => skipType(tt.tpe) + case _ => skipSym(t.symbol) } def apply(t: Tree) = skip(t) } diff --git a/src/reflect/scala/reflect/internal/Types.scala b/src/reflect/scala/reflect/internal/Types.scala index 3adbbf13fc..dd6917814e 100644 --- a/src/reflect/scala/reflect/internal/Types.scala +++ b/src/reflect/scala/reflect/internal/Types.scala @@ -2835,9 +2835,6 @@ trait Types // but pattern-matching returned the original constr0 (a bug) // now, pattern-matching returns the most recent constr object TypeVar { - private val ConstantTrue = ConstantType(Constant(true)) - private val ConstantFalse = ConstantType(Constant(false)) - @inline final def trace[T](action: String, msg: => String)(value: T): T = { if (traceTypeVars) { val s = msg match { @@ -3059,13 +3056,13 @@ trait Types // ignore subtyping&equality checks while true -- see findMember // OPT: This could be Either[TypeVar, Boolean], but this encoding was chosen instead to save allocations. - private var _suspended: Type = TypeVar.ConstantFalse + private var _suspended: Type = ConstantFalse private[Types] def suspended: Boolean = (_suspended: @unchecked) match { - case TypeVar.ConstantFalse => false - case TypeVar.ConstantTrue => true - case tv: TypeVar => tv.suspended + case ConstantFalse => false + case ConstantTrue => true + case tv: TypeVar => tv.suspended } - private[Types] def suspended_=(b: Boolean): Unit = _suspended = if (b) TypeVar.ConstantTrue else TypeVar.ConstantFalse + private[Types] def suspended_=(b: Boolean): Unit = _suspended = if (b) ConstantTrue else ConstantFalse // SI-7785 Link the suspended attribute of a TypeVar created in, say, a TypeMap (e.g. AsSeenFrom) to its originator private[Types] def linkSuspended(origin: TypeVar): Unit = _suspended = origin diff --git a/src/reflect/scala/reflect/internal/util/Collections.scala b/src/reflect/scala/reflect/internal/util/Collections.scala index 59af819dad..738baddc08 100644 --- a/src/reflect/scala/reflect/internal/util/Collections.scala +++ b/src/reflect/scala/reflect/internal/util/Collections.scala @@ -34,14 +34,19 @@ trait Collections { xss forall (_ forall p) final def mmap[A, B](xss: List[List[A]])(f: A => B) = xss map (_ map f) - final def mforeach[A](xss: List[List[A]])(f: A => Unit) = - xss foreach (_ foreach f) final def mfind[A](xss: List[List[A]])(p: A => Boolean): Option[A] = { var res: Option[A] = null mforeach(xss)(x => if ((res eq null) && p(x)) res = Some(x)) if (res eq null) None else res } + /** These are all written in terms of List because we're trying to wring all + * the performance we can and List is used almost exclusively in the compiler, + * but people are branching out in their collections so here's an overload. + */ + final def mforeach[A](xss: List[List[A]])(f: A => Unit) = xss foreach (_ foreach f) + final def mforeach[A](xss: Traversable[Traversable[A]])(f: A => Unit) = xss foreach (_ foreach f) + final def map2[A, B, C](xs1: List[A], xs2: List[B])(f: (A, B) => C): List[C] = { val lb = new ListBuffer[C] var ys1 = xs1 diff --git a/src/reflect/scala/reflect/internal/util/package.scala b/src/reflect/scala/reflect/internal/util/package.scala index df63a55090..3618c150ca 100644 --- a/src/reflect/scala/reflect/internal/util/package.scala +++ b/src/reflect/scala/reflect/internal/util/package.scala @@ -7,6 +7,9 @@ import scala.language.existentials // SI-6541 package object util { import StringOps.longestCommonPrefix + // An allocation-avoiding reusable instance of the so-common List(Nil). + val ListOfNil: List[List[Nothing]] = Nil :: Nil + def andFalse(body: Unit): Boolean = false // Shorten a name like Symbols$FooSymbol to FooSymbol. |