Skip to content

Commit

Permalink
Try to remove compiletime.Widen (#11569)
Browse files Browse the repository at this point in the history
  • Loading branch information
smarter authored Mar 8, 2021
2 parents 3b524a4 + 859cdd2 commit 22a9a5a
Showing 1 changed file with 5 additions and 18 deletions.
23 changes: 5 additions & 18 deletions library/src/scala/compiletime/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -100,29 +100,16 @@ package object compiletime {
// implemented in dotty.tools.dotc.typer.Inliner
error("Compiler bug: `constValue` was not evaluated by the compiler")

/**
* Use this type to widen a self-type to a tuple. E.g.
* ```scala
* val x: (1, 3) = (1, 3)
* val y: Widen[x.type] = x
* ```
* @syntax markdown
*/
type Widen[Tup <: Tuple] <: Tuple = Tup match {
case EmptyTuple => EmptyTuple
case h *: t => h *: t
}

/** Given a tuple type `(X1, ..., Xn)`, returns a tuple value
* `(constValue[X1], ..., constValue[Xn])`.
*/
inline def constValueTuple[T <: Tuple]: Widen[T]=
inline def constValueTuple[T <: Tuple]: T =
val res =
inline erasedValue[T] match
case _: EmptyTuple => EmptyTuple
case _: (t *: ts) => constValue[t] *: constValueTuple[ts]
end match
res.asInstanceOf[Widen[T]]
res.asInstanceOf[T]
end constValueTuple

/** Summons first given matching one of the listed cases. E.g. in
Expand Down Expand Up @@ -159,16 +146,16 @@ package object compiletime {
* @tparam T the tuple containing the types of the values to be summoned
* @return the given values typed as elements of the tuple
*/
inline def summonAll[T <: Tuple]: Widen[T] =
inline def summonAll[T <: Tuple]: T =
val res =
inline erasedValue[T] match
case _: EmptyTuple => EmptyTuple
case _: (t *: ts) => summonInline[t] *: summonAll[ts]
end match
res.asInstanceOf[Widen[T]]
res.asInstanceOf[T]
end summonAll

/** Succesor of a natural number where zero is the type 0 and successors are reduced as if the definition was
/** Successor of a natural number where zero is the type 0 and successors are reduced as if the definition was
*
* ```scala
* type S[N <: Int] <: Int = N match {
Expand Down

0 comments on commit 22a9a5a

Please sign in to comment.