Skip to content

Commit

Permalink
Move comment closer to code
Browse files Browse the repository at this point in the history
  • Loading branch information
liufengyun committed Aug 23, 2024
1 parent e388195 commit cba9ed1
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions compiler/src/dotty/tools/dotc/transform/init/Objects.scala
Original file line number Diff line number Diff line change
Expand Up @@ -600,15 +600,15 @@ class Objects(using Context @constructorOnly):
def footprint(heap: Data, thisV: Value, env: Env.Data, currentObj: ObjectRef): Data =
val toVisit = mutable.Queue.empty[Value]
val visited = mutable.Set.empty[Value]
val reachalbeKeys = mutable.Set.empty[Addr]
val reachableKeys = mutable.Set.empty[Addr]

def visit(item: Value | Addr): Unit =
item match
case addr: Addr =>
// Thanks to initialization-time irrelevance, there is no need to
// visit the heap regions owned by other global objects.
if addr.owner == currentObj.klass then
reachalbeKeys += addr
reachableKeys += addr
val value = heap(addr)
if !visited.contains(value) then
toVisit += value
Expand Down Expand Up @@ -636,7 +636,7 @@ class Objects(using Context @constructorOnly):
while toVisit.nonEmpty do
visit(toVisit.dequeue())

heap.filter((k, v) => reachalbeKeys.contains(k))
heap.filter((k, v) => reachableKeys.contains(k))

/** Perform garbage collection on the abstract heap.
*
Expand Down Expand Up @@ -1083,8 +1083,6 @@ class Objects(using Context @constructorOnly):

/**
* Handle new expression `new p.C(args)`.
* The actual instance might be cached without running the constructor.
* See tests/init-global/pos/cache-constructor.scala
*
* @param outer The value for `p`.
* @param klass The symbol of the class `C`.
Expand Down Expand Up @@ -1124,6 +1122,8 @@ class Objects(using Context @constructorOnly):
// klass.enclosingMethod returns its primary constructor
Env.resolveEnv(klass.owner.enclosingMethod, thisV, summon[Env.Data]).getOrElse(Cold -> Env.NoEnv)

// The actual instance might be cached without running the constructor.
// See tests/init-global/pos/cache-constructor.scala
val instance = OfClass(klass, outerWidened, ctor, args.map(_.value), envWidened)
callConstructor(instance, ctor, args)

Expand Down

0 comments on commit cba9ed1

Please sign in to comment.