[Git][ghc/ghc][wip/az/ghc-cpp] 53 commits: Avoid partiality in `Language.Haskell.Syntax.Expr`, `GHC.Hs.Expr`, `GHC.Rename.Expr`, etc.

Alan Zimmerman (@alanz) gitlab at gitlab.haskell.org
Sun Feb 16 12:52:56 UTC 2025



Alan Zimmerman pushed to branch wip/az/ghc-cpp at Glasgow Haskell Compiler / GHC


Commits:
52b6539b by M Farkas-Dyck at 2025-02-08T11:34:51-08:00
Avoid partiality in `Language.Haskell.Syntax.Expr`, `GHC.Hs.Expr`, `GHC.Rename.Expr`, etc.

In particular, use `NonEmpty` where appropriate:
- the argument of `FieldLabelString`
- the argument of `HsMultiIf`
- `grhssGRHSs`

Decreases overall compile-time allocation by about 0.1% in the benchmark suite (min -0.8%, max +0.3%).

Metric Decrease:
    T3294

- - - - -
a566da92 by Ben Gamari at 2025-02-10T03:21:49-05:00
gitlab-ci: Bump docker images

Closes #25693.

- - - - -
a7e23f01 by Ben Gamari at 2025-02-10T03:21:49-05:00
hadrian: Drop uses of head/tail

To silence warnings with GHC 9.10

- - - - -
12752f0c by Ben Gamari at 2025-02-10T03:21:49-05:00
hadrian: Disable x-data-list-nonempty-unzip warning

- - - - -
e22a14fc by Simon Peyton Jones at 2025-02-11T16:21:10+00:00
Deal correctly with Given CallStack constraints

As #25675 showed, the CallStack solving mechanism was failing
to account for Given CallStack constraints.

This small patch fixes it and improves the Notes.

Small improvement to GHCi debugger output in break011, break024,
which is discussed on the MR !13883

- - - - -
db3e810f by Simon Peyton Jones at 2025-02-12T09:12:30-05:00
Fix inlineBoringOk again

This MR fixes #25713, which turned out to be a consequence of not
completing #17182.

I think I have now gotten it right.  See the new
  Note [inlineBoringOk]

- - - - -
17c95957 by Alan Zimmerman at 2025-02-13T18:20:02+00:00
GHC-CPP: first rough proof of concept

Processes

     #define FOO
     #ifdef FOO
     x = 1
     #endif

Into

    [ITcppIgnored [L loc ITcppDefine]
    ,ITcppIgnored [L loc ITcppIfdef]
    ,ITvarid "x"
    ,ITequal
    ,ITinteger (IL {il_text = SourceText "1", il_neg = False, il_value = 1})
    ,ITcppIgnored [L loc ITcppEndif]
    ,ITeof]

In time, ITcppIgnored will be pushed into a comment

- - - - -
c816c522 by Alan Zimmerman at 2025-02-13T18:20:02+00:00
Tidy up before re-visiting the continuation mechanic

- - - - -
c24de54e by Alan Zimmerman at 2025-02-13T18:20:02+00:00
Switch preprocessor to continuation passing style

Proof of concept, needs tidying up

- - - - -
88879c7d by Alan Zimmerman at 2025-02-13T18:20:02+00:00
Small cleanup

- - - - -
fdccad4d by Alan Zimmerman at 2025-02-13T18:20:02+00:00
Get rid of some cruft

- - - - -
97e6f3c2 by Alan Zimmerman at 2025-02-13T18:20:03+00:00
Starting to integrate.

Need to get the pragma recognised and set

- - - - -
4f06534c by Alan Zimmerman at 2025-02-13T18:20:03+00:00
Make cppTokens extend to end of line, and process CPP comments

- - - - -
11c92870 by Alan Zimmerman at 2025-02-13T18:20:03+00:00
Remove unused ITcppDefined

- - - - -
247c24fb by Alan Zimmerman at 2025-02-13T18:20:03+00:00
Allow spaces between # and keyword for preprocessor directive

- - - - -
746ed4d8 by Alan Zimmerman at 2025-02-13T18:20:03+00:00
Process CPP continuation lines

They are emited as separate ITcppContinue tokens.
Perhaps the processing should be more like a comment, and keep on
going to the end.
BUT, the last line needs to be slurped as a whole.

- - - - -
1239ce9e by Alan Zimmerman at 2025-02-13T18:20:03+00:00
Accumulate CPP continuations, process when ready

Can be simplified further, we only need one CPP token

