forked from scala/scala3
-
Notifications
You must be signed in to change notification settings - Fork 15
[Do not merge] Port Capture-checked Scala 2 collections #68
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- 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
…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
Iterator and IterableWrappers are capturing, the rest stays pure-only
Specifically for Scala.js, which the compiler hasn't yet known that Array is pure.
9d61cd9 to
b94bf42
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Changes:
collection.immutable.LazyListIterable[A], implements Iterable and IterableOps.LazyListandStreamare not capture-checked. Note added toLazyList.collection.StrictSeqOps[A, CC[_] <: Pure, C], which extends SeqOps (which can now be impure) and requires the implementation to be pure.Seqand other data structures extend this.collection.StrictIndexedSeqOps,collection.StrictMapOps.collection.SetOpsis pure by default. Maybe we want aStrictSetOpsas well?Suspicious changes:
Map.keySetchanges implementation to be always strict. This means it is less efficient, as it always copy the keys into a new list.keySetreturns aSet[K], which requires strictness. We cannot lie to the compiler about this case, as we can take akeySetout of an impureMapView, which may capture map/filter function bodies.Not capture-checked (yet?)
collection.convert.impla.k.a Steppers, due to some purity problems (maybe because we don't compile steppers and rely on Scala 2, for specialization?).