Skip to content

Commit fb6e1f1

Browse files
committed
Move type to JVM tag conversion to Definitions
1 parent 454cf0c commit fb6e1f1

File tree

4 files changed

+18
-30
lines changed

4 files changed

+18
-30
lines changed

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

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -394,9 +394,9 @@ class Definitions {
394394
def ArrayModule(implicit ctx: Context) = ArrayModuleType.symbol.moduleClass.asClass
395395

396396

397-
lazy val UnitType: TypeRef = valueTypeRef("scala.Unit", BoxedUnitType, java.lang.Void.TYPE, UnitEnc)
397+
lazy val UnitType: TypeRef = valueTypeRef("scala.Unit", BoxedUnitType, java.lang.Void.TYPE, UnitEnc, nme.specializedTypeNames.Void)
398398
def UnitClass(implicit ctx: Context) = UnitType.symbol.asClass
399-
lazy val BooleanType = valueTypeRef("scala.Boolean", BoxedBooleanType, java.lang.Boolean.TYPE, BooleanEnc)
399+
lazy val BooleanType = valueTypeRef("scala.Boolean", BoxedBooleanType, java.lang.Boolean.TYPE, BooleanEnc, nme.specializedTypeNames.Boolean)
400400
def BooleanClass(implicit ctx: Context) = BooleanType.symbol.asClass
401401
lazy val Boolean_notR = BooleanClass.requiredMethodRef(nme.UNARY_!)
402402
def Boolean_! = Boolean_notR.symbol
@@ -415,13 +415,13 @@ class Definitions {
415415
})
416416
def Boolean_!= = Boolean_neqeqR.symbol
417417

