-
Notifications
You must be signed in to change notification settings - Fork 84
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
Support inlining of non-terminals, as Menhir does #148
Comments
For a live example where this is useful, consider https://gitlab.haskell.org/ghc/ghc/blob/68ddb43c44065d0d3a8a6893f7f8e87f15ee9c1e/compiler/parser/Parser.y#L1278. We can't use
Reduce an empty |
I want this a lot too for a project of mine whose grammar is quite large, and so I went ahead and took a stab at implementing it. Here are the changes.
With the caveat that I've only tried toy examples and done nothing to make the code efficient, it seems to be working as expected. Before I spend more time on this:
|
bump, whats the current stances? |
Wait for feedback on design and merge-ability I think. |
Happy to have this feature, it does sound useful. Perhaps We probably shouldn't duplicate the code, how hard is it to abstract it? Do we run into typing issues? I haven't reviewed the code, but happy to give it a read once it's settled down. I have no strong attachment to the internals of Happy, it needs a complete rewrite really. |
This would be useful in the implementation of modifiers, see https://gitlab.haskell.org/ghc/ghc/-/issues/22624#note_471850 |
I think with the introduction of Edit: The following is actually incorrect. |
Are you sure about this? My mental model for parameterised productions was that they were expanded to top-level copies of the template, e.g.
is equivalent to
I don't see where inlining enters the picture. |
Indeed not, I was wrong. Marking a (use or decl) of a non-terminal as |
It has bothered me for a long time that we have so many conflicts in GHC's parser, and https://gitlab.haskell.org/ghc/ghc/issues/17232 is there to track it. Precedence declarations will probably go a long way to ameliorate this.
But as section 5.3 in http://gallium.inria.fr/~fpottier/menhir/manual.pdf points out, there still are conflicts which aren't easily resolved without compromising on software design by inlining all productions of a non-terminal into a call site.
I imagine something like Menhir's
%inline
keyword would help here. But I'd rather not have it at the declaration site of a non-terminal. Instead, we should have a mechanism that allows us to annotate use-site of the non-terminal, similar to the difference between{-# INLINE #-}
and theGHC.Magic.inline
. Also it would help to resolve conflicts on a case-by-case basis rather than just blindly inline the non-terminal everywhere, which might come with exponential blow-up.The text was updated successfully, but these errors were encountered: