summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBurak Emir <emir@epfl.ch>2007-08-14 16:01:06 +0000
committerBurak Emir <emir@epfl.ch>2007-08-14 16:01:06 +0000
commit4357e79096dd3ab9ecc1e78eeba8a20128c6d3d8 (patch)
tree6bf8ddab8dae1dd66eda09d628f368fd822d45fc
parent564bc566d396e163e28abe4dc2b5deb15badebfd (diff)
downloadscala-4357e79096dd3ab9ecc1e78eeba8a20128c6d3d8.tar.gz
scala-4357e79096dd3ab9ecc1e78eeba8a20128c6d3d8.tar.bz2
scala-4357e79096dd3ab9ecc1e78eeba8a20128c6d3d8.zip
small opts, fixed #1270, if target is Literal, ...
small opts, fixed #1270, if target is Literal, generate Literal instead of jump (no sharing)
-rw-r--r--src/compiler/scala/tools/nsc/matching/CodeFactory.scala17
-rw-r--r--src/compiler/scala/tools/nsc/matching/ParallelMatching.scala17
-rw-r--r--src/compiler/scala/tools/nsc/matching/PatternMatchers.scala6
3 files changed, 28 insertions, 12 deletions
diff --git a/src/compiler/scala/tools/nsc/matching/CodeFactory.scala b/src/compiler/scala/tools/nsc/matching/CodeFactory.scala
index b037f20551..ce19ae5446 100644
--- a/src/compiler/scala/tools/nsc/matching/CodeFactory.scala
+++ b/src/compiler/scala/tools/nsc/matching/CodeFactory.scala
@@ -23,7 +23,13 @@ trait CodeFactory {
import posAssigner.atPos // for filling in tree positions
- final def typedValDef(x:Symbol, rhs:Tree) = typed{ValDef(x, typed(rhs,x.tpe))}
+ final def typedValDef(x:Symbol, rhs:Tree) = {
+ //Console.println("1"+x.tpe)
+ x.tpe match {
+ case WildcardType => rhs.setType(null); val rhs1 = typed(rhs); x setInfo rhs1.tpe; typed{ValDef(x, rhs)}
+ case _ => typed{ValDef(x, typed(rhs, x.tpe))}
+ }
+ }
final def mk_(tpe:Type) = Ident(nme.WILDCARD) setType tpe
@@ -81,7 +87,7 @@ trait CodeFactory {
var result = defaultBody
var i = condition.length - 1
while (i >= 0) {
- result = If(condition(i), body(i), result)
+ result = makeIf(condition(i), body(i), result)
i -= 1
}
result
@@ -107,9 +113,10 @@ trait CodeFactory {
Not(Select(Ident(vsym), nme.isEmpty))
}
- final def makeIf(cond: Tree, thenp: Tree, elsep: Tree) = cond match {
- case Literal(Constant(true)) => thenp
- case Literal(Constant(false)) => elsep
+ final def makeIf(cond: Tree, thenp: Tree, elsep: Tree) = (cond,thenp,elsep) match {
+ case (Literal(Constant(true)), _, _) => thenp
+ case (Literal(Constant(false)), _, _) => elsep
+ case (_, Literal(Constant(true)), Literal(Constant(false))) => cond
case _ => If(cond, thenp, elsep)
}
diff --git a/src/compiler/scala/tools/nsc/matching/ParallelMatching.scala b/src/compiler/scala/tools/nsc/matching/ParallelMatching.scala
index af1d2dfca4..0485a0d959 100644
--- a/src/compiler/scala/tools/nsc/matching/ParallelMatching.scala
+++ b/src/compiler/scala/tools/nsc/matching/ParallelMatching.scala
@@ -499,7 +499,7 @@ trait ParallelMatching {
val succ = repToTree(srep, handleOuter)
val fail = repToTree(frep, handleOuter)
try {
- typed{ If(cond2, succ, fail) }
+ typed{ makeIf(cond2, succ, fail) }
} catch {
case e =>
Console.println("failed to type-check If")
@@ -815,17 +815,19 @@ object Rep {
}
}
val body = targets(bx)
- val label = theOwner.newLabel(body.pos, "body%"+bx).setInfo(new MethodType(argts.toList, resultType/*body.tpe*/))
+ // bug: typer is not able to digest a body of type Nothing being assigned result type Unit
+ val tpe = if(body.tpe.typeSymbol eq definitions.AllClass) body.tpe else resultType
+ val label = theOwner.newLabel(body.pos, "body%"+bx).setInfo(new MethodType(argts.toList, tpe))
//Console.println("label.tpe"+label.tpe)
labels(bx) = label
- if(body.isInstanceOf[Throw]) {
- return squeezedBlock(vdefs.reverse, body.duplicate setType resultType)
+ if(body.isInstanceOf[Throw] || body.isInstanceOf[Literal]) {
+ return squeezedBlock(vdefs.reverse, body.duplicate setType tpe)
}
//Console.println("- !isReached returning LabelDef "+label)
//Console.println("- ! and vdefs "+vdefs)
- return Block(vdefs, LabelDef(label, vrev.reverse, body setType resultType))
+ return squeezedBlock(vdefs, LabelDef(label, vrev.reverse, body setType tpe))
}
//Console.println("- isReached before, jump to "+labels(bx))
@@ -851,7 +853,8 @@ object Rep {
}
}
}
- if(targets(bx).isInstanceOf[Throw]) {
+ val body = targets(bx)
+ if(body.isInstanceOf[Throw] || body.isInstanceOf[Literal]) {
val vdefs = new ListBuffer[Tree]
val it = vss(bx).elements; while(it.hasNext) {
val v = it.next
@@ -860,7 +863,7 @@ object Rep {
vdefs += typedValDef(v, substv)
}
}
- return squeezedBlock(vdefs.toList, targets(bx).duplicate setType resultType)
+ return squeezedBlock(vdefs.toList, body.duplicate setType resultType)
}
diff --git a/src/compiler/scala/tools/nsc/matching/PatternMatchers.scala b/src/compiler/scala/tools/nsc/matching/PatternMatchers.scala
index 5538799b5e..8b44b773ad 100644
--- a/src/compiler/scala/tools/nsc/matching/PatternMatchers.scala
+++ b/src/compiler/scala/tools/nsc/matching/PatternMatchers.scala
@@ -133,6 +133,11 @@ trait PatternMatchers { self: transform.ExplicitOuter with PatternNodes with Par
case null => // ignore
return
+ case a:AssertionError =>
+ cunit.error(cases.head.pos, "assertion failed while compiling this case")
+ a.printStackTrace()
+ throw FatalError("died in parallel match algorithm" )
+
case _:AbstractMethodError =>
cunit.error(cases.head.pos, "please recompile matcher component (explicitouter,patternmattcher, parallelmatching,codefactory)")
throw FatalError("died in parallel match algorithm" )
@@ -255,6 +260,7 @@ trait PatternMatchers { self: transform.ExplicitOuter with PatternNodes with Par
//Console.println(app.symbol)
//Console.println(fn.symbol)
if(!xs.isEmpty) {
+ assert(false)
return CantHandleApply // System.exit(-1); // this should never happen
}
null