- - - - -
934446de by Alan Zimmerman at 2025-02-13T18:20:03+00:00
Simplify Lexer interface. Only ITcpp

We transfer directive lines through it, then parse them from scratch
in the preprocessor.

- - - - -
1a1d8136 by Alan Zimmerman at 2025-02-13T18:20:03+00:00
Deal with directive on last line, with no trailing \n

- - - - -
a8e03ca9 by Alan Zimmerman at 2025-02-13T18:20:03+00:00
Start parsing and processing the directives

- - - - -
f13d68d1 by Alan Zimmerman at 2025-02-13T18:20:03+00:00
Prepare for processing include files

- - - - -
8d72e20d by Alan Zimmerman at 2025-02-13T18:20:03+00:00
Move PpState into PreProcess

And initParserState, initPragState too

- - - - -
a1f3da18 by Alan Zimmerman at 2025-02-13T18:20:03+00:00
Process nested include files

Also move PpState out of Lexer.x, so it is easy to evolve it in a ghci
session, loading utils/check-cpp/Main.hs

- - - - -
ce86dcb2 by Alan Zimmerman at 2025-02-13T18:20:03+00:00
Split into separate files

- - - - -
c99c29e1 by Alan Zimmerman at 2025-02-13T18:20:03+00:00
Starting on expression parser.

But it hangs. Time for Text.Parsec.Expr

- - - - -
ede86a33 by Alan Zimmerman at 2025-02-13T18:20:03+00:00
Start integrating the ghc-cpp work

>From https://github.com/alanz/ghc-cpp

- - - - -
6d713b81 by Alan Zimmerman at 2025-02-13T18:20:03+00:00
WIP

- - - - -
445d1fc4 by Alan Zimmerman at 2025-02-13T18:20:03+00:00
Fixup after rebase

- - - - -
ce7d4ee6 by Alan Zimmerman at 2025-02-13T18:20:03+00:00
WIP

- - - - -
baa4a970 by Alan Zimmerman at 2025-02-13T18:20:03+00:00
Fixup after rebase, including all tests pass

- - - - -
56dd911b by Alan Zimmerman at 2025-02-13T18:20:03+00:00
Change pragma usage to GHC_CPP from GhcCPP

- - - - -
b83125ef by Alan Zimmerman at 2025-02-13T18:20:03+00:00
Some comments

- - - - -
cf2e0812 by Alan Zimmerman at 2025-02-13T18:20:03+00:00
Reformat

- - - - -
a423a1b6 by Alan Zimmerman at 2025-02-13T18:20:03+00:00
Delete unused file

- - - - -
eab7917a by Alan Zimmerman at 2025-02-13T18:20:03+00:00
Rename module Parse to ParsePP

- - - - -
4e830d41 by Alan Zimmerman at 2025-02-13T18:20:03+00:00
Clarify naming in the parser

- - - - -
34065d04 by Alan Zimmerman at 2025-02-13T18:20:03+00:00
WIP. Switching to alex/happy to be able to work in-tree

Since Parsec is not available

- - - - -
41f0a961 by Alan Zimmerman at 2025-02-13T18:20:03+00:00
Layering is now correct

- GHC lexer, emits CPP tokens
- accumulated in Preprocessor state
- Lexed by CPP lexer, CPP command extracted, tokens concated with
  spaces (to get rid of token pasting via comments)
- if directive lexed and parsed by CPP lexer/parser, and evaluated

- - - - -
58893e3b by Alan Zimmerman at 2025-02-13T18:20:03+00:00
First example working

Loading Example1.hs into ghci, getting the right results

```
{-# LANGUAGE GHC_CPP #-}
module Example1 where

y = 3

x =
  "hello"
  "bye now"

foo = putStrLn x
```

- - - - -
5f8069b0 by Alan Zimmerman at 2025-02-13T18:20:03+00:00
Rebase, and all tests pass except whitespace for generated parser

- - - - -
8cd7644e by Alan Zimmerman at 2025-02-13T18:20:03+00:00
More plumbing. Ready for testing tomorrow.

- - - - -
60bf159c by Alan Zimmerman at 2025-02-13T18:20:03+00:00
Proress. Renamed module State from Types

And at first blush it seems to handle preprocessor scopes properly.

- - - - -
069ed399 by Alan Zimmerman at 2025-02-13T18:20:03+00:00
Insert basic GHC version macros into parser

__GLASGOW_HASKELL__
__GLASGOW_HASKELL_FULL_VERSION__
__GLASGOW_HASKELL_PATCHLEVEL1__
__GLASGOW_HASKELL_PATCHLEVEL2__

