diff options
author | Martin Odersky <odersky@gmail.com> | 2011-01-16 21:31:31 +0000 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2011-01-16 21:31:31 +0000 |
commit | cf820b8907e60214df974a3b2a88ca0a7e877298 (patch) | |
tree | d84b96abaec22ee0258ceb490917ab2dcd4b71ac /src/compiler | |
parent | 3414335ced07828aef1f50e1e61384c026391376 (diff) | |
download | scala-cf820b8907e60214df974a3b2a88ca0a7e877298.tar.gz scala-cf820b8907e60214df974a3b2a88ca0a7e877298.tar.bz2 scala-cf820b8907e60214df974a3b2a88ca0a7e877298.zip |
Dynamic type added. Array creation optimized.
Diffstat (limited to 'src/compiler')
4 files changed, 46 insertions, 15 deletions
diff --git a/src/compiler/scala/tools/nsc/symtab/Definitions.scala b/src/compiler/scala/tools/nsc/symtab/Definitions.scala index 659b7e80d2..e38f626932 100644 --- a/src/compiler/scala/tools/nsc/symtab/Definitions.scala +++ b/src/compiler/scala/tools/nsc/symtab/Definitions.scala @@ -152,6 +152,8 @@ trait Definitions extends reflect.generic.StandardDefinitions { lazy val StringModule = StringClass.linkedClassOfClass lazy val ClassClass = getClass(sn.Class) def Class_getMethod = getMember(ClassClass, nme.getMethod_) + lazy val DynamicClass = getClass("scala.Dynamic") + val Dynamic_OptInvokeMaxArgCount = 7 // fundamental modules lazy val PredefModule: Symbol = getModule("scala.Predef") @@ -160,6 +162,7 @@ trait Definitions extends reflect.generic.StandardDefinitions { def Predef_error = getMember(PredefModule, nme.error) def Predef_identity = getMember(PredefModule, nme.identity) def Predef_conforms = getMember(PredefModule, nme.conforms) + def Predef_wrapRefArray = getMember(PredefModule, nme.wrapRefArray) lazy val ConsoleModule: Symbol = getModule("scala.Console") lazy val ScalaRunTimeModule: Symbol = getModule("scala.runtime.ScalaRunTime") lazy val SymbolModule: Symbol = getModule("scala.Symbol") @@ -244,6 +247,7 @@ trait Definitions extends reflect.generic.StandardDefinitions { // arrays and their members lazy val ArrayModule = getModule("scala.Array") + def ArrayModule_overloadedApply = getMember(ArrayModule, nme.apply) lazy val ArrayClass = getClass("scala.Array") def Array_apply = getMember(ArrayClass, nme.apply) def Array_update = getMember(ArrayClass, nme.update) diff --git a/src/compiler/scala/tools/nsc/symtab/StdNames.scala b/src/compiler/scala/tools/nsc/symtab/StdNames.scala index 0e28ac54e1..04f71470f8 100644 --- a/src/compiler/scala/tools/nsc/symtab/StdNames.scala +++ b/src/compiler/scala/tools/nsc/symtab/StdNames.scala @@ -235,6 +235,7 @@ trait StdNames extends reflect.generic.StdNames with NameManglers { val view_ : NameType = "view" val wait_ : NameType = "wait" val withFilter: NameType = "withFilter" + val wrapRefArray: NameType = "wrapRefArray" val zip: NameType = "zip" // unencoded operators diff --git a/src/compiler/scala/tools/nsc/transform/CleanUp.scala b/src/compiler/scala/tools/nsc/transform/CleanUp.scala index 66c22fb1ef..3c9e701ee9 100644 --- a/src/compiler/scala/tools/nsc/transform/CleanUp.scala +++ b/src/compiler/scala/tools/nsc/transform/CleanUp.scala @@ -595,6 +595,16 @@ abstract class CleanUp extends Transform with ast.TreeDSL { val ntree = typedWithPos(symapp.pos)(REF(staticFieldSym)) super.transform(ntree) + + // This transform replaces Array(Predef.wrapArray(Array(...)), <manifest>) + // with just Array(...) + case Apply(appMeth, List(Apply(wrapRefArrayMeth, List(array)), _)) + if (wrapRefArrayMeth.symbol == Predef_wrapRefArray && + appMeth.symbol == ArrayModule_overloadedApply.suchThat { + _.tpe.resultType.dealias.typeSymbol == ObjectClass + }) => + super.transform(array) + case _ => super.transform(tree) } diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index 2b6bf6080c..9085affd62 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -3443,21 +3443,21 @@ trait Typers extends Modes { adaptToName(qual, name) } catch { case ex: TypeError => - // this happens if implicits are ambiguous; try again with more context info. - // println("last ditch effort: "+qual+" . "+name) // DEBUG - context.tree match { - case Apply(tree1, args) if tree1 eq tree => // try handling the arguments - // println("typing args: "+args) // DEBUG - silent(_.typedArgs(args, mode)) match { - case args: List[_] => - adaptToArguments(qual, name, args.asInstanceOf[List[Tree]], WildcardType) - case _ => - throw ex - } - case _ => - // println("not in an apply: "+context.tree+"/"+tree) // DEBUG - throw ex - } + // this happens if implicits are ambiguous; try again with more context info. + // println("last ditch effort: "+qual+" . "+name) + context.tree match { + case Apply(tree1, args) if tree1 eq tree => // try handling the arguments + // println("typing args: "+args) + silent(_.typedArgs(args, mode)) match { + case args: List[_] => + adaptToArguments(qual, name, args.asInstanceOf[List[Tree]], WildcardType) + case _ => + throw ex + } + case _ => + // println("not in an apply: "+context.tree+"/"+tree) + throw ex + } } if (qual1 ne qual) return typed(treeCopy.Select(tree, qual1, name), mode, pt) } @@ -3468,6 +3468,22 @@ trait Typers extends Modes { if (tree1 != EmptyTree) return typed1(tree1, mode, pt) } + // try to expand according to Dynamic rules. + + if (qual.tpe.widen.typeSymbol isNonBottomSubClass DynamicClass) { + val op = context.tree match { + case Apply(tree1, args) if tree1 eq tree => + "_invoke_" + + (if (args.length <= Dynamic_OptInvokeMaxArgCount) args.length.toString + else "") + case _ => + "_select_" + } + return typed1( + util.trace("dynatype: ")(Apply(Select(qual, op), List(Literal(Constant(name.toString))))), + mode, pt) + } + if (settings.debug.value) { log( "qual = "+qual+":"+qual.tpe+ |