munificent / craftinginterpreters

Repository for the book "Crafting Interpreters"
http://www.craftinginterpreters.com/
Other
8.87k stars 1.04k forks source link

GC might miss marking some functions #1109

Closed tiendo1011 closed 1 year ago

tiendo1011 commented 1 year ago

In chapter 26, In the implementation of markCompilerRoots, the GC only mark the functions outward from the current function, what about function next to it (its sibling)?

For example:

fun a() {}
fun b() {}

When compiling b, let's say it triggers a garbage collection, markCompilerRoots will not mark a to avoid it from being collected. Isn't it supposed to do so?

tiendo1011 commented 1 year ago

It seems that a will be marked because it's in the enclosing function constants list, since the enclosing function will be marked, its constants will be marked too.