You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/_docs/reference/experimental/capture-checking/separation-checking.md
+7-7Lines changed: 7 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -349,9 +349,9 @@ Therefore, parameters cannot appear in the hidden sets of fresh result caps eith
349
349
350
350
### Consume Parameters
351
351
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:
353
353
```scala
354
-
defincr(@consume a: Ref^):Ref^=
354
+
defincr(consume a: Ref^):Ref^=
355
355
a.set(a.get +1)
356
356
a
357
357
```
@@ -374,19 +374,19 @@ Consume parameters enforce linear access to resources. This can be very useful.
374
374
375
375
For instance, we can define a function `linearAdd` that adds elements to buffers in-place without violating referential transparency:
`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.
381
381
382
382
### Consume Methods
383
383
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.
385
385
```scala
386
386
classBuffer[T] extendsMutable:
387
-
@consume updatedef+=(x: T):Buffer[T]^=this// ok
387
+
consume def+=(x: T):Buffer[T]^=this// ok
388
388
```
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
0 commit comments