Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Update CC Docs Until scoped-caps.md#24677

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
bracevac wants to merge2 commits intoscala:main
base:main
Choose a base branch
Loading
fromdotty-staging:ob-cc-docs2

Conversation

@bracevac
Copy link
Contributor

@bracevacbracevac commentedDec 5, 2025
edited
Loading

Continuation of#24626

[skip ci]

@bracevacbracevacforce-pushed theob-cc-docs2 branch 2 times, most recently from8f6cf6a tod73dd15CompareDecember 9, 2025 12:24
@natsukagaminatsukagami self-requested a reviewDecember 10, 2025 16:54
@bracevacbracevacforce-pushed theob-cc-docs2 branch 2 times, most recently fromb3da99d toe8699e3CompareDecember 15, 2025 14:07
@bracevacbracevac changed the titleUpdate CC Docs 2Update CC Docs Until scoped-caps.mdDec 17, 2025
@bracevacbracevac marked this pull request as ready for reviewDecember 17, 2025 17:46
Comment on lines +115 to +125
####Tracking the evolution of mutable objects
A common use case for explicit capture parameters is when a mutable object’s reachable capabilities
_grow_ due to mutation. For example, concatenating effectful iterators:
```scala
classConcatIterator[A,C^](variterators: mutable.List[IterableOnce[A]^{C}]):
defconcat(it:IterableOnce[A]^):ConcatIterator[A, {C, it}]^{this, it}=
iterators++= it// ^
this// track contents of `it` in the result
```
In such a scenario, we also should ensure that any pre-existing alias of a`ConcatIterator` object should become
inaccessible after invoking its`concat` method. This is achieved with[mutation and separation tracking](separation-checking.md) which are currently in development.
In such cases, the type system must ensure that any existing aliases of the iterator become invalid
after mutation. This is handled by[mutation tracking](mutability.md) and[separation tracking](separation-checking.md), which are currently under development.
Copy link
Contributor

@natsukagaminatsukagamiDec 17, 2025
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I think this is a poor example, as it instantly leads the reader into writing this (very buggy, doesn't guarantee anything until separation checking) code.

The problem with mutable collections with non-type-parameter element types is that you cannot use implicit capture polymorphism: they get instantiated with the elements at the construction of the collection.

classIteratorList(privatevariterators: mutable.List[Iterator[A]^])://                                            ^ this cap will be instantiated with whatever is in the initial list// ...def+=(it:Iterator[A]^)= iterators+= itvalxs=IteratorList(mutable.List.empty)// forcefully instantiated to {}

(also we don't have a name to refer to the capture set of the elements, when we write the+= method)

Therefore, we need a capture set variable, to allow the user/inference to specify a capture set suitable for the whole usage of the collection.

classIteratorList[C^](privatevariterators: mutable.List[Iterator[A]^{C}]):// ...def+=(it:Iterator[A]^{C})= iterators+= itvalxs=IteratorList(mutable.List.empty)xs+=Iterator(async)xs+=Iterator(io)// inference will (probably) find out that xs: IteratorList[{async, io}]

Note that this capture set will not change, it's part of the type: it means you have to be able to name all the captures of all the elements at the point of creating the collection. If you want a growing capture set, it's not sound until separation checking.

...
```

Each capability has a_level_ corresponding to the local`cap` of its defining scope. The level determines where a capability can flow: it can flow into`cap`s at the same level or more deeply 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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Nit: I thinkflow is a vague word. Maybe "The level determines where a capability can be part of: it can be a part ofcaps at the same level or more deeply nested..." or something like "assigned to"?

Update: I think we used in a lot of places, so maybe it's fine?

```

The closure is declared pure (`() -> Unit`), meaning its local`cap` is the empty set. The capability`fs` cannot flow into an empty set, so the checker rejects this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Perhaps we should say something about thewithFile[T] pattern here?


**Examples:**

-`A => B` is an alias type that expands to`A ->{cap} B`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

What shouldA => B => C be extended to? I think it's quite unclear here

Co-authored-by: Natsu Kagami <natsukagami@gmail.com>
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@natsukagaminatsukagaminatsukagami left review comments

At least 1 approving review is required to merge this pull request.

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

3 participants

@bracevac@natsukagami@odersky

[8]ページ先頭

©2009-2025 Movatter.jp