Skip to content

chore: drop old stdlib plugin in favour of internal project #23202

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ val `scala3-compiler` = Build.`scala3-compiler`
val `scala3-compiler-bootstrapped` = Build.`scala3-compiler-bootstrapped`
val `scala3-library` = Build.`scala3-library`
val `scala3-library-bootstrapped` = Build.`scala3-library-bootstrapped`
val `scala-library-internal` = Build.`scala-library-internal`
val `scala-library-internal-tasty` = Build.`scala-library-internal-tasty`
val `scala3-library-bootstrappedJS` = Build.`scala3-library-bootstrappedJS`
val `scala3-sbt-bridge` = Build.`scala3-sbt-bridge`
val `scala3-sbt-bridge-tests` = Build.`scala3-sbt-bridge-tests`
Expand Down
58 changes: 58 additions & 0 deletions library-internal/src/scala/AnyVal.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Scala (https://www.scala-lang.org)
*
* Copyright EPFL and Lightbend, Inc. dba Akka
*
* Licensed under Apache License 2.0
* (http://www.apache.org/licenses/LICENSE-2.0).
*
* See the NOTICE file distributed with this work for
* additional information regarding copyright ownership.
*/

package scala

/** `AnyVal` is the root class of all ''value types'', which describe values
* not implemented as objects in the underlying host system. Value classes
* are specified in Scala Language Specification, section 12.2.
*
* The standard implementation includes nine `AnyVal` subtypes:
*
* [[scala.Double]], [[scala.Float]], [[scala.Long]], [[scala.Int]], [[scala.Char]],
* [[scala.Short]], and [[scala.Byte]] are the ''numeric value types''.
*
* [[scala.Unit]] and [[scala.Boolean]] are the ''non-numeric value types''.
*
* Other groupings:
*
* - The ''subrange types'' are [[scala.Byte]], [[scala.Short]], and [[scala.Char]].
* - The ''integer types'' include the subrange types as well as [[scala.Int]] and [[scala.Long]].
* - The ''floating point types'' are [[scala.Float]] and [[scala.Double]].
*
* A subclass of `AnyVal` is called a ''user-defined value class''
* and is treated specially by the compiler. Properly-defined user value classes provide a way
* to improve performance on user-defined types by avoiding object allocation at runtime, and by
* replacing virtual method invocations with static method invocations.
*
* User-defined value classes which avoid object allocation...
*
* - must have a single `val` parameter that is the underlying runtime representation.
* - can define `def`s, but no `val`s, `var`s, or nested `trait`s, `class`es or `object`s.
* - typically extend no other trait apart from `AnyVal`.
* - cannot be used in type tests or pattern matching.
* - may not override `equals` or `hashCode` methods.
*
* A minimal example:
* {{{
* class Wrapper(val underlying: Int) extends AnyVal {
* def foo: Wrapper = new Wrapper(underlying * 19)
* }
* }}}
*
* It's important to note that user-defined value classes are limited, and in some circumstances,
* still must allocate a value class instance at runtime. These limitations and circumstances are
* explained in greater detail in the [[https://docs.scala-lang.org/overviews/core/value-classes.html Value Classes and Universal Traits]].
*/
abstract class AnyVal extends Any {
def getClass(): Class[_ <: AnyVal] = null
}
45 changes: 45 additions & 0 deletions library-internal/src/scala/Function0.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Scala (https://www.scala-lang.org)
*
* Copyright EPFL and Lightbend, Inc. dba Akka
*
* Licensed under Apache License 2.0
* (http://www.apache.org/licenses/LICENSE-2.0).
*
* See the NOTICE file distributed with this work for
* additional information regarding copyright ownership.
*/

// GENERATED CODE: DO NOT EDIT.
// genprod generated these sources at: 2022-01-17T20:47:12.170348200Z

package scala


/** A function of 0 parameters.
*
* In the following example, the definition of `greeting` is
* shorthand, conceptually, for the anonymous class definition
* `anonfun0`, although the implementation details of how the
* function value is constructed may differ:
*
* {{{
* object Main extends App {
* val name = "world"
* val greeting = () => s"hello, $name"
*
* val anonfun0 = new Function0[String] {
* def apply(): String = s"hello, $name"
* }
* assert(greeting() == anonfun0())
* }
* }}}
*/
trait Function0[@specialized(Specializable.Primitives) +R] extends AnyRef { self =>
/** Apply the body of this function to the arguments.
* @return the result of function application.
*/
def apply(): R

override def toString(): String = "<function0>"
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Scala (https://www.scala-lang.org)
*
* Copyright EPFL and Lightbend, Inc.
* Copyright EPFL and Lightbend, Inc. dba Akka
*
* Licensed under Apache License 2.0
* (http://www.apache.org/licenses/LICENSE-2.0).
Expand Down Expand Up @@ -64,21 +64,21 @@ object Function1 {
* is that the latter can specify inputs which it will not handle.
*/
@annotation.implicitNotFound(msg = "No implicit view available from ${T1} => ${R}.")
trait Function1[@specialized(Specializable.Arg) -T1, @specialized(Specializable.Return) +R] extends AnyRef { // FIXME: self =>
trait Function1[@specialized(Specializable.Arg) -T1, @specialized(Specializable.Return) +R] extends AnyRef { // TODO: Fix me self =>
/** Apply the body of this function to the argument.
* @return the result of function application.
*/
def apply(v1: T1): R

/** Composes two instances of Function1 in a new Function1, with this function applied last.
/** Composes two instances of `Function1` in a new `Function1`, with this function applied last.
*
* @tparam A the type to which function `g` can be applied
* @param g a function A => T1
* @return a new function `f` such that `f(x) == apply(g(x))`
*/
@annotation.unspecialized def compose[A](g: A => T1): A => R = { x => apply(g(x)) }

/** Composes two instances of Function1 in a new Function1, with this function applied first.
/** Composes two instances of `Function1` in a new `Function1`, with this function applied first.
*
* @tparam A the result type of function `g`
* @param g a function R => A
Expand Down
58 changes: 58 additions & 0 deletions library-internal/src/scala/Function2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Scala (https://www.scala-lang.org)
*
* Copyright EPFL and Lightbend, Inc. dba Akka
*
* Licensed under Apache License 2.0
* (http://www.apache.org/licenses/LICENSE-2.0).
*
* See the NOTICE file distributed with this work for
* additional information regarding copyright ownership.
*/

// GENERATED CODE: DO NOT EDIT. See scala.Function0 for timestamp.

package scala


/** A function of 2 parameters.
*
* In the following example, the definition of `max` is
* shorthand, conceptually, for the anonymous class definition
* `anonfun2`, although the implementation details of how the
* function value is constructed may differ:
*
* {{{
* object Main extends App {
* val max = (x: Int, y: Int) => if (x < y) y else x
*
* val anonfun2 = new Function2[Int, Int, Int] {
* def apply(x: Int, y: Int): Int = if (x < y) y else x
* }
* assert(max(0, 1) == anonfun2(0, 1))
* }
* }}}
*/
trait Function2[@specialized(Specializable.Args) -T1, @specialized(Specializable.Args) -T2, @specialized(Specializable.Return) +R] extends AnyRef { self =>
/** Apply the body of this function to the arguments.
* @return the result of function application.
*/
def apply(v1: T1, v2: T2): R
/** Creates a curried version of this function.
*
* @return a function `f` such that `f(x1)(x2) == apply(x1, x2)`
*/
@annotation.unspecialized def curried: T1 => T2 => R = {
(x1: T1) => (x2: T2) => apply(x1, x2)
}
/** Creates a tupled version of this function: instead of 2 arguments,
* it accepts a single [[scala.Tuple2]] argument.
*
* @return a function `f` such that `f((x1, x2)) == f(Tuple2(x1, x2)) == apply(x1, x2)`
*/

@annotation.unspecialized def tupled: ((T1, T2)) => R = {
case ((x1, x2)) => apply(x1, x2)
}
override def toString(): String = "<function2>"
}
51 changes: 51 additions & 0 deletions library-internal/src/scala/Product1.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Scala (https://www.scala-lang.org)
*
* Copyright EPFL and Lightbend, Inc. dba Akka
*
* Licensed under Apache License 2.0
* (http://www.apache.org/licenses/LICENSE-2.0).
*
* See the NOTICE file distributed with this work for
* additional information regarding copyright ownership.
*/

// GENERATED CODE: DO NOT EDIT. See scala.Function0 for timestamp.

package scala

object Product1 {
def unapply[T1](x: Product1[T1]): Option[Product1[T1]] =
Some(x)
}

/** Product1 is a Cartesian product of 1 component.
*/
trait Product1[@specialized(Int, Long, Double) +T1] extends Any with Product {
/** The arity of this product.
* @return 1
*/
override def productArity: Int = 1


/** Returns the n-th projection of this product if 0 <= n < productArity,
* otherwise throws an `IndexOutOfBoundsException`.
*
* @param n number of the projection to be returned
* @return same as `._(n+1)`, for example `productElement(0)` is the same as `._1`.
* @throws IndexOutOfBoundsException if the `n` is out of range(n < 0 || n >= 1).
*/

@throws(classOf[IndexOutOfBoundsException])
override def productElement(n: Int): Any = n match {
case 0 => _1
case _ => throw new IndexOutOfBoundsException(s"$n is out of bounds (min 0, max 0)")
}

/** A projection of element 1 of this Product.
* @return A projection of element 1.
*/
def _1: T1


}
56 changes: 56 additions & 0 deletions library-internal/src/scala/Product2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Scala (https://www.scala-lang.org)
*
* Copyright EPFL and Lightbend, Inc. dba Akka
*
* Licensed under Apache License 2.0
* (http://www.apache.org/licenses/LICENSE-2.0).
*
* See the NOTICE file distributed with this work for
* additional information regarding copyright ownership.
*/

// GENERATED CODE: DO NOT EDIT. See scala.Function0 for timestamp.

package scala

object Product2 {
def unapply[T1, T2](x: Product2[T1, T2]): Option[Product2[T1, T2]] =
Some(x)
}

/** Product2 is a Cartesian product of 2 components.
*/
trait Product2[@specialized(Int, Long, Double) +T1, @specialized(Int, Long, Double) +T2] extends Any with Product {
/** The arity of this product.
* @return 2
*/
override def productArity: Int = 2


/** Returns the n-th projection of this product if 0 <= n < productArity,
* otherwise throws an `IndexOutOfBoundsException`.
*
* @param n number of the projection to be returned
* @return same as `._(n+1)`, for example `productElement(0)` is the same as `._1`.
* @throws IndexOutOfBoundsException if the `n` is out of range(n < 0 || n >= 2).
*/

@throws(classOf[IndexOutOfBoundsException])
override def productElement(n: Int): Any = n match {
case 0 => _1
case 1 => _2
case _ => throw new IndexOutOfBoundsException(s"$n is out of bounds (min 0, max 1)")
}

/** A projection of element 1 of this Product.
* @return A projection of element 1.
*/
def _1: T1
/** A projection of element 2 of this Product.
* @return A projection of element 2.
*/
def _2: T2


}
27 changes: 27 additions & 0 deletions library-internal/src/scala/Tuple1.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Scala (https://www.scala-lang.org)
*
* Copyright EPFL and Lightbend, Inc. dba Akka
*
* Licensed under Apache License 2.0
* (http://www.apache.org/licenses/LICENSE-2.0).
*
* See the NOTICE file distributed with this work for
* additional information regarding copyright ownership.
*/

// GENERATED CODE: DO NOT EDIT. See scala.Function0 for timestamp.

package scala


/** A tuple of 1 elements; the canonical representation of a [[scala.Product1]].
*
* @constructor Create a new tuple with 1 elements.
* @param _1 Element 1 of this Tuple1
*/
final case class Tuple1[@specialized(Int, Long, Double) +T1](_1: T1) extends Product1[T1]
{
override def toString(): String = "(" + _1 + ")"

}
35 changes: 35 additions & 0 deletions library-internal/src/scala/Tuple2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Scala (https://www.scala-lang.org)
*
* Copyright EPFL and Lightbend, Inc. dba Akka
*
* Licensed under Apache License 2.0
* (http://www.apache.org/licenses/LICENSE-2.0).
*
* See the NOTICE file distributed with this work for
* additional information regarding copyright ownership.
*/

// GENERATED CODE: DO NOT EDIT. See scala.Function0 for timestamp.

package scala


/** A tuple of 2 elements; the canonical representation of a [[scala.Product2]].
*
* @constructor Create a new tuple with 2 elements. Note that it is more idiomatic to create a Tuple2 via `(t1, t2)`
* @param _1 Element 1 of this Tuple2
* @param _2 Element 2 of this Tuple2
*/
final case class Tuple2[@specialized(Int, Long, Double, Char, Boolean/*, AnyRef*/) +T1, @specialized(Int, Long, Double, Char, Boolean/*, AnyRef*/) +T2](_1: T1, _2: T2)
extends Product2[T1, T2]
{
override def toString(): String = "(" + _1 + "," + _2 + ")"

/** Swaps the elements of this `Tuple`.
* @return a new Tuple where the first element is the second element of this Tuple and the
* second element is the first element of this Tuple.
*/
def swap: Tuple2[T2,T1] = Tuple2(_2, _1)

}
Loading
Loading