Port Capture-checked Scala 2 collections#23769
Merged
natsukagami merged 87 commits intoscala:mainfrom Aug 19, 2025
Merged
Conversation
hamzaremmal
reviewed
Aug 19, 2025
hamzaremmal
reviewed
Aug 19, 2025
library/src/scala/collection/immutable/StrictOptimizedSeqOps.scala
Outdated
Show resolved
Hide resolved
hamzaremmal
requested changes
Aug 19, 2025
Member
hamzaremmal
left a comment
There was a problem hiding this comment.
All good, Martin's upcoming PR should solve all the issues with the bound checker for caps.Pure. There is one added bounded that will not be covered by that check and needs to be (dropped ?) solved.
odersky
approved these changes
Aug 19, 2025
Contributor
|
PR for pure checking: #23784 |
hamzaremmal
approved these changes
Aug 19, 2025
Contributor
|
I'm going to bed now. If the tests are green we can merge. |
bracevac
approved these changes
Aug 19, 2025
hamzaremmal
added a commit
to hamzaremmal/scala3
that referenced
this pull request
Sep 11, 2025
This was introduced in scala#23769 but it makes the following test fail: https://github.com/scala/scala3/blob/48bc891bd317a62956dc86297feb6e86a73083f6/tests/run/t4954.scala#L8
hamzaremmal
added a commit
to hamzaremmal/scala3
that referenced
this pull request
Sep 12, 2025
This was introduced in scala#23769 but it makes the following test fail: https://github.com/scala/scala3/blob/48bc891bd317a62956dc86297feb6e86a73083f6/tests/run/t4954.scala#L8
hamzaremmal
added a commit
to hamzaremmal/scala3
that referenced
this pull request
Sep 13, 2025
This was introduced in scala#23769 but it makes the following test fail: https://github.com/scala/scala3/blob/48bc891bd317a62956dc86297feb6e86a73083f6/tests/run/t4954.scala#L8
hamzaremmal
added a commit
to hamzaremmal/scala3
that referenced
this pull request
Sep 13, 2025
This was introduced in scala#23769 but it makes the following test fail: https://github.com/scala/scala3/blob/48bc891bd317a62956dc86297feb6e86a73083f6/tests/run/t4954.scala#L8
hamzaremmal
added a commit
to hamzaremmal/scala3
that referenced
this pull request
Sep 15, 2025
This was introduced in scala#23769 but it makes the following test fail: https://github.com/scala/scala3/blob/48bc891bd317a62956dc86297feb6e86a73083f6/tests/run/t4954.scala#L8
Gedochao
pushed a commit
that referenced
this pull request
Nov 17, 2025
HarrisL2
pushed a commit
to HarrisL2/scala3
that referenced
this pull request
Nov 18, 2025
Fixed in scala#23769. Closes scala#23225.
bracevac
pushed a commit
to dotty-staging/dotty
that referenced
this pull request
Nov 19, 2025
Fixed in scala#23769. Closes scala#23225.
WojciechMazur
pushed a commit
that referenced
this pull request
Jan 7, 2026
…trict/lazy KeySet implementations (#24767) Fixes #24749. The PR contains two parts, one tiny and the other more involved. ## `KeySet` performance issues Previously we use a `List[K]` to hold keys inside the strict KeySet, in order to keep iteration order stable. However this degrades performance of KeySet as a Set. The fix is to simply use something that has both. Currently it means `mutable.LinkedHashSet`, so we use it, even though we don't intend to mutate the set at all. ## Deprecating `KeySet` as a whole and use our private implementations instead As part of #23769 we categorised most data structures to be strict/pure (as in "not hiding any computation as part of its structure"), which includes `Set`. **It turns out that our change to `MapOps.GenKeySet` in #23769 was never backwards-compatible -- it creates abstract getters and setters for the `allKeys` val.** This however clashes with how `.keySet` method was implemented: it returns a `Set[K]`, but provides _no_ guarantee on whether it is a lazy view over the underlying data structure (which _can_ be lazy, e.g. when you call `.keySet` from a `MapView`) or a strict set. With API compatibility in mind, we now create strict key sets (with a copy of the keys) in the generic case, while trying to detect whether the `.keySet` method was called from an already strict data-structure (which is the majority case) - returning a thin-wrapper `LazyKeySet` in that case. As the LazyKeySet works like a view with no aggregation, applying it over a strict data structure doesn't violate strictness. This left a few holes however, which was overlooked: some data structures such as `mutable.HashSet` overrides `.keySet` with their own (protected!) classes, extending from the previously-ambiguous KeySet classes (that is now made strict), and accidentally ending up always using the strict version. Unfortunately we cannot modify these extended classes (for TASTy compatibility), so similar versions extending the thin wrapper are added instead, and the old classes deprecated. To not shoot ourselves in the foot in the future, these classes are also made `private[collection]`: We don't expect classes like `HashMap` to be extended with a custom `KeySet`, and in the cases that it does, it is not a problem to reimplement the missing 4-5 methods in the most efficient way for your extended data structure.
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
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.New traitno longer neededcollection.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.Suspicious changes:
MapOps.keySetchanges implementation to be always strict, unless it is one of the library's known strict collectionsNot 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?).