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/mutability.md
-31Lines changed: 0 additions & 31 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -445,34 +445,3 @@ The subcapturing theory for sets is then as before, with the following additiona
445
445
-`{x, ...}.reader = {x.rd, ...}.reader`
446
446
-`{x.rd, ...} <: {x, ...}`
447
447
448
-
## The `freeze` Wrapper
449
-
450
-
We often want to create a mutable data structure like an array, initialize by assigning to its elements and then return the array as an immutable type that does not
451
-
capture any capabilities. This can be achieved using the `freeze` wrapper.
452
-
453
-
As an example, consider a class `Arr` which is modelled after `Array` and its immutable counterpart `IArr`:
The `freeze` wrapper allows us to go from an `Arr` to an `IArr`, safely:
464
-
```scala
465
-
importcaps.freeze
466
-
467
-
valf:IArr[String] =freeze:
468
-
vala=Arr[String](2)
469
-
a(0) ="hello"
470
-
a(1) ="world"
471
-
a
472
-
```
473
-
The `freeze` method is defined in `caps` like this:
474
-
```scala
475
-
deffreeze[T](op: ->T):T= op
476
-
```
477
-
It takes a pure by-name parameter and returns its result. But the actual return type after capture checking is special. Instead of just `T` as in the declaration above suggests, it's `T` where every covariant occurrence of a `Mutable` type gets its capture set mapped to `{}`.
Copy file name to clipboardExpand all lines: docs/_docs/reference/experimental/capture-checking/separation-checking.md
+33Lines changed: 33 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -235,3 +235,36 @@ val c = b += 3
235
235
```
236
236
This code is equivalent to functional append with `+`, and is at the same time more efficient since it re-uses the storage of the argument buffer.
237
237
238
+
## The `freeze` Wrapper
239
+
240
+
We often want to create a mutable data structure like an array, initialize by assigning to its elements and then return the array as an immutable type that does not
241
+
capture any capabilities. This can be achieved using the `freeze` wrapper.
242
+
243
+
As an example, consider a class `Arr` which is modelled after `Array` and its immutable counterpart `IArr`:
The `freeze` wrapper allows us to go from an `Arr` to an `IArr`, safely:
254
+
```scala
255
+
importcaps.freeze
256
+
257
+
valf:IArr[String] =
258
+
vala=Arr[String](2)
259
+
a(0) ="hello"
260
+
a(1) ="world"
261
+
freeze(a)
262
+
```
263
+
The `freeze` method is defined in `caps` like this:
264
+
```scala
265
+
deffreeze[T](consume x: Mutable^): x.type= x
266
+
```
267
+
It consumes a value of `Mutable` type with arbitrary capture set. The actual signature of
268
+
`consume` declares that `x.type` is returned, but the actual return type after capture checking is special. Instead of `x.type` it is the underlying `Mutable` type with its top-level capture set
269
+
mapped to `{}`. Applications of `freeze` are safe only if separation checking is enabled.
0 commit comments