Skip to content
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

WIP Template-Haskell based version #233

Open
wants to merge 39 commits into
base: master
Choose a base branch
from

Conversation

fleex-x
Copy link

@fleex-x fleex-x commented Mar 29, 2022

Here I am writing a template-haskell version of happy to generate code directly in (TH.Q TH.Exp) and use it with the template-haskell extension. @kirelagin helps me with this.

What is going on:

  • I've created a class that gives functionality to generate code. Also I've added its instances to generate strings (like in ProduceCode using syntax combinators #218) and abstract representation from Language.Haskell.TH.

  • I am rewriting ProduceCode.lhs with code-combinators. As I plan, when I rewrite it all, it will immediately be able to generate template-haskell-based parsers (because of CodeGen TH.Exp instance).

What do you think about approach I am taking here? Is it nice or I have to change something in it?

@fleex-x fleex-x force-pushed the template-haskell-version branch from 8a7331f to 6cae39d Compare April 16, 2022 10:38
fleex-x added 23 commits April 16, 2022 16:32
…d Syntax.intE.

`A.` in [A..5] is interpreted as a module name, so a space after `A` is needed here.
Change type in Syntax.intE because of (abs (minBound :: Int)) doesn't work correctly.
I used wrong precedence in patter-generating inside Syntax.clause,
so no brackets were generated when they were needed.
Now such listings are in alphabetical order.
Put correct package-description in cabal-file.
Now it is possible to avoid frequent use of mkName in code.
@Ericson2314
Copy link
Collaborator

Have you talked to @int-index about this?

@int-index
Copy link
Collaborator

We talked with @kirelagin about it, he's supervising this effort. My request was to break it into small parts. First let's get the combinators themselves merged, and then start to rewrite the code gen in small steps, where each of them touches no more than 30-50 lines, easy to review and bisect if we miss something that is not semantics-preserving.

@Ericson2314
Copy link
Collaborator

Agreed combinators first is the right approach.

@sgraf812
Copy link
Collaborator

I'm a bit vary because the combinators library (and with it, the regular happy backend) currently depends on template-haskell. I sure hope that the regular happy executable will not need TH to build?!

@int-index
Copy link
Collaborator

I sure hope that the regular happy executable will not need TH to build?!

This could be arranged with CPP and build flags, but why is that important?

@sgraf812
Copy link
Collaborator

Because GHC has alex/happy as a boot dependency and that usually means we can't use TH. But you're probably right in that it's nothing worth worrying about, because we use happy as an executable to generate code, and one that we don't need to build with the stage1 compiler (say).

Of course it also means we can't use new shiny TH splices in GHC's happy parser, but we can't currently use TH splices in GHC's build to begin with, so that's a non-issue.

TLDR; fine. I do wonder though about compatibility to other Haskell compilers, but that bridge probably has been burned a while ago.

@Ericson2314
Copy link
Collaborator

Can we start with stuff like this #218 ? It is a clear improvement, and also no TH dependency. Not saying we should never do the TH, but in the interest of taking small steps at a time and easy reviewing, I think it could be good to start with that.

@harpocrates
Copy link
Contributor

TLDR; fine. I do wonder though about compatibility to other Haskell compilers, but that bridge probably has been burned a while ago.

I assumed the existence of the -g flag implies that without -g the code is vanilla enough that any Haskell98 compiler would accept it. OTOH, I remember there were a slew of small bugs on the non--g codepath, so I fear it doesn't get much use.

@sgraf812
Copy link
Collaborator

The dependency on TH is mostly problematic if you want to build happy exe on non-GHC. Codegen should be unaffected and brokenness the same as today.

@int-index
Copy link
Collaborator

@fleex-x Are you still pursuing this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants