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
Handle each kind of module field separately in preprocessor #5
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This does mean we have to temporarily match against the entire S-expression instead of peeking at it, but that’ll go away once we start consuming it incrementally. For now the priority is to get #read_list lifted out of #process_field so that it’s operating entirely inside a list like all the other methods do.
We were only wrapping `field` in a single-element array because it was being passed to the #read_list helper inside #process_field, but now the helper’s moved next to the array, the two cancel each other out.
Although this is slightly less efficient, it more directly resembles the specification of export abbreviations (e.g. [0]) and so should be easier to understand at a glance. [0] https://webassembly.github.io/spec/core/text/modules.html#text-global-abbrev
Just as in #expand_inline_export, we can use #process_command to desugar the result of expanding the module abbreviation [0]. [0] https://webassembly.github.io/spec/core/text/modules.html#id10
This makes it possible for each method to expand inline exports, which produce multiple fields. In practice it’s only #process_function that needs to do this, but I’ve made the same change to #process_type and #process_import to keep all of the field-processing methods consistent.
The spec calls these fields “function definitions” [0] and “type definitions” [1], so we should use the same terminology here. [0] https://webassembly.github.io/spec/core/text/modules.html#functions [1] https://webassembly.github.io/spec/core/text/modules.html#types
This removes the need to support inline imports & exports for functions in #process_field.
It’s handled in #process_function_definition now.
…itions This removes the need to support inline imports & exports for any kind of field in #process_field.
It’s entirely handled in field-specific methods now.
They’re called by both #process_function_definition and #process_table_memory_global_definition, and the code is easier to read if callers come before callees.
…xport We really want to get the optional ID out of the way, but we have to read the field kind first.
…rocess_table_memory_global_definition
We need to do the same work to handle inline imports & exports for function and table/memory/global definitions, so it’s convenient to move the duplicated code into helpers.
We’d like to lift the #read out of this method, so we can’t use it directly in a conditional. Fortunately we can check its side-effect (of assigning to `id`) instead.
Rather than doing the reads inline when they’re needed, we read everything together first and then build the result. The increased similarity to #expand_inline_import makes the methods easier to compare at a glance.
…able_memory_global_definition
We now only need to look at the next thing we’ll read, not the entire S-expression.
Table, memory and global definitions support different abbreviations, so each will need its own slightly different method.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Different WebAssembly module fields can use different abbreviations, so the preprocessor ultimately needs to treat each kind of field separately. As mentioned in 4caaf54, the work of expanding inline imports & exports currently requires looking at the entire field at once and therefore prevents us from first identifying the field and then consuming it incrementally with
peek
andread
as is done elsewhere.This PR refactors the preprocessor’s #process_field method to do nothing except peek at the field’s first atom and call the appropriate method for handling that kind of field. This regularises the preprocessor’s implementation and will make it easier to extend the individual field-specific methods to support whatever abbreviations they need.