Skip to content

Commit f7001a4

Browse files
committed
Make clear where symbols are entered or not.
In definitions some of the new... methods entered the created symbol while others did not. We now make that distrinction clear in the name.
1 parent 3f7614a commit f7001a4

File tree

1 file changed

+51
-51
lines changed

1 file changed

+51
-51
lines changed

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

Lines changed: 51 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -45,32 +45,29 @@ class Definitions {
4545
ctx.newSymbol(owner, name, flags | Permanent, info)
4646

4747
private def newClassSymbol(owner: Symbol, name: TypeName, flags: FlagSet, infoFn: ClassSymbol => Type) =
48-
ctx.newClassSymbol(owner, name, flags | Permanent, infoFn).entered
48+
ctx.newClassSymbol(owner, name, flags | Permanent, infoFn)
4949

50-
private def newCompleteClassSymbol(owner: Symbol, name: TypeName, flags: FlagSet, parents: List[TypeRef], decls: Scope = newScope) =
50+
private def enterCompleteClassSymbol(owner: Symbol, name: TypeName, flags: FlagSet, parents: List[TypeRef], decls: Scope = newScope) =
5151
ctx.newCompleteClassSymbol(owner, name, flags | Permanent, parents, decls).entered
5252

53-
private def newTopClassSymbol(name: TypeName, flags: FlagSet, parents: List[TypeRef]) =
54-
completeClass(newCompleteClassSymbol(ScalaPackageClass, name, flags, parents))
55-
56-
private def newTypeField(cls: ClassSymbol, name: TypeName, flags: FlagSet, scope: MutableScope) =
53+
private def enterTypeField(cls: ClassSymbol, name: TypeName, flags: FlagSet, scope: MutableScope) =
5754
scope.enter(newSymbol(cls, name, flags, TypeBounds.empty))
5855

59-
private def newTypeParam(cls: ClassSymbol, name: TypeName, flags: FlagSet, scope: MutableScope) =
60-
newTypeField(cls, name, flags | ClassTypeParamCreationFlags, scope)
56+
private def enterTypeParam(cls: ClassSymbol, name: TypeName, flags: FlagSet, scope: MutableScope) =
57+
enterTypeField(cls, name, flags | ClassTypeParamCreationFlags, scope)
6158

62-
private def newSyntheticTypeParam(cls: ClassSymbol, scope: MutableScope, paramFlags: FlagSet, suffix: String = "T0") =
63-
newTypeParam(cls, suffix.toTypeName.expandedName(cls), ExpandedName | paramFlags, scope)
59+
private def enterSyntheticTypeParam(cls: ClassSymbol, paramFlags: FlagSet, scope: MutableScope, suffix: String = "T0") =
60+
enterTypeParam(cls, suffix.toTypeName.expandedName(cls), ExpandedName | paramFlags, scope)
6461

6562
// NOTE: Ideally we would write `parentConstrs: => Type*` but SIP-24 is only
6663
// implemented in Dotty and not in Scala 2.
6764
// See <http://docs.scala-lang.org/sips/pending/repeated-byname.html>.
68-
private def specialPolyClass(name: TypeName, paramFlags: FlagSet, parentConstrs: => Seq[Type]): ClassSymbol = {
65+
private def enterSpecialPolyClass(name: TypeName, paramFlags: FlagSet, parentConstrs: => Seq[Type]): ClassSymbol = {
6966
val completer = new LazyType {
7067
def complete(denot: SymDenotation)(implicit ctx: Context): Unit = {
7168
val cls = denot.asClass.classSymbol
7269
val paramDecls = newScope
73-
val typeParam = newSyntheticTypeParam(cls, paramDecls, paramFlags)
70+
val typeParam = enterSyntheticTypeParam(cls, paramFlags, paramDecls)
7471
def instantiate(tpe: Type) =
7572
if (tpe.typeParams.nonEmpty) tpe.appliedTo(typeParam.typeRef)
7673
else tpe
@@ -83,27 +80,30 @@ class Definitions {
8380
}
8481

8582
private def newMethod(cls: ClassSymbol, name: TermName, info: Type, flags: FlagSet = EmptyFlags): TermSymbol =
86-
newSymbol(cls, name.encode, flags | Method, info).entered.asTerm
83+
newSymbol(cls, name.encode, flags | Method, info).asTerm
84+
85+
private def enterMethod(cls: ClassSymbol, name: TermName, info: Type, flags: FlagSet = EmptyFlags): TermSymbol =
86+
newMethod(cls, name, info, flags).entered
8787

88-
private def newAliasType(name: TypeName, tpe: Type, flags: FlagSet = EmptyFlags): TypeSymbol = {
88+
private def enterAliasType(name: TypeName, tpe: Type, flags: FlagSet = EmptyFlags): TypeSymbol = {
8989
val sym = newSymbol(ScalaPackageClass, name, flags, TypeAlias(tpe))
9090
ScalaPackageClass.currentPackageDecls.enter(sym)
9191
sym
9292
}
9393

94-
private def newPolyMethod(cls: ClassSymbol, name: TermName, typeParamCount: Int,
94+
private def enterPolyMethod(cls: ClassSymbol, name: TermName, typeParamCount: Int,
9595
resultTypeFn: PolyType => Type, flags: FlagSet = EmptyFlags) = {
9696
val tparamNames = tpnme.syntheticTypeParamNames(typeParamCount)
9797
val tparamBounds = tparamNames map (_ => TypeBounds.empty)
9898
val ptype = PolyType(tparamNames)(_ => tparamBounds, resultTypeFn)
99-
newMethod(cls, name, ptype, flags)
99+
enterMethod(cls, name, ptype, flags)
100100
}
101101

102-
private def newT1ParameterlessMethod(cls: ClassSymbol, name: TermName, resultTypeFn: PolyType => Type, flags: FlagSet) =
103-
newPolyMethod(cls, name, 1, resultTypeFn, flags)
102+
private def enterT1ParameterlessMethod(cls: ClassSymbol, name: TermName, resultTypeFn: PolyType => Type, flags: FlagSet) =
103+
enterPolyMethod(cls, name, 1, resultTypeFn, flags)
104104

105-
private def newT1EmptyParamsMethod(cls: ClassSymbol, name: TermName, resultTypeFn: PolyType => Type, flags: FlagSet) =
106-
newPolyMethod(cls, name, 1, pt => MethodType(Nil, resultTypeFn(pt)), flags)
105+
private def enterT1EmptyParamsMethod(cls: ClassSymbol, name: TermName, resultTypeFn: PolyType => Type, flags: FlagSet) =
106+
enterPolyMethod(cls, name, 1, pt => MethodType(Nil, resultTypeFn(pt)), flags)
107107

108108
private def mkArityArray(name: String, arity: Int, countFrom: Int): Array[TypeRef] = {
109109
val arr = new Array[TypeRef](arity + 1)
@@ -172,20 +172,20 @@ class Definitions {
172172
* def getClass: java.lang.Class[T] = ???
173173
* }
174174
*/
175-
lazy val AnyClass: ClassSymbol = completeClass(newCompleteClassSymbol(ScalaPackageClass, tpnme.Any, Abstract, Nil))
175+
lazy val AnyClass: ClassSymbol = completeClass(enterCompleteClassSymbol(ScalaPackageClass, tpnme.Any, Abstract, Nil))
176176
def AnyType = AnyClass.typeRef
177-
lazy val AnyValClass: ClassSymbol = completeClass(newCompleteClassSymbol(ScalaPackageClass, tpnme.AnyVal, Abstract, List(AnyClass.typeRef)))
177+
lazy val AnyValClass: ClassSymbol = completeClass(enterCompleteClassSymbol(ScalaPackageClass, tpnme.AnyVal, Abstract, List(AnyClass.typeRef)))
178178
def AnyValType = AnyValClass.typeRef
179179

180-
lazy val Any_== = newMethod(AnyClass, nme.EQ, methOfAny(BooleanType), Final)
181-
lazy val Any_!= = newMethod(AnyClass, nme.NE, methOfAny(BooleanType), Final)
182-
lazy val Any_equals = newMethod(AnyClass, nme.equals_, methOfAny(BooleanType))
183-
lazy val Any_hashCode = newMethod(AnyClass, nme.hashCode_, MethodType(Nil, IntType))
184-
lazy val Any_toString = newMethod(AnyClass, nme.toString_, MethodType(Nil, StringType))
185-
lazy val Any_## = newMethod(AnyClass, nme.HASHHASH, ExprType(IntType), Final)
186-
lazy val Any_getClass = newMethod(AnyClass, nme.getClass_, MethodType(Nil, ClassClass.typeRef.appliedTo(TypeBounds.empty)), Final)
187-
lazy val Any_isInstanceOf = newT1ParameterlessMethod(AnyClass, nme.isInstanceOf_, _ => BooleanType, Final)
188-
lazy val Any_asInstanceOf = newT1ParameterlessMethod(AnyClass, nme.asInstanceOf_, PolyParam(_, 0), Final)
180+
lazy val Any_== = enterMethod(AnyClass, nme.EQ, methOfAny(BooleanType), Final)
181+
lazy val Any_!= = enterMethod(AnyClass, nme.NE, methOfAny(BooleanType), Final)
182+
lazy val Any_equals = enterMethod(AnyClass, nme.equals_, methOfAny(BooleanType))
183+
lazy val Any_hashCode = enterMethod(AnyClass, nme.hashCode_, MethodType(Nil, IntType))
184+
lazy val Any_toString = enterMethod(AnyClass, nme.toString_, MethodType(Nil, StringType))
185+
lazy val Any_## = enterMethod(AnyClass, nme.HASHHASH, ExprType(IntType), Final)
186+
lazy val Any_getClass = enterMethod(AnyClass, nme.getClass_, MethodType(Nil, ClassClass.typeRef.appliedTo(TypeBounds.empty)), Final)
187+
lazy val Any_isInstanceOf = enterT1ParameterlessMethod(AnyClass, nme.isInstanceOf_, _ => BooleanType, Final)
188+
lazy val Any_asInstanceOf = enterT1ParameterlessMethod(AnyClass, nme.asInstanceOf_, PolyParam(_, 0), Final)
189189

190190
def AnyMethods = List(Any_==, Any_!=, Any_equals, Any_hashCode,
191191
Any_toString, Any_##, Any_getClass, Any_isInstanceOf, Any_asInstanceOf)
@@ -205,37 +205,37 @@ class Definitions {
205205
}
206206
def ObjectType = ObjectClass.typeRef
207207

208-
lazy val AnyRefAlias: TypeSymbol = newAliasType(tpnme.AnyRef, ObjectType)
208+
lazy val AnyRefAlias: TypeSymbol = enterAliasType(tpnme.AnyRef, ObjectType)
209209
def AnyRefType = AnyRefAlias.typeRef
210210

211-
lazy val Object_eq = newMethod(ObjectClass, nme.eq, methOfAnyRef(BooleanType), Final)
212-
lazy val Object_ne = newMethod(ObjectClass, nme.ne, methOfAnyRef(BooleanType), Final)
213-
lazy val Object_synchronized = newPolyMethod(ObjectClass, nme.synchronized_, 1,
211+
lazy val Object_eq = enterMethod(ObjectClass, nme.eq, methOfAnyRef(BooleanType), Final)
212+
lazy val Object_ne = enterMethod(ObjectClass, nme.ne, methOfAnyRef(BooleanType), Final)
213+
lazy val Object_synchronized = enterPolyMethod(ObjectClass, nme.synchronized_, 1,
214214
pt => MethodType(List(PolyParam(pt, 0)), PolyParam(pt, 0)), Final)
215-
lazy val Object_clone = newMethod(ObjectClass, nme.clone_, MethodType(Nil, ObjectType), Protected)
216-
lazy val Object_finalize = newMethod(ObjectClass, nme.finalize_, MethodType(Nil, UnitType), Protected)
217-
lazy val Object_notify = newMethod(ObjectClass, nme.notify_, MethodType(Nil, UnitType))
218-
lazy val Object_notifyAll = newMethod(ObjectClass, nme.notifyAll_, MethodType(Nil, UnitType))
219-
lazy val Object_wait = newMethod(ObjectClass, nme.wait_, MethodType(Nil, UnitType))
220-
lazy val Object_waitL = newMethod(ObjectClass, nme.wait_, MethodType(LongType :: Nil, UnitType))
221-
lazy val Object_waitLI = newMethod(ObjectClass, nme.wait_, MethodType(LongType :: IntType :: Nil, UnitType))
215+
lazy val Object_clone = enterMethod(ObjectClass, nme.clone_, MethodType(Nil, ObjectType), Protected)
216+
lazy val Object_finalize = enterMethod(ObjectClass, nme.finalize_, MethodType(Nil, UnitType), Protected)
217+
lazy val Object_notify = enterMethod(ObjectClass, nme.notify_, MethodType(Nil, UnitType))
218+
lazy val Object_notifyAll = enterMethod(ObjectClass, nme.notifyAll_, MethodType(Nil, UnitType))
219+
lazy val Object_wait = enterMethod(ObjectClass, nme.wait_, MethodType(Nil, UnitType))
220+
lazy val Object_waitL = enterMethod(ObjectClass, nme.wait_, MethodType(LongType :: Nil, UnitType))
221+
lazy val Object_waitLI = enterMethod(ObjectClass, nme.wait_, MethodType(LongType :: IntType :: Nil, UnitType))
222222

223223
def ObjectMethods = List(Object_eq, Object_ne, Object_synchronized, Object_clone,
224224
Object_finalize, Object_notify, Object_notifyAll, Object_wait, Object_waitL, Object_waitLI)
225225

226226
/** Dummy method needed by elimByName */
227-
lazy val dummyApply = newPolyMethod(
227+
lazy val dummyApply = enterPolyMethod(
228228
OpsPackageClass, nme.dummyApply, 1,
229229
pt => MethodType(List(FunctionOf(Nil, PolyParam(pt, 0))), PolyParam(pt, 0)))
230230

231231
/** Method representing a throw */
232-
lazy val throwMethod = newMethod(OpsPackageClass, nme.THROWkw,
232+
lazy val throwMethod = enterMethod(OpsPackageClass, nme.THROWkw,
233233
MethodType(List(ThrowableType), NothingType))
234234

235-
lazy val NothingClass: ClassSymbol = newCompleteClassSymbol(
235+
lazy val NothingClass: ClassSymbol = enterCompleteClassSymbol(
236236
ScalaPackageClass, tpnme.Nothing, AbstractFinal, List(AnyClass.typeRef))
237237
def NothingType = NothingClass.typeRef
238-
lazy val NullClass: ClassSymbol = newCompleteClassSymbol(
238+
lazy val NullClass: ClassSymbol = enterCompleteClassSymbol(
239239
ScalaPackageClass, tpnme.Null, AbstractFinal, List(ObjectClass.typeRef))
240240
def NullType = NullClass.typeRef
241241

@@ -281,7 +281,7 @@ class Definitions {
281281
lazy val SingletonClass: ClassSymbol =
282282
// needed as a synthetic class because Scala 2.x refers to it in classfiles
283283
// but does not define it as an explicit class.
284-
newCompleteClassSymbol(
284+
enterCompleteClassSymbol(
285285
ScalaPackageClass, tpnme.Singleton, PureInterfaceCreationFlags | Final,
286286
List(AnyClass.typeRef), EmptyScope)
287287

@@ -387,17 +387,17 @@ class Definitions {
387387
lazy val BoxedDoubleModule = ctx.requiredModule("java.lang.Double")
388388
lazy val BoxedUnitModule = ctx.requiredModule("java.lang.Void")
389389

390-
lazy val ByNameParamClass2x = specialPolyClass(tpnme.BYNAME_PARAM_CLASS, Covariant, Seq(AnyType))
391-
lazy val EqualsPatternClass = specialPolyClass(tpnme.EQUALS_PATTERN, EmptyFlags, Seq(AnyType))
390+
lazy val ByNameParamClass2x = enterSpecialPolyClass(tpnme.BYNAME_PARAM_CLASS, Covariant, Seq(AnyType))
391+
lazy val EqualsPatternClass = enterSpecialPolyClass(tpnme.EQUALS_PATTERN, EmptyFlags, Seq(AnyType))
392392

393-
lazy val RepeatedParamClass = specialPolyClass(tpnme.REPEATED_PARAM_CLASS, Covariant, Seq(ObjectType, SeqType))
393+
lazy val RepeatedParamClass = enterSpecialPolyClass(tpnme.REPEATED_PARAM_CLASS, Covariant, Seq(ObjectType, SeqType))
394394

395395
// fundamental classes
396396
lazy val StringClass = ctx.requiredClass("java.lang.String")
397397
def StringType: Type = StringClass.typeRef
398398
lazy val StringModule = StringClass.linkedClass
399399

400-
lazy val String_+ = newMethod(StringClass, nme.raw.PLUS, methOfAny(StringType), Final)
400+
lazy val String_+ = enterMethod(StringClass, nme.raw.PLUS, methOfAny(StringType), Final)
401401
lazy val String_valueOf_Object = StringModule.info.member(nme.valueOf).suchThat(_.info.firstParamTypes match {
402402
case List(pt) => (pt isRef AnyClass) || (pt isRef ObjectClass)
403403
case _ => false

0 commit comments

Comments
 (0)