Skip to content

Cleanup compiletime package #10604

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 4 commits into from
Dec 9, 2020
Merged
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
24 changes: 12 additions & 12 deletions compiler/src/dotty/tools/dotc/core/Definitions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -231,20 +231,20 @@ class Definitions {
@tu lazy val Compiletime_constValue : Symbol = CompiletimePackageObject.requiredMethod("constValue")
@tu lazy val Compiletime_constValueOpt: Symbol = CompiletimePackageObject.requiredMethod("constValueOpt")
@tu lazy val Compiletime_summonFrom : Symbol = CompiletimePackageObject.requiredMethod("summonFrom")
@tu lazy val CompiletimeTestingPackageObject: Symbol = requiredModule("scala.compiletime.testing.package")
@tu lazy val CompiletimeTesting_typeChecks: Symbol = CompiletimeTestingPackageObject.requiredMethod("typeChecks")
@tu lazy val CompiletimeTesting_typeCheckErrors: Symbol = CompiletimeTestingPackageObject.requiredMethod("typeCheckErrors")
@tu lazy val CompiletimeTestingPackage: Symbol = requiredPackage("scala.compiletime.testing")
@tu lazy val CompiletimeTesting_typeChecks: Symbol = CompiletimeTestingPackage.requiredMethod("typeChecks")
@tu lazy val CompiletimeTesting_typeCheckErrors: Symbol = CompiletimeTestingPackage.requiredMethod("typeCheckErrors")
@tu lazy val CompiletimeTesting_ErrorClass: ClassSymbol = requiredClass("scala.compiletime.testing.Error")
@tu lazy val CompiletimeTesting_Error: Symbol = requiredModule("scala.compiletime.testing.Error")
@tu lazy val CompiletimeTesting_Error_apply = CompiletimeTesting_Error.requiredMethod(nme.apply)
@tu lazy val CompiletimeTesting_ErrorKind: Symbol = requiredModule("scala.compiletime.testing.ErrorKind")
@tu lazy val CompiletimeTesting_ErrorKind_Parser: Symbol = CompiletimeTesting_ErrorKind.requiredMethod("Parser")
@tu lazy val CompiletimeTesting_ErrorKind_Typer: Symbol = CompiletimeTesting_ErrorKind.requiredMethod("Typer")
@tu lazy val CompiletimeOpsPackageObject: Symbol = requiredModule("scala.compiletime.ops.package")
@tu lazy val CompiletimeOpsPackageObjectAny: Symbol = requiredModule("scala.compiletime.ops.package.any")
@tu lazy val CompiletimeOpsPackageObjectInt: Symbol = requiredModule("scala.compiletime.ops.package.int")
@tu lazy val CompiletimeOpsPackageObjectString: Symbol = requiredModule("scala.compiletime.ops.package.string")
@tu lazy val CompiletimeOpsPackageObjectBoolean: Symbol = requiredModule("scala.compiletime.ops.package.boolean")
@tu lazy val CompiletimeOpsPackage: Symbol = requiredPackage("scala.compiletime.ops")
@tu lazy val CompiletimeOpsAny: Symbol = requiredModule("scala.compiletime.ops.any")
@tu lazy val CompiletimeOpsInt: Symbol = requiredModule("scala.compiletime.ops.int")
@tu lazy val CompiletimeOpsString: Symbol = requiredModule("scala.compiletime.ops.string")
@tu lazy val CompiletimeOpsBoolean: Symbol = requiredModule("scala.compiletime.ops.boolean")

/** Note: We cannot have same named methods defined in Object and Any (and AnyVal, for that matter)
* because after erasure the Any and AnyVal references get remapped to the Object methods
Expand Down Expand Up @@ -1088,10 +1088,10 @@ class Definitions {
compiletimePackageOpTypes.contains(sym.name)
&& (
sym.owner == CompiletimePackageObject.moduleClass && sym.name == tpnme.S
|| sym.owner == CompiletimeOpsPackageObjectAny.moduleClass && compiletimePackageAnyTypes.contains(sym.name)
|| sym.owner == CompiletimeOpsPackageObjectInt.moduleClass && compiletimePackageIntTypes.contains(sym.name)
|| sym.owner == CompiletimeOpsPackageObjectBoolean.moduleClass && compiletimePackageBooleanTypes.contains(sym.name)
|| sym.owner == CompiletimeOpsPackageObjectString.moduleClass && compiletimePackageStringTypes.contains(sym.name)
|| sym.owner == CompiletimeOpsAny.moduleClass && compiletimePackageAnyTypes.contains(sym.name)
|| sym.owner == CompiletimeOpsInt.moduleClass && compiletimePackageIntTypes.contains(sym.name)
|| sym.owner == CompiletimeOpsBoolean.moduleClass && compiletimePackageBooleanTypes.contains(sym.name)
|| sym.owner == CompiletimeOpsString.moduleClass && compiletimePackageStringTypes.contains(sym.name)
)

// ----- Scala-2 library patches --------------------------------------
Expand Down
8 changes: 4 additions & 4 deletions compiler/src/dotty/tools/dotc/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3985,11 +3985,11 @@ object Types {
if (owner == defn.CompiletimePackageObject.moduleClass) name match {
case tpnme.S if nArgs == 1 => constantFold1(natValue, _ + 1)
case _ => None
} else if (owner == defn.CompiletimeOpsPackageObjectAny.moduleClass) name match {
} else if (owner == defn.CompiletimeOpsAny.moduleClass) name match {
case tpnme.Equals if nArgs == 2 => constantFold2(constValue, _ == _)
case tpnme.NotEquals if nArgs == 2 => constantFold2(constValue, _ != _)
case _ => None
} else if (owner == defn.CompiletimeOpsPackageObjectInt.moduleClass) name match {
} else if (owner == defn.CompiletimeOpsInt.moduleClass) name match {
case tpnme.Abs if nArgs == 1 => constantFold1(intValue, _.abs)
case tpnme.Negate if nArgs == 1 => constantFold1(intValue, x => -x)
case tpnme.ToString if nArgs == 1 => constantFold1(intValue, _.toString)
Expand Down Expand Up @@ -4017,10 +4017,10 @@ object Types {
case tpnme.Min if nArgs == 2 => constantFold2(intValue, _ min _)
case tpnme.Max if nArgs == 2 => constantFold2(intValue, _ max _)
case _ => None
} else if (owner == defn.CompiletimeOpsPackageObjectString.moduleClass) name match {
} else if (owner == defn.CompiletimeOpsString.moduleClass) name match {
case tpnme.Plus if nArgs == 2 => constantFold2(stringValue, _ + _)
case _ => None
} else if (owner == defn.CompiletimeOpsPackageObjectBoolean.moduleClass) name match {
} else if (owner == defn.CompiletimeOpsBoolean.moduleClass) name match {
case tpnme.Not if nArgs == 1 => constantFold1(boolValue, x => !x)
case tpnme.And if nArgs == 2 => constantFold2(boolValue, _ && _)
case tpnme.Or if nArgs == 2 => constantFold2(boolValue, _ || _)
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/Inliner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ object Inliner {
*/
def inlineCall(tree: Tree)(using Context): Tree = {
if tree.symbol.denot != SymDenotations.NoDenotation
&& tree.symbol.owner.companionModule == defn.CompiletimeTestingPackageObject
&& tree.symbol.effectiveOwner == defn.CompiletimeTestingPackage.moduleClass
then
if (tree.symbol == defn.CompiletimeTesting_typeChecks) return Intrinsics.typeChecks(tree)
if (tree.symbol == defn.CompiletimeTesting_typeCheckErrors) return Intrinsics.typeCheckErrors(tree)
Expand Down
21 changes: 21 additions & 0 deletions library/src/scala/compiletime/ops/any.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package scala.compiletime
package ops

object any:
/** Equality comparison of two singleton types.
* ```scala
* val eq1: 1 == 1 = true
* val eq2: 1 == "1" = false
* val eq3: "1" == "1" = true
* ```
*/
type ==[X, Y] <: Boolean

/** Inequality comparison of two singleton types.
* ```scala
* val eq1: 1 != 1 = false
* val eq2: 1 != "1" = true
* val eq3: "1" != "1" = false
* ```
*/
type !=[X, Y] <: Boolean
36 changes: 36 additions & 0 deletions library/src/scala/compiletime/ops/boolean.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package scala.compiletime
package ops

object boolean:

/** Negation of a `Boolean` singleton type.
* ```scala
* val notFalse: ![false] = true
* val notTrue: ![true] = false
* ```
*/
type ![X <: Boolean] <: Boolean

/** Exclusive disjunction of two `Boolean` singleton types.
* ```scala
* val a: true ^ true = false
* val b: false ^ true = true
* ```
*/
type ^[X <: Boolean, Y <: Boolean] <: Boolean

/** Conjunction of two `Boolean` singleton types.
* ```scala
* val a: true && true = true
* val b: false && true = false
* ```
*/
type &&[X <: Boolean, Y <: Boolean] <: Boolean

/** Disjunction of two `Boolean` singleton types.
* ```scala
* val a: true || false = true
* val b: false || false = false
* ```
*/
type ||[X <: Boolean, Y <: Boolean] <: Boolean
149 changes: 149 additions & 0 deletions library/src/scala/compiletime/ops/int.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
package scala.compiletime
package ops

object int:
/** Addition of two `Int` singleton types.
* ```scala
* val sum: 2 + 2 = 4
* ```
*/
type +[X <: Int, Y <: Int] <: Int

/** Subtraction of two `Int` singleton types.
* ```scala
* val sub: 4 - 2 = 2
* ```
*/
type -[X <: Int, Y <: Int] <: Int

/** Multiplication of two `Int` singleton types.
* ```scala
* val mul: 4 * 2 = 8
* ```
*/
type *[X <: Int, Y <: Int] <: Int

/** Integer division of two `Int` singleton types.
* ```scala
* val div: 5 / 2 = 2
* ```
*/
type /[X <: Int, Y <: Int] <: Int

/** Remainder of the division of `X` by `Y`.
* ```scala
* val mod: 5 % 2 = 1
* ```
*/
type %[X <: Int, Y <: Int] <: Int

/** Binary left shift of `X` by `Y`.
* ```scala
* val lshift: 1 << 2 = 4
* ```
*/
type <<[X <: Int, Y <: Int] <: Int

/** Binary right shift of `X` by `Y`.
* ```scala
* val rshift: 10 >> 1 = 5
* ```
*/
type >>[X <: Int, Y <: Int] <: Int

/** Binary right shift of `X` by `Y`, filling the left with zeros.
* ```scala
* val rshiftzero: 10 >>> 1 = 5
* ```
*/
type >>>[X <: Int, Y <: Int] <: Int

/** Bitwise xor of `X` and `Y`.
* ```scala
* val xor: 10 ^ 30 = 20
* ```
*/
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
* ```
*/
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
* ```
*/
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
* ```
*/
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
* ```
*/
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
* ```
*/
type BitwiseAnd[X <: Int, Y <: Int] <: Int

/** Bitwise or of `X` and `Y`.
* ```scala
* val or: BitwiseOr[10, 11] = 11
* ```
*/
type BitwiseOr[X <: Int, Y <: Int] <: Int

/** Absolute value of an `Int` singleton type.
* ```scala
* val abs: Abs[-1] = 1
* ```
*/
type Abs[X <: Int] <: Int

/** Negation of an `Int` singleton type.
* ```scala
* val neg1: Neg[-1] = 1
* val neg2: Neg[1] = -1
* ```
*/
type Negate[X <: Int] <: Int

/** Minimum of two `Int` singleton types.
* ```scala
* val min: Min[-1, 1] = -1
* ```
*/
type Min[X <: Int, Y <: Int] <: Int

/** Maximum of two `Int` singleton types.
* ```scala
* val max: Max[-1, 1] = 1
* ```
*/
type Max[X <: Int, Y <: Int] <: Int

/** String conversion of an `Int` singleton type.
* ```scala
* val abs: ToString[1] = "1"
* ```
*/
type ToString[X <: Int] <: String
Loading