happy icon indicating copy to clipboard operation
happy copied to clipboard

WIP Template-Haskell based version

Open fleex-x opened this issue 3 years ago • 10 comments
trafficstars

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 https://github.com/haskell/happy/pull/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 avatar Mar 29 '22 17:03 fleex-x

Have you talked to @int-index about this?

Ericson2314 avatar May 18 '22 13:05 Ericson2314

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.

int-index avatar May 18 '22 13:05 int-index

Agreed combinators first is the right approach.

Ericson2314 avatar May 18 '22 20:05 Ericson2314

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?!

sgraf812 avatar May 30 '22 12:05 sgraf812

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?

int-index avatar May 30 '22 14:05 int-index

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.

sgraf812 avatar May 30 '22 18:05 sgraf812

Can we start with stuff like this https://github.com/haskell/happy/pull/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.

Ericson2314 avatar May 30 '22 21:05 Ericson2314

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.

harpocrates avatar May 30 '22 23:05 harpocrates

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.

sgraf812 avatar May 31 '22 06:05 sgraf812

@fleex-x Are you still pursuing this?

int-index avatar Jul 19 '22 11:07 int-index