Skip to content

Commit 8b8ebaa

Browse files
committed
Revert "Merge pull request scala#749 from phaller/backport/cps-ticket-1681"
This reverts commit 0132464, reversing changes made to 764bd8e.
1 parent 0132464 commit 8b8ebaa

File tree

13 files changed

+3
-207
lines changed

13 files changed

+3
-207
lines changed

src/compiler/scala/tools/nsc/typechecker/Modes.scala

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,6 @@ trait Modes {
8686
*/
8787
final val TYPEPATmode = 0x10000
8888

89-
/** RETmode is set when we are typing a return expression.
90-
*/
91-
final val RETmode = 0x20000
92-
9389
final private val StickyModes = EXPRmode | PATTERNmode | TYPEmode | ALTmode
9490

9591
final def onlyStickyModes(mode: Int) =
@@ -134,4 +130,4 @@ trait Modes {
134130
def modeString(mode: Int): String =
135131
if (mode == 0) "NOmode"
136132
else (modeNameMap filterKeys (bit => inAllModes(mode, bit))).values mkString " "
137-
}
133+
}

src/compiler/scala/tools/nsc/typechecker/Typers.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3181,7 +3181,7 @@ trait Typers extends Modes {
31813181
errorTree(tree, enclMethod.owner + " has return statement; needs result type")
31823182
else {
31833183
context.enclMethod.returnsSeen = true
3184-
val expr1: Tree = typed(expr, EXPRmode | BYVALmode | RETmode, restpt.tpe)
3184+
val expr1: Tree = typed(expr, EXPRmode | BYVALmode, restpt.tpe)
31853185
// Warn about returning a value if no value can be returned.
31863186
if (restpt.tpe.typeSymbol == UnitClass) {
31873187
// The typing in expr1 says expr is Unit (it has already been coerced if

src/continuations/plugin/scala/tools/selectivecps/CPSAnnotationChecker.scala

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,6 @@ abstract class CPSAnnotationChecker extends CPSUtils with Modes {
175175
vprintln("yes we can!! (byval)")
176176
return true
177177
}
178-
} else if ((mode & global.analyzer.RETmode) != 0) {
179-
vprintln("yes we can!! (return)")
180-
return true
181178
}
182179
}
183180
false
@@ -191,7 +188,6 @@ abstract class CPSAnnotationChecker extends CPSUtils with Modes {
191188
val patMode = (mode & global.analyzer.PATTERNmode) != 0
192189
val exprMode = (mode & global.analyzer.EXPRmode) != 0
193190
val byValMode = (mode & global.analyzer.BYVALmode) != 0
194-
val retMode = (mode & global.analyzer.RETmode) != 0
195191

196192
val annotsTree = cpsParamAnnotation(tree.tpe)
197193
val annotsExpected = cpsParamAnnotation(pt)
@@ -218,12 +214,6 @@ abstract class CPSAnnotationChecker extends CPSUtils with Modes {
218214
val res = tree modifyType addMinusMarker
219215
vprintln("adapted annotations (by val) of " + tree + " to " + res.tpe)
220216
res
221-
} else if (retMode && !hasPlusMarker(tree.tpe) && annotsTree.isEmpty && annotsExpected.nonEmpty) {
222-
// add a marker annotation that will make tree.tpe behave as pt, subtyping wise
223-
// tree will look like having no annotation
224-
val res = tree modifyType (_ withAnnotations List(newPlusMarker()))
225-
vprintln("adapted annotations (return) of " + tree + " to " + res.tpe)
226-
res
227217
} else tree
228218
}
229219

@@ -479,11 +469,6 @@ abstract class CPSAnnotationChecker extends CPSUtils with Modes {
479469
}
480470
tpe
481471

482-
case ret @ Return(expr) =>
483-
if (hasPlusMarker(expr.tpe))
484-
ret setType expr.tpe
485-
ret.tpe
486-
487472
case _ =>
488473
tpe
489474
}

src/continuations/plugin/scala/tools/selectivecps/CPSUtils.scala

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ package scala.tools.selectivecps
55
import scala.tools.nsc.Global
66
import scala.tools.nsc.ast.TreeGen
77
import scala.tools.nsc.symtab.Flags._
8-
import scala.collection.mutable.ListBuffer
98

