Repository navigation
Conversation
`tagged_code_units` used the source memory's tag, but `store_string_into_range` decoded it with the target memory's tag, so passing strings between 32- and 64-bit memories checked the wrong tag and this was guest-observable due to the wrong `realloc` calls getting made. This is fixed by having `load_string_from_range` eagerly decode and remember the `String`'s encoding hint and `store_string_into_range` to just use that hint, rather than try to read the hint itself. Additionally, I made a `class StringHint(Enum)` so that it is more clear what the hint cases are, and to differentiate dynamic hints from actual encodings and the `string-encoding` canon option values.
|
(Responding to this comment over here in the PR thread, where I think it makes sense to discuss specifics of the proposed ABI, now that it exists as a proper PR instead of an issue comment.)
It is already the case today, with the linear memory ABI, that adding or removing a
To make sure I understand, you're suggesting that
Is that correct? How does one do I guess if there was a single common supertype for all the block (result (ref i31))
...
local.get $my-variant
;; Check for payload-free `case`s.
br_on_cast (ref i31) 0
;; Handle `case`s with payloads.
block
block
...
block
local.get $my-variant
ref.cast $my-variant-with-payload-supertype
struct.get $my-variant-with-payload-supertype $discriminant
br_table ...
end
...
end
...
end
...
unreachable
end
;; Handle payload-free cases
block
block
...
block
local.get $my-variant
ref.cast (ref i31)
br_table ...
end
...
end
...
end
...And while I admit that will give Alternatively, if we wanted to statically choose a representation statically at compile-time between something like
then we could achieve a Yet another alternative is to remove the no- |
|
We don't need to actually allocate anything for the cases without payload, even when they are represented as structs. They are statically known singletons; they can be allocated once and for all (well, once per component, since it doesn't know about the other ones). For enums, I agree a simple integer is still better. Either way to me using |
Unfortunately, it isn't something orthogonal that we can discuss or special-case separately because the component model defines
That's a good point that the toolchain can pre-allocate or hashcons But this actually raises an issue with the PR's current state: it specs allocating new objects during lowering (e.g. invoking |
|
Can we spec it as intentionally unspecified whether we reallocate? Like we do for NaN's? |
|
Just on this point:
"Specializations" aren't quite syntactic sugar: they're treated as distinct type constructors (not type-equal to what they are a specialization of) and in some cases are given distinct ABIs (viz., |
Yes, that's a typical representation that functional languages, which invented variants after all, have been using for decades. It's true that this requires an extra cast for dispatching on a non-nullary constructor in Wasm, but many things do. Accessing such a constructor already requires a cast anyway. The difficulty with avoiding allocations is that this effectively only works when you have a dedicated "owner" for a type definition who can provide the canonical constants, which is difficult to reconcile with structural and modular type definitions. Following what @lukewagner says, that seems unrelated to unboxing types that are explicitly declared as enums. |
lukewagner
left a comment
There was a problem hiding this comment.
Great to see work on this! A few high-level questions/suggestions that affect the broader strokes:
| | (canon thread.spawn-ref shared? core-prefix(<core:typeidx>) (core func <id>?)) 🧵② | ||
| | (canon thread.spawn-indirect shared? core-prefix(<core:typeidx>) core-prefix(<core:tableidx>) (core func <id>?)) 🧵② | ||
| | (canon thread.available-parallelism shared? (core func <id>?)) 🧵② | ||
| | (canon gc.resource.new <typeidx> (core func <id>?)) 🛸 |
There was a problem hiding this comment.
Understood that in the binary format, we need new opcodes b/c they don't already take opts. But in the AST and text format, I think we can backwards-compatibly add a gc? immediate to all the existing built-ins and then have the new opcodes decode to the existing built-ins with gc set. (We do this hack/trick in a number of other cases, like when we added async? to func type constructors.) Then, in CanonicalABI.md, we don't need a bunch of new built-in function definitions but, rather, you just in-place add a new gc boolean parameter (which is nice for code-sharing and seeing more-clearly how and where gc differs from linear memory).
| | 0x40 sh?:<sh?> ft:<core:typeidx> => (canon thread.spawn-ref sh? ft (core func)) 🧵② | ||
| | 0x41 sh?:<sh?> ft:<core:typeidx> t:<core:tableidx> => (canon thread.spawn-indirect sh? ft t (core func)) 🧵② | ||
| | 0x42 sh?:<sh?> => (canon thread.available-parallelism sh? (core func)) 🧵② | ||
| | 0x43 dst:<core:typeidx> src:<core:typeidx> => (canon array.new-array dst src (core func)) 🛸 |
There was a problem hiding this comment.
I wonder if, for simplicity of implementation, we can pick a single new opcode byte representing "the following built-in but with the gc option set", and then follow that with the existing binary encoding of an existing built-in. Taking a few liberties, I think we could write it like this:
| 0x50 b:<gcable-builtin> => add-gc(b) where add-gc((name rest)) = (name gc rest)
and then (in a refactoring PR/commit we could merge eagerly to minimize rebase pain) we could split out gcable-builtin from canon:
canon ::= 0x00 ... => (canon lift ...)
| 0x01 ... => (canon lower ...)
| b:<gcable-builtin> => b
| ... everything else not covered by the above
and then when we add built-ins we can stick them in gcable-builtin as appropriate and hopefully both the spec and impl can have an easy time with it.
| ```wat | ||
| (func (param $event-code i32) | ||
| (param $payload i32) | ||
| (param $waitable (ref null extern)) |
There was a problem hiding this comment.
Question: do we need GC references for waitables? The big difference between waitables and owned handles is that they are implicitly kept alive while they are waiting for an event (whether you are explicitly waiting for them via waitable-set or not) and then once you receive that terminal event, you know you can drop them. Even with streams/futures, I think we don't want/need unreachability to implicitly cancel/drop (and, e.g., the WHATWG Streams API explicitly forbids this: a stream stays alive until the other end explicitly closes it or it is explicitly cancelled). Similarly, I think waitable-sets don't need to be GC'd (afaik, they are either global singletons or are scoped to a task which again has an explicit end-of-life that can be used to waitable-set.drop).
EDIT: in my initial version of this comment, I was asking about how you you correlate data with a waitable if it's an externref, but I see gc.handle-ref.get now is proposed to address that. However, if my suggestion in the previous paragraph works out and we can keep using i32 indicies for waitables, then I think it's quite possible we won't need handle-ref.{index,new,get} just for owned/borrowed handles either (they don't have the analogous challenge since there's no waitable-set.wait/callback where you're given an externref that you need to correlate with some previous usage of that same externref... you always get a fresh externref). This would be good b/c otherwise it seems like, if a host finalizer implicitly frees a handle-table element that has i32-index-correlated state, since guest code doesn't find out when this happens, the guest code can't reliably free/unregister the i32-indexed correlated state.
Fixes #525
Depends on #772