Skip to content

Commit 69630bf

Browse files
committed
Don't force BoxedUnitType when forcing UnitType
Otherwise we might end up trying to initialize UnitType recursively, which happens to work with the current implementation of non-volatile lazy vals, but won't work after the next commit.
1 parent 7ce5bcd commit 69630bf

File tree

1 file changed

+27
-15
lines changed

1 file changed

+27
-15
lines changed

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

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -469,10 +469,10 @@ class Definitions {
469469
def ArrayModule(implicit ctx: Context): ClassSymbol = ArrayModuleType.symbol.moduleClass.asClass
470470

471471

472-
lazy val UnitType: TypeRef = valueTypeRef("scala.Unit", BoxedUnitType, java.lang.Void.TYPE, UnitEnc, nme.specializedTypeNames.Void)
472+
lazy val UnitType: TypeRef = valueTypeRef("scala.Unit", java.lang.Void.TYPE, UnitEnc, nme.specializedTypeNames.Void)
473473
def UnitClass(implicit ctx: Context): ClassSymbol = UnitType.symbol.asClass
474474
def UnitModuleClass(implicit ctx: Context): Symbol = UnitType.symbol.asClass.linkedClass
475-
lazy val BooleanType: TypeRef = valueTypeRef("scala.Boolean", BoxedBooleanType, java.lang.Boolean.TYPE, BooleanEnc, nme.specializedTypeNames.Boolean)
475+
lazy val BooleanType: TypeRef = valueTypeRef("scala.Boolean", java.lang.Boolean.TYPE, BooleanEnc, nme.specializedTypeNames.Boolean)
476476
def BooleanClass(implicit ctx: Context): ClassSymbol = BooleanType.symbol.asClass
477477
lazy val Boolean_notR: TermRef = BooleanClass.requiredMethodRef(nme.UNARY_!)
478478
def Boolean_! : Symbol = Boolean_notR.symbol
@@ -491,13 +491,13 @@ class Definitions {
491491
})
492492
def Boolean_!= : Symbol = Boolean_neqeqR.symbol
493493