109
trait CPSUtils {
1110
val global: Global
@@ -209,42 +208,4 @@ trait CPSUtils {
209208
case _ => None
210209
}
211210
}
212-
213-
def isTailReturn(retExpr: Tree, body: Tree): Boolean = {
214-
val removed = ListBuffer[Tree]()
215-
removeTailReturn(body, removed)
216-
removed contains retExpr
217-
}
218-
219-
def removeTailReturn(tree: Tree, removed: ListBuffer[Tree]): Tree = tree match {
220-
case Block(stms, r @ Return(expr)) =>
221-
removed += r
222-
treeCopy.Block(tree, stms, expr)
223-
224-
case Block(stms, expr) =>
225-
treeCopy.Block(tree, stms, removeTailReturn(expr, removed))
226-
227-
case If(cond, r1 @ Return(thenExpr), r2 @ Return(elseExpr)) =>
228-
removed ++= Seq(r1, r2)
229-
treeCopy.If(tree, cond, removeTailReturn(thenExpr, removed), removeTailReturn(elseExpr, removed))
230-
231-
case If(cond, thenExpr, elseExpr) =>
232-
treeCopy.If(tree, cond, removeTailReturn(thenExpr, removed), removeTailReturn(elseExpr, removed))
233-
234-
case Try(block, catches, finalizer) =>
235-
treeCopy.Try(tree,
236-
removeTailReturn(block, removed),
237-
(catches map (t => removeTailReturn(t, removed))).asInstanceOf[List[CaseDef]],
238-
removeTailReturn(finalizer, removed))
239-
240-
case CaseDef(pat, guard, r @ Return(expr)) =>
241-
removed += r
242-
treeCopy.CaseDef(tree, pat, guard, expr)
243-
244-
case CaseDef(pat, guard, body) =>
245-
treeCopy.CaseDef(tree, pat, guard, removeTailReturn(body, removed))
246-
247-
case _ =>
248-
tree
249-
}
250211
}

src/continuations/plugin/scala/tools/selectivecps/SelectiveANFTransform.scala

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ import scala.tools.nsc.plugins._
99

1010
import scala.tools.nsc.ast._
1111

12-
import scala.collection.mutable.ListBuffer
13-
1412
/**
1513
* In methods marked @cps, explicitly name results of calls to other @cps methods
1614
*/
@@ -48,20 +46,10 @@ abstract class SelectiveANFTransform extends PluginComponent with Transform with
4846
// this would cause infinite recursion. But we could remove the
4947
// ValDef case here.
5048

51-
case dd @ DefDef(mods, name, tparams, vparamss, tpt, rhs0) =>
49+
case dd @ DefDef(mods, name, tparams, vparamss, tpt, rhs) =>
5250
debuglog("transforming " + dd.symbol)
5351

5452
atOwner(dd.symbol) {
55-
val tailReturns = ListBuffer[Tree]()
56-
val rhs = removeTailReturn(rhs0, tailReturns)
57-
// throw an error if there is a Return tree which is not intail position
58-
rhs0 foreach {
59-
case r @ Return(_) =>
60-
if (!tailReturns.contains(r))
61-
unit.error(r.pos, "return expressions in CPS code must be in tail position")
62-
case _ => /* do nothing */
63-
}
64-
6553
val rhs1 = transExpr(rhs, None, getExternalAnswerTypeAnn(tpt.tpe))
6654

6755
debuglog("result "+rhs1)

test/files/continuations-neg/ts-1681-nontail-return.check

Lines changed: 0 additions & 4 deletions
This file was deleted.

test/files/continuations-neg/ts-1681-nontail-return.scala

Lines changed: 0 additions & 18 deletions
This file was deleted.

test/files/continuations-run/ts-1681-2.check

Lines changed: 0 additions & 5 deletions
This file was deleted.

test/files/continuations-run/ts-1681-2.scala

Lines changed: 0 additions & 44 deletions
This file was deleted.

test/files/continuations-run/ts-1681-3.check

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)