Skip to content

Commit 051ad46

Browse files
committed
making definitions flow into where it's needed
1 parent b6d6580 commit 051ad46

File tree

3 files changed

+67
-42
lines changed

3 files changed

+67
-42
lines changed

src/dotty/tools/dotc/backend/jvm/BCodeTypes.scala

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -76,27 +76,29 @@ abstract class BCodeTypes extends BCodeIdiomatic {
7676
/*
7777
* must-single-thread
7878
*/
79-
def initBCodeTypes() {
79+
def initBCodeTypes(implicit ctx: core.Contexts.Context) {
80+
81+
import core.Symbols.defn
8082

8183
primitiveTypeMap =
8284
Map(
83-
UnitClass -> UNIT,
84-
BooleanClass -> BOOL,
85-
CharClass -> CHAR,
86-
ByteClass -> BYTE,
87-
ShortClass -> SHORT,
88-
IntClass -> INT,
89-
LongClass -> LONG,
90-
FloatClass -> FLOAT,
91-
DoubleClass -> DOUBLE
85+
defn.UnitClass -> UNIT,
86+
defn.BooleanClass -> BOOL,
87+
defn.CharClass -> CHAR,
88+
defn.ByteClass -> BYTE,
89+
defn.ShortClass -> SHORT,
90+
defn.IntClass -> INT,
91+
defn.LongClass -> LONG,
92+
defn.FloatClass -> FLOAT,
93+
defn.DoubleClass -> DOUBLE
9294
)
9395

9496
phantomTypeMap =
9597
Map(
96-
NothingClass -> RT_NOTHING,
97-
NullClass -> RT_NULL,
98-
NothingClass -> RT_NOTHING, // we map on purpose to RT_NOTHING, getting rid of the distinction compile-time vs. runtime for NullClass.
99-
NullClass -> RT_NULL // ditto.
98+
defn.NothingClass -> RT_NOTHING,
99+
defn.NullClass -> RT_NULL,
100+
defn.NothingClass -> RT_NOTHING, // we map on purpose to RT_NOTHING, getting rid of the distinction compile-time vs. runtime for NullClass.
101+
defn.NullClass -> RT_NULL // ditto.
100102
)
101103

102104
boxResultType =
@@ -109,7 +111,16 @@ abstract class BCodeTypes extends BCodeIdiomatic {
109111

110112
// boxed classes are looked up in the `exemplars` map by jvmWiseLUB().
111113
// Other than that, they aren't needed there (e.g., `isSubtypeOf()` special-cases boxed classes, similarly for others).
112-
val boxedClasses = List(BoxedBooleanClass, BoxedCharacterClass, BoxedByteClass, BoxedShortClass, BoxedIntClass, BoxedLongClass, BoxedFloatClass, BoxedDoubleClass)
114+
val boxedClasses = List(
115+
defn.BoxedBooleanClass,
116+
defn.BoxedCharClass,
117+
defn.BoxedByteClass,
118+
defn.BoxedShortClass,
119+
defn.BoxedIntClass,
120+
defn.BoxedLongClass,
121+
defn.BoxedFloatClass,
122+
defn.BoxedDoubleClass
123+
)
113124
for(csym <- boxedClasses) {
114125
val key = brefType(csym.javaBinaryName.toTypeName)
115126
val tr = buildExemplar(key, csym)
@@ -161,12 +172,12 @@ abstract class BCodeTypes extends BCodeIdiomatic {
161172
BType.getMethodType("()V") // necessary for JCodeMethodN.genStartConcat
162173
BType.getMethodType("()Ljava/lang/String;") // necessary for JCodeMethodN.genEndConcat
163174

164-
PartialFunctionReference = exemplar(PartialFunctionClass).c
175+
PartialFunctionReference = exemplar(defn.PartialFunctionClass).c
165176
for(idx <- 0 to definitions.MaxFunctionArity) {
166-
FunctionReference(idx) = exemplar(FunctionClass(idx))
167-
AbstractFunctionReference(idx) = exemplar(AbstractFunctionClass(idx))
177+
FunctionReference(idx) = exemplar(defn.FunctionClass(idx))
178+
AbstractFunctionReference(idx) = exemplar(defn.AbstractFunctionClass(idx))
168179
abstractFunctionArityMap += (AbstractFunctionReference(idx).c -> idx)
169-
AbstractPartialFunctionReference = exemplar(AbstractPartialFunctionClass).c
180+
AbstractPartialFunctionReference = exemplar(defn.AbstractPartialFunctionClass).c
170181
}
171182

172183
// later a few analyses (e.g. refreshInnerClasses) will look up BTypes based on descriptors in instructions

src/dotty/tools/dotc/backend/jvm/GenBCode.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ object GenBCode extends BCodeSyncAndTry {
267267

268268
arrivalPos = 0 // just in case
269269
scalaPrimitives.init
270-
initBCodeTypes()
270+
initBCodeTypes
271271

272272
// initBytecodeWriter invokes fullName, thus we have to run it before the typer-dependent thread is activated.
273273
bytecodeWriter = initBytecodeWriter(cleanup.getEntryPoints)

src/dotty/tools/dotc/backend/jvm/scalaPrimitives.scala

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -195,33 +195,40 @@ object scalaPrimitives {
195195
}
196196

197197
/** Initialize the primitive map */
198-
def init() {
198+
def init(implicit ctx: core.Contexts.Context) {
199+
200+
import core.Symbols.defn
201+
199202
primitives.clear()
200203
// scala.Any
201-
addPrimitive(Any_==, EQ)
202-
addPrimitive(Any_!=, NE)
203-
addPrimitive(Any_isInstanceOf, IS)
204-
addPrimitive(Any_asInstanceOf, AS)
205-
addPrimitive(Any_##, HASH)
204+
addPrimitive(defn.Any_==, EQ)
205+
addPrimitive(defn.Any_!=, NE)
206+
addPrimitive(defn.Any_isInstanceOf, IS)
207+
addPrimitive(defn.Any_asInstanceOf, AS)
208+
addPrimitive(defn.Any_##, HASH)
206209

207210
// java.lang.Object
208-
addPrimitive(Object_eq, ID)
209-
addPrimitive(Object_ne, NI)
210-
addPrimitive(Object_==, EQ)
211-
addPrimitive(Object_!=, NE)
212-
addPrimitive(Object_synchronized, SYNCHRONIZED)
213-
addPrimitive(Object_isInstanceOf, IS)
214-
addPrimitive(Object_asInstanceOf, AS)
211+
addPrimitive(defn.Object_eq, ID)
212+
addPrimitive(defn.Object_ne, NI)
213+
addPrimitive(defn.Object_==, EQ)
214+
addPrimitive(defn.Object_!=, NE)
215+
addPrimitive(defn.Object_synchronized, SYNCHRONIZED)
216+
addPrimitive(defn.Object_isInstanceOf, IS)
217+
addPrimitive(defn.Object_asInstanceOf, AS)
215218

216219
// java.lang.String
217-
addPrimitive(String_+, CONCAT)
220+
addPrimitive(defn.String_+, CONCAT)
221+
222+
import core.StdNames.nme
218223

219224
// scala.Array
225+
val ArrayClass = defn.ArrayClass
220226
addPrimitives(ArrayClass, nme.length, LENGTH)
221227
addPrimitives(ArrayClass, nme.apply, APPLY)
222228
addPrimitives(ArrayClass, nme.update, UPDATE)
223229

224230
// scala.Boolean
231+
val BooleanClass = defn.BooleanClass
225232
addPrimitives(BooleanClass, nme.EQ, EQ)
226233
addPrimitives(BooleanClass, nme.NE, NE)
227234
addPrimitives(BooleanClass, nme.UNARY_!, ZNOT)
@@ -232,6 +239,7 @@ object scalaPrimitives {
232239
addPrimitives(BooleanClass, nme.XOR, XOR)
233240

234241
// scala.Byte
242+
val ByteClass = defn.ByteClass
235243
addPrimitives(ByteClass, nme.EQ, EQ)
236244
addPrimitives(ByteClass, nme.NE, NE)
237245
addPrimitives(ByteClass, nme.ADD, ADD)
@@ -264,6 +272,7 @@ object scalaPrimitives {
264272
addPrimitives(ByteClass, nme.toDouble, B2D)
265273

266274
// scala.Short
275+
val ShortClass = defn.ShortClass
267276
addPrimitives(ShortClass, nme.EQ, EQ)
268277
addPrimitives(ShortClass, nme.NE, NE)
269278
addPrimitives(ShortClass, nme.ADD, ADD)
@@ -296,6 +305,7 @@ object scalaPrimitives {
296305
addPrimitives(ShortClass, nme.toDouble, S2D)
297306

298307
// scala.Char
308+
val CharClass = defn.CharClass
299309
addPrimitives(CharClass, nme.EQ, EQ)
300310
addPrimitives(CharClass, nme.NE, NE)
301311
addPrimitives(CharClass, nme.ADD, ADD)
@@ -327,6 +337,7 @@ object scalaPrimitives {
327337
addPrimitives(CharClass, nme.toDouble, C2D)
328338

329339
// scala.Int
340+
val IntClass = defn.IntClass
330341
addPrimitives(IntClass, nme.EQ, EQ)
331342
addPrimitives(IntClass, nme.NE, NE)
332343
addPrimitives(IntClass, nme.ADD, ADD)
@@ -358,6 +369,7 @@ object scalaPrimitives {
358369
addPrimitives(IntClass, nme.toDouble, I2D)
359370

360371
// scala.Long
372+
val LongClass = defn.LongClass
361373
addPrimitives(LongClass, nme.EQ, EQ)
362374
addPrimitives(LongClass, nme.NE, NE)
363375
addPrimitives(LongClass, nme.ADD, ADD)
@@ -389,6 +401,7 @@ object scalaPrimitives {
389401
addPrimitives(LongClass, nme.toDouble, L2D)
390402

391403
// scala.Float
404+
val FloatClass = defn.FloatClass
392405
addPrimitives(FloatClass, nme.EQ, EQ)
393406
addPrimitives(FloatClass, nme.NE, NE)
394407
addPrimitives(FloatClass, nme.ADD, ADD)
@@ -413,6 +426,7 @@ object scalaPrimitives {
413426
addPrimitives(FloatClass, nme.UNARY_-, NEG)
414427

415428
// scala.Double
429+
val DoubleClass = defn.DoubleClass
416430
addPrimitives(DoubleClass, nme.EQ, EQ)
417431
addPrimitives(DoubleClass, nme.NE, NE)
418432
addPrimitives(DoubleClass, nme.ADD, ADD)
@@ -526,14 +540,14 @@ object scalaPrimitives {
526540
}
527541

528542
/** If code is a coercion primitive, the result type */
529-
def generatedKind(code: Int): BType = code match {
530-
case B2B | C2B | S2B | I2B | L2B | F2B | D2B => BType.BYTE
531-
case B2C | C2C | S2C | I2C | L2C | F2C | D2C => BType.CHAR
532-
case B2S | C2S | S2S | I2S | L2S | F2S | D2S => BType.SHORT
533-
case B2I | C2I | S2I | I2I | L2I | F2I | D2I => BType.INT
534-
case B2L | C2L | S2L | I2L | L2L | F2L | D2L => BType.LONG
535-
case B2F | C2F | S2F | I2F | L2F | F2F | D2F => BType.FLOAT
536-
case B2D | C2D | S2D | I2D | L2D | F2D | D2D => BType.DOUBLE
543+
def generatedKind(code: Int): GenBCode.BType = code match {
544+
case B2B | C2B | S2B | I2B | L2B | F2B | D2B => GenBCode.BType.BYTE
545+
case B2C | C2C | S2C | I2C | L2C | F2C | D2C => GenBCode.BType.CHAR
546+
case B2S | C2S | S2S | I2S | L2S | F2S | D2S => GenBCode.BType.SHORT
547+
case B2I | C2I | S2I | I2I | L2I | F2I | D2I => GenBCode.BType.INT
548+
case B2L | C2L | S2L | I2L | L2L | F2L | D2L => GenBCode.BType.LONG
549+
case B2F | C2F | S2F | I2F | L2F | F2F | D2F => GenBCode.BType.FLOAT
550+
case B2D | C2D | S2D | I2D | L2D | F2D | D2D => GenBCode.BType.DOUBLE
537551
}
538552

539553
def isPrimitive(sym: Symbol): Boolean = primitives contains sym

0 commit comments

Comments
 (0)