Skip to content

Commit b89eb41

Browse files
committed
Update doc page to consume as a modifier
1 parent 33faf67 commit b89eb41

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

docs/_docs/reference/experimental/capture-checking/separation-checking.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -349,9 +349,9 @@ Therefore, parameters cannot appear in the hidden sets of fresh result caps eith
349349

350350
### Consume Parameters
351351

352-
Returning parameters in fresh result caps is safe if the actual argument to the parameter is not used afterwards. We can signal and enforce this pattern by adding a `@consume` annotation to a parameter. With that annotation, the following variant of `incr` is legal:
352+
Returning parameters in fresh result caps is safe if the actual argument to the parameter is not used afterwards. We can signal and enforce this pattern by adding a `consume` modifier to a parameter. With that new soft modifier, the following variant of `incr` is legal:
353353
```scala
354-
def incr(@consume a: Ref^): Ref^ =
354+
def incr(consume a: Ref^): Ref^ =
355355
a.set(a.get + 1)
356356
a
357357
```
@@ -374,19 +374,19 @@ Consume parameters enforce linear access to resources. This can be very useful.
374374

375375
For instance, we can define a function `linearAdd` that adds elements to buffers in-place without violating referential transparency:
376376
```scala
377-
def linearAdd[T](@consume buf: Buffer[T]^, elem: T): Buffer[T]^ =
377+
def linearAdd[T](consume buf: Buffer[T]^, elem: T): Buffer[T]^ =
378378
buf += elem
379379
```
380-
`linearAdd` returns a fresh buffer resulting from appending `elem` to `buf`. It overwrites `buf`, but that's OK since the `@consume` annotation on `buf` ensures that the argument is not used after the call.
380+
`linearAdd` returns a fresh buffer resulting from appending `elem` to `buf`. It overwrites `buf`, but that's OK since the `consume` modifier on `buf` ensures that the argument is not used after the call.
381381

382382
### Consume Methods
383383

384-
Buffers in Scala's standard library use a single-argument method `+=` instead of a two argument global function like `linearAdd`. We can enforce linearity in this case by adding the `@consume` annotation to the method itself.
384+
Buffers in Scala's standard library use a single-argument method `+=` instead of a two argument global function like `linearAdd`. We can enforce linearity in this case by adding the `consume` modifier to the method itself.
385385
```scala
386386
class Buffer[T] extends Mutable:
387-
@consume update def +=(x: T): Buffer[T]^ = this // ok
387+
consume def +=(x: T): Buffer[T]^ = this // ok
388388
```
389-
Then we can write
389+
`consume` on a method implies `update`, so there's no need to label `+=` separately as an update method. Then we can write
390390
```scala
391391
val b = Buffer[Int]() += 1 += 2
392392
val c = b += 3

tests/run-tasty-inspector/stdlibExperimentalDefinitions.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ val experimentalDefinitionInLibrary = Set(
3939
"scala.caps.ExclusiveCapability",
4040
"scala.caps.Mutable",
4141
"scala.caps.Read",
42-
"scala.caps.Control",
4342
"scala.caps.internal",
4443
"scala.caps.internal$",
4544
"scala.caps.cap",

0 commit comments

Comments
 (0)