Skip to content

Named tuples second implementation #19174

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

Merged
merged 68 commits into from
May 7, 2024
Merged
Changes from 1 commit
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
9d1f20d
Improvements to tuples: Drop experimental
odersky Dec 13, 2023
2395ece
Improvements to Tuples: New methods
odersky Dec 13, 2023
64a79c9
Improvements to tuples: Allow prefix slice in fromArray
odersky Dec 13, 2023
cb95265
Improvements to tuples: Rearrange types into a more logical order
odersky Dec 13, 2023
6ae8252
Improvements to tuples: more new types and methods
odersky Dec 13, 2023
1f79b87
Add NamedTuple object to library
odersky Dec 2, 2023
b9899b7
Support for named tuples with new representation
odersky Dec 3, 2023
27d6288
Add doc page
odersky Dec 3, 2023
5dd48f9
Make NamedTuple covariant in its value type
odersky Dec 3, 2023
bd9bb8a
Various tweaks
odersky Dec 5, 2023
e0a11cd
Harden NamedTuple handling against ill-formed NamedTuples
odersky Dec 5, 2023
b9d86fe
Fix test
odersky Dec 5, 2023
0fbdb49
Simplify tupleElementTypes unapply handling
odersky Dec 8, 2023
6f53dcd
Fix pattern matching for get matches
odersky Dec 8, 2023
b44f15d
Another fix for named get patterns
odersky Dec 14, 2023
02aa578
Avoid widening into unreducible types when inferring types
odersky Dec 14, 2023
b7115e7
Fix rebase breakage
odersky Jan 12, 2024
5c9bb5f
Make NamedTuples work under new MatchType spec
odersky Jan 12, 2024
4758830
Avoid TypeError exception in RefinedPrinter
odersky Jan 12, 2024
18f600d
Move named-tuples-strawman.ccala to pending
odersky Jan 12, 2024
5513ed6
Update check file
odersky Jan 12, 2024
fb1541a
Better printing of NamedTuple type trees
odersky Jan 14, 2024
cf09b19
Add FieldsOf type
odersky Jan 14, 2024
4baa509
Describe and add tests for source incompabilities
odersky Jan 14, 2024
702dcd5
Rename NamedTuple.FieldsOf --> NamedTuple.From
odersky Jan 14, 2024
1e31d16
Implement Fields as a Selectable type member
odersky Feb 5, 2024
22e6c89
Refactor typedSelect
odersky Feb 5, 2024
d0888f6
Add section on computable field names to reference doc page
odersky Feb 5, 2024
69964b0
Fix fields as a selectable type member
odersky Feb 6, 2024
a3409e0
Make NamedTuple.From work for named tuple arguments
odersky Feb 6, 2024
111674c
Fix NamedArg term/type classification
odersky Feb 7, 2024
1fd5962
Rename inMode to withModeBits
odersky Feb 10, 2024
c0b792f
Revert NamedArg term/type classification
odersky Feb 10, 2024
611861b
Update MimaFilters
odersky Feb 10, 2024
640da16
Fix rebase breakage in Parsers.scala
odersky Feb 16, 2024
67c0af2
Add tyql test case
odersky Feb 16, 2024
2cd5d7e
Introduce auto-conversion from named tuples to tuples
odersky Feb 17, 2024
d8b7595
Update documentation following review suggestions
odersky Feb 18, 2024
e0eb247
Drop TreeInfo's `dropNamedArg`
odersky Apr 24, 2024
4279a58
Print wildcard types in named tuples correctly
odersky Apr 24, 2024
c0bd1e4
Don't abbreviate tuple bindings if right-hand-side is named
odersky Apr 24, 2024
b997f3d
Strip named tuple from scrutinee when testing refutability of a named…
odersky Apr 24, 2024
2206d88
Fix tuple selection in pattern matcher
odersky Apr 24, 2024
ca19f1a
Fixes to NamedTuple
odersky Apr 25, 2024
984fe62
More tests
odersky Apr 25, 2024
21bcfef
Mention restriction against `_1`, `_2`, ... as named tuple labels
odersky Apr 25, 2024
92d22c9
Address review comments on Tuple.scala
odersky Apr 26, 2024
1613ee1
Reject recursive dynamicSelect corner case
odersky Apr 27, 2024
a04d3a7
Update compiler/src/dotty/tools/dotc/typer/Typer.scala
odersky Apr 27, 2024
37b1bd2
Update tests/neg/unselectable-fields.check
odersky Apr 27, 2024
3f8f6c6
Use consistent naming and drop remaining braces in tuple type ops
EugeneFlesselle Apr 29, 2024
9627c08
Add an infix shorthand for `Append[X, Y]`
EugeneFlesselle Apr 29, 2024
8a4162f
Drop unreachable case from `type Zip`
EugeneFlesselle Apr 29, 2024
0ab9e7b
Document `Concat` covariance in 2nd parameter
EugeneFlesselle Apr 29, 2024
075b7d1
Refine bounds of `type Filter` predicate
EugeneFlesselle Apr 29, 2024
c58c8c2
Do `contains` runtime operation based on term equality
EugeneFlesselle Apr 29, 2024
57b17ac
Do `indexOf` runtime operation based on term equality
EugeneFlesselle Apr 29, 2024
f427ec9
Do `filter` runtime operation based on a term level predicate
EugeneFlesselle Apr 29, 2024
94b7c1f
Mark `type Append` 2nd argument as covariant
EugeneFlesselle Apr 29, 2024
5df2120
Move `NonEmptyTuple` methods into `Tuple`
EugeneFlesselle Apr 29, 2024
40c6138
Reorder operations to be same between term and type level
EugeneFlesselle Apr 29, 2024
03509b8
Drop braces remaining at term level
EugeneFlesselle Apr 29, 2024
9047ac3
Fix `def indexOf` to return the size instead of -1
EugeneFlesselle May 1, 2024
579e14a
Revert doing tuple runtime operations based on a term level predicates
EugeneFlesselle May 1, 2024
8d6fa37
Make named-tuples-strawman-2.scala a run test
EugeneFlesselle May 1, 2024
1e29c4f
import language.experimental.namedTuples in pos/fieldsOf.scala
EugeneFlesselle May 2, 2024
0c89c92
Undo all unnecessary changes to Tuples.
odersky May 7, 2024
f80a8dd
Revert the addition of `type Fields` in `Selectable`.
sjrd May 6, 2024
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
Prev Previous commit
Next Next commit
Drop braces remaining at term level
  • Loading branch information
