Skip to content

Commit e879f3b

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 e0dbba6 commit e879f3b

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
@@ -467,10 +467,10 @@ class Definitions {
467467
def ArrayModule(implicit ctx: Context): ClassSymbol = ArrayModuleType.symbol.moduleClass.asClass
468468

469469

470-
lazy val UnitType: TypeRef = valueTypeRef("scala.Unit", BoxedUnitType, java.lang.Void.TYPE, UnitEnc, nme.specializedTypeNames.Void)
470+
lazy val UnitType: TypeRef = valueTypeRef("scala.Unit", java.lang.Void.TYPE, UnitEnc, nme.specializedTypeNames.Void)
471471
def UnitClass(implicit ctx: Context): ClassSymbol = UnitType.symbol.asClass
472472
def UnitModuleClass(implicit ctx: Context): Symbol = UnitType.symbol.asClass.linkedClass
473-
lazy val BooleanType: TypeRef = valueTypeRef("scala.Boolean", BoxedBooleanType, java.lang.Boolean.TYPE, BooleanEnc, nme.specializedTypeNames.Boolean)
473+
lazy val BooleanType: TypeRef = valueTypeRef("scala.Boolean", java.lang.Boolean.TYPE, BooleanEnc, nme.specializedTypeNames.Boolean)
474474
def BooleanClass(implicit ctx: Context): ClassSymbol = BooleanType.symbol.asClass
475475
lazy val Boolean_notR: TermRef = BooleanClass.requiredMethodRef(nme.UNARY_!)
476476
def Boolean_! : Symbol = Boolean_notR.symbol
@@ -489,13 +489,13 @@ class Definitions {
489489
})
490490
def Boolean_!= : Symbol = Boolean_neqeqR.symbol
491491

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

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

534534
lazy val BoxedUnitType: TypeRef = ctx.requiredClassRef("scala.runtime.BoxedUnit")
@@ -1310,23 +1310,23 @@ class Definitions {
13101310

13111311
private lazy val ScalaNumericValueTypes: collection.Set[TypeRef] = ScalaNumericValueTypeList.toSet
13121312
private lazy val ScalaValueTypes: collection.Set[TypeRef] = ScalaNumericValueTypes + UnitType + BooleanType
1313-
private lazy val ScalaBoxedTypes = ScalaValueTypes map (t => boxedTypes(t.name))
13141313

13151314
val ScalaNumericValueClasses: PerRun[collection.Set[Symbol]] = new PerRun(implicit ctx => ScalaNumericValueTypes.map(_.symbol))
13161315
val ScalaValueClasses: PerRun[collection.Set[Symbol]] = new PerRun(implicit ctx => ScalaValueTypes.map(_.symbol))
1317-
val ScalaBoxedClasses: PerRun[collection.Set[Symbol]] = new PerRun(implicit ctx => ScalaBoxedTypes.map(_.symbol))
13181316

1319-
private val boxedTypes = mutable.Map[TypeName, TypeRef]()
1317+
val ScalaBoxedClasses: PerRun[collection.Set[Symbol]] = new PerRun(implicit ctx =>
1318+
Set(BoxedByteClass, BoxedShortClass, BoxedCharClass, BoxedIntClass, BoxedLongClass, BoxedFloatClass, BoxedDoubleClass, BoxedUnitClass, BoxedBooleanClass)
1319+
)
1320+
13201321
private val valueTypeEnc = mutable.Map[TypeName, PrimitiveClassEnc]()
13211322
private val typeTags = mutable.Map[TypeName, Name]().withDefaultValue(nme.specializedTypeNames.Object)
13221323

13231324
// private val unboxedTypeRef = mutable.Map[TypeName, TypeRef]()
13241325
// private val javaTypeToValueTypeRef = mutable.Map[Class[_], TypeRef]()
13251326
// private val valueTypeNamesToJavaType = mutable.Map[TypeName, Class[_]]()
13261327

1327-
private def valueTypeRef(name: String, boxed: TypeRef, jtype: Class[_], enc: Int, tag: Name): TypeRef = {
1328+
private def valueTypeRef(name: String, jtype: Class[_], enc: Int, tag: Name): TypeRef = {
13281329
val vcls = ctx.requiredClassRef(name)
1329-
boxedTypes(vcls.name) = boxed
13301330
valueTypeEnc(vcls.name) = enc
13311331
typeTags(vcls.name) = tag
13321332
// unboxedTypeRef(boxed.name) = vcls
@@ -1336,7 +1336,19 @@ class Definitions {
13361336
}
13371337

13381338
/** The type of the boxed class corresponding to primitive value type `tp`. */
1339-
def boxedType(tp: Type)(implicit ctx: Context): TypeRef = boxedTypes(scalaClassName(tp))
1339+
def boxedType(tp: Type)(implicit ctx: Context): TypeRef = {
1340+
val cls = tp.classSymbol
1341+
if (cls eq ByteClass) BoxedByteType
1342+
else if (cls eq ShortClass) BoxedShortType
1343+
else if (cls eq CharClass) BoxedCharType
1344+
else if (cls eq IntClass) BoxedIntType
1345+
else if (cls eq LongClass) BoxedLongType
1346+
else if (cls eq FloatClass) BoxedFloatType
1347+
else if (cls eq DoubleClass) BoxedDoubleType
1348+
else if (cls eq UnitClass) BoxedUnitType
1349+
else if (cls eq BooleanClass) BoxedBooleanType
1350+
else sys.error(s"Not a primitive value type: $tp")
1351+
}
13401352

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

0 commit comments

Comments
 (0)