This is an archive of the discontinued LLVM Phabricator instance.

[pseudo] Remove the explicit Accept actions.
ClosedPublic

Authored by hokein on May 16 2022, 3:12 AM.

Details

Summary

As pointed out in the previous review section, having a dedicated accept
action doesn't seem to be necessary. This patch implements the the same behavior
without accept acction, which will save some code complexity.

Diff Detail

Event Timeline

hokein created this revision.May 16 2022, 3:12 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 16 2022, 3:12 AM
hokein requested review of this revision.May 16 2022, 3:12 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 16 2022, 3:12 AM
sammccall accepted this revision.Jun 7 2022, 5:51 AM

This is a great simplification, thanks!

clang-tools-extra/pseudo/lib/GLR.cpp
117–119

rather than mingling this with the glrReduce, I'd suggest collecting the set of final heads first and then analyzing them afterwards.

This means looping a second time, but I think the logic around recognizing patterns that look like accept might grow (e.g. if we want to incorporate some error tolerance)

This revision is now accepted and ready to land.Jun 7 2022, 5:51 AM
hokein updated this revision to Diff 435103.Jun 8 2022, 4:46 AM

pull out the logic of detecting acceptable state out of glrReduce callback.

clang-tools-extra/pseudo/lib/GLR.cpp
117–119

that sounds reasonable, but it requires some additional changes (to identify inactive heads in the callback of glrReduce):

  • AddSteps now returns true/false whether there is any actions in LRTable[NewHead->state][nextTok];
  • no available action in the acceptable state on the eof token in LRTable (see the change in lr-build-basic.test);
sammccall accepted this revision.Jun 8 2022, 7:16 AM
sammccall added inline comments.
clang-tools-extra/pseudo/lib/GLR.cpp
117–119

Hmm, I'm not sure whether the conditional or unconditional version is better, and we're really borrowing problems from the future here.

Let's go back to this simplest version, and update the opaque forest node comment below to a FIXME.
(We will need to invoke our generic error-recovery handlers when we reach EOF without reaching accept state, and simulating shifting an eof token may be the best way to reuse the code)

118

this line introduces a requirement that the start symbol be a nonterminal - if this is new, can we doc it?

hokein updated this revision to Diff 435309.Jun 8 2022, 1:19 PM
hokein marked an inline comment as done.

switch to the previous simple version

clang-tools-extra/pseudo/lib/GLR.cpp
118

this is not a new requirement, it is rather implicit previously (we use G.findNonterminal to pass the start-symbol argument of the glrParse). I added an assertion in the glrParse.

It would be nice to diagnose it in the bnf grammar parsing time (will add a followup patch).

sammccall accepted this revision.Jun 8 2022, 2:34 PM
sammccall added inline comments.
clang-tools-extra/pseudo/lib/GLR.cpp
118

FWIW I think an assertion (and possibly a comment) is the right tradeoff here, maintaining diagnostics for all this stuff seems like overkill

hokein added inline comments.Jun 9 2022, 2:19 AM
clang-tools-extra/pseudo/lib/GLR.cpp
118

Fair enough. I underestimated the effort of doing this stuff (we need to adjust a few existing tests in GrammarTests as well).

This revision was landed with ongoing or failed builds.Jun 9 2022, 2:20 AM
This revision was automatically updated to reflect the committed changes.