Skip to content

Rewrite dotty to indent after #17522 #17618

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

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Rewrite scala3-library to indent
  • Loading branch information
adpi2 committed May 30, 2023
commit 25f6977c45c7d71164a0690f073bd3ed35168448
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import scala.util.TupledFunction
import scala.annotation.experimental

@experimental
object TupledFunctions {
object TupledFunctions:

def tupledFunction0[F, G]: TupledFunction[F, G] = TupledFunction[F, G](
tupledImpl = (f: F) => ((args: EmptyTuple) => f.asInstanceOf[() => Any].apply()).asInstanceOf[G],
Expand Down Expand Up @@ -162,4 +162,3 @@ object TupledFunctions {
}.asInstanceOf[F]
)

}
3 changes: 1 addition & 2 deletions library/src/scala/CanEqual.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ sealed trait CanEqual[-L, -R]
* CanEqual instances involving primitive types or the Null type are handled directly in
* the compiler (see Implicits.synthesizedCanEqual), so they are not included here.
*/
object CanEqual {
object CanEqual:
/** A universal `CanEqual` instance. */
object derived extends CanEqual[Any, Any]

Expand Down Expand Up @@ -44,4 +44,3 @@ object CanEqual {
given canEqualEither[L1, R1, L2, R2](
using eqL: CanEqual[L1, L2], eqR: CanEqual[R1, R2]
): CanEqual[Either[L1, R1], Either[L2, R2]] = derived
}
20 changes: 7 additions & 13 deletions library/src/scala/IArray.scala
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ object IArray:
* @param ys an array of AnyRef
* @return true if corresponding elements are equal
*/
def equals(xs: IArray[AnyRef], ys: IArray[AnyRef]): Boolean =
def equals(xs: IArray[AnyRef], ys: IArray[AnyRef]): Boolean =
Array.equals(xs.asInstanceOf[Array[AnyRef]], ys.asInstanceOf[Array[AnyRef]])

/** Returns a decomposition of the array into a sequence. This supports
Expand All @@ -624,15 +624,13 @@ object IArray:
/** Apply `f` to each element for its side effects.
* Note: [U] parameter needed to help scalac's type inference.
*/
def foreach[U](f: T => U): Unit = {
def foreach[U](f: T => U): Unit =
val len = xs.length
var i = 0
while(i < len) {
while(i < len)
val x = xs(i)
if(p(x)) f(x)
i += 1
}
}

/** Builds a new array by applying a function to all elements of this array.
*
Expand All @@ -641,16 +639,14 @@ object IArray:
* @return a new array resulting from applying the given function
* `f` to each element of this array and collecting the results.
*/
def map[U: ClassTag](f: T => U): IArray[U] = {
def map[U: ClassTag](f: T => U): IArray[U] =
val b = IArray.newBuilder[U]
var i = 0
while (i < xs.length) {
while (i < xs.length)
val x = xs(i)
if(p(x)) b += f(x)
i = i + 1
}
b.result()
}

/** Builds a new array by applying a function to all elements of this array
* and using the elements of the resulting collections.
Expand All @@ -660,16 +656,14 @@ object IArray:
* @return a new array resulting from applying the given collection-valued function
* `f` to each element of this array and concatenating the results.
*/
def flatMap[U: ClassTag](f: T => IterableOnce[U]): IArray[U] = {
def flatMap[U: ClassTag](f: T => IterableOnce[U]): IArray[U] =
val b = IArray.newBuilder[U]
var i = 0
while(i < xs.length) {
while(i < xs.length)
val x = xs(i)
if(p(x)) b ++= f(xs(i))
i += 1
}
b.result()
}

def flatMap[BS, U](f: T => BS)(using asIterable: BS => Iterable[U], m: ClassTag[U]): IArray[U] =
flatMap[U](x => asIterable(f(x)))
Expand Down
96 changes: 34 additions & 62 deletions library/src/scala/Tuple.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import compiletime._
import compiletime.ops.int._

/** Tuple of arbitrary arity */
sealed trait Tuple extends Product {
sealed trait Tuple extends Product:
import Tuple._

/** Create a copy of this tuple as an Array */
Expand Down Expand Up @@ -78,76 +78,64 @@ sealed trait Tuple extends Product {
*/
inline def splitAt[This >: this.type <: Tuple](n: Int): Split[This, n.type] =
runtime.Tuples.splitAt(this, n).asInstanceOf[Split[This, n.type]]
}

object Tuple {
object Tuple:

/** Type of a tuple with an element appended */
type Append[X <: Tuple, Y] <: NonEmptyTuple = X match {
type Append[X <: Tuple, Y] <: NonEmptyTuple = X match
case EmptyTuple => Y *: EmptyTuple
case x *: xs => x *: Append[xs, Y]
}

/** Type of the head of a tuple */
type Head[X <: NonEmptyTuple] = X match {
type Head[X <: NonEmptyTuple] = X match
case x *: _ => x
}

/** Type of the initial part of the tuple without its last element */
type Init[X <: Tuple] <: Tuple = X match {
type Init[X <: Tuple] <: Tuple = X match
case _ *: EmptyTuple => EmptyTuple
case x *: xs =>
x *: Init[xs]
}

/** Type of the tail of a tuple */
type Tail[X <: NonEmptyTuple] <: Tuple = X match {
type Tail[X <: NonEmptyTuple] <: Tuple = X match
case _ *: xs => xs
}

/** Type of the last element of a tuple */
type Last[X <: Tuple] = X match {
type Last[X <: Tuple] = X match
case x *: EmptyTuple => x
case _ *: xs => Last[xs]
}

/** Type of the concatenation of two tuples */
type Concat[X <: Tuple, +Y <: Tuple] <: Tuple = X match {
type Concat[X <: Tuple, +Y <: Tuple] <: Tuple = X match
case EmptyTuple => Y
case x1 *: xs1 => x1 *: Concat[xs1, Y]
}

/** Type of the element at position N in the tuple X */
type Elem[X <: Tuple, N <: Int] = X match {
type Elem[X <: Tuple, N <: Int] = X match
case x *: xs =>
N match {
N match
case 0 => x
case S[n1] => Elem[xs, n1]
}
}

/** Literal constant Int size of a tuple */
type Size[X <: Tuple] <: Int = X match {
type Size[X <: Tuple] <: Int = X match
case EmptyTuple => 0
case x *: xs => S[Size[xs]]
}

/** Fold a tuple `(T1, ..., Tn)` into `F[T1, F[... F[Tn, Z]...]]]` */
type Fold[Tup <: Tuple, Z, F[_, _]] = Tup match
case EmptyTuple => Z
case h *: t => F[h, Fold[t, Z, F]]

/** Converts a tuple `(T1, ..., Tn)` to `(F[T1], ..., F[Tn])` */
type Map[Tup <: Tuple, F[_ <: Union[Tup]]] <: Tuple = Tup match {
type Map[Tup <: Tuple, F[_ <: Union[Tup]]] <: Tuple = Tup match
case EmptyTuple => EmptyTuple
case h *: t => F[h] *: Map[t, F]
}

/** Converts a tuple `(T1, ..., Tn)` to a flattened `(..F[T1], ..., ..F[Tn])` */
type FlatMap[Tup <: Tuple, F[_ <: Union[Tup]] <: Tuple] <: Tuple = Tup match {
type FlatMap[Tup <: Tuple, F[_ <: Union[Tup]] <: Tuple] <: Tuple = Tup match
case EmptyTuple => EmptyTuple
case h *: t => Concat[F[h], FlatMap[t, F]]
}

/** Filters out those members of the tuple for which the predicate `P` returns `false`.
* A predicate `P[X]` is a type that can be either `true` or `false`. For example:
Expand All @@ -160,31 +148,27 @@ object Tuple {
* ```
* @syntax markdown
*/
type Filter[Tup <: Tuple, P[_] <: Boolean] <: Tuple = Tup match {
type Filter[Tup <: Tuple, P[_] <: Boolean] <: Tuple = Tup match
case EmptyTuple => EmptyTuple
case h *: t => P[h] match {
case true => h *: Filter[t, P]
case false => Filter[t, P]
}
}
case h *: t => P[h] match
case true => h *: Filter[t, P]
case false => Filter[t, P]

/** Given two tuples, `A1 *: ... *: An * At` and `B1 *: ... *: Bn *: Bt`
* where at least one of `At` or `Bt` is `EmptyTuple` or `Tuple`,
* returns the tuple type `(A1, B1) *: ... *: (An, Bn) *: Ct`
* where `Ct` is `EmptyTuple` if `At` or `Bt` is `EmptyTuple`, otherwise `Ct` is `Tuple`.
*/
type Zip[T1 <: Tuple, T2 <: Tuple] <: Tuple = (T1, T2) match {
type Zip[T1 <: Tuple, T2 <: Tuple] <: Tuple = (T1, T2) match
case (h1 *: t1, h2 *: t2) => (h1, h2) *: Zip[t1, t2]
case (EmptyTuple, _) => EmptyTuple
case (_, EmptyTuple) => EmptyTuple
case _ => Tuple
}

/** Converts a tuple `(F[T1], ..., F[Tn])` to `(T1, ... Tn)` */
type InverseMap[X <: Tuple, F[_]] <: Tuple = X match {
type InverseMap[X <: Tuple, F[_]] <: Tuple = X match
case F[x] *: t => x *: InverseMap[t, F]
case EmptyTuple => EmptyTuple
}

/** Implicit evidence. IsMappedBy[F][X] is present in the implicit scope iff
* X is a tuple for which each element's type is constructed via `F`. E.g.
Expand All @@ -194,22 +178,18 @@ object Tuple {
type IsMappedBy[F[_]] = [X <: Tuple] =>> X =:= Map[InverseMap[X, F], F]

/** Transforms a tuple `(T1, ..., Tn)` into `(T1, ..., Ti)`. */
type Take[T <: Tuple, N <: Int] <: Tuple = N match {
type Take[T <: Tuple, N <: Int] <: Tuple = N match
case 0 => EmptyTuple
case S[n1] => T match {
case EmptyTuple => EmptyTuple
case x *: xs => x *: Take[xs, n1]
}
}
case S[n1] => T match
case EmptyTuple => EmptyTuple
case x *: xs => x *: Take[xs, n1]

/** Transforms a tuple `(T1, ..., Tn)` into `(Ti+1, ..., Tn)`. */
type Drop[T <: Tuple, N <: Int] <: Tuple = N match {
type Drop[T <: Tuple, N <: Int] <: Tuple = N match
case 0 => T
case S[n1] => T match {
case EmptyTuple => EmptyTuple
case x *: xs => Drop[xs, n1]
}
}
case S[n1] => T match
case EmptyTuple => EmptyTuple
case x *: xs => Drop[xs, n1]

/** Splits a tuple (T1, ..., Tn) into a pair of two tuples `(T1, ..., Ti)` and
* `(Ti+1, ..., Tn)`.
Expand All @@ -231,23 +211,19 @@ object Tuple {
def unapply(x: EmptyTuple): true = true

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

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

/** Convert a Product into a tuple of unknown arity and types */
def fromProduct(product: Product): Tuple =
Expand All @@ -260,18 +236,16 @@ object Tuple {
given canEqualTuple[H1, T1 <: Tuple, H2, T2 <: Tuple](
using eqHead: CanEqual[H1, H2], eqTail: CanEqual[T1, T2]
): CanEqual[H1 *: T1, H2 *: T2] = CanEqual.derived
}

/** A tuple of 0 elements */
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 {
sealed trait NonEmptyTuple extends Tuple:
import Tuple._

/** Get the i-th element of this tuple.
Expand All @@ -298,11 +272,9 @@ sealed trait NonEmptyTuple extends Tuple {
inline def tail[This >: this.type <: NonEmptyTuple]: Tail[This] =
runtime.Tuples.tail(this).asInstanceOf[Tail[This]]

}

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

object *: {
object `*:`:
Comment on lines -306 to +279
Copy link
Member Author

Choose a reason for hiding this comment

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

A back-quoted operator

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