- - - - -
61dad56b by Alan Zimmerman at 2025-02-13T18:20:03+00:00
Re-sync check-cpp for easy ghci work

- - - - -
cdaad6a4 by Alan Zimmerman at 2025-02-13T18:20:03+00:00
Get rid of warnings

- - - - -
854fca16 by Alan Zimmerman at 2025-02-13T18:20:03+00:00
Rework macro processing, in check-cpp

Macros kept at the top level, looked up via name, multiple arity
versions per name can be stored

- - - - -
c223ff66 by Alan Zimmerman at 2025-02-13T18:20:03+00:00
WIP. Can crack arguments for #define

Next step it to crack out args in an expansion

- - - - -
17e942eb by Alan Zimmerman at 2025-02-13T18:20:03+00:00
WIP on arg parsing.

- - - - -
8e6af12c by Alan Zimmerman at 2025-02-13T21:41:17+00:00
Progress. Still screwing up nested parens.

- - - - -
58cb4d2e by Alan Zimmerman at 2025-02-15T13:47:08+00:00
Seems to work, but has redundant code

- - - - -
f00dcda5 by Alan Zimmerman at 2025-02-15T14:26:38+00:00
Remove redundant code

- - - - -
c677e529 by Alan Zimmerman at 2025-02-15T14:27:14+00:00
Reformat

- - - - -
85e370c7 by Alan Zimmerman at 2025-02-16T12:52:28+00:00
Expand args, single pass

Still need to repeat until fixpoint

- - - - -


125 changed files:

