Skip to content

Commit

Permalink
happy-frontend: check in generated code
Browse files Browse the repository at this point in the history
This drastically simplifies the bootstrapping mechanism.
If you have `happy` pre-installed, you can run:

  packages/frontend/bootstrap.sh

to regenerate Parser.hs and AttrGrammar/Parser.hs
  • Loading branch information
int-index committed Jun 13, 2024
1 parent 535ce96 commit 3eca9d0
Show file tree
Hide file tree
Showing 17 changed files with 2,002 additions and 483 deletions.
3 changes: 1 addition & 2 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ The main focus of this release was modularizing Happy.
- `happy-grammar`
- `happy-tabular`

* Partially revert the new bootstrapping system of 1.21.0 to mitigate
build issues.
* Revert the new bootstrapping system of 1.21.0 to mitigate build issues.

## 1.21.0

Expand Down
8 changes: 2 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,8 @@ sdist-test-only ::
echo "packages: ." > "${SDIST_DIR}/happy-$(HAPPY_VER)/cabal.project"
echo "tests: True" >> "${SDIST_DIR}/happy-$(HAPPY_VER)/cabal.project"
cd "${SDIST_DIR}/happy-$(HAPPY_VER)/" \
&& cabal v2-build all --flag -bootstrap \
&& cabal v2-install --flag -bootstrap --installdir="./bootstrap-root" \
&& cabal v2-test all -j --flag -bootstrap \
&& export PATH=./bootstrap-root:$$PATH \
&& cabal v2-build all --flag +bootstrap \
&& cabal v2-test all -j --flag +bootstrap
&& cabal v2-build all \
&& cabal v2-test all -j
@echo ""
@echo "Success! ${SDIST_DIR}/happy-$(HAPPY_VER).tar.gz is ready for distribution!"
@echo ""
35 changes: 0 additions & 35 deletions bootstrap.hs

This file was deleted.

34 changes: 12 additions & 22 deletions doc/contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,34 +30,24 @@ Repo Layout
Build Instructions
------------------

Happy is normal Cabal-packaged Haskell executable, except for the fact that a
pre-built Happy is *required* to build the full version of Happy, which is the default.

- If you *do* have an existing Happy executable on the PATH or in the default
installation location (`~/.cabal/bin` for example), do regular

::
Happy is mostly a normal Cabal-packaged Haskell executable::

$ cabal build

like with any other project.

- If you do *not* have an existing Happy executable, instead do

::
The only wrinkle is that developing Happy's own parser (i.e. the frontend
component that parses ``.y`` files) requires an existing Happy executable on
the PATH.

$ cabal build -f -bootstrap
Do *not* modify these files by hand::

- If you install that minimial, non-bootstrapped happy
packages/frontend/src/Happy/Frontend/Parser.hs
packages/frontend/src/Happy/Frontend/AttrGrammar/Parser.hs

::
Instead, edit these files::

$ cabal install -f -bootstrap
packages/frontend/boot-src/Parser.ly
packages/frontend/boot-src/AttrGrammarParser.ly

you can then build normally (with the bootstrap flag enabled).
and regenerate the ``.hs``-files with::

*We're sorry the bootstrap process is a bit tedious right now; we hope to
improve it in the future. The ideal fix would be to make cabal-installer's
cycle detector to be less pessimistic, per
`<https://github.com/haskell/cabal/issues/7189>`_, so that the build tool dependency
can be properly expressed and everything works automatically.*
$ packages/frontend/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ or a conditional statement.
> {-# OPTIONS_GHC -w #-}
> module Happy.Frontend.AttrGrammar.Parser (agParser) where
> import Happy.Frontend.ParseMonad.Class
> import Happy.Frontend.ParseMonad.Bootstrapped
> import Happy.Frontend.ParseMonad
> import Happy.Frontend.AttrGrammar
> }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ The parser.

> {
> {-# OPTIONS_GHC -w #-}
> module Happy.Frontend.Parser.Bootstrapped (ourParser) where
> module Happy.Frontend.Parser (ourParser) where
> import Happy.Frontend.ParseMonad.Class
> import Happy.Frontend.ParseMonad.Bootstrapped
> import Happy.Frontend.ParseMonad
> import Happy.Frontend.AbsSyn
> import Happy.Frontend.Lexer
> }
Expand Down
5 changes: 5 additions & 0 deletions packages/frontend/bootstrap.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env sh

BASEDIR=$(dirname "$0")
happy -agc "$BASEDIR/boot-src/Parser.ly" -o "$BASEDIR/src/Happy/Frontend/Parser.hs"
happy -agc "$BASEDIR/boot-src/AttrGrammarParser.ly" -o "$BASEDIR/src/Happy/Frontend/AttrGrammar/Parser.hs"
28 changes: 3 additions & 25 deletions packages/frontend/happy-frontend.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,6 @@ tested-with:
GHC == 7.4.2
GHC == 7.0.4

flag bootstrap
description:
Optimize the implementation of happy using a pre-built happy,
and add support for attribute grammars.
manual: True
default: True

library
hs-source-dirs: src
exposed-modules: Happy.Frontend,
Expand All @@ -70,21 +63,6 @@ library
Happy.Frontend.Parser
Happy.Frontend.Lexer
Happy.Frontend.ParamRules


if flag(bootstrap)
-- TODO put this back when Cabal can use it's qualified goals to better
-- understand bootstrapping, see
-- https://github.com/haskell/cabal/issues/7189
--build-tools: happy
cpp-options: -DHAPPY_BOOTSTRAP
other-modules:
Happy.Frontend.ParseMonad.Bootstrapped
Happy.Frontend.Parser.Bootstrapped
Happy.Frontend.AttrGrammar
Happy.Frontend.AttrGrammar.Parser
Happy.Frontend.AttrGrammar.Mangler
else
other-modules:
Happy.Frontend.ParseMonad.Oracle
Happy.Frontend.Parser.Oracle
Happy.Frontend.AttrGrammar
Happy.Frontend.AttrGrammar.Parser
Happy.Frontend.AttrGrammar.Mangler
10 changes: 1 addition & 9 deletions packages/frontend/src/Happy/Frontend.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Happy.Frontend where

import Happy.Frontend.AbsSyn
import Happy.Frontend.Parser
import Happy.Frontend.ParseMonad.Class
Expand Down Expand Up @@ -30,11 +30,3 @@ deLitify = deLit where
deLit2 ('\n':r) = '\n' : deLit r
deLit2 (_:r) = deLit2 r
deLit2 [] = []

-- Iff happy is built with bootstrapping, attribute grammars are supported
supportsParsingAttributeGrammars :: Bool
#ifdef HAPPY_BOOTSTRAP
supportsParsingAttributeGrammars = True
#else
supportsParsingAttributeGrammars = False
#endif
Loading

0 comments on commit 3eca9d0

Please sign in to comment.