Our great sponsors
-
WorkOS
The modern identity platform for B2B SaaS. The APIs are flexible and easy-to-use, supporting authentication, user identity, and complex enterprise features like SSO and SCIM provisioning.
-
boa
Boa is an embeddable and experimental Javascript engine written in Rust. Currently, it has support for some of the language.
> How is anything rooted here? The lifetime changed from 'arena to 'root but I don't see a root being created.
In this example, the Vec has been rooted previously. So pushing an object into the Vec will make it "transitively" rooted (accessible from the root). You would root a struct with the root_struct![1] macro, which works very similar to the root! macro shown in the post.
However you made you realize one error; The rooted `Vec` in the example you pointed is a by value type, but in the implementation you can only get references to rooted structs, so that example needs to be updated.
> But later we see roots not obeying a LIFO order, under "Preventing escapes" where roots are dynamically created and destroyed in an arbitrary order.
Objects are just a copyable wrapper around a pointer, so they are not the part that has the LIFO semantics. inside the root! macro[2] there is a `StackRoot` type that is the actual "root". The object just borrows from that so that is has a 'root lifetime and is valid post gc. The actual root struct is not exposed outside of the macro.
I hope this makes the distinction between "roots" and "objects" clearer. Objects are just pointers to heap data. When we root an object we store the data it points to on the root stack and create a new `StackRoot`. Then we say this object is rooted. But the struct that "does the rooting" is inside the macro and not exposed. Rooting a struct works similarly.
[1] https://github.com/CeleritasCelery/rune/blob/5a616efbed763b9...
Although you probably could use it for something else, Boa[1] is a good demonstration of this (it uses the GC crate, but the same principle probably applies).
[1]: https://github.com/boa-dev/boa
You might be interested to learn about the MMTk [1, 2] project which aspires to be a language agnostic library for garbage collection. It was used by the LXR authors [3] to develop a GC that beat production OpenJDK 11 collectors in throughput and latency. I believe they have a bunch of bindings to other VMs as well such as V8 (JavaScript), MRI (Ruby), Julia, GHC (Haskell), and PyPy (Python)!
[1]: https://www.mmtk.io/
Related posts
- Boa JavaScript Engine v0.17 released
- Given how powerful Emacs is and how important it has been for my computing over the past four decades, I think it would be more useful to me for people to label all non-emacs articles [Not Emacs]
- How dare you call Node.js "blazing fast"!
- Design of Emacs in Rust
- Really it have to be some kind of virus that spreads sneakly