From 8d663303e8cc7e891b74d20ccf46babec406e375 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Fri, 19 Mar 2021 11:23:47 +0100 Subject: [PATCH] Re-bootstrap compiler --- .../tools/dotc/config/ScalaSettings.scala | 1 - .../dotty/tools/dotc/parsing/Scanners.scala | 2 +- .../scala/compiletime/ops/int.scala | 169 ----------------- .../scala/compiletime/package.scala | 176 ------------------ .../scala/quoted/Type.scala | 22 --- .../scala/compiletime/ops/int.scala | 0 .../scala/compiletime/package.scala | 2 + .../scala/quoted/Type.scala | 0 project/Build.scala | 6 +- 9 files changed, 4 insertions(+), 374 deletions(-) delete mode 100644 library/src-non-bootstrapped/scala/compiletime/ops/int.scala delete mode 100644 library/src-non-bootstrapped/scala/compiletime/package.scala delete mode 100644 library/src-non-bootstrapped/scala/quoted/Type.scala rename library/{src-bootstrapped => src}/scala/compiletime/ops/int.scala (100%) rename library/{src-bootstrapped => src}/scala/compiletime/package.scala (98%) rename library/{src-bootstrapped => src}/scala/quoted/Type.scala (100%) diff --git a/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala b/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala index 01e7d87117d2..8fa37eb45931 100644 --- a/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala +++ b/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala @@ -229,7 +229,6 @@ class ScalaSettings extends Settings.SettingGroup with CommonScalaSettings { val YexplicitNulls: Setting[Boolean] = BooleanSetting("-Yexplicit-nulls", "Make reference types non-nullable. Nullable types can be expressed with unions: e.g. String|Null.") val YcheckInit: Setting[Boolean] = BooleanSetting("-Ysafe-init", "Ensure safe initialization of objects") val YrequireTargetName: Setting[Boolean] = BooleanSetting("-Yrequire-targetName", "Warn if an operator is defined without a @targetName annotation") - val YerasedTerms: Setting[Boolean] = BooleanSetting("-Yerased-terms", "(disabled, use -language:experimental.erasedDefinitions instead)") /** Area-specific debug output */ val YexplainLowlevel: Setting[Boolean] = BooleanSetting("-Yexplain-lowlevel", "When explaining type errors, show types at a lower level.") diff --git a/compiler/src/dotty/tools/dotc/parsing/Scanners.scala b/compiler/src/dotty/tools/dotc/parsing/Scanners.scala index 789a76e88190..683fa8761d23 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Scanners.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Scanners.scala @@ -191,7 +191,7 @@ object Scanners { final def languageImportContext_=(c: Context) = myLanguageImportContext = c def featureEnabled(name: TermName) = Feature.enabled(name)(using languageImportContext) - def erasedEnabled = featureEnabled(Feature.erasedDefinitions) || ctx.settings.YerasedTerms.value + def erasedEnabled = featureEnabled(Feature.erasedDefinitions) /** All doc comments kept by their end position in a `Map`. * diff --git a/library/src-non-bootstrapped/scala/compiletime/ops/int.scala b/library/src-non-bootstrapped/scala/compiletime/ops/int.scala deleted file mode 100644 index bfefc3fc8d0e..000000000000 --- a/library/src-non-bootstrapped/scala/compiletime/ops/int.scala +++ /dev/null @@ -1,169 +0,0 @@ -package scala.compiletime -package ops - -object int: - /** Addition of two `Int` singleton types. - * ```scala - * val sum: 2 + 2 = 4 - * ``` - * @syntax markdown - */ - type +[X <: Int, Y <: Int] <: Int - - /** Subtraction of two `Int` singleton types. - * ```scala - * val sub: 4 - 2 = 2 - * ``` - * @syntax markdown - */ - type -[X <: Int, Y <: Int] <: Int - - /** Multiplication of two `Int` singleton types. - * ```scala - * val mul: 4 * 2 = 8 - * ``` - * @syntax markdown - */ - type *[X <: Int, Y <: Int] <: Int - - /** Integer division of two `Int` singleton types. - * ```scala - * val div: 5 / 2 = 2 - * ``` - * @syntax markdown - */ - type /[X <: Int, Y <: Int] <: Int - - /** Remainder of the division of `X` by `Y`. - * ```scala - * val mod: 5 % 2 = 1 - * ``` - * @syntax markdown - */ - type %[X <: Int, Y <: Int] <: Int - - /** Binary left shift of `X` by `Y`. - * ```scala - * val lshift: 1 << 2 = 4 - * ``` - * @syntax markdown - */ - type <<[X <: Int, Y <: Int] <: Int - - /** Binary right shift of `X` by `Y`. - * ```scala - * val rshift: 10 >> 1 = 5 - * ``` - * @syntax markdown - */ - type >>[X <: Int, Y <: Int] <: Int - - /** Binary right shift of `X` by `Y`, filling the left with zeros. - * ```scala - * val rshiftzero: 10 >>> 1 = 5 - * ``` - * @syntax markdown - */ - type >>>[X <: Int, Y <: Int] <: Int - - /** Bitwise xor of `X` and `Y`. - * ```scala - * val xor: 10 ^ 30 = 20 - * ``` - * @syntax markdown - */ - type ^[X <: Int, Y <: Int] <: Int - - /** Less-than comparison of two `Int` singleton types. - * ```scala - * val lt1: 4 < 2 = false - * val lt2: 2 < 4 = true - * ``` - * @syntax markdown - */ - type <[X <: Int, Y <: Int] <: Boolean - - /** Greater-than comparison of two `Int` singleton types. - * ```scala - * val gt1: 4 > 2 = true - * val gt2: 2 > 2 = false - * ``` - * @syntax markdown - */ - type >[X <: Int, Y <: Int] <: Boolean - - /** Greater-or-equal comparison of two `Int` singleton types. - * ```scala - * val ge1: 4 >= 2 = true - * val ge2: 2 >= 3 = false - * ``` - * @syntax markdown - */ - type >=[X <: Int, Y <: Int] <: Boolean - - /** Less-or-equal comparison of two `Int` singleton types. - * ```scala - * val lt1: 4 <= 2 = false - * val lt2: 2 <= 2 = true - * ``` - * @syntax markdown - */ - type <=[X <: Int, Y <: Int] <: Boolean - - /** Bitwise and of `X` and `Y`. - * ```scala - * val and1: BitwiseAnd[4, 4] = 4 - * val and2: BitwiseAnd[10, 5] = 0 - * ``` - * @syntax markdown - */ - type BitwiseAnd[X <: Int, Y <: Int] <: Int - - /** Bitwise or of `X` and `Y`. - * ```scala - * val or: BitwiseOr[10, 11] = 11 - * ``` - * @syntax markdown - */ - type BitwiseOr[X <: Int, Y <: Int] <: Int - - /** Absolute value of an `Int` singleton type. - * ```scala - * val abs: Abs[-1] = 1 - * ``` - * @syntax markdown - */ - type Abs[X <: Int] <: Int - - /** Negation of an `Int` singleton type. - * ```scala - * val neg1: Neg[-1] = 1 - * val neg2: Neg[1] = -1 - * ``` - * @syntax markdown - */ - type Negate[X <: Int] <: Int - - /** Minimum of two `Int` singleton types. - * ```scala - * val min: Min[-1, 1] = -1 - * ``` - * @syntax markdown - */ - type Min[X <: Int, Y <: Int] <: Int - - /** Maximum of two `Int` singleton types. - * ```scala - * val max: Max[-1, 1] = 1 - * ``` - * @syntax markdown - */ - type Max[X <: Int, Y <: Int] <: Int - - /** String conversion of an `Int` singleton type. - * ```scala - * val abs: ToString[1] = "1" - * ``` - * @syntax markdown - */ - type ToString[X <: Int] <: String diff --git a/library/src-non-bootstrapped/scala/compiletime/package.scala b/library/src-non-bootstrapped/scala/compiletime/package.scala deleted file mode 100644 index 37d5a123c5da..000000000000 --- a/library/src-non-bootstrapped/scala/compiletime/package.scala +++ /dev/null @@ -1,176 +0,0 @@ -package scala -import annotation.compileTimeOnly - -package object compiletime { - import language.experimental.erasedDefinitions - - /** Use this method when you have a type, do not have a value for it but want to - * pattern match on it. For example, given a type `Tup <: Tuple`, one can - * pattern-match on it as follows: - * ```scala - * inline erasedValue[Tup] match { - * case _: EmptyTuple => ... - * case _: h *: t => ... - * } - * ``` - * This value can only be used in an inline match and the value cannot be used in - * the branches. - * @syntax markdown - */ - erased def erasedValue[T]: T = ??? - - /** Used as the initializer of a mutable class or object field, like this: - * - * var x: T = uninitialized - * - * This signifies that the field is not initialized on its own. It is still initialized - * as part of the bulk initialization of the object it belongs to, which assigns zero - * values such as `null`, `0`, `0.0`, `false` to all object fields. - */ - @compileTimeOnly("`uninitialized` can only be used as the right hand side of a mutable field definition") - def uninitialized: Nothing = ??? - - /** The error method is used to produce user-defined compile errors during inline expansion. - * If an inline expansion results in a call error(msgStr) the compiler produces an error message containing the given msgStr. - * - * ```scala - * error("My error message") - * ``` - * or - * ```scala - * inline def errorOnThisCode(inline x: Any) = - * error("My error of this code: " + codeOf(x)) - * ``` - * @syntax markdown - */ - inline def error(inline msg: String): Nothing = ??? - - /** Returns the string representation of argument code: - * - * ```scala - * inline def logged(inline p1: Any) = - * ("code: " + codeOf(p1), p1) - * - * logged(identity("foo")) - * // above is equivalent to: - * // ("code: scala.Predef.identity("foo")", identity("foo")) - * ``` - * - * The formatting of the code is not stable across version of the compiler. - * - * @note only `inline` arguments will be displayed as "code". - * Other values may display unintutively. - * - * @syntax markdown - */ - transparent inline def codeOf(arg: Any): String = - // implemented in dotty.tools.dotc.typer.Inliner.Intrinsics - error("Compiler bug: `codeOf` was not evaluated by the compiler") - - /** Checks at compiletime that the provided values is a constant after - * inlining and constant folding. - * - * Usage: - * ```scala - * inline def twice(inline n: Int): Int = - * requireConst(n) // compile-time assertion that the parameter `n` is a constant - * n + n - * - * twice(1) - * val m: Int = ... - * twice(m) // error: expected a constant value but found: m - * ``` - * @syntax markdown - */ - inline def requireConst(inline x: Boolean | Byte | Short | Int | Long | Float | Double | Char | String): Unit = - // implemented in dotty.tools.dotc.typer.Inliner - error("Compiler bug: `requireConst` was not evaluated by the compiler") - - /** Same as `constValue` but returns a `None` if a constant value - * cannot be constructed from the provided type. Otherwise returns - * that value wrapped in `Some`. - */ - transparent inline def constValueOpt[T]: Option[T] = - // implemented in dotty.tools.dotc.typer.Inliner - error("Compiler bug: `constValueOpt` was not evaluated by the compiler") - - /** Given a constant, singleton type `T`, convert it to a value - * of the same singleton type. For example: `assert(constValue[1] == 1)`. - */ - transparent inline def constValue[T]: T = - // implemented in dotty.tools.dotc.typer.Inliner - error("Compiler bug: `constValue` was not evaluated by the compiler") - - /** Given a tuple type `(X1, ..., Xn)`, returns a tuple value - * `(constValue[X1], ..., constValue[Xn])`. - */ - 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[T] - end constValueTuple - - /** Summons first given matching one of the listed cases. E.g. in - * - * ```scala - * given B { ... } - * - * summonFrom { - * case given A => 1 - * case given B => 2 - * case given C => 3 - * case _ => 4 - * } - * ``` - * the returned value would be `2`. - * @syntax markdown - */ - transparent inline def summonFrom[T](f: Nothing => T): T = - error("Compiler bug: `summonFrom` was not evaluated by the compiler") - - /** Summon a given value of type `T`. Usually, the argument is not passed explicitly. - * The summoning is delayed until the call has been fully inlined. - * - * @tparam T the type of the value to be summoned - * @return the given value typed as the provided type parameter - */ - transparent inline def summonInline[T]: T = summonFrom { - case t: T => t - } - - /** Given a tuple T, summons each of its member types and returns them in - * a Tuple. - * - * @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]: T = - val res = - inline erasedValue[T] match - case _: EmptyTuple => EmptyTuple - case _: (t *: ts) => summonInline[t] *: summonAll[ts] - end match - res.asInstanceOf[T] - end summonAll - - /** 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 { - * case 0 => 1 - * case 1 => 2 - * case 2 => 3 - * ... - * case 2147483646 => 2147483647 - * } - * ``` - * @syntax markdown - */ - type S[N <: Int] <: Int - - /** Assertion that an argument is by-name. Used for nullability checking. */ - def byName[T](x: => T): T = x -} diff --git a/library/src-non-bootstrapped/scala/quoted/Type.scala b/library/src-non-bootstrapped/scala/quoted/Type.scala deleted file mode 100644 index 721843a48d90..000000000000 --- a/library/src-non-bootstrapped/scala/quoted/Type.scala +++ /dev/null @@ -1,22 +0,0 @@ -package scala.quoted - -import scala.annotation.compileTimeOnly - -/** Type (or type constructor) `T` needed contextually when using `T` in a quoted expression `'{... T ...}` */ -abstract class Type[T <: AnyKind] private[scala]: - /** The type represented `Type` */ - type Underlying = T - throw Exception("non-bootstrapped-lib") -end Type - -/** Methods to interact with the current `Type[T]` in scope */ -object Type: - - /** Show a source code like representation of this type without syntax highlight */ - def show[T <: AnyKind](using Type[T])(using Quotes): String = throw Exception("non-bootstrapped-lib") - - /** Return a quoted.Type with the given type */ - @compileTimeOnly("Reference to `scala.quoted.Type.of` was not handled by PickleQuotes") - given of[T <: AnyKind]: (Quotes ?=> Type[T]) = throw Exception("non-bootstrapped-lib") - -end Type diff --git a/library/src-bootstrapped/scala/compiletime/ops/int.scala b/library/src/scala/compiletime/ops/int.scala similarity index 100% rename from library/src-bootstrapped/scala/compiletime/ops/int.scala rename to library/src/scala/compiletime/ops/int.scala diff --git a/library/src-bootstrapped/scala/compiletime/package.scala b/library/src/scala/compiletime/package.scala similarity index 98% rename from library/src-bootstrapped/scala/compiletime/package.scala rename to library/src/scala/compiletime/package.scala index e3ddedc38a7f..ddc09d183b1e 100644 --- a/library/src-bootstrapped/scala/compiletime/package.scala +++ b/library/src/scala/compiletime/package.scala @@ -1,6 +1,8 @@ package scala package compiletime +import scala.language.experimental.erasedDefinitions + import annotation.compileTimeOnly /** Use this method when you have a type, do not have a value for it but want to diff --git a/library/src-bootstrapped/scala/quoted/Type.scala b/library/src/scala/quoted/Type.scala similarity index 100% rename from library/src-bootstrapped/scala/quoted/Type.scala rename to library/src/scala/quoted/Type.scala diff --git a/project/Build.scala b/project/Build.scala index f0f3b0d67209..ac4236cf4b08 100644 --- a/project/Build.scala +++ b/project/Build.scala @@ -55,7 +55,7 @@ object MyScalaJSPlugin extends AutoPlugin { } object Build { - val referenceVersion = "3.0.0-RC1" + val referenceVersion = "3.0.0-RC2-bin-20210318-e60ef35-NIGHTLY" val baseVersion = "3.0.0-RC2" val baseSbtDottyVersion = "0.5.4" @@ -670,10 +670,6 @@ object Build { (Compile / scalacOptions) ++= Seq( // Needed so that the library sources are visible when `dotty.tools.dotc.core.Definitions#init` is called "-sourcepath", (Compile / sourceDirectories).value.map(_.getAbsolutePath).distinct.mkString(File.pathSeparator), - // support declaration of scala.compiletime.erasedValue - "-Yerased-terms" - // TODO: drop after bootstrap with erasure language import - // scala.compile now contains the roght language import so no global setting is needed ), )