- .gitlab-ci.yml
- compiler/GHC.hs
- compiler/GHC/Cmm/Lexer.x
- compiler/GHC/Cmm/Parser.y
- compiler/GHC/Cmm/Parser/Monad.hs
- compiler/GHC/Core/Opt/SetLevels.hs
- compiler/GHC/Core/Unfold.hs
- compiler/GHC/Core/Unfold/Make.hs
- compiler/GHC/Core/UsageEnv.hs
- + compiler/GHC/Data/List/NonEmpty.hs
- compiler/GHC/Driver/Backpack.hs
- compiler/GHC/Driver/Config/Parser.hs
- compiler/GHC/Driver/Flags.hs
- compiler/GHC/Driver/Main.hs
- compiler/GHC/Driver/Make.hs
- compiler/GHC/Driver/Pipeline/Execute.hs
- compiler/GHC/Driver/Session.hs
- compiler/GHC/Hs/Expr.hs
- compiler/GHC/Hs/Utils.hs
- compiler/GHC/HsToCore/Arrows.hs
- compiler/GHC/HsToCore/Expr.hs
- compiler/GHC/HsToCore/GuardedRHSs.hs
- compiler/GHC/HsToCore/Pmc.hs
- compiler/GHC/HsToCore/Pmc/Desugar.hs
- compiler/GHC/HsToCore/Quote.hs
- compiler/GHC/HsToCore/Ticks.hs
- compiler/GHC/Iface/Ext/Ast.hs
- compiler/GHC/Parser.hs-boot
- compiler/GHC/Parser.y
- compiler/GHC/Parser/Annotation.hs
- compiler/GHC/Parser/HaddockLex.x
- compiler/GHC/Parser/Header.hs
- compiler/GHC/Parser/Lexer.x
- compiler/GHC/Parser/PostProcess.hs
- compiler/GHC/Parser/PostProcess/Haddock.hs
- + compiler/GHC/Parser/PreProcess.hs
- + compiler/GHC/Parser/PreProcess/Eval.hs
- + compiler/GHC/Parser/PreProcess/Lexer.x
- + compiler/GHC/Parser/PreProcess/Macro.hs
- + compiler/GHC/Parser/PreProcess/ParsePP.hs
- + compiler/GHC/Parser/PreProcess/Parser.y
- + compiler/GHC/Parser/PreProcess/ParserM.hs
- + compiler/GHC/Parser/PreProcess/State.hs
- compiler/GHC/Parser/Utils.hs
- compiler/GHC/Prelude/Basic.hs
- compiler/GHC/Rename/Expr.hs
- compiler/GHC/Rename/Module.hs
- compiler/GHC/Rename/Utils.hs
- compiler/GHC/Tc/Errors/Ppr.hs
- compiler/GHC/Tc/Errors/Types.hs
- compiler/GHC/Tc/Gen/Expr.hs
- compiler/GHC/Tc/Gen/Match.hs
- compiler/GHC/Tc/Solver/Dict.hs
- compiler/GHC/Tc/Solver/Types.hs
- compiler/GHC/Tc/Types/Evidence.hs
- compiler/GHC/Tc/Types/Origin.hs
- compiler/GHC/ThToHs.hs
- compiler/GHC/Types/Error/Codes.hs
- compiler/Language/Haskell/Syntax/Expr.hs
- compiler/ghc.cabal.in
- ghc/GHCi/UI.hs
- hadrian/src/Hadrian/Utilities.hs
- hadrian/src/Oracles/ModuleFiles.hs
- hadrian/src/Rules/Dependencies.hs
- hadrian/src/Rules/SourceDist.hs
- hadrian/src/Settings/Parser.hs
- hadrian/stack.yaml.lock
- libraries/ghc-internal/src/GHC/Internal/LanguageExtensions.hs
- testsuite/tests/count-deps/CountDepsAst.stdout
- testsuite/tests/count-deps/CountDepsParser.stdout
- testsuite/tests/driver/T4437.hs
- testsuite/tests/ghc-api/T11579.hs
- testsuite/tests/ghc-api/exactprint/T22919.stderr
- testsuite/tests/ghc-api/exactprint/ZeroWidthSemi.stderr
- testsuite/tests/ghci.debugger/scripts/break011.stdout
- testsuite/tests/ghci.debugger/scripts/break024.stdout
- testsuite/tests/interface-stability/template-haskell-exports.stdout
- testsuite/tests/linters/notes.stdout
- testsuite/tests/module/mod185.stderr
- testsuite/tests/parser/should_compile/DumpParsedAst.stderr
- testsuite/tests/parser/should_compile/DumpParsedAstComments.stderr
- testsuite/tests/parser/should_compile/DumpRenamedAst.stderr
- testsuite/tests/parser/should_compile/DumpSemis.stderr
- testsuite/tests/parser/should_compile/DumpTypecheckedAst.stderr
- testsuite/tests/parser/should_compile/KindSigs.stderr
- testsuite/tests/parser/should_compile/T20718.stderr
- testsuite/tests/parser/should_compile/T20846.stderr
- testsuite/tests/perf/compiler/hard_hole_fits.stderr
- testsuite/tests/printer/Test20297.stdout
- testsuite/tests/printer/Test24533.stdout
- + testsuite/tests/profiling/should_run/T25675.hs
- + testsuite/tests/profiling/should_run/T25675.stdout
- testsuite/tests/profiling/should_run/all.T
- testsuite/tests/simplCore/should_compile/T22375DataFamily.stderr
- + testsuite/tests/simplCore/should_compile/T25713.hs
- + testsuite/tests/simplCore/should_compile/T25713.stderr
- testsuite/tests/simplCore/should_compile/all.T
- + testsuite/tests/th/EmptyGuard.hs
- + testsuite/tests/th/EmptyGuard.stderr
- testsuite/tests/th/all.T
- + utils/check-cpp/.ghci
- + utils/check-cpp/.gitignore
- + utils/check-cpp/Eval.hs
- + utils/check-cpp/Example1.hs
- + utils/check-cpp/Example2.hs
- + utils/check-cpp/Lexer.x
- + utils/check-cpp/Macro.hs
- + utils/check-cpp/Main.hs
- + utils/check-cpp/ParsePP.hs
- + utils/check-cpp/ParseSimulate.hs
- + utils/check-cpp/Parser.y
- + utils/check-cpp/ParserM.hs
- + utils/check-cpp/PreProcess.hs
- + utils/check-cpp/README.md
- + utils/check-cpp/State.hs
- + utils/check-cpp/run.sh
- utils/check-exact/ExactPrint.hs
- utils/check-exact/Main.hs
- utils/check-exact/Parsers.hs
- utils/check-exact/Preprocess.hs
- utils/check-exact/Transform.hs
- utils/check-exact/Utils.hs
- utils/haddock/haddock-api/src/Haddock/Backends/Hyperlinker/Parser.hs
- utils/haddock/haddock-api/src/Haddock/Parser.hs
- utils/haddock/haddock-api/src/Haddock/Types.hs


The diff was not included because it is too large.


View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/c964606e494de5f11ae9838091af3760c8cf0eff...85e370c7541de48c66acc8be30e98c4925f5e2ad

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/c964606e494de5f11ae9838091af3760c8cf0eff...85e370c7541de48c66acc8be30e98c4925f5e2ad
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20250216/1a00e7f4/attachment-0001.html>


More information about the ghc-commits mailing list