Skip to content

Commit 5d441be

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 5d441be

File tree

1 file changed

+27
-14
lines changed

1 file changed

+27
-14
lines changed

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

Lines changed: 27 additions & 14 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,11 +1310,25 @@ 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))
1316+
1317+
private lazy val ScalaBoxedTypes: SimpleIdentityMap[Symbol, TypeRef] =
1318+
SimpleIdentityMap.Empty[Symbol]
1319+
.updated(ByteClass, BoxedByteType)
1320+
.updated(ShortClass, BoxedShortType)
1321+
.updated(CharClass, BoxedCharType)
1322+
.updated(IntClass, BoxedIntType)
1323+
.updated(LongClass, BoxedLongType)
1324+
.updated(FloatClass, BoxedFloatType)
1325+
.updated(DoubleClass, BoxedDoubleType)
1326+
.updated(UnitClass, BoxedUnitType)
1327+
.updated(BooleanClass, BoxedBooleanType)
1328+
1329+
val ScalaBoxedClasses: PerRun[collection.Set[Symbol]] = new PerRun(implicit ctx =>
1330+
Set(BoxedByteClass, BoxedShortClass, BoxedCharClass, BoxedIntClass, BoxedLongClass, BoxedFloatClass, BoxedDoubleClass, BoxedUnitClass, BoxedBooleanClass)
1331+
)
13181332

13191333
private val boxedTypes = mutable.Map[TypeName, TypeRef]()
13201334
private val valueTypeEnc = mutable.Map[TypeName, PrimitiveClassEnc]()
@@ -1324,9 +1338,8 @@ class Definitions {
13241338
// private val javaTypeToValueTypeRef = mutable.Map[Class[_], TypeRef]()
13251339
// private val valueTypeNamesToJavaType = mutable.Map[TypeName, Class[_]]()
13261340

1327-
private def valueTypeRef(name: String, boxed: TypeRef, jtype: Class[_], enc: Int, tag: Name): TypeRef = {
1341+
private def valueTypeRef(name: String, jtype: Class[_], enc: Int, tag: Name): TypeRef = {
13281342
val vcls = ctx.requiredClassRef(name)
1329-
boxedTypes(vcls.name) = boxed
13301343
valueTypeEnc(vcls.name) = enc
13311344
typeTags(vcls.name) = tag
13321345
// unboxedTypeRef(boxed.name) = vcls
@@ -1336,7 +1349,7 @@ class Definitions {
13361349
}
13371350

13381351
/** The type of the boxed class corresponding to primitive value type `tp`. */
1339-
def boxedType(tp: Type)(implicit ctx: Context): TypeRef = boxedTypes(scalaClassName(tp))
1352+
def boxedType(tp: Type)(implicit ctx: Context): TypeRef = ScalaBoxedTypes(tp.classSymbol)
13401353

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

0 commit comments

Comments
 (0)