418-
lazy val ByteType: TypeRef = valueTypeRef("scala.Byte", BoxedByteType, java.lang.Byte.TYPE, ByteEnc)
418+
lazy val ByteType: TypeRef = valueTypeRef("scala.Byte", BoxedByteType, java.lang.Byte.TYPE, ByteEnc, nme.specializedTypeNames.Byte)
419419
def ByteClass(implicit ctx: Context) = ByteType.symbol.asClass
420-
lazy val ShortType: TypeRef = valueTypeRef("scala.Short", BoxedShortType, java.lang.Short.TYPE, ShortEnc)
420+
lazy val ShortType: TypeRef = valueTypeRef("scala.Short", BoxedShortType, java.lang.Short.TYPE, ShortEnc, nme.specializedTypeNames.Short)
421421
def ShortClass(implicit ctx: Context) = ShortType.symbol.asClass
422-
lazy val CharType: TypeRef = valueTypeRef("scala.Char", BoxedCharType, java.lang.Character.TYPE, CharEnc)
422+
lazy val CharType: TypeRef = valueTypeRef("scala.Char", BoxedCharType, java.lang.Character.TYPE, CharEnc, nme.specializedTypeNames.Char)
423423
def CharClass(implicit ctx: Context) = CharType.symbol.asClass
424-
lazy val IntType: TypeRef = valueTypeRef("scala.Int", BoxedIntType, java.lang.Integer.TYPE, IntEnc)
424+
lazy val IntType: TypeRef = valueTypeRef("scala.Int", BoxedIntType, java.lang.Integer.TYPE, IntEnc, nme.specializedTypeNames.Int)
425425
def IntClass(implicit ctx: Context) = IntType.symbol.asClass
426426
lazy val Int_minusR = IntClass.requiredMethodRef(nme.MINUS, List(IntType))
427427
def Int_- = Int_minusR.symbol
@@ -437,7 +437,7 @@ class Definitions {
437437
def Int_>= = Int_geR.symbol
438438
lazy val Int_leR = IntClass.requiredMethodRef(nme.LE, List(IntType))
439439
def Int_<= = Int_leR.symbol
440-
lazy val LongType: TypeRef = valueTypeRef("scala.Long", BoxedLongType, java.lang.Long.TYPE, LongEnc)
440+
lazy val LongType: TypeRef = valueTypeRef("scala.Long", BoxedLongType, java.lang.Long.TYPE, LongEnc, nme.specializedTypeNames.Long)
441441
def LongClass(implicit ctx: Context) = LongType.symbol.asClass
442442
lazy val Long_XOR_Long = LongType.member(nme.XOR).requiredSymbol(
443443
x => (x is Method) && (x.info.firstParamTypes.head isRef defn.LongClass)
@@ -452,9 +452,9 @@ class Definitions {
452452
lazy val Long_divR = LongClass.requiredMethodRef(nme.DIV, List(LongType))
453453
def Long_/ = Long_divR.symbol
454454

455-
lazy val FloatType: TypeRef = valueTypeRef("scala.Float", BoxedFloatType, java.lang.Float.TYPE, FloatEnc)
455+
lazy val FloatType: TypeRef = valueTypeRef("scala.Float", BoxedFloatType, java.lang.Float.TYPE, FloatEnc, nme.specializedTypeNames.Float)
456456
def FloatClass(implicit ctx: Context) = FloatType.symbol.asClass
457-
lazy val DoubleType: TypeRef = valueTypeRef("scala.Double", BoxedDoubleType, java.lang.Double.TYPE, DoubleEnc)
457+
lazy val DoubleType: TypeRef = valueTypeRef("scala.Double", BoxedDoubleType, java.lang.Double.TYPE, DoubleEnc, nme.specializedTypeNames.Double)
458458
def DoubleClass(implicit ctx: Context) = DoubleType.symbol.asClass
459459

460460
lazy val BoxedUnitType: TypeRef = ctx.requiredClassRef("scala.runtime.BoxedUnit")
@@ -976,15 +976,17 @@ class Definitions {
976976

977977
private val boxedTypes = mutable.Map[TypeName, TypeRef]()
978978
private val valueTypeEnc = mutable.Map[TypeName, PrimitiveClassEnc]()
979+
private val typeTags = mutable.Map[TypeName, Name]().withDefaultValue(nme.specializedTypeNames.Object)
979980

980981
// private val unboxedTypeRef = mutable.Map[TypeName, TypeRef]()
981982
// private val javaTypeToValueTypeRef = mutable.Map[Class[_], TypeRef]()
982983
// private val valueTypeNameToJavaType = mutable.Map[TypeName, Class[_]]()
983984

984-
private def valueTypeRef(name: String, boxed: TypeRef, jtype: Class[_], enc: Int): TypeRef = {
985+
private def valueTypeRef(name: String, boxed: TypeRef, jtype: Class[_], enc: Int, tag: Name): TypeRef = {
985986
val vcls = ctx.requiredClassRef(name)
986987
boxedTypes(vcls.name) = boxed
987988
valueTypeEnc(vcls.name) = enc
989+
typeTags(vcls.name) = tag
988990
// unboxedTypeRef(boxed.name) = vcls
989991
// javaTypeToValueTypeRef(jtype) = vcls
990992
// valueTypeNameToJavaType(vcls.name) = jtype
@@ -994,6 +996,9 @@ class Definitions {
994996
/** The type of the boxed class corresponding to primitive value type `tp`. */
995997
def boxedType(tp: Type)(implicit ctx: Context): TypeRef = boxedTypes(scalaClassName(tp))
996998

999+
/** The JVM tag for `tp` if it's a primitive, `java.lang.Object` otherwise. */
1000+
def typeTag(tp: Type)(implicit ctx: Context): Name = typeTags(scalaClassName(tp))
1001+
9971002
type PrimitiveClassEnc = Int
9981003

9991004
val ByteEnc = 2

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,8 @@ object NameOps {
229229

230230
def specializedFor(classTargs: List[Types.Type], classTargsNames: List[Name], methodTargs: List[Types.Type], methodTarsNames: List[Name])(implicit ctx: Context): name.ThisName = {
231231

232-
val methodTags: Seq[Name] = (methodTargs zip methodTarsNames).sortBy(_._2).map(x => x._1.toTag)
233-
val classTags: Seq[Name] = (classTargs zip classTargsNames).sortBy(_._2).map(x => x._1.toTag)
232+
val methodTags: Seq[Name] = (methodTargs zip methodTarsNames).sortBy(_._2).map(x => defn.typeTag(x._1))
233+
val classTags: Seq[Name] = (classTargs zip classTargsNames).sortBy(_._2).map(x => defn.typeTag(x._1))
234234

235235
name.likeSpaced(name ++ nme.specializedTypeNames.prefix ++
236236
methodTags.fold(nme.EMPTY)(_ ++ _) ++ nme.specializedTypeNames.separator ++

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

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -745,23 +745,6 @@ object Types {
745745
else ctx.asSeenFrom(this, pre, cls)
746746
}
747747

748-
/** The JVM tag for this type, if it's a primitive, `java.lang.Object` otherwise. */
749-
final def toTag(implicit ctx: Context): Name = {
750-
classSymbol match {
751-
case t if t eq defn.IntClass => nme.specializedTypeNames.Int
752-
case t if t eq defn.BooleanClass => nme.specializedTypeNames.Boolean
753-
case t if t eq defn.ByteClass => nme.specializedTypeNames.Byte
754-
case t if t eq defn.LongClass => nme.specializedTypeNames.Long
755-
case t if t eq defn.ShortClass => nme.specializedTypeNames.Short
756-
case t if t eq defn.FloatClass => nme.specializedTypeNames.Float
757-
case t if t eq defn.UnitClass => nme.specializedTypeNames.Void
758-
case t if t eq defn.DoubleClass => nme.specializedTypeNames.Double
759-
case t if t eq defn.CharClass => nme.specializedTypeNames.Char
760-
case _ => nme.specializedTypeNames.Object
761-
}
762-
}
763-
764-
765748

766749
// ----- Subtype-related --------------------------------------------
767750

compiler/src/dotty/tools/dotc/transform/GenericSignatures.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ object GenericSignatures {
202202
else if (sym.isPrimitiveValueClass) {
203203
if (!primitiveOK) jsig(defn.ObjectType)
204204
else if (sym == defn.UnitClass) jsig(defn.BoxedUnitType)
205-
else builder.append(sym.info.toTag)
205+
else builder.append(defn.typeTag(sym.info))
206206
}
207207
else if (ValueClasses.isDerivedValueClass(sym)) {
208208
val unboxed = ValueClasses.valueClassUnbox(sym.asClass).info.finalResultType

0 commit comments

Comments
 (0)