CC Language Reference: Rename cap to any/fresh#25057
Conversation
| ``` | ||
|
|
||
| ## Parameter and Result Caps in Function Types | ||
| ## Parameter and Result `any`s in Function Types |
There was a problem hiding this comment.
should Fresh be mentioned here? (it looks like Fresh is used in function type results)
There was a problem hiding this comment.
Yes, I still need to do a reading pass with a fine comb (most of the changes were Clauded).
2b20c25 to
880abc6
Compare
3e0eed4 to
1253280
Compare
docs/_docs/reference/experimental/capture-checking/scoped-capabilities.md
Outdated
Show resolved
Hide resolved
22249b5 to
e66ca0f
Compare
|
@odersky your input, particularly on the separation checking chapter is appreciated. |
| nested, but not outward to enclosing scopes (which would mean a capability lives longer than its | ||
| lexical lifetime). The compiler computes a capability's level by walking up the ownership chain | ||
| until reaching a symbol that represents a level boundary. Level boundaries are: | ||
| - **Classes** (but not inner non-static module classes) |
There was a problem hiding this comment.
"module classes" is used only in the implementation. I would probably say:
classes
static objects
methods
| the smallest visible super capture set: | ||
|
|
||
| ```scala | ||
| def test(fs: FileSystem^/*{any₁}*/): Logger^/*{any₂}*/ = |
There was a problem hiding this comment.
Why not declare test to have result Logger^{fs}? That's more natural and easier to explain, I think.
| ### Checking Return Types | ||
|
|
||
| When a `cap` appears in the return type of a function it means a "fresh" top capability, different from what is known at the call site. Separation checking makes sure this is the case. For instance, the following is OK: | ||
| When a `fresh` appears in the return type of a function it means a "fresh" top capability, different from what is known at the call site. Separation checking makes sure this is the case. For instance, the following is OK: |
There was a problem hiding this comment.
No, this is any (everywhere) not fresh. fresh only appears in the return types of function types, not in the return types of methods.
We should do a scan of the code to verify this (or, better, make sure everything typechecks).
| ### Consume Parameters | ||
|
|
||
| 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: | ||
| Returning `fresh` parameters 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: |
There was a problem hiding this comment.
Should be "returning parameters is result any's".
| ```scala | ||
| class Buffer[T] extends Mutable: | ||
| consume def +=(x: T): Buffer[T]^ = this // ok | ||
| consume def +=(x: T): Buffer[T]^{fresh} = this // ok |
There was a problem hiding this comment.
same here: it's any, not fresh.
| layout: doc-page | ||
| title: "Scoped Capabilities" | ||
| nightlyOf: https://docs.scala-lang.org/scala3/reference/experimental/capture-checking/scoped-capabilities.html | ||
| --- |
There was a problem hiding this comment.
I wonder whether it's not better to say from the start here that each any (and each fresh) is a different capability. Each any can subsume capabilities of the same or outer level, including other anys. Then we don't need to make fine distinctions which anys are different and which are unified. Also, we prepare the ground for separation checking, where each any gets a hidden set.
4144ba8 to
91d26b6
Compare
This reflects the recent [CC changes](scala#24923) in the docs.
Co-authored-by: Jamie Thompson <bishbashboshjt@gmail.com>
- Intro: introduce `fresh` with its import path before first use - Result `fresh`s: clarify applies only to function types, not methods - separation-checking: add section on `fresh` in function type results
91d26b6 to
3c9145f
Compare
This reflects the recent CC changes in the docs.