File tree 5 files changed +27
-11
lines changed
compiler/src/dotty/tools/dotc
5 files changed +27
-11
lines changed Original file line number Diff line number Diff line change @@ -968,9 +968,9 @@ class Definitions {
968
968
def TupledFunctionClass (using Context ): ClassSymbol = TupledFunctionTypeRef .symbol.asClass
969
969
def RuntimeTupleFunctionsModule (using Context ): Symbol = requiredModule(" scala.runtime.TupledFunctions" )
970
970
971
+ @ tu lazy val boundaryModule : Symbol = requiredModule(" scala.util.boundary" )
971
972
@ tu lazy val LabelClass : Symbol = requiredClass(" scala.util.boundary.Label" )
972
973
@ tu lazy val BreakClass : Symbol = requiredClass(" scala.util.boundary.Break" )
973
- @ tu lazy val breakModule : Symbol = requiredModule(" scala.util.break" )
974
974
975
975
@ tu lazy val CapsModule : Symbol = requiredModule(" scala.caps" )
976
976
@ tu lazy val captureRoot : TermSymbol = CapsModule .requiredValue(" *" )
Original file line number Diff line number Diff line change @@ -421,6 +421,7 @@ object StdNames {
421
421
val assert_ : N = " assert"
422
422
val assume_ : N = " assume"
423
423
val box : N = " box"
424
+ val break : N = " break"
424
425
val build : N = " build"
425
426
val bundle : N = " bundle"
426
427
val bytes : N = " bytes"
Original file line number Diff line number Diff line change @@ -105,7 +105,7 @@ class DropBreaks extends MiniPhase:
105
105
private object Break :
106
106
107
107
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
109
109
110
110
/** `(local, arg)` provided `tree` matches
111
111
*
@@ -193,7 +193,7 @@ class DropBreaks extends MiniPhase:
193
193
tree
194
194
195
195
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
197
197
198
198
private def transformBreak (tree : Tree , arg : Tree , lbl : Symbol )(using Context ): Tree =
199
199
report.log(i " transform break $tree/ $arg/ $lbl" )
Original file line number Diff line number Diff line change @@ -24,8 +24,19 @@ object boundary:
24
24
25
25
/** Labels are targets indicating which boundary will be exited by a `break`.
26
26
*/
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, ())
29
40
30
41
/** Run `body` with freshly generated label as implicit argument. Catch any
31
42
* 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
6
6
object break :
7
7
8
8
/** 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)
10
12
*/
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)
13
15
14
16
/** 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)
16
20
*/
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()
19
23
20
24
end break
You can’t perform that action at this time.
0 commit comments