forked from scala/scala3
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This provides a way forward to fixing the signatures of some tuple methods, and removes the inlining from the tuple methods. Optimization will be implemented later directly on these method calls, which avoids unnecessary complications due to inlining artifacts. Old definitions are made tasty compatible and just delegate to the new representation. Fixes scala#12721 Fixes scala#15992 Fixes scala#16207
- Loading branch information
1 parent
9eac2b5
commit 585d7a0
Showing
6 changed files
with
177 additions
and
27 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
def bar(t: Any): Int = 1 | ||
def foo(t: AnyRef): Unit = | ||
t.asInstanceOf[NonEmptyTuple].toList.map(bar) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import scala.compiletime.constValueTuple | ||
import scala.deriving.Mirror.ProductOf | ||
|
||
case class C(date: Int, time: Int) | ||
|
||
inline def labelsOf[A](using p: ProductOf[A]): Tuple = constValueTuple[p.MirroredElemLabels] | ||
|
||
val headers: List[String] = labelsOf[C].toList.map(_.toString) |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import language.implicitConversions | ||
|
||
class Inverse[F[_], G[_]] | ||
type MatchSome[X] = X match { case Some[t] => t } | ||
def matchSome[X](x: X): MatchSome[X] = x match { case k: Some[t] => k.get } | ||
given Inverse[MatchSome, Some] = new Inverse | ||
|
||
extension [T](x: T) inline def widen[S >: T]: S = x | ||
|
||
given [X, Y](using ev: X =:= Y): Conversion[X, Y] = ev(_) | ||
inline def rel[A] = <:<.refl[Any].asInstanceOf[A] | ||
given simplify_map_map[T <: Tuple, F[_], G[_]]: (Tuple.Map[Tuple.Map[T, G], F] =:= Tuple.Map[T, [X] =>> F[G[X]]]) = rel | ||
given simplify_map_id[T <: Tuple]: (Tuple.Map[T, [X] =>> X] =:= T) = rel | ||
given mapinverse_inversemap[T <: Tuple, F[_], G[_]](using Inverse[F, G]): (Tuple.Map[T, F] =:= Tuple.InverseMap[T, G]) = rel | ||
given simplify_map_inversemap[T <: Tuple, F[_]]: (Tuple.InverseMap[Tuple.Map[T, F], F] =:= T) = rel | ||
given map_ismappedby[O <: Tuple, F[_], M <: Tuple.Map[O, F]]: Tuple.IsMappedBy[F][M] = rel | ||
|
||
|
||
def f[T <: Tuple](t: T): Tuple.Map[T, [X] =>> Option[List[X]]] = | ||
val tl: Tuple.Map[T, List] = t.widen.map([X] => (x: X) => List(x)) | ||
val tol: Tuple.Map[Tuple.Map[T, List], Option] = tl.widen.map([X] => (x: X) => Option(x)) | ||
tol | ||
|
||
def g[T <: Tuple](t: T): T = | ||
val nt: Tuple.Map[T, [X] =>> X] = t.widen.map[[X] =>> X]([X] => (x: X) => {println(x); x}) | ||
nt | ||
|
||
def h[T <: Tuple](to: T)(using Tuple.IsMappedBy[Some][T]): Tuple.InverseMap[T, Some] = | ||
val t: Tuple.Map[T, MatchSome] = to.widen.map([X] => (x: X) => matchSome(x)) | ||
t | ||
|
||
def back_forth[T <: Tuple](t: T): T = | ||
val ts: Tuple.Map[T, Some] = t.widen.map([X] => (x: X) => Some(x)) | ||
val nt = h(ts) | ||
nt | ||
|
||
|
||
@main def Test = | ||
println(f(4, 2)) | ||
println(g(4, 2)) | ||
println(back_forth(4, 2)) | ||
println(h(Some(1), Some(2))) |
This file contains 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