Skip to content

Commit e7f7e19

Browse files
Merge pull request #13400 from soronpo/ct_ops_expansion
Expand `compiletime.ops`
2 parents 1f48de1 + 18c23f4 commit e7f7e19

17 files changed

+1210
-74
lines changed

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

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,9 @@ class Definitions {
246246
@tu lazy val CompiletimeOpsPackage: Symbol = requiredPackage("scala.compiletime.ops")
247247
@tu lazy val CompiletimeOpsAnyModuleClass: Symbol = requiredModule("scala.compiletime.ops.any").moduleClass
248248
@tu lazy val CompiletimeOpsIntModuleClass: Symbol = requiredModule("scala.compiletime.ops.int").moduleClass
249+
@tu lazy val CompiletimeOpsLongModuleClass: Symbol = requiredModule("scala.compiletime.ops.long").moduleClass
250+
@tu lazy val CompiletimeOpsFloatModuleClass: Symbol = requiredModule("scala.compiletime.ops.float").moduleClass
251+
@tu lazy val CompiletimeOpsDoubleModuleClass: Symbol = requiredModule("scala.compiletime.ops.double").moduleClass
249252
@tu lazy val CompiletimeOpsStringModuleClass: Symbol = requiredModule("scala.compiletime.ops.string").moduleClass
250253
@tu lazy val CompiletimeOpsBooleanModuleClass: Symbol = requiredModule("scala.compiletime.ops.boolean").moduleClass
251254

@@ -1078,19 +1081,40 @@ class Definitions {
10781081
final def isCompiletime_S(sym: Symbol)(using Context): Boolean =
10791082
sym.name == tpnme.S && sym.owner == CompiletimeOpsIntModuleClass
10801083

1081-
private val compiletimePackageAnyTypes: Set[Name] = Set(tpnme.Equals, tpnme.NotEquals)
1082-
private val compiletimePackageIntTypes: Set[Name] = Set(
1084+
private val compiletimePackageAnyTypes: Set[Name] = Set(
1085+
tpnme.Equals, tpnme.NotEquals, tpnme.IsConst, tpnme.ToString
1086+
)
1087+
private val compiletimePackageNumericTypes: Set[Name] = Set(
10831088
tpnme.Plus, tpnme.Minus, tpnme.Times, tpnme.Div, tpnme.Mod,
10841089
tpnme.Lt, tpnme.Gt, tpnme.Ge, tpnme.Le,
1085-
tpnme.Abs, tpnme.Negate, tpnme.Min, tpnme.Max, tpnme.ToString,
1090+
tpnme.Abs, tpnme.Negate, tpnme.Min, tpnme.Max
1091+
)
1092+
private val compiletimePackageIntTypes: Set[Name] = compiletimePackageNumericTypes ++ Set[Name](
1093+
tpnme.ToString, // ToString is moved to ops.any and deprecated for ops.int
1094+
tpnme.NumberOfLeadingZeros, tpnme.ToLong, tpnme.ToFloat, tpnme.ToDouble,
1095+
tpnme.Xor, tpnme.BitwiseAnd, tpnme.BitwiseOr, tpnme.ASR, tpnme.LSL, tpnme.LSR
1096+
)
1097+
private val compiletimePackageLongTypes: Set[Name] = compiletimePackageNumericTypes ++ Set[Name](
1098+
tpnme.NumberOfLeadingZeros, tpnme.ToInt, tpnme.ToFloat, tpnme.ToDouble,
10861099
tpnme.Xor, tpnme.BitwiseAnd, tpnme.BitwiseOr, tpnme.ASR, tpnme.LSL, tpnme.LSR
10871100
)
1101+
private val compiletimePackageFloatTypes: Set[Name] = compiletimePackageNumericTypes ++ Set[Name](
1102+
tpnme.ToInt, tpnme.ToLong, tpnme.ToDouble
1103+
)
1104+
private val compiletimePackageDoubleTypes: Set[Name] = compiletimePackageNumericTypes ++ Set[Name](
1105+
tpnme.ToInt, tpnme.ToLong, tpnme.ToFloat
1106+
)
10881107
private val compiletimePackageBooleanTypes: Set[Name] = Set(tpnme.Not, tpnme.Xor, tpnme.And, tpnme.Or)
1089-
private val compiletimePackageStringTypes: Set[Name] = Set(tpnme.Plus)
1108+
private val compiletimePackageStringTypes: Set[Name] = Set(
1109+
tpnme.Plus, tpnme.Length, tpnme.Substring, tpnme.Matches
1110+
)
10901111
private val compiletimePackageOpTypes: Set[Name] =
10911112
Set(tpnme.S)
10921113
++ compiletimePackageAnyTypes
10931114
++ compiletimePackageIntTypes
1115+
++ compiletimePackageLongTypes
1116+
++ compiletimePackageFloatTypes
1117+
++ compiletimePackageDoubleTypes
10941118
++ compiletimePackageBooleanTypes
10951119
++ compiletimePackageStringTypes
10961120

@@ -1100,6 +1124,9 @@ class Definitions {
11001124
isCompiletime_S(sym)
11011125
|| sym.owner == CompiletimeOpsAnyModuleClass && compiletimePackageAnyTypes.contains(sym.name)
11021126
|| sym.owner == CompiletimeOpsIntModuleClass && compiletimePackageIntTypes.contains(sym.name)
1127+
|| sym.owner == CompiletimeOpsLongModuleClass && compiletimePackageLongTypes.contains(sym.name)
1128+
|| sym.owner == CompiletimeOpsFloatModuleClass && compiletimePackageFloatTypes.contains(sym.name)
1129+
|| sym.owner == CompiletimeOpsDoubleModuleClass && compiletimePackageDoubleTypes.contains(sym.name)
11031130
|| sym.owner == CompiletimeOpsBooleanModuleClass && compiletimePackageBooleanTypes.contains(sym.name)
11041131
|| sym.owner == CompiletimeOpsStringModuleClass && compiletimePackageStringTypes.contains(sym.name)
11051132
)

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

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -211,29 +211,38 @@ object StdNames {
211211
final val IOOBException: N = "IndexOutOfBoundsException"
212212
final val FunctionXXL: N = "FunctionXXL"
213213

214-
final val Abs: N = "Abs"
215-
final val And: N = "&&"
216-
final val BitwiseAnd: N = "BitwiseAnd"
217-
final val BitwiseOr: N = "BitwiseOr"
218-
final val Div: N = "/"
219-
final val Equals: N = "=="
220-
final val Ge: N = ">="
221-
final val Gt: N = ">"
222-
final val Le: N = "<="
223-
final val Lt: N = "<"
224-
final val Max: N = "Max"
225-
final val Min: N = "Min"
226-
final val Minus: N = "-"
227-
final val Mod: N = "%"
228-
final val Negate: N = "Negate"
229-
final val Not: N = "!"
230-
final val NotEquals: N = "!="
231-
final val Or: N = "||"
232-
final val Plus: N = "+"
233-
final val S: N = "S"
234-
final val Times: N = "*"
235-
final val ToString: N = "ToString"
236-
final val Xor: N = "^"
214+
final val Abs: N = "Abs"
215+
final val And: N = "&&"
216+
final val BitwiseAnd: N = "BitwiseAnd"
217+
final val BitwiseOr: N = "BitwiseOr"
218+
final val Div: N = "/"
219+
final val Equals: N = "=="
220+
final val Ge: N = ">="
221+
final val Gt: N = ">"
222+
final val IsConst: N = "IsConst"
223+
final val Le: N = "<="
224+
final val Length: N = "Length"
225+
final val Lt: N = "<"
226+
final val Matches: N = "Matches"
227+
final val Max: N = "Max"
228+
final val Min: N = "Min"
229+
final val Minus: N = "-"
230+
final val Mod: N = "%"
231+
final val Negate: N = "Negate"
232+
final val Not: N = "!"
233+
final val NotEquals: N = "!="
234+
final val NumberOfLeadingZeros: N = "NumberOfLeadingZeros"
235+
final val Or: N = "||"
236+
final val Plus: N = "+"
237+
final val S: N = "S"
238+
final val Substring: N = "Substring"
239+
final val Times: N = "*"
240+
final val ToInt: N = "ToInt"
241+
final val ToLong: N = "ToLong"
242+
final val ToFloat: N = "ToFloat"
243+
final val ToDouble: N = "ToDouble"
244+
final val ToString: N = "ToString"
245+
final val Xor: N = "^"
237246

238247
final val ClassfileAnnotation: N = "ClassfileAnnotation"
239248
final val ClassManifest: N = "ClassManifest"

0 commit comments

Comments
 (0)