Skip to content
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

Add text syntax for defining multiple locals of the same type #1588

Open
alexcrichton opened this issue Feb 8, 2023 · 2 comments
Open

Add text syntax for defining multiple locals of the same type #1588

alexcrichton opened this issue Feb 8, 2023 · 2 comments

Comments

@alexcrichton
Copy link
Contributor

The binary format for WebAssembly defines function locals as a counts of a type to define contiguous sets of typed indices. The s-expression text format for WebAssembly, however, does not have an anlogue of this form and requires that each local is defined individually with its type. For example where the binary format says "I have 5 i32 locals" the text format has to say (local i32 i32 i32 i32 i32).

I work on a binary-to-text printer called wasmprinter in Rust and this printer is additionally fuzzed. Fuzzing historically has brought up that "I have 4 billion i32 locals" is a valid wasm module to print but takes gigabytes more space to print than it does to hold the binary format in memory. For this reason I've matched our validator's limits where the printer will print up to 50k locals before returning an error.

This typically works fine but recent I was working with a wasm module that was failing to validate because it had too many locals in a function. I wanted to print the module to scan over and see if I could see what was going on, but I ended up being unable to print the module due to this restriction as well. While I ended up fixing my issue by debugging via other means, this is what leads me to this issue's feature request.

It would be nice to have textual syntax in the s-expression format for "there are N locals of type T" to mirror the capability of the binary format. This wouldn't have to be used by text printers and the current format could still be used, but if a function says it has 4 million locals it would be helpful to print one item instead of four million items.

@rossberg
Copy link
Member

rossberg commented Feb 8, 2023

Sounds plausible. Something like (local 5 i32)?

@alexcrichton
Copy link
Contributor Author

Indeed yeah that would work well and solve the issue at hand.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants