bytecodealliance / bytecodealliance/wasm-tools

`RefType::new` returning an option is inconvenient

Open
#1,005 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
1.8k
Forks
351
Avg merge
16h 57m
Merged PRs (30d)
38

Description

I’m migrating a crate from a wasmparser 0.99 to 0.104 and there are significant changes around the `ValType`, introduced as part of https://github.com/bytecodealliance/wasm-tools/pull/701.

One of the things that I’ve been doing is something along the lines of:

```rust
impl VisitOperator<'a> for ... {
fn visit_ref_null(&mut self, t: ValType) -> Self::Output {
self.values.push(t);
Ok(())
}
...
}
```

thus effectively tracking the types that are on the stack. In order to adapt to the new API, I’m looking at something like this instead:

```rust
impl VisitOperator<'a> for ... {
fn visit_ref_null(&mut self, t: HeapType) -> Self::Output {
self.values.push(ValueType::Ref(RefType::new(true, t)));
Ok(())
}
...
}
```

but now there's a need to put in an `unwrap` in there or to handle the `None` that's returned by `RefType::new` in some other way. To me it seems somewhat counterintuitive that it is necessary to jump through hoops like these, given that I’ve already have in my hands something that has been successfully parsed.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.