-
Notifications
You must be signed in to change notification settings - Fork 57
How much would "anyref" as a new value type help? #9
Comments
That's a really good point: in the absence of GC data types (or with them turned off), So if we only have Another question is whether, in the web embedding, But with that, it seems like we would avoid:
The remaining uses of the binding section would be:
|
A few questions:
|
@lukewagner That's a good argument about strong types for WebIDL. Worth considering whether imported host types (of representation Looking back at WebAssembly/gc#27, I noticed that @DLehenbauer basically proposed this 21 days ago. |
@lukewagner I also think we definitely want |
@titzer Yeah, NaN-boxing vs. pointer-to-GC-cell is the same thing I was wondering about. While it seems we'll want
|
Agreed that supporting anyref would be much better than the ongoing explosion of features for host bindings. Regarding anyref vs any: I had assumed that the GC extension would eventually allow types like (ref i32) or similar. Semantically, they are references to ints, but an engine could optimise them into tagged ints where applicable. Under this approach, they would naturally inhabit anyref, and so would all JS values. A separate "any" type wouldn't be needed (nor make much sense). I guess I'm missing something regarding the representation of a separate 'any' type. How could a Wasm engine itself benefit from NaN-boxing when all the bits in a NaN are already observable by Wasm programs? AFAICS an engine would need to box all float values injected into type 'any' anyways. |
I think we want to avoid boxing floating point values that are injected into |
We considered something similar for exception handling. See some discussion at WebAssembly/exception-handling#30 (comment) There we abandoned this idea because it introduced some thorny lifetime issues. If there's more interest in this kind of feature now, maybe we could also simplify the exception handling proposal. |
Proposal for basic reference types is here. |
Closing as out-of-date: these concepts don't map to the current proposal, which has evolved a lot since this issue was opened. |
We have a pretty uncontroversial plan to introduce an
anyref
type to WASM in the future. Instead of restricting this type to tables only, what if we also allowanyref
as a WASM value type (not to be stored in linear memory) andtable_get
andtable_set
operations? Ifanyref
remains an opaque type for now (i.e. no new operators), I think this has minimal impact on engine complexity. (For non-JS embedded engines there are implementation strategies that don't require pointer maps, see below*)This could remove a lot of table/slot management complexity, especially for references that never need to be stored into memory, where table/slot management is just overhead. Instead, user code can implement its own WASM wrappers around imports and exports to manage tables and slots so that slot indexes can be stored into the linear memory.
I think this would be more forward-compatible, since I can imagine a world where managed data is dominant and JS/WASM interop is much smoother. In that future world the table bindings would be legacy complexity that we'd probably want to remove.
The text was updated successfully, but these errors were encountered: