Use typed indices via a new wasm-types
crate
#2049
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Following up on some conversation in #1985, this draft PR is a start on what it might look like to use typed indices throughout the whole codebase. I was originally planning to finish this before coming back to #1985, but it eventually became clear to me that this is considerably bigger than I expected.
In any case, I'm opening this PR to gauge whether there's any interest in going further down this path, or if I should just call this an interesting experiment and abandon it. There were some unintuitive cases, so maybe there is some potential value in these from a codebase documentation/consistency perspective? For example:
wasm-tools/crates/wasm-encoder/src/reencode/component.rs
Lines 963 to 966 in beac7de
This code made me mark the
func_ty_index
field of theCanonicalFunction::ThreadSpawn
variant asTypeIdx
instead ofComponentTypeIdx
, unlike all the fields in all theResource
variants. Is this correct? I don't know much about the component model, so maybe threads just happen to use core type indices while other similar-looking things use component type indices. Maybe it's clear from the spec (?), but it's not clear from the docstring:wasm-tools/crates/wasmparser/src/readers/component/canonicals.rs
Lines 70 to 74 in beac7de
Another random question I had while working on this: why do both
wasm_encoder::NameSection::tag
andwasm_encoder::NameSection::tags
exist? Don't they do the same thing?