Skip to content

Conversation

@natsukagami
Copy link

@natsukagami natsukagami commented Aug 16, 2025

Changes:

  • New final class collection.immutable.LazyListIterable[A], implements Iterable and IterableOps. LazyList and Stream are not capture-checked. Note added to LazyList.
  • New trait collection.StrictSeqOps[A, CC[_] <: Pure, C], which extends SeqOps (which can now be impure) and requires the implementation to be pure. Seq and other data structures extend this.
  • Similarly, collection.StrictIndexedSeqOps, collection.StrictMapOps.
    • Note that collection.SetOps is pure by default. Maybe we want a StrictSetOps as well?
    • Sorted versions of Ops (SortedSeq, SortedSet, SortedMap) are also pure by default.

Suspicious changes:

  • Might be suspicious: Map.keySet changes implementation to be always strict. This means it is less efficient, as it always copy the keys into a new list.
    • Why? keySet returns a Set[K], which requires strictness. We cannot lie to the compiler about this case, as we can take a keySet out of an impure MapView, which may capture map/filter function bodies.

Not capture-checked (yet?)

  • Generated functions and tuples files. I tried turning CC on for functions and it hung the compiler. Maybe not a problem.
  • collection.convert.impl a.k.a Steppers, due to some purity problems (maybe because we don't compile steppers and rely on Scala 2, for specialization?).
  • LazyList and Streams.

noti0na1 and others added 24 commits August 15, 2025 13:29
 - Split doc page into individual sub-pages
 - Add new material on classifiers
 - Revise material on scoped caps

TODO

 - Revise material on reach capabilities
 - Add material on how to use the capture checker
 - Add material on separation checking
 - Check everything for completeness and accuracy

Also: Add two test files named `reference-cc.scala` in neg and pos that let us try out the code on the doc pages.

TODO: Complete these files so that all relevant code is there.
Files should also be listed in sidebar.yml.
Replaced hand-written intra-doc links with automatic doctool linking.
Sidebar now reflects the subsection hierarchy.
Also remove redundant headings
The first paragraph of a doc page is rendered
as some sort of synopsis/subtitle, which looked
awkward with the current text. This change adds
introduction headings, which also improves the
navigation on the right-hand side of a page.
This has to be in sync with `docs/sidebar.yml`
& let the root document be an index, consistent with
the style of other chapters of the reference.

There is also no need to manually write the ToC
with an index page.
Internally, it is still represented as an annotation
With the given example:

```scala
import caps.consume

import scala.language.experimental.captureChecking

class Test extends caps.Mutable:
    @consume def test(@consume x: Int)(using @consume y: Int): Unit = ()
```

It renders as following:

<img width="1051" height="281" alt="Screenshot 2025-08-15 at 16 11 05"
src="https://github.com/user-attachments/assets/022e5c58-827f-42ec-bdd7-938d019f2678"
/>

Related to scala#23755
@natsukagami natsukagami changed the title Port Capture-checked Scala 2 collections [Do not merge] Port Capture-checked Scala 2 collections Aug 16, 2025
noti0na1 and others added 5 commits August 16, 2025 02:39
…3524)

The bind variable should carry the capture set from the selector during
pattern matching.

```scala
import language.experimental.captureChecking

trait A

case class B(x: AnyRef^) extends A

def test =
  val x: AnyRef^ = new AnyRef
  val a: A^{x} = B(x)

  val y1: A = a match
    case b: B => b // error: (b: B) becomes B^{x} implicitly

  val y2: A^{x} = a match
    case b: B => b // ok

  val x3: AnyRef = a match
    case B(x2: AnyRef) => x2 // error: we lose some information about field x, but it still cannot be pure

  val x4: AnyRef = a match
    case b: B => b.x // error
```
If parameters have caps.cap as the only capture set, we would previously
eagerly drop them, as caps.cap.type is thought of as being a pure class
:/
In scala#23755, a `consume` method now implies an `update` method.
This PR changes the rendering in scaladoc to avoid printing `consume
update def` and rather print `consume def`.
Note that at the moment, in scala#23755, writing `consume update def` or
`consume def` has the same effect.
An error or a warning might be added in the feature to highlight that
`update` in `consume update def` is a redundant modifier.

[skip ci]
Internally, it is still represented as an annotation.

Based on scala#23709
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants