summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/typechecker/Infer.scala
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2011-11-19 06:59:19 +0000
committerPaul Phillips <paulp@improving.org>2011-11-19 06:59:19 +0000
commit334872e33be8385678697f3d670c8102d38cdca7 (patch)
treed89531734d6c57e0dcd2eb7bd934e8beae888633 /src/compiler/scala/tools/nsc/typechecker/Infer.scala
parent7eb6f102e8e3bf90319e0339938d7e6eb5aaea43 (diff)
downloadscala-334872e33be8385678697f3d670c8102d38cdca7.tar.gz
scala-334872e33be8385678697f3d670c8102d38cdca7.tar.bz2
scala-334872e33be8385678697f3d670c8102d38cdca7.zip
Bringing a bit of order to symbol substitution.
Painstakingly winnowed out the most frequently duplicated code sequences related to symbol cloning and substitution. Created canonical methods to perform these actions and documented them. Key methods include: def createFromClonedSymbols[T](syms: List[Symbol], tpe: Type)(creator: (List[Symbol], Type) => T): T def deriveSymbols(syms: List[Symbol], symFn: Symbol => Symbol): List[Symbol] def deriveType(syms: List[Symbol], symFn: Symbol => Symbol)(tpe: Type): Type Many example usages enclosed with commit. I did lots of timing tests, I find no material difference before and after. Actually I won by four seconds in this incarnation: Before - Total time: 7 minutes 55 seconds After - Total time: 7 minutes 51 seconds Review by moors.
Diffstat (limited to 'src/compiler/scala/tools/nsc/typechecker/Infer.scala')
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Infer.scala41
1 files changed, 22 insertions, 19 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Infer.scala b/src/compiler/scala/tools/nsc/typechecker/Infer.scala
index cb548ffdab..68c84b8e15 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Infer.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Infer.scala
@@ -304,25 +304,29 @@ trait Infer {
)
}
else {
- if(sym1.isTerm)
+ if (sym1.isTerm)
sym1.cookJavaRawInfo() // xform java rawtypes into existentials
- var owntype = try{
- pre.memberType(sym1)
- } catch {
- case ex: MalformedType =>
- if (settings.debug.value) ex.printStackTrace
- val sym2 = underlyingSymbol(sym1)
- val itype = pre.memberType(sym2)
- new AccessError(tree, sym, pre,
- "\n because its instance type "+itype+
- (if ("malformed type: "+itype.toString==ex.msg) " is malformed"
- else " contains a "+ex.msg)).emit()
- ErrorType
+ val owntype = {
+ try pre.memberType(sym1)
+ catch {
+ case ex: MalformedType =>
+ if (settings.debug.value) ex.printStackTrace
+ val sym2 = underlyingSymbol(sym1)
+ val itype = pre.memberType(sym2)
+ new AccessError(tree, sym, pre,
+ "\n because its instance type "+itype+
+ (if ("malformed type: "+itype.toString==ex.msg) " is malformed"
+ else " contains a "+ex.msg)).emit()
+ ErrorType
+ }
+ }
+ tree setSymbol sym1 setType {
+ pre match {
+ case _: SuperType => owntype map (tp => if (tp eq pre) site.symbol.thisType else tp)
+ case _ => owntype
+ }
}
- if (pre.isInstanceOf[SuperType])
- owntype = owntype.substSuper(pre, site.symbol.thisType)
- tree setSymbol sym1 setType owntype
}
}
@@ -905,8 +909,7 @@ trait Infer {
case NullaryMethodType(restpe) => // strip nullary method type, which used to be done by the polytype case below
isApplicable(undetparams, restpe, argtpes0, pt)
case PolyType(tparams, restpe) =>
- val tparams1 = cloneSymbols(tparams)
- isApplicable(tparams1 ::: undetparams, restpe.substSym(tparams, tparams1), argtpes0, pt)
+ createFromClonedSymbols(tparams, restpe)((tps1, restpe1) => isApplicable(tps1 ::: undetparams, restpe1, argtpes0, pt))
case ErrorType =>
true
case _ =>
@@ -1278,7 +1281,7 @@ trait Infer {
case Nil => Nil
case xs =>
// #3890
- val xs1 = treeSubst.typeSubst mapOver xs
+ val xs1 = treeSubst.typeMap mapOver xs
if (xs ne xs1)
new TreeSymSubstTraverser(xs, xs1) traverseTrees fn :: args