Skip to content

Commit 5d1fe86

Browse files
committed
Rename Addr to Ref
1 parent ef43eb5 commit 5d1fe86

File tree

1 file changed

+44
-44
lines changed

1 file changed

+44
-44
lines changed

compiler/src/dotty/tools/dotc/transform/init/Semantic.scala

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class Semantic {
6363
/** An object with unknown initialization status */
6464
case object Cold extends Value
6565

66-
sealed abstract class Addr extends Value {
66+
sealed abstract class Ref extends Value {
6767
def klass: ClassSymbol
6868
def outer: Value
6969
def objekt: Objekt
@@ -84,7 +84,7 @@ class Semantic {
8484
}
8585

8686
/** A reference to the object under initialization pointed by `this` */
87-
case class ThisRef(klass: ClassSymbol, outer: Value, ctor: Symbol, args: List[Value]) extends Addr {
87+
case class ThisRef(klass: ClassSymbol, outer: Value, ctor: Symbol, args: List[Value]) extends Ref {
8888
/** Caches initialized fields */
8989
val objekt = Objekt(klass, fields = mutable.Map.empty, outers = mutable.Map(klass -> outer))
9090
}
@@ -93,7 +93,7 @@ class Semantic {
9393
*
9494
* We need to restrict nesting levels of `outer` to finitize the domain.
9595
*/
96-
case class Warm(klass: ClassSymbol, outer: Value, args: List[Value]) extends Addr {
96+
case class Warm(klass: ClassSymbol, outer: Value, args: List[Value]) extends Ref {
9797
val objekt = getCachedObject()
9898

9999
private def getCachedObject() =
@@ -106,13 +106,13 @@ class Semantic {
106106
}
107107

108108
/** A function value */
109-
case class Fun(expr: Tree, thisV: Addr, klass: ClassSymbol, env: Env) extends Value
109+
case class Fun(expr: Tree, thisV: Ref, klass: ClassSymbol, env: Env) extends Value
110110

111111
/** A value which represents a set of addresses
112112
*
113113
* It comes from `if` expressions.
114114
*/
115-
case class RefSet(refs: List[Fun | Addr]) extends Value
115+
case class RefSet(refs: List[Fun | Ref]) extends Value
116116

117117
// end of value definition
118118

@@ -152,10 +152,10 @@ class Semantic {
152152
def empty: Heap = mutable.Map.empty
153153

154154
extension (heap: Heap)
155-
def contains(addr: Warm): Boolean = heap.contains(addr)
156-
def apply(addr: Warm): Objekt = heap(addr)
157-
def update(addr: Warm, obj: Objekt): Unit =
158-
heap(addr) = obj
155+
def contains(ref: Warm): Boolean = heap.contains(ref)
156+
def apply(ref: Warm): Objekt = heap(ref)
157+
def update(ref: Warm, obj: Objekt): Unit =
158+
heap(ref) = obj
159159
end extension
160160
}
161161
type Heap = Heap.Heap
@@ -331,7 +331,7 @@ class Semantic {
331331
/** Conservatively approximate the value with `Cold` or `Hot` */
332332
def widenArg: Value =
333333
a match
334-
case _: Addr | _: Fun => Cold
334+
case _: Ref | _: Fun => Cold
335335
case RefSet(refs) => refs.map(_.widenArg).join
336336
case _ => a
337337

@@ -354,18 +354,18 @@ class Semantic {
354354
val error = AccessCold(field, source, trace.toVector)
355355
Result(Hot, error :: Nil)
356356

357-
case addr: Addr =>
358-
val target = if needResolve then resolve(addr.klass, field) else field
357+
case ref: Ref =>
358+
val target = if needResolve then resolve(ref.klass, field) else field
359359
val trace1 = trace.add(source)
360360
if target.is(Flags.Lazy) then
361361
given Trace = trace1
362362
val rhs = target.defTree.asInstanceOf[ValDef].rhs
363-
eval(rhs, addr, target.owner.asClass, cacheResult = true)
363+
eval(rhs, ref, target.owner.asClass, cacheResult = true)
364364
else
365-
val obj = addr.objekt
365+
val obj = ref.objekt
366366
if obj.hasField(target) then
367367
Result(obj.field(target), Nil)
368-
else if addr.isInstanceOf[Warm] then
368+
else if ref.isInstanceOf[Warm] then
369369
if target.is(Flags.ParamAccessor) then
370370
// possible for trait parameters
371371
// see tests/init/neg/trait2.scala
@@ -374,7 +374,7 @@ class Semantic {
374374
Result(Hot, Nil)
375375
else if target.hasSource then
376376
val rhs = target.defTree.asInstanceOf[ValOrDefDef].rhs
377-
eval(rhs, addr, target.owner.asClass, cacheResult = true)
377+
eval(rhs, ref, target.owner.asClass, cacheResult = true)
378378
else
379379
val error = CallUnknown(field, source, trace.toVector)
380380
Result(Hot, error :: Nil)
@@ -407,15 +407,15 @@ class Semantic {
407407
val error = CallCold(meth, source, trace.toVector)
408408
Result(Hot, error :: checkArgs)
409409

410-
case addr: Addr =>
410+
case ref: Ref =>
411411
val isLocal = !meth.owner.isClass
412412
val target =
413413
if !needResolve then
414414
meth
415415
else if superType.exists then
416-
resolveSuper(addr.klass, superType, meth)
416+
resolveSuper(ref.klass, superType, meth)
417417
else
418-
resolve(addr.klass, meth)
418+
resolve(ref.klass, meth)
419419

420420
if target.isOneOf(Flags.Method) then
421421
val trace1 = trace.add(source)
@@ -427,25 +427,25 @@ class Semantic {
427427
if target.isPrimaryConstructor then
428428
given Env = env2
429429
val tpl = cls.defTree.asInstanceOf[TypeDef].rhs.asInstanceOf[Template]
430-
val res = withTrace(trace.add(cls.defTree)) { eval(tpl, addr, cls, cacheResult = true) }
431-
Result(addr, res.errors)
430+
val res = withTrace(trace.add(cls.defTree)) { eval(tpl, ref, cls, cacheResult = true) }
431+
Result(ref, res.errors)
432432
else if target.isConstructor then
433433
given Env = env2
434-
eval(ddef.rhs, addr, cls, cacheResult = true)
434+
eval(ddef.rhs, ref, cls, cacheResult = true)
435435
else
436436
// normal method call
437437
withEnv(if isLocal then env else Env.empty) {
438-
eval(ddef.rhs, addr, cls, cacheResult = true) ++ checkArgs
438+
eval(ddef.rhs, ref, cls, cacheResult = true) ++ checkArgs
439439
}
440-
else if addr.canIgnoreMethodCall(target) then
440+
else if ref.canIgnoreMethodCall(target) then
441441
Result(Hot, Nil)
442442
else
443443
// no source code available
444444
val error = CallUnknown(target, source, trace.toVector)
445445
Result(Hot, error :: checkArgs)
446446
else
447447
// method call resolves to a field
448-
val obj = addr.objekt
448+
val obj = ref.objekt
449449
if obj.hasField(target) then
450450
Result(obj.field(target), Nil)
451451
else
@@ -494,12 +494,12 @@ class Semantic {
494494
val error = CallCold(ctor, source, trace1.toVector)
495495
Result(Hot, error :: Nil)
496496

497-
case addr: Addr =>
497+
case ref: Ref =>
498498
given Trace = trace1
499499
// widen the outer to finitize addresses
500-
val outer = addr match
500+
val outer = ref match
501501
case Warm(_, _: Warm, _) => Cold
502-
case _ => addr
502+
case _ => ref
503503

504504
val argsWidened = args.map(_.value).widenArgs
505505
val value = Warm(klass, outer, argsWidened)
@@ -549,7 +549,7 @@ class Semantic {
549549

550550
case Cold => Result(Cold, Nil)
551551

552-
case addr: Addr => eval(vdef.rhs, addr, klass)
552+
case ref: Ref => eval(vdef.rhs, ref, klass)
553553

554554
case _ =>
555555
report.error("unexpected defTree when accessing local variable, sym = " + sym.show + ", defTree = " + sym.defTree.show, source)
@@ -561,7 +561,7 @@ class Semantic {
561561
end extension
562562

563563
// ----- Promotion ----------------------------------------------------
564-
extension (addr: Addr)
564+
extension (ref: Ref)
565565
/** Whether the object is fully assigned
566566
*
567567
* It means all fields and outers are set. For performance, we don't check
@@ -572,9 +572,9 @@ class Semantic {
572572
* object freely, as its fields or outers may still reach uninitialized
573573
* objects.
574574
*/
575-
def isFullyFilled: Contextual[Boolean] = log("isFullyFilled " + addr, printer) {
576-
val obj = addr.objekt
577-
addr.klass.baseClasses.forall { klass =>
575+
def isFullyFilled: Contextual[Boolean] = log("isFullyFilled " + ref, printer) {
576+
val obj = ref.objekt
577+
ref.klass.baseClasses.forall { klass =>
578578
!klass.hasSource || {
579579
val nonInits = klass.info.decls.filter { member =>
580580
!member.isOneOf(Flags.Method | Flags.Lazy | Flags.Deferred)
@@ -690,7 +690,7 @@ class Semantic {
690690
end extension
691691

692692
// ----- Policies ------------------------------------------------------
693-
extension (value: Addr)
693+
extension (value: Ref)
694694
/** Can the method call on `value` be ignored?
695695
*
696696
* Note: assume overriding resolution has been performed.
@@ -713,7 +713,7 @@ class Semantic {
713713

714714
/** Process the worklist until done */
715715
@tailrec
716-
def work()(using Context): Unit =
716+
final def work()(using Context): Unit =
717717
pendingTasks match
718718
case task :: rest =>
719719
pendingTasks = rest
@@ -769,7 +769,7 @@ class Semantic {
769769
*
770770
* This method only handles cache logic and delegates the work to `cases`.
771771
*/
772-
def eval(expr: Tree, thisV: Addr, klass: ClassSymbol, cacheResult: Boolean = false): Contextual[Result] = log("evaluating " + expr.show + ", this = " + thisV.show, printer, (_: Result).show) {
772+
def eval(expr: Tree, thisV: Ref, klass: ClassSymbol, cacheResult: Boolean = false): Contextual[Result] = log("evaluating " + expr.show + ", this = " + thisV.show, printer, (_: Result).show) {
773773
val innerMap = cache.getOrElseUpdate(thisV, new EqHashMap[Tree, Value])
774774
if (innerMap.contains(expr)) Result(innerMap(expr), Errors.empty)
775775
else {
@@ -785,11 +785,11 @@ class Semantic {
785785
}
786786

787787
/** Evaluate a list of expressions */
788-
def eval(exprs: List[Tree], thisV: Addr, klass: ClassSymbol): Contextual[List[Result]] =
788+
def eval(exprs: List[Tree], thisV: Ref, klass: ClassSymbol): Contextual[List[Result]] =
789789
exprs.map { expr => eval(expr, thisV, klass) }
790790

791791
/** Evaluate arguments of methods */
792-
def evalArgs(args: List[Arg], thisV: Addr, klass: ClassSymbol): Contextual[(List[Error], List[ArgInfo])] =
792+
def evalArgs(args: List[Arg], thisV: Ref, klass: ClassSymbol): Contextual[(List[Error], List[ArgInfo])] =
793793
val errors = new mutable.ArrayBuffer[Error]
794794
val argInfos = new mutable.ArrayBuffer[ArgInfo]
795795
args.foreach { arg =>
@@ -809,7 +809,7 @@ class Semantic {
809809
*
810810
* Note: Recursive call should go to `eval` instead of `cases`.
811811
*/
812-
def cases(expr: Tree, thisV: Addr, klass: ClassSymbol): Contextual[Result] =
812+
def cases(expr: Tree, thisV: Ref, klass: ClassSymbol): Contextual[Result] =
813813
expr match {
814814
case Ident(nme.WILDCARD) =>
815815
// TODO: disallow `var x: T = _`
@@ -975,7 +975,7 @@ class Semantic {
975975
}
976976

977977
/** Handle semantics of leaf nodes */
978-
def cases(tp: Type, thisV: Addr, klass: ClassSymbol, source: Tree): Contextual[Result] = log("evaluating " + tp.show, printer, (_: Result).show) {
978+
def cases(tp: Type, thisV: Ref, klass: ClassSymbol, source: Tree): Contextual[Result] = log("evaluating " + tp.show, printer, (_: Result).show) {
979979
tp match {
980980
case _: ConstantType =>
981981
Result(Hot, Errors.empty)
@@ -1044,8 +1044,8 @@ class Semantic {
10441044
thisV match
10451045
case Hot => Hot
10461046

1047-
case addr: Addr =>
1048-
val obj = addr.objekt
1047+
case ref: Ref =>
1048+
val obj = ref.objekt
10491049
val curOpt = obj.klass.baseClasses.find(cls => reachable(cls, hops))
10501050
curOpt match
10511051
case Some(cur) =>
@@ -1066,7 +1066,7 @@ class Semantic {
10661066
}
10671067

10681068
/** Compute the outer value that correspond to `tref.prefix` */
1069-
def outerValue(tref: TypeRef, thisV: Addr, klass: ClassSymbol, source: Tree): Contextual[Result] =
1069+
def outerValue(tref: TypeRef, thisV: Ref, klass: ClassSymbol, source: Tree): Contextual[Result] =
10701070
val cls = tref.classSymbol.asClass
10711071
if tref.prefix == NoPrefix then
10721072
val enclosing = cls.owner.lexicallyEnclosingClass.asClass
@@ -1197,7 +1197,7 @@ class Semantic {
11971197
*
11981198
* This is intended to avoid type soundness issues in Dotty.
11991199
*/
1200-
def checkTermUsage(tpt: Tree, thisV: Addr, klass: ClassSymbol): Contextual[List[Error]] =
1200+
def checkTermUsage(tpt: Tree, thisV: Ref, klass: ClassSymbol): Contextual[List[Error]] =
12011201
val buf = new mutable.ArrayBuffer[Error]
12021202
val traverser = new TypeTraverser {
12031203
def traverse(tp: Type): Unit = tp match {

0 commit comments

Comments
 (0)