Skip to content
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

Implement the legalizer #438

Open
wants to merge 37 commits into
base: main
Choose a base branch
from
Open

Implement the legalizer #438

wants to merge 37 commits into from

Conversation

mcy
Copy link
Member

@mcy mcy commented Jan 29, 2025

This PR adds the legalizer: a collection of diagnostics that follow parsing to eliminate and diagnose invalid constructs that the parser accepted in order the make progress.

This PR also adds a new syntax package for e.g. syntax.Proto2 and other editions knowledge. It adds functions for classifying predeclared.Names and some new taxa.Nouns for naming concepts in diagnostics relevant to the legalizer. Parsing is also tweaked in a few places to generate better diagnostics.

@mcy mcy requested a review from jhump January 29, 2025 23:20
@mcy mcy requested review from emcfarlane and doriable February 3, 2025 18:17
Copy link
Member

@jhump jhump left a comment

Choose a reason for hiding this comment

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

I've made it through 16 out of 26 commits. I know I've got some big commits still ahead of me (legalize message and friends; legalize fields), which I am still working through.

But I figured I should go ahead and publish the remarks I have so far since there has been no other activity on the PR since we talked a couple of days ago. I promise I've been working on it and not ignoring it! :)

experimental/ast/predeclared/methods.go Outdated Show resolved Hide resolved
experimental/ast/syntax/syntax.yaml Show resolved Hide resolved
experimental/parser/testdata/parser/field/group.proto.yaml Outdated Show resolved Hide resolved
experimental/parser/parse_decl.go Show resolved Hide resolved
experimental/parser/testdata/parser/package/42.proto Outdated Show resolved Hide resolved
experimental/parser/legalize_file.go Outdated Show resolved Hide resolved
Comment on lines 4 to 7
19 | package 42;
| ^^^^^^^
= help: to place a file in the empty package, remove the `package` declaration
= help: however, using the empty package is discouraged
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't seem like a good diagnostic. Perhaps the AST node should allow an expression instead of just a path here, so that you diagnose 42 is an invalid type for the package name?

(Totally fine to be a TODO: I know changing the AST at this point might be enough churn to warrant a separate PR.)

Copy link
Member Author

Choose a reason for hiding this comment

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

I explained elsewhere why this doesn't work properly. There's already a TODO in the .proto file.

experimental/parser/legalize_file.go Outdated Show resolved Hide resolved
... |
22 | | import weak "foo.proto";
| | ^^^^^^^^^^^^^^^^^^^^^^^^ this weak import...
23 | |
Copy link
Member

Choose a reason for hiding this comment

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

Why does this diagnostic have an extra line of context after the snippet? The two above do not, so perhaps it's a bug?

If it's a quirk/bug in the reporting, totally fine to fix that in a separate PR. But, if it's an issue in the way the diagnostic is constructed in this commit, then let's try to fix in this branch.

Copy link
Member Author

Choose a reason for hiding this comment

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

it's a quirk with the renderer, but it was easy enough to find and fix.

|
19 | / message M {
... |
23 | |
Copy link
Member

Choose a reason for hiding this comment

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

Same as above: why is there an extra line of context before the snippet?

Copy link
Member Author

Choose a reason for hiding this comment

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

Also fixed :)

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