494-
lazy val ByteType: TypeRef = valueTypeRef("scala.Byte", BoxedByteType, java.lang.Byte.TYPE, ByteEnc, nme.specializedTypeNames.Byte)
494+
lazy val ByteType: TypeRef = valueTypeRef("scala.Byte", java.lang.Byte.TYPE, ByteEnc, nme.specializedTypeNames.Byte)
495495
def ByteClass(implicit ctx: Context): ClassSymbol = ByteType.symbol.asClass
496-
lazy val ShortType: TypeRef = valueTypeRef("scala.Short", BoxedShortType, java.lang.Short.TYPE, ShortEnc, nme.specializedTypeNames.Short)
496+
lazy val ShortType: TypeRef = valueTypeRef("scala.Short", java.lang.Short.TYPE, ShortEnc, nme.specializedTypeNames.Short)
497497
def ShortClass(implicit ctx: Context): ClassSymbol = ShortType.symbol.asClass
498-
lazy val CharType: TypeRef = valueTypeRef("scala.Char", BoxedCharType, java.lang.Character.TYPE, CharEnc, nme.specializedTypeNames.Char)
498+
lazy val CharType: TypeRef = valueTypeRef("scala.Char", java.lang.Character.TYPE, CharEnc, nme.specializedTypeNames.Char)
499499
def CharClass(implicit ctx: Context): ClassSymbol = CharType.symbol.asClass
500-
lazy val IntType: TypeRef = valueTypeRef("scala.Int", BoxedIntType, java.lang.Integer.TYPE, IntEnc, nme.specializedTypeNames.Int)
500+
lazy val IntType: TypeRef = valueTypeRef("scala.Int", java.lang.Integer.TYPE, IntEnc, nme.specializedTypeNames.Int)
501501
def IntClass(implicit ctx: Context): ClassSymbol = IntType.symbol.asClass
502502
lazy val Int_minusR: TermRef = IntClass.requiredMethodRef(nme.MINUS, List(IntType))
503503
def Int_- : Symbol = Int_minusR.symbol
@@ -513,7 +513,7 @@ class Definitions {
513513
def Int_>= : Symbol = Int_geR.symbol
514514
lazy val Int_leR: TermRef = IntClass.requiredMethodRef(nme.LE, List(IntType))
515515
def Int_<= : Symbol = Int_leR.symbol
516-
lazy val LongType: TypeRef = valueTypeRef("scala.Long", BoxedLongType, java.lang.Long.TYPE, LongEnc, nme.specializedTypeNames.Long)
516+
lazy val LongType: TypeRef = valueTypeRef("scala.Long", java.lang.Long.TYPE, LongEnc, nme.specializedTypeNames.Long)
517517
def LongClass(implicit ctx: Context): ClassSymbol = LongType.symbol.asClass
518518
lazy val Long_XOR_Long: Symbol = LongType.member(nme.XOR).requiredSymbol("method", nme.XOR, LongType.denot)(
519519
x => (x is Method) && (x.info.firstParamTypes.head isRef defn.LongClass)
@@ -528,9 +528,9 @@ class Definitions {
528528
lazy val Long_divR: TermRef = LongClass.requiredMethodRef(nme.DIV, List(LongType))
529529
def Long_/ : Symbol = Long_divR.symbol
530530

531-
lazy val FloatType: TypeRef = valueTypeRef("scala.Float", BoxedFloatType, java.lang.Float.TYPE, FloatEnc, nme.specializedTypeNames.Float)
531+
lazy val FloatType: TypeRef = valueTypeRef("scala.Float", java.lang.Float.TYPE, FloatEnc, nme.specializedTypeNames.Float)
532532
def FloatClass(implicit ctx: Context): ClassSymbol = FloatType.symbol.asClass
533-
lazy val DoubleType: TypeRef = valueTypeRef("scala.Double", BoxedDoubleType, java.lang.Double.TYPE, DoubleEnc, nme.specializedTypeNames.Double)
533+
lazy val DoubleType: TypeRef = valueTypeRef("scala.Double", java.lang.Double.TYPE, DoubleEnc, nme.specializedTypeNames.Double)
534534
def DoubleClass(implicit ctx: Context): ClassSymbol = DoubleType.symbol.asClass
535535

536536
lazy val BoxedUnitType: TypeRef = ctx.requiredClassRef("scala.runtime.BoxedUnit")
@@ -1330,23 +1330,23 @@ class Definitions {
13301330

13311331
private lazy val ScalaNumericValueTypes: collection.Set[TypeRef] = ScalaNumericValueTypeList.toSet
13321332
private lazy val ScalaValueTypes: collection.Set[TypeRef] = ScalaNumericValueTypes + UnitType + BooleanType
1333-
private lazy val ScalaBoxedTypes = ScalaValueTypes map (t => boxedTypes(t.name))
13341333

13351334
val ScalaNumericValueClasses: PerRun[collection.Set[Symbol]] = new PerRun(implicit ctx => ScalaNumericValueTypes.map(_.symbol))
13361335
val ScalaValueClasses: PerRun[collection.Set[Symbol]] = new PerRun(implicit ctx => ScalaValueTypes.map(_.symbol))
1337-
val ScalaBoxedClasses: PerRun[collection.Set[Symbol]] = new PerRun(implicit ctx => ScalaBoxedTypes.map(_.symbol))
13381336

1339-
private val boxedTypes = mutable.Map[TypeName, TypeRef]()
1337+
val ScalaBoxedClasses: PerRun[collection.Set[Symbol]] = new PerRun(implicit ctx =>
1338+
Set(BoxedByteClass, BoxedShortClass, BoxedCharClass, BoxedIntClass, BoxedLongClass, BoxedFloatClass, BoxedDoubleClass, BoxedUnitClass, BoxedBooleanClass)
1339+
)
1340+
13401341
private val valueTypeEnc = mutable.Map[TypeName, PrimitiveClassEnc]()
13411342
private val typeTags = mutable.Map[TypeName, Name]().withDefaultValue(nme.specializedTypeNames.Object)
13421343

13431344
// private val unboxedTypeRef = mutable.Map[TypeName, TypeRef]()
13441345
// private val javaTypeToValueTypeRef = mutable.Map[Class[_], TypeRef]()
13451346
// private val valueTypeNamesToJavaType = mutable.Map[TypeName, Class[_]]()
13461347

1347-
private def valueTypeRef(name: String, boxed: TypeRef, jtype: Class[_], enc: Int, tag: Name): TypeRef = {
1348+
private def valueTypeRef(name: String, jtype: Class[_], enc: Int, tag: Name): TypeRef = {
13481349
val vcls = ctx.requiredClassRef(name)
1349-
boxedTypes(vcls.name) = boxed
13501350
valueTypeEnc(vcls.name) = enc
13511351
typeTags(vcls.name) = tag
13521352
// unboxedTypeRef(boxed.name) = vcls
@@ -1356,7 +1356,19 @@ class Definitions {
13561356
}
13571357

13581358
/** The type of the boxed class corresponding to primitive value type `tp`. */
1359-
def boxedType(tp: Type)(implicit ctx: Context): TypeRef = boxedTypes(scalaClassName(tp))
1359+
def boxedType(tp: Type)(implicit ctx: Context): TypeRef = {
1360+
val cls = tp.classSymbol
1361+
if (cls eq ByteClass) BoxedByteType
1362+
else if (cls eq ShortClass) BoxedShortType
1363+
else if (cls eq CharClass) BoxedCharType
1364+
else if (cls eq IntClass) BoxedIntType
1365+
else if (cls eq LongClass) BoxedLongType
1366+
else if (cls eq FloatClass) BoxedFloatType
1367+
else if (cls eq DoubleClass) BoxedDoubleType
1368+
else if (cls eq UnitClass) BoxedUnitType
1369+
else if (cls eq BooleanClass) BoxedBooleanType
1370+
else sys.error(s"Not a primitive value type: $tp")
1371+
}
13601372

13611373
/** The JVM tag for `tp` if it's a primitive, `java.lang.Object` otherwise. */
13621374
def typeTag(tp: Type)(implicit ctx: Context): Name = typeTags(scalaClassName(tp))

0 commit comments

Comments
 (0)