[Git][ghc/ghc][wip/az/ghc-cpp] 51 commits: interpreter: Fix INTERP_STATS profiling code

Alan Zimmerman (@alanz) gitlab at gitlab.haskell.org
Sun Feb 9 22:16:20 UTC 2025



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


Commits:
66c7f656 by Matthew Pickering at 2025-02-06T17:15:25-05:00
interpreter: Fix INTERP_STATS profiling code

The profiling code had slightly bitrotted since the last time it was
used. This just fixes things so that if you toggle the INTERP_STATS
macro then it just works and prints out the stats.

Fixes #25695

- - - - -
f71c2835 by Matthew Pickering at 2025-02-06T17:16:02-05:00
perf: Key the interpreter symbol cache by Name rather than FastString

Profiles showed that about 0.2s was being spend constructing the keys
before looking up values in the old symbol cache.

The performance of this codepath is critical as it translates directly
to a delay when a user evaluates a function like `main` in the
interpreter.

Therefore we implement a solution which keys the cache(s) by `Name`
rather than the symbol directly, so the cache can be consulted before
the symbol is constructed.

Fixes #25731

- - - - -
8f8d3a90 by Ben Gamari at 2025-02-08T01:17:28-05:00
base: Label threads forked by IO operations

Addresses part of #25452.

Addresses core-libraries-committee#305.

- - - - -
28600825 by Ben Gamari at 2025-02-08T01:17:28-05:00
base: Label threads forked by System.Timeout

Addresses part of #25452.

Addresses core-libraries-committee#305.

- - - - -
8a249827 by Ben Gamari at 2025-02-08T01:17:28-05:00
base: Label signal handling threads

Addresses part of #25452.

Addresses core-libraries-committee#305.

- - - - -
26af26f0 by Ben Gamari at 2025-02-08T01:17:28-05:00
base: Label Windows console event handling threads

Addresses part of #25452.

Addresses core-libraries-committee#305.

- - - - -
bf9c3d4f by Ben Gamari at 2025-02-08T01:17:28-05:00
ghci: Label evaluation sandbox thread

Addresses part of #25452.

Addresses core-libraries-committee#305.

- - - - -
38f78ce5 by Ben Gamari at 2025-02-08T01:17:28-05:00
base: Add changelog entry for addition of thread labels

Addresses #25452.

Addresses core-libraries-committee#305.

- - - - -
c100deb5 by Ben Gamari at 2025-02-08T01:18:05-05:00
gen-ci: Clean up style

This cleans up a number of stylistic inconsistencies although it's still
far from perfect.

- - - - -
c4a7680a by Ben Gamari at 2025-02-08T01:18:05-05:00
gen-ci: Properly encapsulate GitLab predicates

- - - - -
3b5b15e1 by Alan Zimmerman at 2025-02-08T09:36:31+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

- - - - -
46c2bafd by Alan Zimmerman at 2025-02-08T09:36:31+00:00
Tidy up before re-visiting the continuation mechanic

- - - - -
a84c8454 by Alan Zimmerman at 2025-02-08T09:36:31+00:00
Switch preprocessor to continuation passing style

Proof of concept, needs tidying up

- - - - -
13f1482f by Alan Zimmerman at 2025-02-08T09:36:31+00:00
Small cleanup

- - - - -
39ca42b8 by Alan Zimmerman at 2025-02-08T09:36:31+00:00
Get rid of some cruft

- - - - -
3cbc5d68 by Alan Zimmerman at 2025-02-08T09:36:31+00:00
Starting to integrate.

Need to get the pragma recognised and set

- - - - -
61e2a7d7 by Alan Zimmerman at 2025-02-08T09:36:31+00:00
Make cppTokens extend to end of line, and process CPP comments

- - - - -
fac69bc5 by Alan Zimmerman at 2025-02-08T09:36:31+00:00
Remove unused ITcppDefined

- - - - -
2757741b by Alan Zimmerman at 2025-02-08T09:36:31+00:00
Allow spaces between # and keyword for preprocessor directive

- - - - -
cbebbd8f by Alan Zimmerman at 2025-02-08T09:36:31+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.

- - - - -
c9a7fd91 by Alan Zimmerman at 2025-02-08T09:36:32+00:00
Accumulate CPP continuations, process when ready

Can be simplified further, we only need one CPP token

- - - - -
cbae76a4 by Alan Zimmerman at 2025-02-08T09:36:32+00:00
Simplify Lexer interface. Only ITcpp

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

- - - - -
67cccefe by Alan Zimmerman at 2025-02-08T09:36:32+00:00
Deal with directive on last line, with no trailing \n

- - - - -
51c06eca by Alan Zimmerman at 2025-02-08T09:36:32+00:00
Start parsing and processing the directives

- - - - -
eed6c4a6 by Alan Zimmerman at 2025-02-08T09:36:32+00:00
Prepare for processing include files

- - - - -
78e40f85 by Alan Zimmerman at 2025-02-08T09:36:32+00:00
Move PpState into PreProcess

And initParserState, initPragState too

- - - - -
b908e27f by Alan Zimmerman at 2025-02-08T09:36:32+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

- - - - -
ddb9a0f8 by Alan Zimmerman at 2025-02-08T09:36:32+00:00
Split into separate files

- - - - -
6747454c by Alan Zimmerman at 2025-02-08T09:36:32+00:00
Starting on expression parser.

But it hangs. Time for Text.Parsec.Expr

