This is a good point. There are two issues here: (1) Ensuring that layout does not retain strong references to DOM nodes across layout requests. Since JS GC is not concurrent, we need this invariant, as layout runs in a separate task. Currently layout places references to DOM nodes inside RenderBoxes. These need to become true weak references. Then we need to enforce that strong references to DOM nodes live no longer than a layout request. The typical way to enforce that some value never leaves a block of code is to use the region system, and I believe we can do that here. Will need to think it over and discuss with Niko.
(2) Ensuring that the Rust code in the script task does not retain strong references to DOM nodes that are invisible to JS GC. One way to do that would be to use the JS GC for the Rust GC in that task. Brian and I have talked about pluggable per-task garbage collectors; there nothing in Rust's design that comes to mind that would preclude using the JS GC for all Rust GC data in that one task (while using the Rust GC for other tasks). This is a more long-term project though, so perhaps it would be feasible in the short term to prevent nodes from being stored in untraced objects at all (perhaps by making them noncopyable and using the region system in a similar way to layout above). Will need to think about this a bit more. Patrick Robert O'Callahan <rob...@ocallahan.org> wrote: >On Mon, Feb 18, 2013 at 7:27 AM, Patrick Walton <pwal...@mozilla.com> >wrote: > >> On 2/17/13 3:16 AM, smaug wrote: >> >>> Curious, how does GC manage nodes? Do we explicitly trace even those >>> nodes which don't have js wrappers or do >>> we just use GC for everything in Rust? >>> >> >> All the nodes in Servo have JS wrappers at the moment, and their >lifetimes >> are managed by the JS garbage collector. The JS garbage collector >traces >> all nodes. The Rust garbage collector isn't really involved as far as >DOM >> nodes are concerned. > > >It's pretty important that we handle cycles through JS and Rust in a >clean >way without having to write unsafe code. Ideally we could do it without >having to write any special code. What prevents us from integrating >Rust >and JS GC so it Just Works (tm)? > >Rob >-- >Wrfhf pnyyrq gurz gbtrgure naq fnvq, “Lbh xabj gung gur ehyref bs gur >Tragvyrf ybeq vg bire gurz, naq gurve uvtu bssvpvnyf rkrepvfr nhgubevgl >bire gurz. Abg fb jvgu lbh. Vafgrnq, jubrire jnagf gb orpbzr terng >nzbat >lbh zhfg or lbhe freinag, naq jubrire jnagf gb or svefg zhfg or lbhe >fynir >— whfg nf gur Fba bs Zna qvq abg pbzr gb or freirq, ohg gb freir, naq >gb >tvir uvf yvsr nf n enafbz sbe znal.” [Znggurj 20:25-28] -- Sent from my Android phone with K-9 Mail. Please excuse my brevity. _______________________________________________ dev-servo mailing list dev-servo@lists.mozilla.org https://lists.mozilla.org/listinfo/dev-servo