[NFC] Track grammar of definitions in parser#8931
Merged
Merged
Conversation
When e.g. a function is declared in the text format, it can either be with a normal `func` production (which may or may not have an inline import declaration) or it can be an `import` production. Previously the parser would just store the location of the declaration but not the kind of production it used. In later parser phases where the declaration has to be parsed again, we would just try both productions to see which one worked. This is rather hacky and brittle and will not play nicely with the text format for compact imports, so refactor to explicitly track how the declaration should be parsed.
stevenfontanella
approved these changes
Jul 23, 2026
| }; | ||
|
|
||
| enum class DefKind { | ||
| ImportDesc, |
Member
There was a problem hiding this comment.
nit: maybe just call it Import since the name is scoped to DefKind and not ambiguous? It's not clear to me what Desc is (description?)
Member
Author
There was a problem hiding this comment.
This PR associates DefKind::ImportDesc with import_(), but the next PR changes it to use importdesc() instead. Looks like the upstream spec calls the relevant grammar production externtype instead of importdesc now, so we could update the enum and function names together in the future.
This file contains hidden or 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
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.
When e.g. a function is declared in the text format, it can either be with a normal
funcproduction (which may or may not have an inline import declaration) or it can be animportproduction. Previously the parser would just store the location of the declaration but not the kind of production it used. In later parser phases where the declaration has to be parsed again, we would just try both productions to see which one worked. This is rather hacky and brittle and will not play nicely with the text format for compact imports, so refactor to explicitly track how the declaration should be parsed.