- - - - -
051d8545 by Alan Zimmerman at 2025-02-08T09:36:32+00:00
Start integrating the ghc-cpp work

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

- - - - -
c6763690 by Alan Zimmerman at 2025-02-08T09:36:32+00:00
WIP

- - - - -
0626b2a7 by Alan Zimmerman at 2025-02-08T09:36:32+00:00
Fixup after rebase

- - - - -
1dc2c5de by Alan Zimmerman at 2025-02-08T09:36:32+00:00
WIP

- - - - -
9c24c3af by Alan Zimmerman at 2025-02-08T09:36:32+00:00
Fixup after rebase, including all tests pass

- - - - -
3d1c7fa2 by Alan Zimmerman at 2025-02-08T09:36:32+00:00
Change pragma usage to GHC_CPP from GhcCPP

- - - - -
c0750678 by Alan Zimmerman at 2025-02-08T09:36:32+00:00
Some comments

- - - - -
9ba99ece by Alan Zimmerman at 2025-02-08T09:36:32+00:00
Reformat

- - - - -
e3bea5ac by Alan Zimmerman at 2025-02-08T09:36:32+00:00
Delete unused file

- - - - -
1308c9f3 by Alan Zimmerman at 2025-02-08T09:36:32+00:00
Rename module Parse to ParsePP

- - - - -
30344e7e by Alan Zimmerman at 2025-02-08T09:36:32+00:00
Clarify naming in the parser

- - - - -
f1c449b1 by Alan Zimmerman at 2025-02-08T09:36:32+00:00
WIP. Switching to alex/happy to be able to work in-tree

Since Parsec is not available

- - - - -
6d2ebef1 by Alan Zimmerman at 2025-02-08T09:36:32+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

- - - - -
820e0a6a by Alan Zimmerman at 2025-02-08T09:36:32+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
```

- - - - -
131c2d6c by Alan Zimmerman at 2025-02-08T09:36:32+00:00
Rebase, and all tests pass except whitespace for generated parser

- - - - -
4ec42e20 by Alan Zimmerman at 2025-02-08T09:36:32+00:00
More plumbing. Ready for testing tomorrow.

- - - - -
e64e6bb1 by Alan Zimmerman at 2025-02-08T09:36:32+00:00
Proress. Renamed module State from Types

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

- - - - -
40e24b59 by Alan Zimmerman at 2025-02-08T09:36:32+00:00
Insert basic GHC version macros into parser

__GLASGOW_HASKELL__
__GLASGOW_HASKELL_FULL_VERSION__
__GLASGOW_HASKELL_PATCHLEVEL1__
__GLASGOW_HASKELL_PATCHLEVEL2__

- - - - -
1b8ae7f7 by Alan Zimmerman at 2025-02-08T11:03:54+00:00
Re-sync check-cpp for easy ghci work

- - - - -
7009479a by Alan Zimmerman at 2025-02-08T12:38:03+00:00
Get rid of warnings

- - - - -
56c761d9 by Alan Zimmerman at 2025-02-09T20:18:49+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

- - - - -
c964606e by Alan Zimmerman at 2025-02-09T22:15:29+00:00
WIP. Can crack arguments for #define

Next step it to crack out args in an expansion

- - - - -


80 changed files:

- .gitlab/generate-ci/gen_ci.hs
- compiler/GHC.hs
- compiler/GHC/ByteCode/Linker.hs
- compiler/GHC/Cmm/Lexer.x
- compiler/GHC/Cmm/Parser.y
- compiler/GHC/Cmm/Parser/Monad.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/Linker/Loader.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/Runtime/Interpreter.hs
- compiler/GHC/Runtime/Interpreter/Types.hs
- + compiler/GHC/Runtime/Interpreter/Types/SymbolCache.hs
- compiler/ghc.cabal.in
- ghc/GHCi/UI.hs
- hadrian/src/Rules/SourceDist.hs
- hadrian/stack.yaml.lock
- libraries/base/changelog.md
- libraries/base/src/Control/Concurrent.hs
- libraries/base/src/System/Timeout.hs
- libraries/ghc-internal/src/GHC/Internal/Conc/Signal.hs
- libraries/ghc-internal/src/GHC/Internal/Event/Windows/ConsoleEvent.hsc
- libraries/ghc-internal/src/GHC/Internal/LanguageExtensions.hs
- libraries/ghci/GHCi/Run.hs
- rts/Interpreter.c
- rts/Interpreter.h
- rts/RtsMain.c
- testsuite/tests/count-deps/CountDepsParser.stdout
- testsuite/tests/driver/T4437.hs
- testsuite/tests/ghc-api/T11579.hs
- testsuite/tests/interface-stability/base-exports.stdout
- testsuite/tests/interface-stability/base-exports.stdout-javascript-unknown-ghcjs
- testsuite/tests/interface-stability/base-exports.stdout-mingw32
- testsuite/tests/interface-stability/base-exports.stdout-ws-32
- testsuite/tests/interface-stability/template-haskell-exports.stdout
- testsuite/tests/linters/notes.stdout
- + 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/Main.hs
- utils/check-exact/Parsers.hs
- utils/check-exact/Preprocess.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/f2c26471cb9ae42192d7ee70c66a4251070817c3...c964606e494de5f11ae9838091af3760c8cf0eff

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/f2c26471cb9ae42192d7ee70c66a4251070817c3...c964606e494de5f11ae9838091af3760c8cf0eff
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/20250209/a8c71255/attachment-0001.html>


More information about the ghc-commits mailing list