Skip to content

Commit

Permalink
Fix another crash in footprint computation
Browse files Browse the repository at this point in the history
  • Loading branch information
liufengyun committed Aug 23, 2024
1 parent dad0a95 commit 25a414b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
15 changes: 11 additions & 4 deletions compiler/src/dotty/tools/dotc/transform/init/Objects.scala
Original file line number Diff line number Diff line change
Expand Up @@ -605,14 +605,21 @@ class Objects(using Context @constructorOnly):
def visit(item: Value | Addr): Unit =
item match
case addr: Addr =>
reachalbeKeys += addr
val value = heap(addr)
if !visited.contains(value) then
toVisit += value
// 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
val value = heap(addr)
if !visited.contains(value) then
toVisit += value

case objRef: ObjectRef =>
// Thanks to initialization-time irrelevance, there is no need to
// visit the heap regions owned by other global objects.
//
// Other objects may also refer to memory regions of the current
// global object. However, they must do so by referring to fields
// of the current global objects --- which are already visited.

case value: Value =>
recur(value)
Expand Down
15 changes: 15 additions & 0 deletions tests/init-global/pos/footprint.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class Box(var x: String)

object A:
val a = new Box("a")
val c = foo()
def foo(): Box = C.c

object B:
val b = new Box("b")
val a = bar()

def bar(): Box = A.a

object C:
val c = new Box("c")

0 comments on commit 25a414b

Please sign in to comment.