-
Notifications
You must be signed in to change notification settings - Fork 245
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
wasm-encoder: Return Indices from builder functions where applicable #876
base: main
Are you sure you want to change the base?
Conversation
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.
I don't think this change makes sense for the component model sections because there isn't a 1:1 with section and index space like there is in core modules.
If we pare this down to only the module type sections, then I think this would be fine.
That makes sense, I've reverted all the component model indexing logic for now and we can revisit it at a future point. From the spec:
Reviewing the index spaces, only a few make sense to include:
So, I'm going to further pare this down to types, elements, and data. |
@alexcrichton is, as usual, correct! We'd have to move to a pattern similar to the nested encoders in component type encoding where the module being encoded hands out new section encoders so that the index spaces are tracked across all sections being encoded in the module. That'd be a pretty big breaking change, although it sure would be nice if component encoding tools didn't have to manually track the index spaces as component index spaces are a bit more complicated than index spaces in a module. Stepping back for a second, I do wonder if it's worth taking the pared-down change when the index of the added item can be retrieved from the section with the |
I personally think it's ok to remove the For consistency though it might make the most sense to have |
This refactor changes the returns of builder methods which create indexed entries (e.g. types) so that they return the index of the newly created entry. This means users don't need to otherwise calculate the value or know what it will be.
For example, the README no longer needs the line
let type_index = 0;
since it can be obtained whentypes.function(...)
is called.