summaryrefslogtreecommitdiff
path: root/src/compiler
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/compiler
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/compiler')
-rw-r--r--src/compiler/scala/tools/nsc/transform/CleanUp.scala2
-rw-r--r--src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala2
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Infer.scala6
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/MethodSynthesis.scala2
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/PatternMatching.scala2
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/RefChecks.scala2
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala2
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Typers.scala26
8 files changed, 22 insertions, 22 deletions
diff --git a/src/compiler/scala/tools/nsc/transform/CleanUp.scala b/src/compiler/scala/tools/nsc/transform/CleanUp.scala
index e02e10b5ad..570704f049 100644
--- a/src/compiler/scala/tools/nsc/transform/CleanUp.scala
+++ b/src/compiler/scala/tools/nsc/transform/CleanUp.scala
@@ -451,7 +451,7 @@ abstract class CleanUp extends Transform with ast.TreeDSL {
BLOCK(
VAL(sym) === qual0,
- callAsReflective(mparams map tpeOfSymbol, resType)
+ callAsReflective(mparams map (_.tpe), resType)
)
}
}
diff --git a/src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala b/src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala
index 7247770f4b..77ad65957d 100644
--- a/src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala
+++ b/src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala
@@ -385,7 +385,7 @@ abstract class ExplicitOuter extends InfoTransform
def makeGuardDef(vs: List[Symbol], guard: Tree) = {
val gdname = unit.freshTermName("gd")
val method = currentOwner.newMethod(gdname, tree.pos, SYNTHETIC)
- val params = method newSyntheticValueParams vs.map(tpeOfSymbol)
+ val params = method newSyntheticValueParams vs.map(_.tpe)
method setInfo new MethodType(params, BooleanClass.tpe)
localTyper typed {
diff --git a/src/compiler/scala/tools/nsc/typechecker/Infer.scala b/src/compiler/scala/tools/nsc/typechecker/Infer.scala
index 1870e1511e..aa1bc0ce9d 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Infer.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Infer.scala
@@ -664,7 +664,7 @@ trait Infer {
val appmeth = {
//OPT cut down on #closures by special casing non-overloaded case
// was: tp.nonPrivateMember(nme.apply) filter (_.isPublic)
- val result = tp.nonPrivateMember(nme.apply)
+ val result = tp.nonPrivateMember(nme.apply)
if ((result eq NoSymbol) || !result.isOverloaded && result.isPublic) result
else result filter (_.isPublic)
}
@@ -1646,7 +1646,7 @@ trait Infer {
else eligible filter { alt =>
// for functional values, the `apply` method might be overloaded
val mtypes = followApply(alt.tpe) match {
- case OverloadedType(_, alts) => alts map tpeOfSymbol
+ case OverloadedType(_, alts) => alts map (_.tpe)
case t => t :: Nil
}
// Drop those that use a default; keep those that use vararg/tupling conversion.
@@ -1783,7 +1783,7 @@ trait Infer {
else if (sym.isOverloaded) {
val xs = sym.alternatives
val tparams = new AsSeenFromMap(pre, xs.head.owner) mapOver xs.head.typeParams
- val bounds = tparams map tpeHKOfSymbol // see e.g., #1236
+ val bounds = tparams map (_.tpeHK) // see e.g., #1236
val tpe = PolyType(tparams, OverloadedType(AntiPolyType(pre, bounds), xs))
(sym setInfo tpe, tpe)
diff --git a/src/compiler/scala/tools/nsc/typechecker/MethodSynthesis.scala b/src/compiler/scala/tools/nsc/typechecker/MethodSynthesis.scala
index cdbdb82e9f..4f597f97c9 100644
--- a/src/compiler/scala/tools/nsc/typechecker/MethodSynthesis.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/MethodSynthesis.scala
@@ -41,7 +41,7 @@ trait MethodSynthesis {
require(container.owner.isPackageClass, "Container must be a top-level class in a package: " + container)
require(tparams.size == args.size, "Arguments must match type constructor arity: " + tparams + ", " + args)
- appliedType(container, args map tpeOfSymbol: _*)
+ appliedType(container, args map (_.tpe): _*)
}
def companionType[T](implicit ct: CT[T]) =
diff --git a/src/compiler/scala/tools/nsc/typechecker/PatternMatching.scala b/src/compiler/scala/tools/nsc/typechecker/PatternMatching.scala
index eaa18c142c..c60118a8b4 100644
--- a/src/compiler/scala/tools/nsc/typechecker/PatternMatching.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/PatternMatching.scala
@@ -3299,7 +3299,7 @@ trait PatternMatching extends Transform with TypingTransformers with ast.TreeDSL
// TODO: I don't think the binder's types can actually be different (due to checks in caseEquals)
// if they do somehow manage to diverge, the lub might not be precise enough and we could get a type error
// TODO: reuse name exactly if there's only one binder in binders
- val binder = freshSym(binders.head.pos, lub(binders.map(tpeOfSymbol)), binders.head.name.toString)
+ val binder = freshSym(binders.head.pos, lub(binders.map(_.tpe)), binders.head.name.toString)
// the patterns in same are equal (according to caseEquals)
// we can thus safely pick the first one arbitrarily, provided we correct binding
diff --git a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala
index f87ca4997d..9201981635 100644
--- a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala
@@ -1677,7 +1677,7 @@ abstract class RefChecks extends InfoTransform with reflect.internal.transform.R
tree
case TypeApply(fn, args) =>
- checkBounds(tree, NoPrefix, NoSymbol, fn.tpe.typeParams, args map tpeOfTree)
+ checkBounds(tree, NoPrefix, NoSymbol, fn.tpe.typeParams, args map (_.tpe))
transformCaseApply(tree, ())
case x @ Apply(_, _) =>
diff --git a/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala b/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala
index 80777aa701..63050bc032 100644
--- a/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala
@@ -418,7 +418,7 @@ abstract class SuperAccessors extends transform.Transform with transform.TypingT
val code = DefDef(newAcc, {
val (receiver :: _) :: tail = newAcc.paramss
val base: Tree = Select(Ident(receiver), sym)
- val allParamTypes = mapParamss(sym)(tpeOfSymbol)
+ val allParamTypes = mapParamss(sym)(_.tpe)
val args = map2(tail, allParamTypes)((params, tpes) => map2(params, tpes)(makeArg(_, receiver, _)))
args.foldLeft(base)(Apply(_, _))
})
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
index 2e680c8df6..dfe08c398e 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
@@ -1315,7 +1315,7 @@ trait Typers extends Modes with Adaptations with Tags {
def adaptToArguments(qual: Tree, name: Name, args: List[Tree], pt: Type, reportAmbiguous: Boolean, saveErrors: Boolean): Tree = {
def doAdapt(restpe: Type) =
//util.trace("adaptToArgs "+qual+", name = "+name+", argtpes = "+(args map (_.tpe))+", pt = "+pt+" = ")
- adaptToMember(qual, HasMethodMatching(name, args map tpeOfTree, restpe), reportAmbiguous, saveErrors)
+ adaptToMember(qual, HasMethodMatching(name, args map (_.tpe), restpe), reportAmbiguous, saveErrors)
if (pt != WildcardType) {
silent(_ => doAdapt(pt)) match {
case SilentResultValue(result) if result != qual =>
@@ -1443,7 +1443,7 @@ trait Typers extends Modes with Adaptations with Tags {
val supertparams = if (supertpt.hasSymbol) supertpt.symbol.typeParams else List()
var supertpe = supertpt.tpe
if (!supertparams.isEmpty)
- supertpe = PolyType(supertparams, appliedType(supertpe, supertparams map tpeHKOfSymbol))
+ supertpe = PolyType(supertparams, appliedType(supertpe, supertparams map (_.tpeHK)))
// A method to replace a super reference by a New in a supercall
def transformSuperCall(scall: Tree): Tree = (scall: @unchecked) match {
@@ -1877,7 +1877,7 @@ trait Typers extends Modes with Adaptations with Tags {
val params = fn.tpe.params
val args2 = if (params.isEmpty || !isRepeatedParamType(params.last.tpe)) args
else args.take(params.length - 1) :+ EmptyTree
- assert(sameLength(args2, params) || call.isErrorTyped, "mismatch " + clazz + " " + (params map tpeOfSymbol) + " " + args2)//debug
+ assert(sameLength(args2, params) || call.isErrorTyped, "mismatch " + clazz + " " + (params map (_.tpe)) + " " + args2)//debug
(superConstr, args1 ::: args2)
case Block(stats, expr) if !stats.isEmpty =>
decompose(stats.last)
@@ -2011,7 +2011,7 @@ trait Typers extends Modes with Adaptations with Tags {
case SilentResultValue(tpt) =>
val alias = enclClass.newAliasType(name.toTypeName, useCase.pos)
val tparams = cloneSymbolsAtOwner(tpt.tpe.typeSymbol.typeParams, alias)
- val newInfo = genPolyType(tparams, appliedType(tpt.tpe, tparams map tpeOfSymbol))
+ val newInfo = genPolyType(tparams, appliedType(tpt.tpe, tparams map (_.tpe)))
alias setInfo newInfo
context.scope.enter(alias)
case _ =>
@@ -2340,7 +2340,7 @@ trait Typers extends Modes with Adaptations with Tags {
val (resTp, needAdapt) =
if (opt.virtPatmat) ptOrLubPacked(casesTyped, pt)
- else ptOrLub(casesTyped map tpeOfTree, pt)
+ else ptOrLub(casesTyped map (_.tpe), pt)
val casesAdapted = if (!needAdapt) casesTyped else casesTyped map (adaptCase(_, mode, resTp))
@@ -2428,7 +2428,7 @@ trait Typers extends Modes with Adaptations with Tags {
val match_ = methodBodyTyper.typedMatch(gen.mkUnchecked(selector), cases, mode, ptRes)
val resTp = match_.tpe
- val methFormals = paramSyms map tpeOfSymbol
+ val methFormals = paramSyms map (_.tpe)
val parents = (
if (isPartial) parentsPartial(List(methFormals.head, resTp))
else addSerializable(abstractFunctionType(methFormals, resTp))
@@ -2594,7 +2594,7 @@ trait Typers extends Modes with Adaptations with Tags {
// for (vparam <- vparams) {
// checkNoEscaping.locals(context.scope, WildcardType, vparam.tpt); ()
// }
- val formals = vparamSyms map tpeOfSymbol
+ val formals = vparamSyms map (_.tpe)
val body1 = typed(fun.body, respt)
val restpe = packedType(body1, fun.symbol).deconst.resultType
val funtpe = typeRef(clazz.tpe.prefix, clazz, formals :+ restpe)
@@ -3565,7 +3565,7 @@ trait Typers extends Modes with Adaptations with Tags {
// Higher-kinded existentials are not yet supported, but this is
// tpeHK for when they are: "if a type constructor is expected/allowed,
// tpeHK must be called instead of tpe."
- val typeParamTypes = typeParams map tpeHKOfSymbol
+ val typeParamTypes = typeParams map (_.tpeHK)
def doSubst(info: Type) = info.subst(rawSyms, typeParamTypes)
creator(typeParams map (_ modifyInfo doSubst), doSubst(tp))
@@ -3701,7 +3701,7 @@ trait Typers extends Modes with Adaptations with Tags {
// lifted out of typed1 because it's needed in typedImplicit0
protected def typedTypeApply(tree: Tree, mode: Int, fun: Tree, args: List[Tree]): Tree = fun.tpe match {
case OverloadedType(pre, alts) =>
- inferPolyAlternatives(fun, args map tpeOfTree)
+ inferPolyAlternatives(fun, args map (_.tpe))
val tparams = fun.symbol.typeParams //@M TODO: fun.symbol.info.typeParams ? (as in typedAppliedTypeTree)
val args1 = if (sameLength(args, tparams)) {
//@M: in case TypeApply we can't check the kind-arities of the type arguments,
@@ -3721,7 +3721,7 @@ trait Typers extends Modes with Adaptations with Tags {
typedTypeApply(tree, mode, fun setType fun.tpe.widen, args)
case PolyType(tparams, restpe) if tparams.nonEmpty =>
if (sameLength(tparams, args)) {
- val targs = args map tpeOfTree
+ val targs = args map (_.tpe)
checkBounds(tree, NoPrefix, NoSymbol, tparams, targs, "")
if (fun.symbol == Predef_classOf)
typedClassOf(tree, args.head, true)
@@ -4139,7 +4139,7 @@ trait Typers extends Modes with Adaptations with Tags {
context.undetparams = cloneSymbols(tpt0.symbol.typeParams)
notifyUndetparamsAdded(context.undetparams)
TypeTree().setOriginal(tpt0)
- .setType(appliedType(tpt0.tpe, context.undetparams map tpeHKOfSymbol)) // @PP: tpeHK! #3343, #4018, #4347.
+ .setType(appliedType(tpt0.tpe, context.undetparams map (_.tpeHK))) // @PP: tpeHK! #3343, #4018, #4347.
} else tpt0
else tpt0
}
@@ -4921,7 +4921,7 @@ trait Typers extends Modes with Adaptations with Tags {
else {
val decls = newScope
//Console.println("Owner: " + context.enclClass.owner + " " + context.enclClass.owner.id)
- val self = refinedType(parents1 map tpeOfTree, context.enclClass.owner, decls, templ.pos)
+ val self = refinedType(parents1 map (_.tpe), context.enclClass.owner, decls, templ.pos)
newTyper(context.make(templ, self.typeSymbol, decls)).typedRefinement(templ)
templ addAttachment CompoundTypeTreeOriginalAttachment(parents1, Nil) // stats are set elsewhere
tree setType self
@@ -4948,7 +4948,7 @@ trait Typers extends Modes with Adaptations with Tags {
//@M! the polytype denotes the expected kind
typedHigherKindedType(arg, mode, GenPolyType(tparam.typeParams, AnyClass.tpe))
}
- val argtypes = args1 map tpeOfTree
+ val argtypes = args1 map (_.tpe)
foreach2(args, tparams)((arg, tparam) => arg match {
// note: can't use args1 in selector, because Bind's got replaced