Closed dubiousjim closed 4 weeks ago
Yeah this comment is backwards, this is from original Lua 5.1 source. Recent Lua source contains a correct comment (https://github.com/lua/lua/blob/master/lgc.h#L17-L28) that also applies to Luau implementation except that "moreover" statement would need to be tweaked.
lgc.cpp contains a full description of the scheme which correctly spells the invariant: https://github.com/luau-lang/luau/blob/master/VM/src/lgc.cpp#L58
This line describes the GC invariant as being the white objects can never point to black ones. Reading that made the GC code and other comments bewildering, until I realized that the referenced comment is probably just backwards. Isn't the invariant instead that black objects can never point to white ones? Before an object can be promoted from gray to black, all the collectable objects it points to must themselves be darkened (from white to gray, or left as gray or black if they've already been so marked).