Skip to content

Commit dba4dc3

Browse files
committed
Address review comments
syntheticCoreClasses and syntheticScalaClasses should be memoized (lazy val instead of def). Don't use braces when testing for explicit nulls flag.
1 parent 6d7f995 commit dba4dc3

File tree

1 file changed

+10
-34
lines changed

1 file changed

+10
-34
lines changed

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

Lines changed: 10 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -305,16 +305,8 @@ class Definitions {
305305
def AnyRefType: TypeRef = AnyRefAlias.typeRef
306306

307307
// TODO(abeln): modify usage sites to use `RefEq_eq/ne` once we migrate to explicit nulls?
308-
lazy val Object_eq: TermSymbol = if (ctx.explicitNulls) {
309-
RefEq_eq
310-
} else {
311-
enterMethod(ObjectClass, nme.eq, methOfAnyRef(BooleanType), Final)
312-
}
313-
lazy val Object_ne: TermSymbol = if (ctx.explicitNulls) {
314-
RefEq_ne
315-
} else {
316-
enterMethod(ObjectClass, nme.ne, methOfAnyRef(BooleanType), Final)
317-
}
308+
lazy val Object_eq: TermSymbol = if (ctx.explicitNulls) RefEq_eq else enterMethod(ObjectClass, nme.eq, methOfAnyRef(BooleanType), Final)
309+
lazy val Object_ne: TermSymbol = if (ctx.explicitNulls) RefEq_ne else enterMethod(ObjectClass, nme.ne, methOfAnyRef(BooleanType), Final)
318310
lazy val Object_synchronized: TermSymbol = enterPolyMethod(ObjectClass, nme.synchronized_, 1,
319311
pt => MethodType(List(pt.paramRefs(0)), pt.paramRefs(0)), Final)
320312
lazy val Object_clone: TermSymbol = enterMethod(ObjectClass, nme.clone_, MethodType(Nil, ObjectType), Protected)
@@ -349,11 +341,7 @@ class Definitions {
349341

350342
/** Method representing a throw */
351343
lazy val throwMethod: TermSymbol = {
352-
val argTpe = if (ctx.explicitNulls) {
353-
OrType(ThrowableType, NullType)
354-
} else {
355-
ThrowableType
356-
}
344+
val argTpe = if (ctx.explicitNulls) OrType(ThrowableType, NullType) else ThrowableType
357345
enterMethod(OpsPackageClass, nme.THROWkw, MethodType(List(argTpe), NothingType))
358346
}
359347

@@ -362,7 +350,7 @@ class Definitions {
362350
def NothingType: TypeRef = NothingClass.typeRef
363351
lazy val RuntimeNothingModuleRef: TermRef = ctx.requiredModuleRef("scala.runtime.Nothing")
364352

365-
/** `RefEq` is the trait defining the reference equality operators (`eq`, `neq`).
353+
/** `RefEq` is the trait defining the reference equality operators (`eq`, `ne`).
366354
* It's a supertype of both `AnyRef` (which is non-nullable) and `Null`.
367355
* With `RefEq`, we can compare `null` for reference equality a la `null eq foo`.
368356
* `RefEq` is just a marker trait and there's no corresponding class file, since it gets erased to `Object`.
@@ -391,11 +379,7 @@ class Definitions {
391379
}
392380

393381
lazy val NullClass: ClassSymbol = {
394-
val parents = if (ctx.explicitNulls) {
395-
List(AnyType, RefEqType)
396-
} else {
397-
List(ObjectType)
398-
}
382+
val parents = if (ctx.explicitNulls) List(AnyType, RefEqType) else List(ObjectType)
399383
enterCompleteClassSymbol(ScalaPackageClass, tpnme.Null, AbstractFinal, parents)
400384
}
401385
def NullType: TypeRef = NullClass.typeRef
@@ -1250,11 +1234,7 @@ class Definitions {
12501234

12511235
lazy val NotRuntimeClasses: Set[Symbol] = {
12521236
val classes: Set[Symbol] = Set(AnyClass, AnyValClass, NullClass, NothingClass)
1253-
if (ctx.explicitNulls) {
1254-
classes + RefEqClass
1255-
} else {
1256-
classes
1257-
}
1237+
if (ctx.explicitNulls) classes + RefEqClass else classes
12581238
}
12591239

12601240
/** Classes that are known not to have an initializer irrespective of
@@ -1468,7 +1448,7 @@ class Definitions {
14681448
// ----- Initialization ---------------------------------------------------
14691449

14701450
/** Lists core classes that don't have underlying bytecode, but are synthesized on-the-fly in every reflection universe */
1471-
def syntheticScalaClasses(implicit ctx: Context): List[TypeSymbol] = {
1451+
lazy val syntheticScalaClasses: List[TypeSymbol] = {
14721452
val synth = List(
14731453
AnyClass,
14741454
AnyRefAlias,
@@ -1487,18 +1467,14 @@ class Definitions {
14871467
else synth
14881468
}
14891469

1490-
def syntheticCoreClasses(implicit ctx: Context): List[Symbol] = syntheticScalaClasses ++ List(
1470+
lazy val syntheticCoreClasses: List[Symbol] = syntheticScalaClasses ++ List(
14911471
EmptyPackageVal,
14921472
OpsPackageClass)
14931473

14941474
/** Lists core methods that don't have underlying bytecode, but are synthesized on-the-fly in every reflection universe */
14951475
lazy val syntheticCoreMethods: List[TermSymbol] = {
14961476
val methods = AnyMethods ++ ObjectMethods ++ List(String_+, throwMethod)
1497-
if (ctx.explicitNulls) {
1498-
methods ++ RefEqMethods
1499-
} else {
1500-
methods
1501-
}
1477+
if (ctx.explicitNulls) methods ++ RefEqMethods else methods
15021478
}
15031479

15041480
lazy val reservedScalaClassNames: Set[Name] = syntheticScalaClasses.map(_.name).toSet
@@ -1513,7 +1489,7 @@ class Definitions {
15131489
ScalaPackageClass.enter(m)
15141490

15151491
// force initialization of every symbol that is synthesized or hijacked by the compiler
1516-
val forced = syntheticCoreClasses(ctx) ++ syntheticCoreMethods ++ ScalaValueClasses()
1492+
val forced = syntheticCoreClasses ++ syntheticCoreMethods ++ ScalaValueClasses()
15171493

15181494
isInitialized = true
15191495
}

0 commit comments

Comments
 (0)