Skip to content

[NFC] Track grammar of definitions in parser#8931

Merged
tlively merged 1 commit into
mainfrom
prefactor-compact-imports-text
Jul 23, 2026
Merged

[NFC] Track grammar of definitions in parser#8931
tlively merged 1 commit into
mainfrom
prefactor-compact-imports-text

Conversation

@tlively

@tlively tlively commented Jul 23, 2026

Copy link
Copy Markdown
Member

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.

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.
@tlively
tlively requested a review from a team as a code owner July 23, 2026 00:14
@tlively
tlively requested review from stevenfontanella and removed request for a team July 23, 2026 00:14
Comment thread src/parser/contexts.h
};

enum class DefKind {
ImportDesc,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@tlively
tlively merged commit bbeae83 into main Jul 23, 2026
16 checks passed
@tlively
tlively deleted the prefactor-compact-imports-text branch July 23, 2026 17:50
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

Successfully merging this pull request may close these issues.

2 participants