Skip to content

Commit bb0ee8c

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 f3961ac commit bb0ee8c

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
@@ -1252,11 +1236,7 @@ class Definitions {
12521236

12531237
lazy val NotRuntimeClasses: Set[Symbol] = {
12541238
val classes: Set[Symbol] = Set(AnyClass, AnyValClass, NullClass, NothingClass)
1255-
if (ctx.explicitNulls) {
1256-
classes + RefEqClass
1257-
} else {
1258-
classes
1259-
}
1239+
if (ctx.explicitNulls) classes + RefEqClass else classes
12601240
}
12611241

12621242
/** Classes that are known not to have an initializer irrespective of
@@ -1470,7 +1450,7 @@ class Definitions {
14701450
// ----- Initialization ---------------------------------------------------
14711451

14721452
/** Lists core classes that don't have underlying bytecode, but are synthesized on-the-fly in every reflection universe */
1473-
def syntheticScalaClasses(implicit ctx: Context): List[TypeSymbol] = {
1453+
lazy val syntheticScalaClasses: List[TypeSymbol] = {
14741454
val synth = List(
14751455
AnyClass,
14761456
AnyRefAlias,
@@ -1489,18 +1469,14 @@ class Definitions {
14891469
else synth
14901470
}
14911471

1492-
def syntheticCoreClasses(implicit ctx: Context): List[Symbol] = syntheticScalaClasses ++ List(
1472+
lazy val syntheticCoreClasses: List[Symbol] = syntheticScalaClasses ++ List(
14931473
EmptyPackageVal,
14941474
OpsPackageClass)
14951475

14961476
/** Lists core methods that don't have underlying bytecode, but are synthesized on-the-fly in every reflection universe */
14971477
lazy val syntheticCoreMethods: List[TermSymbol] = {
14981478
val methods = AnyMethods ++ ObjectMethods ++ List(String_+, throwMethod)
1499-
if (ctx.explicitNulls) {
1500-
methods ++ RefEqMethods
1501-
} else {
1502-
methods
1503-
}
1479+
if (ctx.explicitNulls) methods ++ RefEqMethods else methods
15041480
}
15051481

15061482
lazy val reservedScalaClassNames: Set[Name] = syntheticScalaClasses.map(_.name).toSet
@@ -1515,7 +1491,7 @@ class Definitions {
15151491
ScalaPackageClass.enter(m)
15161492

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

15201496
isInitialized = true
15211497
}

0 commit comments

Comments
 (0)