-
-
Notifications
You must be signed in to change notification settings - Fork 1.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
Refactor the parser somewhat #9776
Conversation
this is a proper subset of Formals anyway, so let's just use those and avoid the extra allocations and moves.
since nix doesn't use the bison `error` terminal anywhere any invocation of yyerror will immediately cause a failure. since we're *already* leaking tons of memory whatever little bit bison allocates internally doesn't much matter any more, and we'll be replacing the parser soon anyway. coincidentally this now also matches the error behavior of URIs when they are disabled or ~/ paths in pure eval mode, duplicate attr detection etc.
all of them need access to parser state in some way. make them members to allow this without fussing so much.
ParserState better describes what this struct really is. the parser really does modify its state (most notably position and symbol tables), so calling it that rather than obliquely "data" (which implies being input only) makes sense.
most instances of this being used do not refer to the "current" position, sometimes not even to one reasonably close by. it could also be called `makePos` instead, but `at` seems clear in context.
most EvalState and Expr members defined here could be elsewhere, where they'd be easier to maintain (not being embedded in a file with arcane syntax) and *somewhat* more faithfully placed according to the path of the file they're defined in.
there's no reason the parser itself should be doing semantic analysis like bindVars. split this bit apart (retaining the previous name in EvalState) and have the parser really do *only* parsing, decoupled from EvalState.
these symbols are used a *lot*, so it makes sense to cache them. this mostly increases clarity of the code (however clear one may wish to call the parser desugaring here), but it also provides a small performance benefit.
Co-authored-by: John Ericson <[email protected]>
} | ||
|
||
else if (hasPrefix(value, "flake:")) { | ||
experimentalFeatureSettings.require(Xp::Flakes); |
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.
I was not aware of this feature. (Ref: #7026)
@@ -20,6 +20,9 @@ | |||
#include "gc-small-vector.hh" | |||
#include "url.hh" | |||
#include "fetch-to-store.hh" | |||
#include "tarball.hh" | |||
#include "flake/flakeref.hh" |
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 oddity was already in the parser. Moving it here is directionally correct, further future work might refactor this more. It is for the NIX_PATH handling of "flake:something" URLs.
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 to be exactly as advertised, refactoring the parser and separting concerns a bit better than before.
Discussed during the Nix maintainers meeting on 2024-01-22.
- Talked about @pennae's larger plans for a parser rewrite
Goals/requirements
Decision Options (decision is #2):
Decision: the new PEGTL parser is "Idea Approved" |
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/2024-01-22-nix-team-meeting-minutes-117/38838/1 |
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.
I tried confirming things were just moved around with git diff --color-moved
. Looks good!
Motivation
the parser is currently not in great shape. it's tightly coupled to EvalState, it does more than just parsing, and it contains heaps of not entirely related code in the core
parser.y
file. let's refactor it a bit to make it easier to work with.Context
Priorities and Process
Add 👍 to pull requests you find important.
The Nix maintainer team uses a GitHub project board to schedule and track reviews.