diff options
author | Paul Phillips <paulp@improving.org> | 2011-06-16 01:45:19 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2011-06-16 01:45:19 +0000 |
commit | 3cbf6bf54e4dab30b0c759d20b7f63876a4c0aaa (patch) | |
tree | 955b22a37ec0cadd4bb24b07397927fe2b962c4f /src | |
parent | 5de317f769c2e9bead1cadceafbf87cb4223065f (diff) | |
download | scala-3cbf6bf54e4dab30b0c759d20b7f63876a4c0aaa.tar.gz scala-3cbf6bf54e4dab30b0c759d20b7f63876a4c0aaa.tar.bz2 scala-3cbf6bf54e4dab30b0c759d20b7f63876a4c0aaa.zip |
Triumph over various unsolved mysteries of the ...
Triumph over various unsolved mysteries of the pattern matcher. More
elimination of redundant ways of doing things. More allowing the typer
to do its typing thing. No review.
Diffstat (limited to 'src')
-rw-r--r-- | src/compiler/scala/tools/nsc/ast/TreeDSL.scala | 6 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/matching/Matrix.scala | 13 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/matching/ParallelMatching.scala | 29 |
3 files changed, 18 insertions, 30 deletions
diff --git a/src/compiler/scala/tools/nsc/ast/TreeDSL.scala b/src/compiler/scala/tools/nsc/ast/TreeDSL.scala index 404c9156fe..6c35514110 100644 --- a/src/compiler/scala/tools/nsc/ast/TreeDSL.scala +++ b/src/compiler/scala/tools/nsc/ast/TreeDSL.scala @@ -253,12 +253,6 @@ trait TreeDSL { class SymbolMethods(target: Symbol) { def BIND(body: Tree) = Bind(target, body) - - // Option - def IS_DEFINED() = - if (target.tpe.typeSymbol == SomeClass) TRUE // is Some[_] - else NOT(ID(target) DOT nme.isEmpty) // is Option[_] - def IS_NULL() = REF(target) OBJ_EQ NULL def NOT_NULL() = REF(target) OBJ_NE NULL diff --git a/src/compiler/scala/tools/nsc/matching/Matrix.scala b/src/compiler/scala/tools/nsc/matching/Matrix.scala index 6b691826a9..83213c498c 100644 --- a/src/compiler/scala/tools/nsc/matching/Matrix.scala +++ b/src/compiler/scala/tools/nsc/matching/Matrix.scala @@ -198,16 +198,14 @@ trait Matrix extends MatrixAdditions { */ class PatternVar(val lhs: Symbol, val rhs: Tree, val checked: Boolean) { def sym = lhs - def valsym = valDef.symbol - // XXX how will valsym.tpe differ from sym.tpe ? - def tpe = valsym.tpe + def tpe = lhs.tpe // See #1427 for an example of a crash which occurs unless we retype: // in that instance there is an existential in the pattern. - lazy val ident = typer typed { ID(lhs) setType null } - lazy val valDef = typer typed { (VAL(lhs) withType ident.tpe) === rhs } + lazy val ident = typer typed Ident(lhs) + lazy val valDef = typer typedValDef ValDef(lhs, rhs) - override def toString() = "%s: %s = %s".format(lhs, lhs.info, rhs) + override def toString() = "%s: %s = %s".format(lhs, tpe, rhs) } /** Sets the rhs to EmptyTree, which makes the valDef ignored in Scrutinee. @@ -257,8 +255,5 @@ trait Matrix extends MatrixAdditions { // careful: pos has special meaning recordSyntheticSym(owner.newVariable(pos, n) setInfo tpe setFlag (SYNTHETIC.toLong /: flags)(_|_)) } - - def typedValDef(x: Symbol, rhs: Tree) = - tracing("typedVal")(typer typedValDef (VAL(x) === rhs)) } }
\ No newline at end of file diff --git a/src/compiler/scala/tools/nsc/matching/ParallelMatching.scala b/src/compiler/scala/tools/nsc/matching/ParallelMatching.scala index e198656eb5..bd78ba0f3d 100644 --- a/src/compiler/scala/tools/nsc/matching/ParallelMatching.scala +++ b/src/compiler/scala/tools/nsc/matching/ParallelMatching.scala @@ -25,7 +25,7 @@ trait ParallelMatching extends ast.TreeDSL self: ExplicitOuter => import global.{ typer => _, _ } - import definitions.{ AnyRefClass, NothingClass, IntClass, BooleanClass, getProductArgs, productProj } + import definitions.{ AnyRefClass, NothingClass, IntClass, BooleanClass, SomeClass, getProductArgs, productProj } import CODE._ import Types._ import Debug._ @@ -355,8 +355,9 @@ trait ParallelMatching extends ast.TreeDSL scrut.createVar(unMethod.tpe, Apply(unTarget, scrut.id :: trailing) setType _.tpe) lazy val cond: Tree = - if (unapplyResult.tpe.isBoolean) ID(unapplyResult.valsym) - else unapplyResult.valsym IS_DEFINED + if (unapplyResult.tpe.isBoolean) unapplyResult.ident + else if (unapplyResult.tpe.typeSymbol == SomeClass) TRUE + else NOT(unapplyResult.ident DOT nme.isEmpty) lazy val failure = mkFail(zipped.tail filterNot (x => SameUnapplyPattern(x._1)) map { case (pat, r) => r insert pat }) @@ -665,16 +666,20 @@ trait ParallelMatching extends ast.TreeDSL def unreached = referenceCount == 0 def shouldInline(sym: Symbol) = referenceCount == 1 && label.exists(_.symbol == sym) - protected def maybeCast(lhs: Symbol, rhs: Symbol)(tree: Tree) = { - if (rhs.tpe <:< lhs.tpe) tree - else tree AS lhs.tpe - } + // Creates a simple Ident if the symbol's type conforms to + // the val definition's type, or a casted Ident if not. + private def newValIdent(lhs: Symbol, rhs: Symbol) = + if (rhs.tpe <:< lhs.tpe) Ident(rhs) + else Ident(rhs) AS lhs.tpe protected def newValDefinition(lhs: Symbol, rhs: Symbol) = - VAL(lhs) === maybeCast(lhs, rhs)(Ident(rhs)) + typer typedValDef ValDef(lhs, newValIdent(lhs, rhs)) protected def newValReference(lhs: Symbol, rhs: Symbol) = - maybeCast(lhs, rhs)(Ident(rhs)) + typer typed newValIdent(lhs, rhs) + + protected def valDefsFor(subst: Map[Symbol, Symbol]) = mapSubst(subst)(newValDefinition) + protected def identsFor(subst: Map[Symbol, Symbol]) = mapSubst(subst)(newValReference) protected def mapSubst[T](subst: Map[Symbol, Symbol])(f: (Symbol, Symbol) => T): List[T] = params flatMap { lhs => @@ -686,12 +691,6 @@ trait ParallelMatching extends ast.TreeDSL } } - protected def valDefsFor(subst: Map[Symbol, Symbol]) = - mapSubst(subst)(typer typedValDef newValDefinition(_, _)) - - protected def identsFor(subst: Map[Symbol, Symbol]) = - mapSubst(subst)(typer typed newValReference(_, _)) - // typer is not able to digest a body of type Nothing being assigned result type Unit protected def caseResultType = if (body.tpe.isNothing) body.tpe else matchResultType |