Permalink
Browse files

Revert "Merge pull request #749 from phaller/backport/cps-ticket-1681"

This reverts commit 0132464, reversing
changes made to 764bd8e.
  • Loading branch information...
1 parent 0132464 commit 8b8ebaa44d91ed4ae4fedbb43c2cc5fd93b9b611 @phaller phaller committed Jun 27, 2012
@@ -86,10 +86,6 @@ trait Modes {
*/
final val TYPEPATmode = 0x10000
- /** RETmode is set when we are typing a return expression.
- */
- final val RETmode = 0x20000
-
final private val StickyModes = EXPRmode | PATTERNmode | TYPEmode | ALTmode
final def onlyStickyModes(mode: Int) =
@@ -134,4 +130,4 @@ trait Modes {
def modeString(mode: Int): String =
if (mode == 0) "NOmode"
else (modeNameMap filterKeys (bit => inAllModes(mode, bit))).values mkString " "
-}
+}
@@ -3181,7 +3181,7 @@ trait Typers extends Modes {
errorTree(tree, enclMethod.owner + " has return statement; needs result type")
else {
context.enclMethod.returnsSeen = true
- val expr1: Tree = typed(expr, EXPRmode | BYVALmode | RETmode, restpt.tpe)
+ val expr1: Tree = typed(expr, EXPRmode | BYVALmode, restpt.tpe)
// Warn about returning a value if no value can be returned.
if (restpt.tpe.typeSymbol == UnitClass) {
// The typing in expr1 says expr is Unit (it has already been coerced if
@@ -175,9 +175,6 @@ abstract class CPSAnnotationChecker extends CPSUtils with Modes {
vprintln("yes we can!! (byval)")
return true
}
- } else if ((mode & global.analyzer.RETmode) != 0) {
- vprintln("yes we can!! (return)")
- return true
}
}
false
@@ -191,7 +188,6 @@ abstract class CPSAnnotationChecker extends CPSUtils with Modes {
val patMode = (mode & global.analyzer.PATTERNmode) != 0
val exprMode = (mode & global.analyzer.EXPRmode) != 0
val byValMode = (mode & global.analyzer.BYVALmode) != 0
- val retMode = (mode & global.analyzer.RETmode) != 0
val annotsTree = cpsParamAnnotation(tree.tpe)
val annotsExpected = cpsParamAnnotation(pt)
@@ -218,12 +214,6 @@ abstract class CPSAnnotationChecker extends CPSUtils with Modes {
val res = tree modifyType addMinusMarker
vprintln("adapted annotations (by val) of " + tree + " to " + res.tpe)
res
- } else if (retMode && !hasPlusMarker(tree.tpe) && annotsTree.isEmpty && annotsExpected.nonEmpty) {
- // add a marker annotation that will make tree.tpe behave as pt, subtyping wise
- // tree will look like having no annotation
- val res = tree modifyType (_ withAnnotations List(newPlusMarker()))
- vprintln("adapted annotations (return) of " + tree + " to " + res.tpe)
- res
} else tree
}
@@ -479,11 +469,6 @@ abstract class CPSAnnotationChecker extends CPSUtils with Modes {
}
tpe
- case ret @ Return(expr) =>
- if (hasPlusMarker(expr.tpe))
- ret setType expr.tpe
- ret.tpe
-
case _ =>
tpe
}
@@ -5,7 +5,6 @@ package scala.tools.selectivecps
import scala.tools.nsc.Global
import scala.tools.nsc.ast.TreeGen
import scala.tools.nsc.symtab.Flags._
-import scala.collection.mutable.ListBuffer
trait CPSUtils {
val global: Global
@@ -209,42 +208,4 @@ trait CPSUtils {
case _ => None
}
}
-
- def isTailReturn(retExpr: Tree, body: Tree): Boolean = {
- val removed = ListBuffer[Tree]()
- removeTailReturn(body, removed)
- removed contains retExpr
- }
-
- def removeTailReturn(tree: Tree, removed: ListBuffer[Tree]): Tree = tree match {
- case Block(stms, r @ Return(expr)) =>
- removed += r
- treeCopy.Block(tree, stms, expr)
-
- case Block(stms, expr) =>
- treeCopy.Block(tree, stms, removeTailReturn(expr, removed))
-
- case If(cond, r1 @ Return(thenExpr), r2 @ Return(elseExpr)) =>
- removed ++= Seq(r1, r2)
- treeCopy.If(tree, cond, removeTailReturn(thenExpr, removed), removeTailReturn(elseExpr, removed))
-
- case If(cond, thenExpr, elseExpr) =>
- treeCopy.If(tree, cond, removeTailReturn(thenExpr, removed), removeTailReturn(elseExpr, removed))
-
- case Try(block, catches, finalizer) =>
- treeCopy.Try(tree,
- removeTailReturn(block, removed),
- (catches map (t => removeTailReturn(t, removed))).asInstanceOf[List[CaseDef]],
- removeTailReturn(finalizer, removed))
-
- case CaseDef(pat, guard, r @ Return(expr)) =>
- removed += r
- treeCopy.CaseDef(tree, pat, guard, expr)
-
- case CaseDef(pat, guard, body) =>
- treeCopy.CaseDef(tree, pat, guard, removeTailReturn(body, removed))
-
- case _ =>
- tree
- }
}
@@ -9,8 +9,6 @@ import scala.tools.nsc.plugins._
import scala.tools.nsc.ast._
-import scala.collection.mutable.ListBuffer
-
/**
* In methods marked @cps, explicitly name results of calls to other @cps methods
*/
@@ -48,20 +46,10 @@ abstract class SelectiveANFTransform extends PluginComponent with Transform with
// this would cause infinite recursion. But we could remove the
// ValDef case here.
- case dd @ DefDef(mods, name, tparams, vparamss, tpt, rhs0) =>
+ case dd @ DefDef(mods, name, tparams, vparamss, tpt, rhs) =>
debuglog("transforming " + dd.symbol)
atOwner(dd.symbol) {
- val tailReturns = ListBuffer[Tree]()
- val rhs = removeTailReturn(rhs0, tailReturns)
- // throw an error if there is a Return tree which is not intail position
- rhs0 foreach {
- case r @ Return(_) =>
- if (!tailReturns.contains(r))
- unit.error(r.pos, "return expressions in CPS code must be in tail position")
- case _ => /* do nothing */
- }
-
val rhs1 = transExpr(rhs, None, getExternalAnswerTypeAnn(tpt.tpe))
debuglog("result "+rhs1)
@@ -1,4 +0,0 @@
-ts-1681-nontail-return.scala:10: error: return expressions in CPS code must be in tail position
- return v
- ^
-one error found
@@ -1,18 +0,0 @@
-import scala.util.continuations._
-
-class ReturnRepro {
- def s1: Int @cpsParam[Any, Unit] = shift { k => k(5) }
- def caller = reset { println(p(3)) }
-
- def p(i: Int): Int @cpsParam[Unit, Any] = {
- val v= s1 + 3
- if (v == 8)
- return v
- v + 1
- }
-}
-
-object Test extends App {
- val repro = new ReturnRepro
- repro.caller
-}
@@ -1,5 +0,0 @@
-8
-hi
-8
-from try
-8
@@ -1,44 +0,0 @@
-import scala.util.continuations._
-
-class ReturnRepro {
- def s1: Int @cps[Any] = shift { k => k(5) }
- def caller = reset { println(p(3)) }
- def caller2 = reset { println(p2(3)) }
- def caller3 = reset { println(p3(3)) }
-
- def p(i: Int): Int @cps[Any] = {
- val v= s1 + 3
- return v
- }
-
- def p2(i: Int): Int @cps[Any] = {
- val v = s1 + 3
- if (v > 0) {
- println("hi")
- return v
- } else {
- println("hi")
- return 8
- }
- }
-
- def p3(i: Int): Int @cps[Any] = {
- val v = s1 + 3
- try {
- println("from try")
- return v
- } catch {
- case e: Exception =>
- println("from catch")
- return 7
- }
- }
-
-}
-
-object Test extends App {
- val repro = new ReturnRepro
- repro.caller
- repro.caller2
- repro.caller3
-}
@@ -1,4 +0,0 @@
-enter return expr
-8
-hi
-8
@@ -1,27 +0,0 @@
-import scala.util.continuations._
-
-class ReturnRepro {
- def s1: Int @cpsParam[Any, Unit] = shift { k => k(5) }
- def caller = reset { println(p(3)) }
- def caller2 = reset { println(p2(3)) }
-
- def p(i: Int): Int @cpsParam[Unit, Any] = {
- val v= s1 + 3
- return { println("enter return expr"); v }
- }
-
- def p2(i: Int): Int @cpsParam[Unit, Any] = {
- val v = s1 + 3
- if (v > 0) {
- return { println("hi"); v }
- } else {
- return { println("hi"); 8 }
- }
- }
-}
-
-object Test extends App {
- val repro = new ReturnRepro
- repro.caller
- repro.caller2
-}
@@ -1,3 +0,0 @@
-8
-hi
-8
@@ -1,29 +0,0 @@
-import scala.util.continuations._
-
-class ReturnRepro {
- def s1: Int @cpsParam[Any, Unit] = shift { k => k(5) }
- def caller = reset { println(p(3)) }
- def caller2 = reset { println(p2(3)) }
-
- def p(i: Int): Int @cpsParam[Unit, Any] = {
- val v= s1 + 3
- return v
- }
-
- def p2(i: Int): Int @cpsParam[Unit, Any] = {
- val v = s1 + 3
- if (v > 0) {
- println("hi")
- return v
- } else {
- println("hi")
- return 8
- }
- }
-}
-
-object Test extends App {
- val repro = new ReturnRepro
- repro.caller
- repro.caller2
-}

0 comments on commit 8b8ebaa

Please sign in to comment.