-
Notifications
You must be signed in to change notification settings - Fork 73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Local Discardable Heaps #149
Comments
I would make a related point, echoing @titzer from the meeting, that having to thread EDIT: with some care needed to support the cases where we want to put a host reference in a field of a Wasm object, or allow a Wasm reference to escape into the host. |
To be able to port optimizations from Erlang/BEAM, the heaps must be able to still reference things in the main heap. This is used for the optimization that binaries over 64 bytes are stored in the process heap as references to a reference counted copy in a global heap. The other external references are references to resources, which in WASM we use to hold DOM elements and other JS stuff. Everything else is copied between the Process heaps when sending messages. The Process heaps are currently protected with locks, so that either the owning Process or the send can write directly to the heap. If the owning Process has its own heap locked, then heap fragments are used, where the terms are copied into the heap fragment and that fragment is attached to the Process in a faster manner than the heap lock (using an intrusive list data structure). Both the global heap, the Process heaps and the heap fragments could all be this heap type. We use the same trait for all of them in our Rust code. |
I figured, which is why I mentioned (albeit in a buried fashion) the ability to define the new heap as an extension of a main heap so that all references in the main heap can be treated as references in the new heap. (Though you have to design your mutability/readability right for the appropriate covariance to be accepted.)
Most instructions already use the type of the reference they're operating on to determine, say, what the value of a field is. So similarly most instructions would not need a heap annotation. For most applications, they'll be using an instance-global heap, and so functions do not have to be parameterized. (That is, it's a pay-as-you-go feature with respect to functions.) Imports are only affected as much as their types are (and the fact that you'd need to import a heap). Typing rules would do a simple heap-subtyping check. Also, remember to put this in context. Currently
|
This is an apples-to-oranges comparison. There's a compounding cost to adding another dimension to the type system in that it touches the design and implementation (EDIT: and tooling) of every future feature - its not about the length of generated code. Consider for example that we're already planning a |
|
It's worth pointing out that taking heaps as parameters to functions is not enough; they have to be type parameters to functions, since they are part of types. Also, you have to disallow partial application of functions w.r.t. either heap parameters or references that mention heap parameters because then closures escape the scope of the declared heap. This is by no means a trivial problem to express in any type system. |
We already don't allow partial application of functions. Are you talking about And sorry for the lack of clarity—when I said parameters, I did not mean value parameters. As I mentioned above, I was thinking polymorphism with respect to heaps (for the case of Lumen). This would likely be similar in complexity to type polymorphism. I'm not advocating for any form of polymorphism for the MVP; I'm just exploring what would be necessary for a Post-MVP to support this feature (and what would be necessary for the MVP to be forwards-compatible with this feature). |
Yes, |
In #100, there was discussion of how to implement (OCaml) closures, and |
Issue WebAssembly/reference-types#69 requires that `ref.null` instructions include a reference type immediate. This concept isn't present in the bulk-memory proposal, but the encoding is (in element segment expressions). This change updates the binary and text format, but not the syntax. This is OK for now, since the only reference type allowed here is `funcref`.
This is not going to be included in the MVP, so I'll close this issue, but PRs adding future ideas to the post-MVP doc would be welcome. Perhaps this could be noted alongside the type parameters extension. |
In #121 (specifically here), there is discussion of how Erlang relies on keeping process heaps isolated for quick clean up. It seems this might be very important to good performance for at least Erlang, possibly for other systems as well, so I thought it might be useful to provide high-level notes on how to make this possible.
First, we need an instruction like
new_heap $h instr* end
. This creates a new heap that can be referenced withininstr*
via$h
. Supposing each Erlang process is run in its own stack, this instruction could be one of the first things in the root of each stack. Second, we need a reference type (constructor) that can be parameterized by a heap, sayheapref $h
(which also takes some additional parameter specifying the layout of the referenced data). Within the body ofnew_heap
, one would then be able to construct and track references within specifically the new heap. Third, we will need to make it possible for functions to have heaps as parameters. This makes it possible to call such functions from withinnew_heap
.If you design your (sub)typing system right, you can ensure no references in this new heap are still live once
end
is reached (or the relevant stack frame is cleaned up). Consequently, you can clean up the entire new heap all at once. It's also possible to have a variant of thenew_heap
instruction that makes it so that the new heap is an extension of an existing heap, which (with appropriate subtyping rules) would enable data in the new heap to (easily) point into the existing heap but not the other way around.Of course, this all relies on having the write (sub)typing rules. In particular, if
heapref $h <: anyref
holds, then all references in the new heap can leak asanyref
values. So this feature seems incompatible with having a (global) top type for references.The text was updated successfully, but these errors were encountered: