Skip to content

Commit a17a6df

Browse files
committed
Drop break object in scala.util
1 parent fcef230 commit a17a6df

File tree

14 files changed

+26
-40
lines changed

14 files changed

+26
-40
lines changed

compiler/test/dotty/tools/backend/jvm/LabelBytecodeTests.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ class LabelBytecodeTests extends DottyBytecodeTest {
145145

146146
private def checkLabelBytecodeInstructions(code: String, tpe: String)(checkOutput: List[Instruction] => Unit): Unit = {
147147
val source =
148-
s"""import scala.util.*
148+
s"""import scala.util.boundary, boundary.break
149149
|class Test:
150150
| def test: $tpe = {
151151
| ${code.linesIterator.toList.mkString("", "\n ", "")}

library/src/scala/util/boundary.scala

+11-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,17 @@ package scala.util
1111
* The `Break` exception class extends `RuntimeException` and is optimized so
1212
* that stack trace generation is suppressed.
1313
* - Better performance: breaks to enclosing scopes in the same method can
14-
* be rwritten to jumps.
14+
* be rewritten to jumps.
15+
*
16+
* Example usage:
17+
*
18+
* import scala.util.boundary, boundary.break
19+
*
20+
* def firstIndex[T](xs: List[T], elem: T): Int =
21+
* boundary:
22+
* for (x, i) <- xs.zipWithIndex do
23+
* if x == elem then break(i)
24+
* -1
1525
*/
1626
object boundary:
1727

library/src/scala/util/break.scala

-24
This file was deleted.

library/src/scala/util/control/NonLocalReturns.scala

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ package scala.util.control
1717
* performant, since returns within the scope of the same method can be
1818
* rewritten by the compiler to jumps.
1919
*/
20-
@deprecated("Use scala.util.boundary and scala.util.break instead", "3.3")
20+
@deprecated("Use scala.util.boundary instead", "3.3")
2121
object NonLocalReturns {
2222
@deprecated("Use scala.util.boundary.Break instead", "3.3")
2323
class ReturnThrowable[T] extends ControlThrowable {
@@ -30,12 +30,12 @@ object NonLocalReturns {
3030
}
3131

3232
/** Performs a nonlocal return by throwing an exception. */
33-
@deprecated("Use scala.util.break and scala.util.boundary instead", "3.3")
33+
@deprecated("Use scala.util.boundary.break instead", "3.3")
3434
def throwReturn[T](result: T)(using returner: ReturnThrowable[? >: T]): Nothing =
3535
returner.throwReturn(result)
3636

3737
/** Enable nonlocal returns in `op`. */
38-
@deprecated("Use scala.util.boundary and scala.util.break instead", "3.3")
38+
@deprecated("Use scala.util.boundary instead", "3.3")
3939
def returning[T](op: ReturnThrowable[T] ?=> T): T = {
4040
val returner = new ReturnThrowable[T]
4141
try op(using returner)

tests/pos/simple-boundary.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import scala.util.*
1+
import scala.util.boundary, boundary.break
22
def test: Unit =
33
boundary: label ?=>
44
while true do break()

tests/run/break-opt.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import scala.util.*
1+
import scala.util.boundary, boundary.break
22

33
object breakOpt:
44

tests/run/breaks.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import scala.util.*
1+
import scala.util.boundary, boundary.break
22
import collection.mutable.ListBuffer
33

44
object Test {

tests/run/errorhandling/Result.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
package scala.util
2-
import boundary.Label
2+
import boundary.{Label, break}
33

44
abstract class Result[+T, +E]
55
case class Ok[+T](value: T) extends Result[T, Nothing]

tests/run/errorhandling/Test.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import scala.util.*
1+
import scala.util.*, boundary.break
22

33
/** boundary/break as a replacement for non-local returns */
44
def indexOf[T](xs: List[T], elem: T): Int =

tests/run/errorhandling/kostas.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
package optionMockup:
2-
import scala.util.{boundary, break}
2+
import scala.util.boundary, boundary.break
33
object optional:
44
transparent inline def apply[T](inline body: boundary.Label[None.type] ?=> T): Option[T] =
55
boundary(Some(body))

tests/run/errorhandling/optional.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
package scala.util
2-
import boundary.Label
2+
import boundary.{break, Label}
33

44
/** A mockup of scala.Option */
55
abstract class Option[+T]

tests/run/loops-alt.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import scala.util.{boundary, break}
2-
import boundary.Label
1+
import scala.util.boundary
2+
import boundary.{break, Label}
33
import java.util.concurrent.TimeUnit
44

55
object loop:

tests/run/loops.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import scala.util.{boundary, break}
1+
import scala.util.boundary, boundary.break
22

33
object loop:
44

tests/run/rescue-boundary.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import scala.util.control.NonFatal
2-
import scala.util.*
2+
import scala.util.boundary, boundary.break
33

44
object lib:
55
extension [T](op: => T) inline def rescue (fallback: => T) =

0 commit comments

Comments
 (0)