Skip to content

Commit 9a68644

Browse files
authored
chore: update scala to 3.6.4 (#1091)
Fixes problem from scala/scala3#22661 (comment) Also I have got new compiler warnings that inner (inside `def`) types `cannot be checked at runtime because it's a local class`, so I moved It to internal object.
1 parent c277a4a commit 9a68644

File tree

3 files changed

+24
-22
lines changed

3 files changed

+24
-22
lines changed

build.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import org.typelevel.scalacoptions.ScalacOptions
55
import org.typelevel.scalacoptions.ScalaVersion
66
import sbtdynver.DynVerPlugin.autoImport.*
77

8-
val scala3Version = "3.6.2"
8+
val scala3Version = "3.6.4"
99
val scala212Version = "2.12.20"
1010
val scala213Version = "2.13.15"
1111

kyo-data/shared/src/main/scala/kyo/Record.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,10 +293,12 @@ object Record:
293293
end Record
294294

295295
object AsFieldsInternal:
296-
private type HasAsField[Field] =
296+
private type HasAsField[Field] <: AsField[?, ?] =
297297
Field match
298298
case name ~ value => AsField[name, value]
299299

300300
inline def summonAsField[Fields](using ev: TypeIntersection[Fields]): Set[Field[?, ?]] =
301-
TypeIntersection.summonAll[Fields, HasAsField].map(Record.AsField.toField).toSet
301+
TypeIntersection.summonAll[Fields, HasAsField].map {
302+
case a: AsField[?, ?] => Record.AsField.toField(a)
303+
}.toSet
302304
end AsFieldsInternal

kyo-prelude/shared/src/main/scala/kyo/Batch.scala

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package kyo
22

33
import Batch.internal.*
4+
import Batch.internal.Pending.Expanded
5+
import Batch.internal.Pending.ToExpand
46
import kyo.Tag
57
import kyo.kernel.*
68

@@ -102,54 +104,46 @@ object Batch:
102104
* A sequence of results from executing the batched operations
103105
*/
104106
def run[A: Flat, S](v: A < (Batch & S))(using Frame): Chunk[A] < S =
105-
106-
type SourceAny = Source[Any, Any, S]
107-
type ContAny = Any < (Batch & S) => (ToExpand | Expanded | A) < (Batch & S)
108-
109-
abstract class Pending
110-
case class ToExpand(op: Seq[Any], cont: ContAny) extends Pending
111-
case class Expanded(value: Any, source: SourceAny, cont: ContAny) extends Pending
112-
113107
// An item can be a final value (`A`),
114108
// a sequence from `Batch.eval` (`ToExpand`),
115109
// or a call to a source (`Expanded`).
116-
type Item = A | ToExpand | Expanded
110+
type Item = A | ToExpand[A, S] | Expanded[A, S]
117111

118112
// Transforms effect suspensions into an item.
119113
// Captures the continuation in the `Item` objects for `ToExpand` and `Expanded` cases.
120114
def capture(v: Item < (Batch & S)): Item < S =
121115
ArrowEffect.handle(Tag[Batch], v) {
122116
[C] =>
123117
(input, cont) =>
124-
val contAny = cont.asInstanceOf[ContAny]
118+
val contAny = cont.asInstanceOf[ContAny[A, S]]
125119
input match
126-
case Call(v, source) => Expanded(v, source.asInstanceOf[SourceAny], contAny)
120+
case Call(v, source) => Expanded(v, source.asInstanceOf[SourceAny[S]], contAny)
127121
case Eval(v) => ToExpand(v, contAny)
128122
}
129123

130124
// Expands any `Batch.eval` calls, capturing items for each element in the sequence.
131125
// Returns a `Chunk[Chunk[A]]` to reduce `map` calls.
132126
def expand(items: Chunk[Item]): Chunk[Chunk[Item]] < S =
133127
Kyo.foreach(items) {
134-
case ToExpand(seq: Seq[Any], cont) =>
128+
case ToExpand[A @unchecked, S @unchecked](seq: Seq[Any], cont) =>
135129
Kyo.foreach(seq)(v => capture(cont(v)))
136130
case item => Chunk(item)
137131
}
138132

139133
// Groups all source calls (`Expanded`), calls their source functions, and reassembles the results.
140134
// Returns a `Chunk[Chunk[A]]` to reduce `map` calls.
141135
def flush(items: Chunk[Item]): Chunk[Chunk[Item]] < S =
142-
val pending: Map[SourceAny | Unit, Seq[Item]] =
136+
val pending: Map[SourceAny[S] | Unit, Seq[Item]] =
143137
items.groupBy {
144-
case Expanded(_, source, _) => source
145-
case _ => () // Used as a placeholder for items that aren't source calls
138+
case (Expanded[A @unchecked, S @unchecked](_, source, _)) => source
139+
case _ => () // Used as a placeholder for items that aren't source calls
146140
}
147141
Kyo.foreach(pending.toSeq) { tuple =>
148142
(tuple: @unchecked) match
149143
case (_: Unit, items) =>
150144
// No need for flushing
151145
Chunk.from(items)
152-
case (source: SourceAny, items: Seq[Expanded] @unchecked) =>
146+
case (source: SourceAny[S], items: Seq[Expanded[A, S]] @unchecked) =>
153147
// Only request distinct items from the source
154148
source(items.map(_.value).distinct).map { results =>
155149
// Reassemble the results by iterating on the original collection
@@ -163,13 +157,13 @@ object Batch:
163157

164158
// The main evaluation loop that expands and flushes items until all values are final.
165159
def loop(items: Chunk[Item]): Chunk[A] < S =
166-
if !items.exists((_: @unchecked).isInstanceOf[Pending]) then
160+
if !items.exists((_: @unchecked).isInstanceOf[Pending[A, S]]) then
167161
// All values are final, done
168162
items.asInstanceOf[Chunk[A]]
169163
else
170164
// The code repetition in the branches is a performance optimization to reduce
171165
// `map` calls.
172-
if items.exists((_: @unchecked).isInstanceOf[ToExpand]) then
166+
if items.exists((_: @unchecked).isInstanceOf[ToExpand[A, S]]) then
173167
// Expand `Batch.eval` calls if present
174168
expand(items).map { expanded =>
175169
flush(expanded.flattenChunk)
@@ -185,10 +179,16 @@ object Batch:
185179

186180
object internal:
187181
type Source[A, B, S] = Seq[A] => (A => B < S) < S
182+
type SourceAny[S] = Source[Any, Any, S]
188183

189184
sealed trait Op[A]
190185
case class Eval[A](seq: Seq[A]) extends Op[A]
191186
case class Call[A, B, S](v: A, source: Source[A, B, S]) extends Op[B < (Batch & S)]
192-
end internal
193187

188+
enum Pending[A, S]:
189+
case ToExpand(op: Seq[Any], cont: ContAny[A, S])
190+
case Expanded(value: Any, source: SourceAny[S], cont: ContAny[A, S])
191+
192+
type ContAny[A, S] = Any < (Batch & S) => (ToExpand[A, S] | Expanded[A, S] | A) < (Batch & S)
193+
end internal
194194
end Batch

0 commit comments

Comments
 (0)