Skip to content

Commit 73c8849

Browse files
Merge pull request #10604 from dotty-staging/cleanup-compiletime
Cleanup compiletime package
2 parents efc9edb + a0a3742 commit 73c8849

File tree

11 files changed

+263
-263
lines changed

11 files changed

+263
-263
lines changed

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -231,20 +231,20 @@ class Definitions {
231231
@tu lazy val Compiletime_constValue : Symbol = CompiletimePackageObject.requiredMethod("constValue")
232232
@tu lazy val Compiletime_constValueOpt: Symbol = CompiletimePackageObject.requiredMethod("constValueOpt")
233233
@tu lazy val Compiletime_summonFrom : Symbol = CompiletimePackageObject.requiredMethod("summonFrom")
234-
@tu lazy val CompiletimeTestingPackageObject: Symbol = requiredModule("scala.compiletime.testing.package")
235-
@tu lazy val CompiletimeTesting_typeChecks: Symbol = CompiletimeTestingPackageObject.requiredMethod("typeChecks")
236-
@tu lazy val CompiletimeTesting_typeCheckErrors: Symbol = CompiletimeTestingPackageObject.requiredMethod("typeCheckErrors")
234+
@tu lazy val CompiletimeTestingPackage: Symbol = requiredPackage("scala.compiletime.testing")
235+
@tu lazy val CompiletimeTesting_typeChecks: Symbol = CompiletimeTestingPackage.requiredMethod("typeChecks")
236+
@tu lazy val CompiletimeTesting_typeCheckErrors: Symbol = CompiletimeTestingPackage.requiredMethod("typeCheckErrors")
237237
@tu lazy val CompiletimeTesting_ErrorClass: ClassSymbol = requiredClass("scala.compiletime.testing.Error")
238238
@tu lazy val CompiletimeTesting_Error: Symbol = requiredModule("scala.compiletime.testing.Error")
239239
@tu lazy val CompiletimeTesting_Error_apply = CompiletimeTesting_Error.requiredMethod(nme.apply)
240240
@tu lazy val CompiletimeTesting_ErrorKind: Symbol = requiredModule("scala.compiletime.testing.ErrorKind")
241241
@tu lazy val CompiletimeTesting_ErrorKind_Parser: Symbol = CompiletimeTesting_ErrorKind.requiredMethod("Parser")
242242
@tu lazy val CompiletimeTesting_ErrorKind_Typer: Symbol = CompiletimeTesting_ErrorKind.requiredMethod("Typer")
243-
@tu lazy val CompiletimeOpsPackageObject: Symbol = requiredModule("scala.compiletime.ops.package")
244-
@tu lazy val CompiletimeOpsPackageObjectAny: Symbol = requiredModule("scala.compiletime.ops.package.any")
245-
@tu lazy val CompiletimeOpsPackageObjectInt: Symbol = requiredModule("scala.compiletime.ops.package.int")
246-
@tu lazy val CompiletimeOpsPackageObjectString: Symbol = requiredModule("scala.compiletime.ops.package.string")
247-
@tu lazy val CompiletimeOpsPackageObjectBoolean: Symbol = requiredModule("scala.compiletime.ops.package.boolean")
243+
@tu lazy val CompiletimeOpsPackage: Symbol = requiredPackage("scala.compiletime.ops")
244+
@tu lazy val CompiletimeOpsAny: Symbol = requiredModule("scala.compiletime.ops.any")
245+
@tu lazy val CompiletimeOpsInt: Symbol = requiredModule("scala.compiletime.ops.int")
246+
@tu lazy val CompiletimeOpsString: Symbol = requiredModule("scala.compiletime.ops.string")
247+
@tu lazy val CompiletimeOpsBoolean: Symbol = requiredModule("scala.compiletime.ops.boolean")
248248

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

10971097
// ----- Scala-2 library patches --------------------------------------

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3985,11 +3985,11 @@ object Types {
39853985
if (owner == defn.CompiletimePackageObject.moduleClass) name match {
39863986
case tpnme.S if nArgs == 1 => constantFold1(natValue, _ + 1)
39873987
case _ => None
3988-
} else if (owner == defn.CompiletimeOpsPackageObjectAny.moduleClass) name match {
3988+
} else if (owner == defn.CompiletimeOpsAny.moduleClass) name match {
39893989
case tpnme.Equals if nArgs == 2 => constantFold2(constValue, _ == _)
39903990
case tpnme.NotEquals if nArgs == 2 => constantFold2(constValue, _ != _)
39913991
case _ => None
3992-
} else if (owner == defn.CompiletimeOpsPackageObjectInt.moduleClass) name match {
3992+
} else if (owner == defn.CompiletimeOpsInt.moduleClass) name match {
39933993
case tpnme.Abs if nArgs == 1 => constantFold1(intValue, _.abs)
39943994
case tpnme.Negate if nArgs == 1 => constantFold1(intValue, x => -x)
39953995
case tpnme.ToString if nArgs == 1 => constantFold1(intValue, _.toString)
@@ -4017,10 +4017,10 @@ object Types {
40174017
case tpnme.Min if nArgs == 2 => constantFold2(intValue, _ min _)
40184018
case tpnme.Max if nArgs == 2 => constantFold2(intValue, _ max _)
40194019
case _ => None
4020-
} else if (owner == defn.CompiletimeOpsPackageObjectString.moduleClass) name match {
4020+
} else if (owner == defn.CompiletimeOpsString.moduleClass) name match {
40214021
case tpnme.Plus if nArgs == 2 => constantFold2(stringValue, _ + _)
40224022
case _ => None
4023-
} else if (owner == defn.CompiletimeOpsPackageObjectBoolean.moduleClass) name match {
4023+
} else if (owner == defn.CompiletimeOpsBoolean.moduleClass) name match {
40244024
case tpnme.Not if nArgs == 1 => constantFold1(boolValue, x => !x)
40254025
case tpnme.And if nArgs == 2 => constantFold2(boolValue, _ && _)
40264026
case tpnme.Or if nArgs == 2 => constantFold2(boolValue, _ || _)

compiler/src/dotty/tools/dotc/typer/Inliner.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ object Inliner {
7272
*/
7373
def inlineCall(tree: Tree)(using Context): Tree = {
7474
if tree.symbol.denot != SymDenotations.NoDenotation
75-
&& tree.symbol.owner.companionModule == defn.CompiletimeTestingPackageObject
75+
&& tree.symbol.effectiveOwner == defn.CompiletimeTestingPackage.moduleClass
7676
then
7777
if (tree.symbol == defn.CompiletimeTesting_typeChecks) return Intrinsics.typeChecks(tree)
7878
if (tree.symbol == defn.CompiletimeTesting_typeCheckErrors) return Intrinsics.typeCheckErrors(tree)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package scala.compiletime
2+
package ops
3+
4+
object any:
5+
/** Equality comparison of two singleton types.
6+
* ```scala
7+
* val eq1: 1 == 1 = true
8+
* val eq2: 1 == "1" = false
9+
* val eq3: "1" == "1" = true
10+
* ```
11+
*/
12+
type ==[X, Y] <: Boolean
13+
14+
/** Inequality comparison of two singleton types.
15+
* ```scala
16+
* val eq1: 1 != 1 = false
17+
* val eq2: 1 != "1" = true
18+
* val eq3: "1" != "1" = false
19+
* ```
20+
*/
21+
type !=[X, Y] <: Boolean
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package scala.compiletime
2+
package ops
3+
4+
object boolean:
5+
6+
/** Negation of a `Boolean` singleton type.
7+
* ```scala
8+
* val notFalse: ![false] = true
9+
* val notTrue: ![true] = false
10+
* ```
11+
*/
12+
type ![X <: Boolean] <: Boolean
13+
14+
/** Exclusive disjunction of two `Boolean` singleton types.
15+
* ```scala
16+
* val a: true ^ true = false
17+
* val b: false ^ true = true
18+
* ```
19+
*/
20+
type ^[X <: Boolean, Y <: Boolean] <: Boolean
21+
22+
/** Conjunction of two `Boolean` singleton types.
23+
* ```scala
24+
* val a: true && true = true
25+
* val b: false && true = false
26+
* ```
27+
*/
28+
type &&[X <: Boolean, Y <: Boolean] <: Boolean
29+
30+
/** Disjunction of two `Boolean` singleton types.
31+
* ```scala
32+
* val a: true || false = true
33+
* val b: false || false = false
34+
* ```
35+
*/
36+
type ||[X <: Boolean, Y <: Boolean] <: Boolean
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
package scala.compiletime
2+
package ops
3+
4+
object int:
5+
/** Addition of two `Int` singleton types.
6+
* ```scala
7+
* val sum: 2 + 2 = 4
8+
* ```
9+
*/
10+
type +[X <: Int, Y <: Int] <: Int
11+
12+
/** Subtraction of two `Int` singleton types.
13+
* ```scala
14+
* val sub: 4 - 2 = 2
15+
* ```
16+
*/
17+
type -[X <: Int, Y <: Int] <: Int
18+
19+
/** Multiplication of two `Int` singleton types.
20+
* ```scala
21+
* val mul: 4 * 2 = 8
22+
* ```
23+
*/
24+
type *[X <: Int, Y <: Int] <: Int
25+
26+
/** Integer division of two `Int` singleton types.
27+
* ```scala
28+
* val div: 5 / 2 = 2
29+
* ```
30+
*/
31+
type /[X <: Int, Y <: Int] <: Int
32+
33+
/** Remainder of the division of `X` by `Y`.
34+
* ```scala
35+
* val mod: 5 % 2 = 1
36+
* ```
37+
*/
38+
type %[X <: Int, Y <: Int] <: Int
39+
40+
/** Binary left shift of `X` by `Y`.
41+
* ```scala
42+
* val lshift: 1 << 2 = 4
43+
* ```
44+
*/
45+
type <<[X <: Int, Y <: Int] <: Int
46+
47+
/** Binary right shift of `X` by `Y`.
48+
* ```scala
49+
* val rshift: 10 >> 1 = 5
50+
* ```
51+
*/
52+
type >>[X <: Int, Y <: Int] <: Int
53+
54+
/** Binary right shift of `X` by `Y`, filling the left with zeros.
55+
* ```scala
56+
* val rshiftzero: 10 >>> 1 = 5
57+
* ```
58+
*/
59+
type >>>[X <: Int, Y <: Int] <: Int
60+
61+
/** Bitwise xor of `X` and `Y`.
62+
* ```scala
63+
* val xor: 10 ^ 30 = 20
64+
* ```
65+
*/
66+
type ^[X <: Int, Y <: Int] <: Int
67+
68+
/** Less-than comparison of two `Int` singleton types.
69+
* ```scala
70+
* val lt1: 4 < 2 = false
71+
* val lt2: 2 < 4 = true
72+
* ```
73+
*/
74+
type <[X <: Int, Y <: Int] <: Boolean
75+
76+
/** Greater-than comparison of two `Int` singleton types.
77+
* ```scala
78+
* val gt1: 4 > 2 = true
79+
* val gt2: 2 > 2 = false
80+
* ```
81+
*/
82+
type >[X <: Int, Y <: Int] <: Boolean
83+
84+
/** Greater-or-equal comparison of two `Int` singleton types.
85+
* ```scala
86+
* val ge1: 4 >= 2 = true
87+
* val ge2: 2 >= 3 = false
88+
* ```
89+
*/
90+
type >=[X <: Int, Y <: Int] <: Boolean
91+
92+
/** Less-or-equal comparison of two `Int` singleton types.
93+
* ```scala
94+
* val lt1: 4 <= 2 = false
95+
* val lt2: 2 <= 2 = true
96+
* ```
97+
*/
98+
type <=[X <: Int, Y <: Int] <: Boolean
99+
100+
/** Bitwise and of `X` and `Y`.
101+
* ```scala
102+
* val and1: BitwiseAnd[4, 4] = 4
103+
* val and2: BitwiseAnd[10, 5] = 0
104+
* ```
105+
*/
106+
type BitwiseAnd[X <: Int, Y <: Int] <: Int
107+
108+
/** Bitwise or of `X` and `Y`.
109+
* ```scala
110+
* val or: BitwiseOr[10, 11] = 11
111+
* ```
112+
*/
113+
type BitwiseOr[X <: Int, Y <: Int] <: Int
114+
115+
/** Absolute value of an `Int` singleton type.
116+
* ```scala
117+
* val abs: Abs[-1] = 1
118+
* ```
119+
*/
120+
type Abs[X <: Int] <: Int
121+
122+
/** Negation of an `Int` singleton type.
123+
* ```scala
124+
* val neg1: Neg[-1] = 1
125+
* val neg2: Neg[1] = -1
126+
* ```
127+
*/
128+
type Negate[X <: Int] <: Int
129+
130+
/** Minimum of two `Int` singleton types.
131+
* ```scala
132+
* val min: Min[-1, 1] = -1
133+
* ```
134+
*/
135+
type Min[X <: Int, Y <: Int] <: Int
136+
137+
/** Maximum of two `Int` singleton types.
138+
* ```scala
139+
* val max: Max[-1, 1] = 1
140+
* ```
141+
*/
142+
type Max[X <: Int, Y <: Int] <: Int
143+
144+
/** String conversion of an `Int` singleton type.
145+
* ```scala
146+
* val abs: ToString[1] = "1"
147+
* ```
148+
*/
149+
type ToString[X <: Int] <: String

0 commit comments

Comments
 (0)