-
Notifications
You must be signed in to change notification settings - Fork 644
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
Text.Parser: support for stateful grammars #4286
base: master
Are you sure you want to change the base?
Conversation
The latest update causes the compiler to hang when processing the I've added State directly to the A fix to the above problem with |
458fb7e
to
410be2c
Compare
It turns out Idris doesn't hang indefinitely, but it does take an additional 19 minutes on my machine to build |
@msmorgan Hmm, that seems not nice. I know it is not your fault, but that is a significant slowdown. |
As an experiment, I removed the However, as |
@msmorgan Any status on this PR? Also, the tests are currently failing. |
The tests are failing because the builds are timing out, as I mentioned earlier. I'm not sure how to correct this. If I get the time, I could try one of the following approaches. Which do you think has the best chance of speeding up the compiler?
The third option doesn't sounds like a very good idea, now that I've written it out. |
@msmorgan Have you considered doing partial evaluation on the input grammar? |
@ahmadsalim I have not, nor do I know what it is. |
@msmorgan You can annotate a term with Partial evaluation tries to specialize the code for that argument, and hopefully generate more efficient code 😄 |
I tried annotating various arguments to I built Idris with profiling enabled, removed the I've uploaded the full profiling dump (which weighs in at 118 MB) as a 5.5 MB zip archive here. |
`Grammar` is now a type-level function producing a grammar with unit state.
Also, prefer constructors to exported functions in `modify` and `gets`.
This allows a grammar with a different state type to be run in the current input stream context. Problematically, this causes the compiler to hang while processing `doParse`.
This was never used.
c89cd4e
to
1a7a84d
Compare
@msmorgan Maybe integrating https://hackage.haskell.org/package/intern in |
The issue seems to be one of asymptotic complexity, causing this function to be called hundreds of thousands of times while compiling doParse. Speeding up name lookup would be helpful but wouldn't solve the problem. |
I ran profiling for this compile and have uploaded the results here. Be warned: the uncompressed file is enormous. |
This PR adds simple state support (state type is constant) to Text.Parser.
Grammar
has been renamedGrammarT
, and is additionally parameterized by a state type.Grammar
is now a type-level function producing aGrammarT
type with unit state.Introduces
get
,put
,modify
, andgets
.Introduces
parseState
, which parses according to a grammar and an initial state.Items that need feedback:
Failure
constructor ofParseResult
really need to include a state? Update: State has been removed from theParseResult.Failure
constructor.How to implementUpdate: This is implemented, but the compiler hangs.runGrammar : innerST -> GrammarT innerST tok c a -> GrammarT outerST tok c (a, innerST)
.