Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
87 commits
Select commit Hold shift + click to select a range
ac2ffaa
Extend TODO with Scala 2
natsukagami Aug 7, 2025
40f875f
Add capture checking to scala.Array
natsukagami Aug 7, 2025
0e37625
Copy generator implementations from scala 2.13.17
natsukagami Aug 11, 2025
00dc9d3
Add Scala 2.13 import to generated files to match current source
natsukagami Aug 11, 2025
6372132
Rename cardinal to integer
natsukagami Aug 11, 2025
88ee08c
Make opType documentation and code clearer
natsukagami Aug 11, 2025
9070166
Typo and style changes
natsukagami Aug 11, 2025
0c31c4a
Add documentation and simplify some implicit classes
natsukagami Aug 11, 2025
fe0c8ca
Simplify some generation logic of GenerateFunctionConverters
natsukagami Aug 11, 2025
f00abf8
Style changes in GenerateLibraryNTemplates
natsukagami Aug 11, 2025
2152a4d
Drop self type for FunctionN
natsukagami Aug 11, 2025
7aca413
Add capture checking to PartialFunction
natsukagami Aug 11, 2025
ce268f3
Add captures to ArrayOps
natsukagami Aug 11, 2025
300ee39
Add captures to BitSet
natsukagami Aug 12, 2025
426b0c7
Add capture checking to BufferedIterator
natsukagami Aug 12, 2025
498f156
Add capture checking to BuildFrom
natsukagami Aug 12, 2025
c235ee2
First pass thru IterableOnce
natsukagami Aug 12, 2025
2e2393a
First pass to Iterable
natsukagami Aug 12, 2025
20a38bb
Iterators are compiling
natsukagami Aug 12, 2025
83c3d01
Add this capture to Iterator methods
natsukagami Aug 12, 2025
117b9ab
Add capture checking to View
natsukagami Aug 12, 2025
3ac001a
DO NOT MERGE remove warnings when building stdlib
natsukagami Aug 12, 2025
ba6167f
Split IterableFactory to a strict version, with a pure collection con…
natsukagami Aug 13, 2025
db84885
Capture-check Seq and IndexedSeq
natsukagami Aug 13, 2025
b3f868a
Capture check LazyZipOps, LinearSeq, Searching
natsukagami Aug 13, 2025
9993dd6
Capture-check stepper
natsukagami Aug 13, 2025
71a45e3
Capture-check StrictOptimizedOps for Seq and Iterable
natsukagami Aug 13, 2025
919a59d
Capture check StringOps and StringParsers
natsukagami Aug 13, 2025
48044bc
Capture-check WithFilter
natsukagami Aug 13, 2025
a864d71
Capture-check Set and SortedSet
natsukagami Aug 13, 2025
f161436
Add captures to Map, SeqMap, MapView
natsukagami Aug 13, 2025
ba2c1b0
Capture-check sorted maps
natsukagami Aug 13, 2025
c4e076e
Capture check SeqView
natsukagami Aug 13, 2025
1165f3e
Capture-check JavaConverters
natsukagami Aug 13, 2025
a01682f
Add strict operations to StrictIndexedSeqOps
natsukagami Aug 14, 2025
778f86d
Capture check immutable.Seq, ArraySeq
natsukagami Aug 14, 2025
4f56818
Capture-check immutable.Iterable and ChampCommon
natsukagami Aug 14, 2025
ef53024
Capture-checking immutable.StrictOptimizedSeqOps
natsukagami Aug 14, 2025
3a01da5
Capture check immutable.Map and HashMap
natsukagami Aug 14, 2025
9d850c0
Capture check immutable.Set and HashSet
natsukagami Aug 14, 2025
3a0999e
Capture-check IntMap and LongMap
natsukagami Aug 14, 2025
e31c1a2
Capture-check mutable maps
Linyxus Aug 14, 2025
0df11f9
Capture check mutable buffers
Linyxus Aug 14, 2025
5f26a75
Capture-check various collections
Linyxus Aug 14, 2025
c49e17b
Capture check Builder
Linyxus Aug 14, 2025
25ce3ec
Capture check mutable collections done
Linyxus Aug 14, 2025
849254c
Capture check ImmutableBuilder
Linyxus Aug 14, 2025
5dd6c81
One missing carrot
Linyxus Aug 14, 2025
4222eba
Capture check LazyList as LazyListIterable
natsukagami Aug 14, 2025
4b70944
Add back LazyList with a note
natsukagami Aug 14, 2025
1d6da4c
Make Set/HashSet compile again
natsukagami Aug 14, 2025
92b84db
Capture check immutable.List{,Map,Set}
natsukagami Aug 14, 2025
b4db5d9
Capture check Range and NumericRange
natsukagami Aug 14, 2025
fbf47c4
Use ListBuffer.mapResult instead of declaring our own builder class
natsukagami Aug 14, 2025
618fa31
Capture-check immutable.Queue and WrappedString
natsukagami Aug 14, 2025
fc0b733
Capture-check immutable.Tree and Sorted
natsukagami Aug 14, 2025
dbac08e
Capture-check immutable.Vector and VectorMap
natsukagami Aug 14, 2025
7d83add
Capture-check concurrent files
natsukagami Aug 14, 2025
6121ae2
Capture-check converters
natsukagami Aug 14, 2025
6214347
Capture-check collection/generic
natsukagami Aug 14, 2025
468e05c
Capture-check AsJavaConverters
natsukagami Aug 14, 2025
ebd6887
Capture-check collection package
natsukagami Aug 14, 2025
8f2fd14
Fix partial function test
natsukagami Aug 14, 2025
c8dd681
Fix wrong casting to Nothing
natsukagami Aug 15, 2025
9fd6bb1
Map's KeySet has to be pure, so we make it strict
natsukagami Aug 15, 2025
f5f5b94
Removal of extra captures
natsukagami Aug 15, 2025
07547f4
For some reason Pure has to extend Any
natsukagami Aug 15, 2025
cb2fd3b
Add a couple missing hats
natsukagami Aug 16, 2025
ab8cde1
Remove generators
natsukagami Aug 16, 2025
64c3cd0
Undo build changes
natsukagami Aug 16, 2025
7d99e9f
Remove TODO
natsukagami Aug 16, 2025
b94bf42
Emit StrictFactory for arrays and strings
natsukagami Aug 16, 2025
6540914
Fix new errors stemming from pattern matching working ;)
natsukagami Aug 16, 2025
703cceb
Remove the TODO on WrappedString
natsukagami Aug 16, 2025
783ea88
Properly _not_ capture *this* inside the KeySet implementation
natsukagami Aug 16, 2025
98e7b80
Drop strict overrides from StrictMapOps and StrictSeqOps
natsukagami Aug 18, 2025
839c37e
Drop StrictFactory and capture check library-js version of Array instead
natsukagami Aug 19, 2025
ae7f589
Drop StrictIterableFactory in favor of caps.Pure constraints
natsukagami Aug 19, 2025
5ef1606
Drop StrictSeqOps and StrictIndexedSeqOps
natsukagami Aug 19, 2025
4e8df36
Drop StrictMapFactory in favor of caps.Pure constraints
natsukagami Aug 19, 2025
0cf4715
Remove KeySet overload, we can remove StrictMapOps now
natsukagami Aug 19, 2025
8eb1a8e
Drop StrictMapOps and replace them with caps.Pure bounds
natsukagami Aug 19, 2025
6650110
Temporarily disable the partial function tests
natsukagami Aug 19, 2025
7b18bce
Address smaller changes
natsukagami Aug 19, 2025
fd0281e
Fix build failure
natsukagami Aug 19, 2025
c343eff
Some fixes from review
natsukagami Aug 19, 2025
c6a8ba5
Pls compile
natsukagami Aug 19, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 21 additions & 15 deletions library/src/scala/collection/Map.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ package collection

