-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Recursive stage2 parser #2405
Recursive stage2 parser #2405
Conversation
Exciting. I'll look through all of this once you're done :) |
All tests passing 🎉 🎉 Ready for some review? |
I still have some work to do to finish the PR description, but since this a big one, I suppose it's time to get started. Let's do it! |
For a branch this large, if there are conflicts, merge master into the branch, then fix the conflicts. If there are no conflicts - which it looks to be the case - no work is needed on your part, I'll merge it into master with a merge commit. |
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.
This looks amazing. I left a few comments, but I already consider this ready to merge. I'll give @Hejsil a chance to take a look, and then I think it's good to go!
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.
Nice work @hryx. I have a few comments.
Looking through the commits, I think you can first reduce their number by doing an interactive rebase and use many small commits as fixups for previous ones. |
Thanks @Sahnvour, that's my plan now. After addressing all these review comments today, I'll turn a bunch of commits into fixups. But since it sounds like having several commits is allowed, I won't obsess over getting it perfect. |
Those ❌ marks gave me a good scare; all tests pass locally. I assume Azure cancels a run when a newer commit is pushed on the branch. |
The `arena` instance being used bythe parse tree was valid and pointed to valid memory, but existed as a local variable inside the stack frame of the `parse` function (the `const arena`), which was never stored anywhere before leaving the scope. This meant that code above the `parse` function saw a valid instance of an `ArenaAllocator` that pointed to the same backing memory, but didn't posess any of the local state built up after the call to `parseRoot`, basically the caller saw an empty arena. This meant that when `deinit` was called, it saw an Arena with 0 allocations in it's `buffer_list` and wasn't able to destroy any of the memory. This caused it to leak and caused FailingAllocator to balk. The fix is to make sure the parse tree is using the same instance of ArenaAllocator as is reported up the call stack, the one inside the `Tree{}` object. I'm not sure why that field is marked with a comment to remove it, as it's used by the `std.ast.Tree.deinit()` function, but this change seems to solve the problem.
be0f97e
to
0d62942
Compare
The git history has been cleaned up. Please don't ask me how I did it. The original 138 commits can be seen at this tag: master...hryx:stage2-recursive-parser-pre-cleanup Regarding the most recent changes: some other files did get touched, either to address review comments or to make the parser conform more strictly to the grammar rules. Either way, I now consider this ready to merge if there are no more concerns or blockers! and now, art ⬜ ⬜ ⬜ ⬜ 🌞 ⬜ ⬜ ⬜ |
TODO
TODO
comments as possible by getting answers to questions in code review and creating follow-ups and tickets as neededCloses #1729
Keep your eyes open for any
TODO
comments and leave your suggestions or opinions. Some of these comments will likely be retained and their corresponding changes postponed till a later PR, but maybe some of them can be solved now.Performance impact
Here are some informal tests of
parser_test.zig
withperf stat -d
on x86_64 Linux. In the absence of visualizations and more formal testing, some quick findings based on my system:Readability impact
Indentation stats of
std/zig/parse.zig
:Follow-up items
Because this was a heavy change, a few ideas and concerns came up along the way which would unnecessarily increase the scope of this PR or add diff noise but which I would like to address.
ArrayTypeStart
can be either an array or a slice, butconst
andallowzero
only work on pointers; slices are pointers but arrays aren't. ThePrefixTypeOp
rule might need to be updated to prevent those qualifiers on slices, e.g.:test/compile_errors.zig
:render()
andloc()
methods, and exists in theast.Error
union. If it's possible, it would be more flexible, concise, legible, and expressive to generate errors from string literals at the site of the error itself. Something like this:Miscellany
🙇♂️ Massive thanks to @tyler569 for unblocking me by finding a memory leak I caused along the way.
🌹 I am so sorry I killed your art @Hejsil