Skip to content
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

Remove compiletime.Widen #11569

Merged
merged 1 commit into from
Mar 8, 2021
Merged
Changes from all commits
Commits
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
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]
Copy link
Member

Choose a reason for hiding this comment

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

Is that cast actually still needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, before inlining the type of res is Tuple.

Copy link
Member

Choose a reason for hiding this comment

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

Can these two be implemented in terms of map, which already deals with casting it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The issue is that we do not have a tuple on which we could call map.

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