Skip to content

Commit cb3ab69

Browse files
committed
Move all singleton ops to scala.compiletime.ops package
As suggested in code review
1 parent b458372 commit cb3ab69

9 files changed

+20
-35
lines changed

compiler/src/dotty/tools/dotc/core/Definitions.scala

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,7 @@ class Definitions {
233233
@tu lazy val CompiletimeTesting_ErrorKind: Symbol = ctx.requiredModule("scala.compiletime.testing.ErrorKind")
234234
@tu lazy val CompiletimeTesting_ErrorKind_Parser: Symbol = CompiletimeTesting_ErrorKind.requiredMethod("Parser")
235235
@tu lazy val CompiletimeTesting_ErrorKind_Typer: Symbol = CompiletimeTesting_ErrorKind.requiredMethod("Typer")
236-
@tu lazy val CompiletimeIntPackageObject: Symbol = ctx.requiredModule("scala.compiletime.int.package")
237-
@tu lazy val CompiletimeBooleanPackageObject: Symbol = ctx.requiredModule("scala.compiletime.boolean.package")
236+
@tu lazy val CompiletimeOpsPackageObject: Symbol = ctx.requiredModule("scala.compiletime.ops.package")
238237

239238
/** The `scalaShadowing` package is used to safely modify classes and
240239
* objects in scala so that they can be used from dotty. They will
@@ -901,24 +900,16 @@ class Definitions {
901900
sym.name == tpnme.S && sym.owner == CompiletimePackageObject.moduleClass
902901

903902
final def isCompiletimeAppliedType(sym: Symbol)(implicit ctx: Context): Boolean = {
904-
def isPackageObjectAppliedType: Boolean =
905-
sym.owner == CompiletimePackageObject.moduleClass && Set(
906-
tpnme.S, tpnme.Equals, tpnme.NotEquals
907-
).contains(sym.name)
908-
909-
def isIntAppliedType: Boolean =
910-
sym.owner == CompiletimeIntPackageObject.moduleClass && Set(
903+
def isOpsPackageObjectAppliedType: Boolean =
904+
sym.owner == CompiletimeOpsPackageObject.moduleClass && Set(
905+
tpnme.Equals, tpnme.NotEquals,
911906
tpnme.Plus, tpnme.Minus, tpnme.Times, tpnme.Div, tpnme.Mod,
912907
tpnme.Lt, tpnme.Gt, tpnme.Ge, tpnme.Le,
913-
tpnme.Abs, tpnme.Negate, tpnme.Min, tpnme.Max
914-
).contains(sym.name)
915-
916-
def isBooleanAppliedType: Boolean =
917-
sym.owner == CompiletimeBooleanPackageObject.moduleClass && Set(
908+
tpnme.Abs, tpnme.Negate, tpnme.Min, tpnme.Max,
918909
tpnme.Not, tpnme.Xor, tpnme.And, tpnme.Or
919910
).contains(sym.name)
920911

921-
sym.isType && (isPackageObjectAppliedType || isIntAppliedType || isBooleanAppliedType)
912+
sym.isType && (isCompiletime_S(sym) || isOpsPackageObjectAppliedType)
922913
}
923914

924915

library/src/scala/compiletime/boolean/package.scala

Lines changed: 0 additions & 8 deletions
This file was deleted.

library/src/scala/compiletime/int/package.scala renamed to library/src/scala/compiletime/ops/package.scala

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package scala.compiletime
22

3-
package object int {
3+
package object ops {
4+
type ==[X <: AnyVal, Y <: AnyVal] <: Boolean
5+
type !=[X <: AnyVal, Y <: AnyVal] <: Boolean
6+
47
type +[X <: Int, Y <: Int] <: Int
58
type -[X <: Int, Y <: Int] <: Int
69
type *[X <: Int, Y <: Int] <: Int
@@ -16,4 +19,9 @@ package object int {
1619
type Negate[X <: Int] <: Int
1720
type Min[X <: Int, Y <: Int] <: Int
1821
type Max[X <: Int, Y <: Int] <: Int
22+
23+
type ![X <: Boolean] <: Boolean
24+
type ^[X <: Boolean, Y <: Boolean] <: Boolean
25+
type &&[X <: Boolean, Y <: Boolean] <: Boolean
26+
type ||[X <: Boolean, Y <: Boolean] <: Boolean
1927
}

library/src/scala/compiletime/package.scala

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,4 @@ package object compiletime {
6363
* }
6464
*/
6565
type S[N <: Int] <: Int
66-
67-
type ==[X <: AnyVal, Y <: AnyVal] <: Boolean
68-
type !=[X <: AnyVal, Y <: AnyVal] <: Boolean
6966
}

tests/neg/singleton-ops-match-type-scrutinee.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import scala.compiletime.int._
1+
import scala.compiletime.ops._
22

33
object Test {
44
type Max2[A <: Int, B <: Int] <: Int = (A < B) match {

tests/neg/singleton-ops-recursive-match-type.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import scala.compiletime.int._
1+
import scala.compiletime.ops._
22

33
object Test {
44
type GCD[A <: Int, B <: Int] <: Int = B match {

tests/neg/singleton-ops-type-alias.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import scala.compiletime.boolean._
1+
import scala.compiletime.ops._
22

33
object Test {
44
type Xor[A <: Boolean, B <: Boolean] = (A && ![B]) || (![A] && B)

tests/neg/singleton-ops.scala

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
import scala.compiletime._
2-
import scala.compiletime.int._
3-
import scala.compiletime.boolean._
1+
import scala.compiletime.ops._
42

53
object Test {
64
summon[2 + 3 =:= 6 - 1]

tests/pos/singleton-ops-composition.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import scala.compiletime.int._
2-
import scala.compiletime.boolean._
1+
import scala.compiletime.ops._
32

43
object Test {
54
val t0: 1 + 2 * 3 = 7

0 commit comments

Comments
 (0)