EugeneFlesselle authored and odersky committed May 6, 2024
commit 03509b8c09c519cc9fc8e5d9479ce939d23642bc
24 changes: 8 additions & 16 deletions library/src/scala/Tuple.scala
Original file line number Diff line number Diff line change
Expand Up @@ -246,10 +246,9 @@ object Tuple:
* constant `true`. A predicate `P[X]` is a type that can be either `true`
* or `false`. For example:
* ```scala
* type IsString[x] <: Boolean = x match {
* type IsString[x] <: Boolean = x match
* case String => true
* case _ => false
* }
* summon[Tuple.Filter[(1, "foo", 2, "bar"), IsString] =:= ("foo", "bar")]
* ```
* @syntax markdown
Expand Down Expand Up @@ -325,26 +324,21 @@ object Tuple:
fromArray(xs, xs.length)

/** Convert the first `n` elements of an array into a tuple of unknown arity and types */
def fromArray[T](xs: Array[T], n: Int): Tuple = {
val xs2 = xs match {
def fromArray[T](xs: Array[T], n: Int): Tuple =
val xs2 = xs match
case xs: Array[Object] => xs
case xs => xs.map(_.asInstanceOf[Object])
}
runtime.Tuples.fromArray(xs2, n)
}

/** Convert an immutable array into a tuple of unknown arity and types */
def fromIArray[T](xs: IArray[T]): Tuple = fromIArray(xs, xs.length)

/** Convert the first `n` elements of an immutable array into a tuple of unknown arity and types */
def fromIArray[T](xs: IArray[T], n: Int): Tuple = {
val xs2: IArray[Object] = xs match {
def fromIArray[T](xs: IArray[T], n: Int): Tuple =
val xs2: IArray[Object] = xs match
case xs: IArray[Object] @unchecked => xs
case _ =>
xs.map(_.asInstanceOf[Object])
}
case _ => xs.map(_.asInstanceOf[Object])
runtime.Tuples.fromIArray(xs2, n)
}

/** Convert a Product into a tuple of unknown arity and types */
def fromProduct(product: Product): Tuple =
Expand Down Expand Up @@ -394,16 +388,14 @@ end Tuple
type EmptyTuple = EmptyTuple.type

/** A tuple of 0 elements. */
case object EmptyTuple extends Tuple {
case object EmptyTuple extends Tuple:
override def toString(): String = "()"
}

/** Tuple of arbitrary non-zero arity */
sealed trait NonEmptyTuple extends Tuple

@showAsInfix
sealed abstract class *:[+H, +T <: Tuple] extends NonEmptyTuple

object *: {
object `*:`:
def unapply[H, T <: Tuple](x: H *: T): (H, T) = (x.head, x.tail)
}