diff options
author | Adriaan Moors <adriaan.moors@epfl.ch> | 2011-11-22 23:10:15 +0000 |
---|---|---|
committer | Adriaan Moors <adriaan.moors@epfl.ch> | 2011-11-22 23:10:15 +0000 |
commit | 1189476b0e48bb0e82565b75d7997b33a67c31e9 (patch) | |
tree | 07f8475ffbd534e91e467ce8a8de10addf654812 /src/compiler | |
parent | 370841db4be1290b46c169dc7b92637b5c13cfd7 (diff) | |
download | scala-1189476b0e48bb0e82565b75d7997b33a67c31e9.tar.gz scala-1189476b0e48bb0e82565b75d7997b33a67c31e9.tar.bz2 scala-1189476b0e48bb0e82565b75d7997b33a67c31e9.zip |
optimized version of cond
Diffstat (limited to 'src/compiler')
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/PatMatVirtualiser.scala | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/PatMatVirtualiser.scala b/src/compiler/scala/tools/nsc/typechecker/PatMatVirtualiser.scala index ef02fd0b03..38c97e8828 100644 --- a/src/compiler/scala/tools/nsc/typechecker/PatMatVirtualiser.scala +++ b/src/compiler/scala/tools/nsc/typechecker/PatMatVirtualiser.scala @@ -892,6 +892,25 @@ trait PatMatVirtualiser extends ast.TreeDSL { self: Analyzer => // an object of a type that only has two concrete subclasses, and inlines both bodies, guarded by an if to distinguish the two cases trait MatchingStrategyGenOpt extends MatchingStrategyGen { self: CommonCodeGen with MatchingStrategyGen with MonadInstGen => override def guard(c: Tree): Tree = condOptimized(c, one(UNIT)) + override def cond(c: Tree, then: Tree = UNIT, tp: Type = NoType): Tree = condOptimized(c, one(then, repackExistential(tp))) + // override def runOrElse(scrut: Tree, matcher: Tree): Tree = matcher match { + // case Function(List(x: ValDef), body) => + // val tp = x.symbol.tpe + // val restp = appliedType(matchingMonadType, List(pt)) // don't always know pt.... + // val isEmpty = restp member vpmName.isEmpty + // val get = restp member vpmName.get + // + // val vs = freshSym(scrut.pos, tp, "s") + // val vres = freshSym(scrut.pos, restp, "res") + // val s = VAL(vs) === scrut + // val res = VAL(vres) === typedSubst(body, List(x.symbol), List(REF(vs))) + // + // BLOCK( + // s, + // res, + // IF (res DOT isEmpty) THEN ELSE (res DOT get) + // ) + // } } trait MonadInstGenOpt extends MonadInstGen { self: CommonCodeGen with MatchingStrategyGen with MonadInstGen => |