-
Notifications
You must be signed in to change notification settings - Fork 244
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
Initial support for value section parsing #1541
base: main
Are you sure you want to change the base?
Conversation
Thanks for the PR and the work here!
I posted a comment on the spec PR about this, but otherwise for now you'll probably want to take a
This might be good to change at the spec-level perhaps too and to spec that beyond 32-bits the value is represented as N 32-bit values so we would decode 32-bit chunks here.
I'm a bit wary of the current representation of |
Thank you for taking a look so rapidly and the suggestions. I’ve made the following changes based on your response: I’m now using I agree that the initial representation for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks to me like you got most of the bits and pieces all sorted out and this looks great to me, thanks!
Thank you very much for taking another look. struct Printer {
output: String,
}
/// ...
impl Record<Self> for &mut Printer {
fn field(&mut self, name: &str) -> Self {
self.output.push_str(name);
self /// <- Does not work
}
} I tried to solve this in different attempts by adding lifetimes or changing from owned to borrowed values in both the |
The serde crates/traits might be a good inspiration to draw from for this use case? They're solving a pretty similar problem and might be good to model after. |
This draft adds support for component value sections to wasmparser.
WebAssembly/component-model#336
Questions, issues and remarks:
The validator currently does not support validation of the actual values:
The parsing of values depends on the component type space, so a value section can’t be parsed in isolation WebAssembly/component-model#352 How should this be handled? Currently,
ComponentValue
only parses the type and keeps the bytes of theval
. To read the actual value theval
method takes a slice ofComponentType
s which must be in the order they were read from the current componentsComponentTypeSectionReader
.wasmparser duplicates the types in validator and reader. Currently
values.rs
uses the ones from reader. Should it usetypes::Types
from validator instead?Validation only needs to call
val
, as the parser then checks if the types of values are correct.Crates depending on wasmparser (such as wasmprinter) need to keep track of the component type space. wasmprinter already keeps some global module/component information in the
state
variable. wasmparser itself does that in its validator.Parsing of
flag
s that set labels past 64 totrue
currently fails. Needs support for arbitrarily large unsigned LEB128.How should
flags
be stored in wasmparser? Explainer.md: list oflabel
s of fields set totrue
. For wasmparser I think this will likely confuse people into thinking theu32
s are justbool
s encoded as integers. So I instead choseVec<bool>
, which would treat it as a specialrecord
with only bool fields (it already is). More symmetrical and ergonomic.Should
Record
,Flags
,Variant
andEnum
store the label names? They are already provided in theComponentType
.Flags
could then also be aVec<&str>
.BinaryReaderError
s use the offsetreader.original_position()
. Might not always be correct (off by one or couple bytes).