-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix #9033, fix #9056: Add EmptyTuple #9049
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
Conversation
0bf02ff
to
4e61497
Compare
18a04c8
to
fcdcfdb
Compare
51e6298
to
1eadb03
Compare
We change to the following hierarchy where all generic tuple types erase to `Product`. ``` Product -- Tuple -+- EmptyTuple | +- NonEmptyTuple -- *:[Head, Tail <: Tuple] ``` These are encoded using the following compile-time only classes ```scalla sealed trait Tuple extends Product { ... } object EmptyTuple extends Tuple { ... } type EmptyTuple = EmptyTuple.type sealed trait NonEmptyTuple extends Tuple { ... } sealed abstract class *:[+H, +T <: Tuple] extends NonEmptyTuple { ... } ``` `TupleN` classes for `1 < N <= 22` are made subtypes of `*:` with precise type (as done before). But `Unit` is not anymore related to `Tuple`. Construction of empty tuples can be done with `Tuple()`, tuples with one element with `Tuple(e)` while any other tuple are created with `(e1, ..., en)`.
// () | ||
Literal(Constant(())) | ||
// scala.EmptyTuple | ||
ref(defn.EmptyTupleModule.termRef) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe define a type in Definitions for defn.EmptyTupleModule.termRef
.
FWIW, it looks like this PR lead to a 30% slowdown in the "Tuple reverse (Runtime)" benchmark: http://dotty-bench.epfl.ch/ |
@liufengyun how can I run this benchmark locally? |
Found it |
The performance regression comes from the sound type test to fix #9056. We will be able to recover this performance when we brack the API in 3.1 by not erasing https://github.com/lampepfl/dotty/pull/9049/files#diff-69edc152a7680e521f5bfba13aef8220R462 |
With this PR we change to the following hierarchy where all generic tuple types erase to
Product
.These are encoded using the following compile-time only classes
TupleN
classes for1 < N <= 22
are made subtypes of*:
with precise type (as done before). ButUnit
is not anymore related toTuple
.Construction of empty tuples can be done with
Tuple()
, tuples with one element withTuple(e)
while any other tuple are created with(e1, ..., en)
. These syntactic forms can also be used to match over tuples.Fixes #9033 and fixes #9056.