File tree Expand file tree Collapse file tree 5 files changed +27
-11
lines changed
compiler/src/dotty/tools/dotc Expand file tree Collapse file tree 5 files changed +27
-11
lines changed Original file line number Diff line number Diff line change @@ -968,9 +968,9 @@ class Definitions {
968968 def TupledFunctionClass (using Context ): ClassSymbol = TupledFunctionTypeRef .symbol.asClass
969969 def RuntimeTupleFunctionsModule (using Context ): Symbol = requiredModule(" scala.runtime.TupledFunctions" )
970970
971+ @ tu lazy val boundaryModule : Symbol = requiredModule(" scala.util.boundary" )
971972 @ tu lazy val LabelClass : Symbol = requiredClass(" scala.util.boundary.Label" )
972973 @ tu lazy val BreakClass : Symbol = requiredClass(" scala.util.boundary.Break" )
973- @ tu lazy val breakModule : Symbol = requiredModule(" scala.util.break" )
974974
975975 @ tu lazy val CapsModule : Symbol = requiredModule(" scala.caps" )
976976 @ tu lazy val captureRoot : TermSymbol = CapsModule .requiredValue(" *" )
Original file line number Diff line number Diff line change @@ -421,6 +421,7 @@ object StdNames {
421421 val assert_ : N = " assert"
422422 val assume_ : N = " assume"
423423 val box : N = " box"
424+ val break : N = " break"
424425 val build : N = " build"
425426 val bundle : N = " bundle"
426427 val bytes : N = " bytes"
Original file line number Diff line number Diff line change @@ -105,7 +105,7 @@ class DropBreaks extends MiniPhase:
105105 private object Break :
106106
107107 private def isBreak (sym : Symbol )(using Context ): Boolean =
108- sym.name == nme.apply && sym.owner == defn.breakModule .moduleClass
108+ sym.name == nme.break && sym.owner == defn.boundaryModule .moduleClass
109109
110110 /** `(local, arg)` provided `tree` matches
111111 *
@@ -193,7 +193,7 @@ class DropBreaks extends MiniPhase:
193193 tree
194194
195195 private def isBreak (sym : Symbol )(using Context ): Boolean =
196- sym.name == nme.apply && sym.owner == defn.breakModule .moduleClass
196+ sym.name == nme.break && sym.owner == defn.boundaryModule .moduleClass
197197
198198 private def transformBreak (tree : Tree , arg : Tree , lbl : Symbol )(using Context ): Tree =
199199 report.log(i " transform break $tree/ $arg/ $lbl" )
Original file line number Diff line number Diff line change @@ -24,8 +24,19 @@ object boundary:
2424
2525 /** Labels are targets indicating which boundary will be exited by a `break`.
2626 */
27- final class Label [- T ]:
28- private [util] def break (value : T ): Nothing = throw Break (this , value)
27+ final class Label [- T ]
28+
29+ /** Abort current computation and instead return `value` as the value of
30+ * the enclosing `boundary` call that created `label`.
31+ */
32+ def break [T ](value : T )(using label : Label [T ]): Nothing =
33+ throw Break (label, value)
34+
35+ /** Abort current computation and instead continue after the `boundary` call that
36+ * created `label`.
37+ */
38+ def break ()(using label : Label [Unit ]): Nothing =
39+ throw Break (label, ())
2940
3041 /** Run `body` with freshly generated label as implicit argument. Catch any
3142 * breaks associated with that label and return their results instead of
Original file line number Diff line number Diff line change @@ -6,15 +6,19 @@ package scala.util
66object break :
77
88 /** Abort current computation and instead return `value` as the value of
9- * the enclosing `boundary` call that created `label`.
9+ * the enclosing `boundary` call that created `label`. Expands to
10+ *
11+ * boundary.break(value)(using label)
1012 */
11- def apply [T ](value : T )(using label : boundary.Label [T ]): Nothing =
12- label .break(value)
13+ inline def apply [T ](value : T )(using label : boundary.Label [T ]): Nothing =
14+ boundary .break(value)
1315
1416 /** Abort current computation and instead continue after the `boundary` call that
15- * created `label`.
17+ * created `label`. Expands to
18+ *
19+ * boundary.break()(using label)
1620 */
17- def apply ()(using label : boundary.Label [Unit ]): Nothing =
18- label .break(() )
21+ inline def apply ()(using label : boundary.Label [Unit ]): Nothing =
22+ boundary .break()
1923
2024end break
You can’t perform that action at this time.
0 commit comments