-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Port Capture-checked Scala 2 collections #23769
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
base: main
Are you sure you want to change the base?
Conversation
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.
@@ -7,5 +7,5 @@ import language.experimental.captureChecking | |||
* sense that their values retain no capabilities including capabilities needed | |||
* to perform effects. This has formal meaning only under capture checking. | |||
*/ | |||
trait Pure: | |||
trait Pure extends Any: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought I left a comment about this somewhere but I'm glad it is a universal trait now.
@@ -711,7 +713,7 @@ final class TrieMap[K, V] private (r: AnyRef, rtupd: AtomicReferenceFieldUpdater | |||
|
|||
def this() = this(Hashing.default, Equiv.universal) | |||
|
|||
override def mapFactory: MapFactory[TrieMap] = TrieMap | |||
override def mapFactory: StrictMapFactory[TrieMap] = TrieMap |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be a good idea if we created a changelog?
@@ -91,7 +94,7 @@ trait AsScalaConverters { | |||
*/ | |||
def asScala[A](c: ju.Collection[A]): Iterable[A] = c match { | |||
case null => null | |||
case wrapper: IterableWrapper[A @uc] => wrapper.underlying | |||
case wrapper: IterableWrapper[A @uc] => wrapper.underlying.unsafeAssumePure // TODO: Remove when pattern matching recognizes this is safe |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have an issue ticket for those?
Also, provide a LazyKeySet implementation when the Map is strict.
CC test is failing because We can also just disable it for now, since it only test |
I will see what I can do this morning. |
The compiler can properly figure out the return types based on the Pure upper bound on CC
d67f99c
to
98e7b80
Compare
Changes:
collection.immutable.LazyListIterable[A]
, implements Iterable and IterableOps.LazyList
andStream
are 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.Seq
and other data structures extend this.collection.StrictIndexedSeqOps
,collection.StrictMapOps
,collection.StrictFactory
.collection.SetOps
is pure by default. Maybe we want aStrictSetOps
as well?Suspicious changes:
MapOps.keySet
changes implementation to be always strict. This means it is less efficient, as it always copy the keys into a new list.StrictMapOps
however overrides this behavior back to a lazy KeySet.keySet
returns aSet[K]
, which requires strictness. We cannot lie to the compiler about this case, as we can take akeySet
out of an impureMapView
, which may capture map/filter function bodies.Not capture-checked (yet?)
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?).