summaryrefslogtreecommitdiff
path: root/src/reflect
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2012-08-18 11:02:06 +0200
committerGrzegorz Kossakowski <grzegorz.kossakowski@gmail.com>2012-08-20 08:11:11 +0100
commitbc4e1442b4f7942ffb64bdcc15ce93600611576b (patch)
treed1fecac3eeb4877f254003e8db66c446faf1acfc /src/reflect
parentd7b73d439249cdac7b4c6c0624b18da40abdd580 (diff)
downloadscala-bc4e1442b4f7942ffb64bdcc15ce93600611576b.tar.gz
scala-bc4e1442b4f7942ffb64bdcc15ce93600611576b.tar.bz2
scala-bc4e1442b4f7942ffb64bdcc15ce93600611576b.zip
Reverted closure hoisting except for functions returning a Boolean result
If our theory wrt map is correct (i.e. that it gets inlined by JVM), then closure hoisting is counter-productive because it migh well prevent the closure from being inlined. This commit removes all hoisted closures that are passed to map and leaves only those boolean closures that are passed to exists and forall. I should have split the early optimizations including closures into separate commits. As that train has left, I am now reverting some bits to see whether the reverts affect performance at all, and in what direction.
Diffstat (limited to 'src/reflect')
-rw-r--r--src/reflect/scala/reflect/internal/Definitions.scala4
-rw-r--r--src/reflect/scala/reflect/internal/Symbols.scala8
-rw-r--r--src/reflect/scala/reflect/internal/Trees.scala4
-rw-r--r--src/reflect/scala/reflect/internal/Types.scala38
-rw-r--r--src/reflect/scala/reflect/internal/pickling/UnPickler.scala4
5 files changed, 23 insertions, 35 deletions
diff --git a/src/reflect/scala/reflect/internal/Definitions.scala b/src/reflect/scala/reflect/internal/Definitions.scala
index 14547123b0..98d42b724c 100644
--- a/src/reflect/scala/reflect/internal/Definitions.scala
+++ b/src/reflect/scala/reflect/internal/Definitions.scala
@@ -759,7 +759,7 @@ trait Definitions extends api.StandardDefinitions {
// java.lang.Object. Java also special cases the return type.
lazy val Any_getClass = enterNewMethod(AnyClass, nme.getClass_, Nil, getMemberMethod(ObjectClass, nme.getClass_).tpe.resultType, DEFERRED)
lazy val Any_isInstanceOf = newT1NullaryMethod(AnyClass, nme.isInstanceOf_, FINAL)(_ => booltype)
- lazy val Any_asInstanceOf = newT1NullaryMethod(AnyClass, nme.asInstanceOf_, FINAL)(typeConstructorOfSymbol)
+ lazy val Any_asInstanceOf = newT1NullaryMethod(AnyClass, nme.asInstanceOf_, FINAL)(_.typeConstructor)
// A type function from T => Class[U], used to determine the return
// type of getClass calls. The returned type is:
@@ -851,7 +851,7 @@ trait Definitions extends api.StandardDefinitions {
lazy val Object_eq = enterNewMethod(ObjectClass, nme.eq, anyrefparam, booltype, FINAL)
lazy val Object_ne = enterNewMethod(ObjectClass, nme.ne, anyrefparam, booltype, FINAL)
lazy val Object_isInstanceOf = newT1NoParamsMethod(ObjectClass, nme.isInstanceOf_Ob, FINAL | SYNTHETIC)(_ => booltype)
- lazy val Object_asInstanceOf = newT1NoParamsMethod(ObjectClass, nme.asInstanceOf_Ob, FINAL | SYNTHETIC)(typeConstructorOfSymbol)
+ lazy val Object_asInstanceOf = newT1NoParamsMethod(ObjectClass, nme.asInstanceOf_Ob, FINAL | SYNTHETIC)(_.typeConstructor)
lazy val Object_synchronized = newPolyMethod(1, ObjectClass, nme.synchronized_, FINAL)(tps =>
(Some(List(tps.head.typeConstructor)), tps.head.typeConstructor)
)
diff --git a/src/reflect/scala/reflect/internal/Symbols.scala b/src/reflect/scala/reflect/internal/Symbols.scala
index 5ae045b404..09ac3e5f6f 100644
--- a/src/reflect/scala/reflect/internal/Symbols.scala
+++ b/src/reflect/scala/reflect/internal/Symbols.scala
@@ -1906,7 +1906,7 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
if ((result eq NoSymbol) || !result.isOverloaded && qualifies(result)) result
else result filter qualifies
}
-
+
/** The non-private member of `site` whose type and name match the type of this symbol. */
final def matchingSymbol(site: Type, admit: Long = 0L): Symbol =
site.nonPrivateMemberAdmitting(name, admit).filter(sym =>
@@ -2631,7 +2631,7 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
tpeCache = NoType
val targs =
if (phase.erasedTypes && this != ArrayClass) List()
- else unsafeTypeParams map typeConstructorOfSymbol
+ else unsafeTypeParams map (_.typeConstructor)
//@M! use typeConstructor to generate dummy type arguments,
// sym.tpe should not be called on a symbol that's supposed to be a higher-kinded type
// memberType should be used instead, that's why it uses tpeHK and not tpe
@@ -3217,10 +3217,6 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
private[scala] final val symbolIsPossibleInRefinement = (sym: Symbol) => sym.isPossibleInRefinement
private[scala] final val symbolIsNonVariant = (sym: Symbol) => sym.variance == 0
- private[scala] final val typeConstructorOfSymbol = (sym: Symbol) => sym.typeConstructor
- private[scala] final val tpeOfSymbol = (sym: Symbol) => sym.tpe
- private[scala] final val infoOfSymbol = (sym: Symbol) => sym.info
- private[scala] final val tpeHKOfSymbol = (sym: Symbol) => sym.tpeHK
@tailrec private[scala] final
def allSymbolsHaveOwner(syms: List[Symbol], owner: Symbol): Boolean = syms match {
diff --git a/src/reflect/scala/reflect/internal/Trees.scala b/src/reflect/scala/reflect/internal/Trees.scala
index b4bfbd410a..0180ed4c4f 100644
--- a/src/reflect/scala/reflect/internal/Trees.scala
+++ b/src/reflect/scala/reflect/internal/Trees.scala
@@ -1543,10 +1543,6 @@ trait Trees extends api.Trees { self: SymbolTable =>
sys.error("Not a LabelDef: " + t + "/" + t.getClass)
}
-// ----- Hoisted closures and convenience methods, for compile time reductions -------
-
- private[scala] final val tpeOfTree = (tree: Tree) => tree.tpe
-
// -------------- Classtags --------------------------------------------------------
implicit val TreeTag = ClassTag[Tree](classOf[Tree])
diff --git a/src/reflect/scala/reflect/internal/Types.scala b/src/reflect/scala/reflect/internal/Types.scala
index 6d718eed79..01f615c5cc 100644
--- a/src/reflect/scala/reflect/internal/Types.scala
+++ b/src/reflect/scala/reflect/internal/Types.scala
@@ -517,7 +517,7 @@ trait Types extends api.Types { self: SymbolTable =>
/** A list of placeholder types derived from the type parameters.
* Used by RefinedType and TypeRef.
*/
- protected def dummyArgs: List[Type] = typeParams map typeConstructorOfSymbol
+ protected def dummyArgs: List[Type] = typeParams map (_.typeConstructor)
/** For a (nullary) method or poly type, its direct result type,
* the type itself for all other types. */
@@ -869,7 +869,7 @@ trait Types extends api.Types { self: SymbolTable =>
case (TypeRef(_, ArrayClass, List(arg1)), TypeRef(_, ArrayClass, List(arg2))) if arg2.typeSymbol.typeParams.nonEmpty =>
arg1 matchesPattern arg2
case (_, TypeRef(_, _, args)) =>
- val newtp = existentialAbstraction(args map typeSymbolOfType, that)
+ val newtp = existentialAbstraction(args map (_.typeSymbol), that)
!(that =:= newtp) && (this <:< newtp)
case _ =>
false
@@ -1759,7 +1759,7 @@ trait Types extends api.Types { self: SymbolTable =>
//@M may result in an invalid type (references to higher-order args become dangling )
override def typeConstructor =
- copyRefinedType(this, parents map typeConstructorOfType, decls)
+ copyRefinedType(this, parents map (_.typeConstructor), decls)
final override def normalize: Type =
if (phase.erasedTypes) normalizeImpl
@@ -2349,7 +2349,7 @@ trait Types extends api.Types { self: SymbolTable =>
private[reflect] var baseTypeSeqCache: BaseTypeSeq = _
private[reflect] var baseTypeSeqPeriod = NoPeriod
private var normalized: Type = _
-
+
//OPT specialize hashCode
override final def computeHashCode = {
import scala.util.hashing.MurmurHash3._
@@ -2357,9 +2357,9 @@ trait Types extends api.Types { self: SymbolTable =>
var h = productSeed
h = mix(h, pre.hashCode)
h = mix(h, sym.hashCode)
- if (hasArgs)
+ if (hasArgs)
finalizeHash(mix(h, args.hashCode), 3)
- else
+ else
finalizeHash(h, 2)
}
@@ -2608,7 +2608,7 @@ trait Types extends api.Types { self: SymbolTable =>
override def paramss: List[List[Symbol]] = params :: resultType.paramss
- override def paramTypes = params map tpeOfSymbol
+ override def paramTypes = params map (_.tpe)
override def boundSyms = resultType.boundSyms ++ params
@@ -2994,7 +2994,7 @@ trait Types extends api.Types { self: SymbolTable =>
tpe exists typeIsExistentiallyBound
def existentialsInType(tpe: Type) =
- tpe withFilter typeIsExistentiallyBound map typeSymbolOfType
+ tpe withFilter typeIsExistentiallyBound map (_.typeSymbol)
/** Precondition: params.nonEmpty. (args.nonEmpty enforced structurally.)
*/
@@ -3311,7 +3311,7 @@ trait Types extends api.Types { self: SymbolTable =>
if (constr.instValid) constr.inst
// get here when checking higher-order subtyping of the typevar by itself
// TODO: check whether this ever happens?
- else if (isHigherKinded) typeFun(params, applyArgs(params map typeConstructorOfSymbol))
+ else if (isHigherKinded) typeFun(params, applyArgs(params map (_.typeConstructor)))
else super.normalize
)
override def typeSymbol = origin.typeSymbol
@@ -3696,7 +3696,7 @@ trait Types extends api.Types { self: SymbolTable =>
val bounds = args map (TypeBounds upper _)
foreach2(eparams, bounds)(_ setInfo _)
- newExistentialType(eparams, typeRef(pre, sym, eparams map tpeOfSymbol))
+ newExistentialType(eparams, typeRef(pre, sym, eparams map (_.tpe)))
case _ =>
appliedType(tycon, args)
}
@@ -4355,7 +4355,7 @@ trait Types extends api.Types { self: SymbolTable =>
else try {
expanded += sym
val eparams = mapOver(typeParamsToExistentials(sym))
- existentialAbstraction(eparams, typeRef(apply(pre), sym, eparams map tpeOfSymbol))
+ existentialAbstraction(eparams, typeRef(apply(pre), sym, eparams map (_.tpe)))
} finally {
expanded -= sym
}
@@ -5174,9 +5174,9 @@ trait Types extends api.Types { self: SymbolTable =>
case NullaryMethodType(result) =>
typeDepth(result)
case PolyType(tparams, result) =>
- typeDepth(result) max typeDepth(tparams map infoOfSymbol) + 1
+ typeDepth(result) max typeDepth(tparams map (_.info)) + 1
case ExistentialType(tparams, result) =>
- typeDepth(result) max typeDepth(tparams map infoOfSymbol) + 1
+ typeDepth(result) max typeDepth(tparams map (_.info)) + 1
case _ =>
1
}
@@ -5193,7 +5193,7 @@ trait Types extends api.Types { self: SymbolTable =>
}
loop(tps, 0)
}
-
+
private def typeDepth(tps: List[Type]): Int = maxDepth(tps, typeDepth)
private def baseTypeSeqDepth(tps: List[Type]): Int = maxDepth(tps, _.baseTypeSeqDepth)
@@ -6346,8 +6346,8 @@ trait Types extends api.Types { self: SymbolTable =>
*/
private def lubList(ts: List[Type], depth: Int): List[Type] = {
// Matching the type params of one of the initial types means dummies.
- val initialTypeParams = ts map typeParamsOfType
- def isHotForTs(xs: List[Type]) = initialTypeParams contains (xs map typeSymbolOfType)
+ val initialTypeParams = ts map (_.typeParams)
+ def isHotForTs(xs: List[Type]) = initialTypeParams contains (xs map (_.typeSymbol))
def elimHigherOrderTypeParam(tp: Type) = tp match {
case TypeRef(pre, sym, args) if args.nonEmpty && isHotForTs(args) => tp.typeConstructor
@@ -7128,10 +7128,6 @@ trait Types extends api.Types { self: SymbolTable =>
private[scala] val typeIsAny = (tp: Type) => tp.typeSymbolDirect eq AnyClass
private[scala] val typeIsHigherKinded = (tp: Type) => tp.isHigherKinded
- private[scala] val typeSymbolOfType = (tp: Type) => tp.typeSymbol
- private[scala] val typeParamsOfType = (tp: Type) => tp.typeParams
- private[scala] val typeConstructorOfType = (tp: Type) => tp.typeConstructor
-
@tailrec private def typesContain(tps: List[Type], sym: Symbol): Boolean = tps match {
case tp :: rest => (tp contains sym) || typesContain(rest, sym)
case _ => false
@@ -7197,7 +7193,7 @@ object TypesStats {
@inline final def timedTypeOp[T](c: Statistics.StackableTimer)(op: => T): T = {
val start = Statistics.pushTimer(typeOpsStack, c)
try op
- finally
+ finally
}
*/
}
diff --git a/src/reflect/scala/reflect/internal/pickling/UnPickler.scala b/src/reflect/scala/reflect/internal/pickling/UnPickler.scala
index 38f61d3e93..2e00316d5b 100644
--- a/src/reflect/scala/reflect/internal/pickling/UnPickler.scala
+++ b/src/reflect/scala/reflect/internal/pickling/UnPickler.scala
@@ -677,7 +677,7 @@ abstract class UnPickler /*extends reflect.generic.UnPickler*/ {
val args = until(end, readTreeRef)
if (fun.symbol.isOverloaded) {
fun.setType(fun.symbol.info)
- inferMethodAlternative(fun, args map tpeOfTree, tpe)
+ inferMethodAlternative(fun, args map (_.tpe), tpe)
}
Apply(fun, args)
@@ -782,7 +782,7 @@ abstract class UnPickler /*extends reflect.generic.UnPickler*/ {
}
r.asInstanceOf[Symbol]
}
-
+
protected def readNameRef(): Name = at(readNat(), readName)
protected def readTypeRef(): Type = at(readNat(), () => readType()) // after the NMT_TRANSITION period, we can leave off the () => ... ()
protected def readConstantRef(): Constant = at(readNat(), readConstant)