import scala.language.`2.13`
import language.experimental.captureChecking
import scala.annotation.unchecked.uncheckedVariance

import scala.annotation.nowarn
import scala.collection.generic.DefaultSerializable
Expand Down Expand Up @@ -96,18 +95,6 @@ transparent trait StrictMapOps[K, +V, +CC[_, _] <: IterableOps[_, AnyConstr, _]
// The original keySet implementation, with a lazy iterator over the keys,
// is only correct if we have a strict Map.
// We restore it here.
override def keySet: Set[K] = new LazyKeySet

/** The implementation class of the set returned by `keySet`, for pure maps.
*/
private class LazyKeySet extends AbstractSet[K] with DefaultSerializable {
def diff(that: Set[K]): Set[K] = LazyKeySet.this.fromSpecific(this.view.filterNot(that))
def iterator: Iterator[K] = StrictMapOps.this.keysIterator
def contains(key: K): Boolean = StrictMapOps.this.contains(key)
override def size: Int = StrictMapOps.this.size
override def knownSize: Int = StrictMapOps.this.knownSize
override def isEmpty: Boolean = StrictMapOps.this.isEmpty
}
}

/** Base Map implementation type
Expand Down Expand Up @@ -214,7 +201,15 @@ transparent trait MapOps[K, +V, +CC[_, _] <: IterableOps[_, AnyConstr, _], +C]
*
* @return a set representing the keys contained by this map
*/
def keySet: Set[K] = new KeySet
def keySet: Set[K] =
// If we know one of the strict implementations inside this library, simply return LazyKeySet
import MapOps.LazyKeySet
this match
case s: SeqMap[K, V] => new LazyKeySet(s)
case s: SortedMap[K, V] => new LazyKeySet(s)
case s: immutable.MapOps[K, V, immutable.Map, immutable.Map[K, V]] => new LazyKeySet(s)
case s: mutable.MapOps[K, V, mutable.Map, mutable.Map[K, V]] => new LazyKeySet(s)
case _ => new KeySet

/** The implementation class of the set returned by `keySet`.
*/
Expand Down Expand Up @@ -250,7 +245,7 @@ transparent trait MapOps[K, +V, +CC[_, _] <: IterableOps[_, AnyConstr, _], +C]
* @return an [[Iterable]] collection of the keys contained by this map
*/
@deprecatedOverriding("This method should be an alias for keySet", since="2.13.13")
def keys: Iterable[K]^{this} = keySet
def keys: Iterable[K]^{this} = this.keySet
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Technically this should've been an alias for this.keysIterator, which would be strictly more efficient, but alas


/** Collects all values of this map in an iterable collection.
*
Expand Down Expand Up @@ -436,6 +431,17 @@ object MapOps {

}


/** The implementation class of the set returned by `keySet`, for pure maps.
*/
private class LazyKeySet[K, +V, +CC[_, _] <: IterableOps[_, AnyConstr, _], +C](mp: MapOps[K, V, CC, C]) extends AbstractSet[K] with DefaultSerializable {
def iterator: Iterator[K] = mp.keysIterator
def diff(that: Set[K]): Set[K] = LazyKeySet.this.fromSpecific(this.view.filterNot(that))
def contains(key: K): Boolean = mp.contains(key)
override def size: Int = mp.size
override def knownSize: Int = mp.knownSize
override def isEmpty: Boolean = mp.isEmpty
}
Comment on lines +429 to +436
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually is the old implementation of KeySet & GenKeySet

}

/**
Expand Down