-
c7aa0c10
by Andreas Klebinger at 2025-06-15T05:47:24-04:00
Revert "Specialise: Don't float out constraint components."
This reverts commit c9abb87ccc0c91cd94f42b3e36270158398326ef.
Turns out two benchmarks from #19747 regresses by a factor of 7-8x if
we do not float those out.
-
fd998679
by Krzysztof Gogolewski at 2025-06-15T05:48:06-04:00
Fix EPT enforcement when mixing unboxed tuples and non-tuples
The code was assuming that an alternative cannot be returning a normal
datacon and an unboxed tuple at the same time. However, as seen in #26107,
this can happen when using a GADT to refine the representation type.
The solution is just to conservatively return TagDunno.
-
b5ca0c88
by Alan Zimmerman at 2025-06-16T20:38:12+01: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
-
b482283e
by Alan Zimmerman at 2025-06-16T20:38:12+01:00
Tidy up before re-visiting the continuation mechanic
-
80712c0e
by Alan Zimmerman at 2025-06-16T20:38:12+01:00
Switch preprocessor to continuation passing style
Proof of concept, needs tidying up
-
07b957e3
by Alan Zimmerman at 2025-06-16T20:38:12+01:00
Small cleanup
-
db0af5e7
by Alan Zimmerman at 2025-06-16T20:38:12+01:00
Get rid of some cruft
-
4cc48e6e
by Alan Zimmerman at 2025-06-16T20:38:12+01:00
Starting to integrate.
Need to get the pragma recognised and set
-
296e5e2c
by Alan Zimmerman at 2025-06-16T20:38:12+01:00
Make cppTokens extend to end of line, and process CPP comments
-
f7f3ce71
by Alan Zimmerman at 2025-06-16T20:38:12+01:00
Remove unused ITcppDefined
-
c6334d99
by Alan Zimmerman at 2025-06-16T20:38:12+01:00
Allow spaces between # and keyword for preprocessor directive
-
5d2cf958
by Alan Zimmerman at 2025-06-16T20:38:12+01: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.
-
5055fa9b
by Alan Zimmerman at 2025-06-16T20:38:12+01:00
Accumulate CPP continuations, process when ready
Can be simplified further, we only need one CPP token
-
e3897801
by Alan Zimmerman at 2025-06-16T20:38:12+01:00
Simplify Lexer interface. Only ITcpp
We transfer directive lines through it, then parse them from scratch
in the preprocessor.
-
75e311e4
by Alan Zimmerman at 2025-06-16T20:38:12+01:00
Deal with directive on last line, with no trailing \n
-
70d337da
by Alan Zimmerman at 2025-06-16T20:38:12+01:00
Start parsing and processing the directives
-
a3b0ecef
by Alan Zimmerman at 2025-06-16T20:38:12+01:00
Prepare for processing include files
-
4cd02936
by Alan Zimmerman at 2025-06-16T20:38:12+01:00
Move PpState into PreProcess
And initParserState, initPragState too
-
13ee850c
by Alan Zimmerman at 2025-06-16T20:38:12+01: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
-
ffe2b0af
by Alan Zimmerman at 2025-06-16T20:38:12+01:00
Split into separate files
-
f647d882
by Alan Zimmerman at 2025-06-16T20:38:12+01:00
Starting on expression parser.
But it hangs. Time for Text.Parsec.Expr
-
cb585d46
by Alan Zimmerman at 2025-06-16T20:38:12+01:00
Start integrating the ghc-cpp work
From https://github.com/alanz/ghc-cpp
-
fd7abae4
by Alan Zimmerman at 2025-06-16T20:38:12+01:00
WIP
-
66d50496
by Alan Zimmerman at 2025-06-16T20:38:12+01:00
Fixup after rebase
-
bd0cf83e
by Alan Zimmerman at 2025-06-16T20:38:13+01:00
WIP
-
ce97a77a
by Alan Zimmerman at 2025-06-16T20:38:13+01:00
Fixup after rebase, including all tests pass
-
f4e72bb6
by Alan Zimmerman at 2025-06-16T20:38:13+01:00
Change pragma usage to GHC_CPP from GhcCPP
-
dc8065ab
by Alan Zimmerman at 2025-06-16T20:38:13+01:00
Some comments
-
94302aa7
by Alan Zimmerman at 2025-06-16T20:38:13+01:00
Reformat
-
6be65f82
by Alan Zimmerman at 2025-06-16T20:38:13+01:00
Delete unused file
-
ebf647b3
by Alan Zimmerman at 2025-06-16T20:38:13+01:00
Rename module Parse to ParsePP
-
d05ee980
by Alan Zimmerman at 2025-06-16T20:38:13+01:00
Clarify naming in the parser
-
2826c91f
by Alan Zimmerman at 2025-06-16T20:38:13+01:00
WIP. Switching to alex/happy to be able to work in-tree
Since Parsec is not available
-
b64334d2
by Alan Zimmerman at 2025-06-16T20:38:13+01: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
-
0a9b98c2
by Alan Zimmerman at 2025-06-16T20:38:13+01: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
```
-
c3a49825
by Alan Zimmerman at 2025-06-16T20:38:13+01:00
Rebase, and all tests pass except whitespace for generated parser
-
02336e80
by Alan Zimmerman at 2025-06-16T20:38:13+01:00
More plumbing. Ready for testing tomorrow.
-
bc3631a6
by Alan Zimmerman at 2025-06-16T20:38:13+01:00
Proress. Renamed module State from Types
And at first blush it seems to handle preprocessor scopes properly.
-
a8ea5ef7
by Alan Zimmerman at 2025-06-16T20:38:13+01:00
Insert basic GHC version macros into parser
__GLASGOW_HASKELL__
__GLASGOW_HASKELL_FULL_VERSION__
__GLASGOW_HASKELL_PATCHLEVEL1__
__GLASGOW_HASKELL_PATCHLEVEL2__
-
af18730b
by Alan Zimmerman at 2025-06-16T20:38:13+01:00
Re-sync check-cpp for easy ghci work
-
d62d4831
by Alan Zimmerman at 2025-06-16T20:38:13+01:00
Get rid of warnings
-
b4b90037
by Alan Zimmerman at 2025-06-16T20:38:13+01: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
-
1145ab9c
by Alan Zimmerman at 2025-06-16T20:38:13+01:00
WIP. Can crack arguments for #define
Next step it to crack out args in an expansion
-
8948f255
by Alan Zimmerman at 2025-06-16T20:38:13+01:00
WIP on arg parsing.
-
5159fd45
by Alan Zimmerman at 2025-06-16T20:38:13+01:00
Progress. Still screwing up nested parens.
-
5a25d711
by Alan Zimmerman at 2025-06-16T20:38:13+01:00
Seems to work, but has redundant code
-
4d8a64f7
by Alan Zimmerman at 2025-06-16T20:38:13+01:00
Remove redundant code
-
d91aa75c
by Alan Zimmerman at 2025-06-16T20:38:13+01:00
Reformat
-
031bbca4
by Alan Zimmerman at 2025-06-16T20:38:13+01:00
Expand args, single pass
Still need to repeat until fixpoint
-
3bfd1415
by Alan Zimmerman at 2025-06-16T20:38:13+01:00
Fixed point expansion
-
2aeb7f75
by Alan Zimmerman at 2025-06-16T20:38:13+01:00
Sync the playground to compiler
-
80ffa7a5
by Alan Zimmerman at 2025-06-16T20:38:13+01:00
Working on dumping the GHC_CPP result
But We need to keep the BufSpan in a comment
-
d08260e2
by Alan Zimmerman at 2025-06-16T20:38:13+01:00
Keep BufSpan in queued comments in GHC.Parser.Lexer
-
bb1aece5
by Alan Zimmerman at 2025-06-16T20:38:13+01:00
Getting close to being able to print the combined tokens
showing what is in and what is out
-
1a4ec313
by Alan Zimmerman at 2025-06-16T20:38:13+01:00
First implementation of dumpGhcCpp.
Example output
First dumps all macros in the state, then the source, showing which
lines are in and which are out
------------------------------
- |#define FOO(A,B) A + B
- |#define FOO(A,B,C) A + B + C
- |#if FOO(1,FOO(3,4)) == 8
- |-- a comment
|x = 1
- |#else
- |x = 5
- |#endif
-
b7ba331a
by Alan Zimmerman at 2025-06-16T20:38:13+01:00
Clean up a bit
-
d09bfbdd
by Alan Zimmerman at 2025-06-16T20:38:13+01:00
Add -ddump-ghc-cpp option and a test based on it
-
9589464e
by Alan Zimmerman at 2025-06-16T20:38:13+01:00
Restore Lexer.x rules, we need them for continuation lines
-
5e0ed352
by Alan Zimmerman at 2025-06-16T20:38:13+01:00
Lexer.x: trying to sort out the span for continuations
- We need to match on \n at the end of the line
- We cannot simply back up for it
-
28110495
by Alan Zimmerman at 2025-06-16T20:38:13+01:00
Inserts predefined macros. But does not dump properly
Because the cpp tokens have a trailing newline
-
9c153370
by Alan Zimmerman at 2025-06-16T20:38:13+01:00
Remove unnecessary LExer rules
We *need* the ones that explicitly match to the end of the line.
-
1dd59f35
by Alan Zimmerman at 2025-06-16T20:38:13+01:00
Generate correct span for ITcpp
Dump now works, except we do not render trailing `\` for continuation
lines. This is good enough for use in test output.
-
7a53616e
by Alan Zimmerman at 2025-06-16T20:38:13+01:00
Reduce duplication in lexer
-
1a5ca838
by Alan Zimmerman at 2025-06-16T20:38:13+01:00
Tweaks
-
36990b03
by Alan Zimmerman at 2025-06-16T20:38:13+01:00
Insert min_version predefined macros into state
The mechanism now works. Still need to flesh out the full set.
-
4504494d
by Alan Zimmerman at 2025-06-16T20:38:13+01:00
Trying my alternative pragma syntax.
It works, but dumpGhcCpp is broken, I suspect from the ITcpp token
span update.
-
b5a4cd12
by Alan Zimmerman at 2025-06-16T20:38:13+01:00
Pragma extraction now works, with both CPP and GHC_CPP
For the following
{-# LANGUAGE CPP #-}
#if __GLASGOW_HASKELL__ >= 913
{-# LANGUAGE GHC_CPP #-}
#endif
We will enable GHC_CPP only
-
58ded48e
by Alan Zimmerman at 2025-06-16T20:38:14+01:00
Remove some tracing
-
eef78db8
by Alan Zimmerman at 2025-06-16T20:38:14+01:00
Fix test exes for changes
-
9a4be927
by Alan Zimmerman at 2025-06-16T20:38:14+01:00
For GHC_CPP tests, normalise config-time-based macros
-
422ddcfe
by Alan Zimmerman at 2025-06-16T20:38:14+01:00
WIP
-
7786c86e
by Alan Zimmerman at 2025-06-16T20:38:14+01:00
WIP again. What is wrong?
-
8817c3d3
by Alan Zimmerman at 2025-06-16T20:38:14+01:00
Revert to dynflags for normal not pragma lexing
-
5905a1b6
by Alan Zimmerman at 2025-06-16T20:38:14+01:00
Working on getting check-exact to work properly
-
64ff3895
by Alan Zimmerman at 2025-06-16T20:38:14+01:00
Passes CppCommentPlacement test
-
e2544f32
by Alan Zimmerman at 2025-06-16T20:38:14+01:00
Starting on exact printing with GHC_CPP
While overriding normal CPP
-
f7014dff
by Alan Zimmerman at 2025-06-16T20:38:14+01:00
Correctly store CPP ignored tokens as comments
By populating the lexeme string in it, based on the bufpos
-
cbc9b1ba
by Alan Zimmerman at 2025-06-16T20:38:14+01:00
WIP
-
3a962f10
by Alan Zimmerman at 2025-06-16T20:38:14+01:00
Simplifying
-
ef14d69f
by Alan Zimmerman at 2025-06-16T20:38:14+01:00
Update the active state logic
-
15adf2cf
by Alan Zimmerman at 2025-06-16T20:38:14+01:00
Work the new logic into the mainline code
-
72291b37
by Alan Zimmerman at 2025-06-16T20:38:14+01:00
Process `defined` operator
-
e19c5b9b
by Alan Zimmerman at 2025-06-16T20:38:14+01:00
Manage lexer state while skipping tokens
There is very intricate layout-related state used when lexing. If a
CPP directive blanks out some tokens, store this state when the
blanking starts, and restore it when they are no longer being blanked.
-
04ca10e5
by Alan Zimmerman at 2025-06-16T20:38:14+01:00
Track the last token buffer index, for ITCppIgnored
We need to attach the source being skipped in an ITCppIgnored token.
We cannot simply use its BufSpan as an index into the underlying
StringBuffer as it counts unicode chars, not bytes.
So we update the lexer state to store the starting StringBuffer
location for the last token, and use the already-stored length to
extract the correct portion of the StringBuffer being parsed.
-
912e169a
by Alan Zimmerman at 2025-06-16T20:38:14+01:00
Process the ! operator in GHC_CPP expressions
-
07272bdf
by Alan Zimmerman at 2025-06-16T20:38:14+01:00
Predefine a constant when GHC_CPP is being used.
-
d4834ef1
by Alan Zimmerman at 2025-06-16T20:38:14+01:00
WIP
-
b7f55fdd
by Alan Zimmerman at 2025-06-16T20:38:14+01:00
Skip lines directly in the lexer when required
-
9c5a9abd
by Alan Zimmerman at 2025-06-16T20:38:14+01:00
Properly manage location when accepting tokens again
-
db5bc52a
by Alan Zimmerman at 2025-06-16T20:38:14+01:00
Seems to be working now, for Example9
-
65afd1eb
by Alan Zimmerman at 2025-06-16T20:38:14+01:00
Remove tracing
-
b92824d0
by Alan Zimmerman at 2025-06-16T20:38:14+01:00
Fix parsing '*' in block comments
Instead of replacing them with '-'
-
8b1107d2
by Alan Zimmerman at 2025-06-16T20:38:14+01:00
Keep the trailing backslash in a ITcpp token
-
3c5b601c
by Alan Zimmerman at 2025-06-16T20:38:14+01:00
Deal with only enabling one section of a group.
A group is an instance of a conditional introduced by
#if/#ifdef/#ifndef,
and ending at the final #endif, including intermediate #elsif sections
-
8a8a30e9
by Alan Zimmerman at 2025-06-16T20:38:14+01:00
Replace remaining identifiers with 0 when evaluating
As per the spec
-
7c517040
by Alan Zimmerman at 2025-06-16T20:38:14+01:00
Snapshot before rebase
-
4509470a
by Alan Zimmerman at 2025-06-16T20:38:14+01:00
Skip non-processed lines starting with #
-
0b86582f
by Alan Zimmerman at 2025-06-16T20:38:14+01:00
Export generateMacros so we can use it in ghc-exactprint
-
d18db291
by Alan Zimmerman at 2025-06-16T20:38:14+01:00
Fix rebase
-
7c67cb7e
by Alan Zimmerman at 2025-06-16T20:38:14+01:00
Expose initParserStateWithMacrosString
-
e5bf75a2
by Alan Zimmerman at 2025-06-16T20:38:14+01:00
Fix buggy lexer cppSkip
It was skipping all lines, not just ones prefixed by #
-
ab732d3d
by Alan Zimmerman at 2025-06-16T20:38:14+01:00
Fix evaluation of && to use the correct operator
-
91fd6476
by Alan Zimmerman at 2025-06-16T20:38:14+01:00
Deal with closing #-} at the start of a line
-
58b9fff9
by Alan Zimmerman at 2025-06-16T20:38:14+01:00
Add the MIN_VERSION_GLASGOW_HASKELL predefined macro
-
958c9c1e
by Alan Zimmerman at 2025-06-16T20:38:14+01:00
Include MIN_VERSION_GLASGOW_HASKELL in GhcCpp01.stderr
-
b1d22df4
by Alan Zimmerman at 2025-06-16T20:38:14+01:00
Use a strict map for macro defines
-
34e98c1a
by Alan Zimmerman at 2025-06-16T20:38:14+01:00
Process TIdentifierLParen
Which only matters at the start of #define
-
ca1afb10
by Alan Zimmerman at 2025-06-16T20:38:14+01:00
Do not provide TIdentifierLParen paren twice
-
6fdd89cd
by Alan Zimmerman at 2025-06-16T20:38:14+01:00
Handle whitespace between identifier and '(' for directive only
-
da0b00d7
by Alan Zimmerman at 2025-06-16T20:38:14+01:00
Expose some Lexer bitmap manipulation helpers
-
2a3424de
by Alan Zimmerman at 2025-06-16T20:38:14+01:00
Deal with line pragmas as tokens
Blows up for dumpGhcCpp though
-
534d6adb
by Alan Zimmerman at 2025-06-16T20:38:14+01:00
Allow strings delimited by a single quote too
-
426b93e3
by Alan Zimmerman at 2025-06-16T20:38:14+01:00
Allow leading whitespace on cpp directives
As per https://timsong-cpp.github.io/cppwp/n4140/cpp#1
-
7c006ee0
by Alan Zimmerman at 2025-06-16T20:38:14+01:00
Implement GHC_CPP undef
-
7a6e0968
by Alan Zimmerman at 2025-06-16T20:38:14+01:00
Sort out expansion of no-arg macros, in a context with args
And make the expansion bottom out, in the case of recursion
-
644688a3
by Alan Zimmerman at 2025-06-16T20:38:14+01:00
Fix GhcCpp01 test
The LINE pragma stuff works in ghc-exactprint when specifically
setting flag to emit ITline_pragma tokens
-
a84dbda6
by Alan Zimmerman at 2025-06-16T20:38:15+01:00
Process comments in CPP directives
-
3290096a
by Alan Zimmerman at 2025-06-16T20:38:15+01:00
Correctly lex pragmas with finel #-} on a newline
-
6ee54c72
by Alan Zimmerman at 2025-06-16T20:38:15+01:00
Do not process CPP-style comments
-
f069ba96
by Alan Zimmerman at 2025-06-16T20:38:15+01:00
Allow cpp-style comments when GHC_CPP enabled
-
a512ecd3
by Alan Zimmerman at 2025-06-16T20:38:15+01:00
Return other pragmas as cpp ignored when GHC_CPP active
-
c1a8d61d
by Alan Zimmerman at 2025-06-16T20:38:15+01:00
Fix exactprinting default decl
-
86f72f62
by Alan Zimmerman at 2025-06-16T20:38:15+01:00
Reorganise getOptionsFromFile for use in ghc-exactprint
We want to be able to inject predefined macro definitions into the
parser preprocessor state for when we do a hackage roundtrip.
-
027e2bbd
by Alan Zimmerman at 2025-06-16T20:38:15+01:00
Tweak testing
-
8d0ec8bf
by Alan Zimmerman at 2025-06-16T20:38:15+01:00
Only allow unknown cpp pragmas with # in left margin
-
305edf29
by Alan Zimmerman at 2025-06-16T20:38:15+01:00
Require # against left margin for all GHC_CPP directives
-
0ab61528
by Alan Zimmerman at 2025-06-16T20:38:15+01:00
Fix CPP directives appearing in pragmas
And add a test for error reporting for missing `#if`
-
56c4a318
by Alan Zimmerman at 2025-06-16T20:38:15+01:00
Starting to report GHC_CPP errors using GHC machinery
-
48cf8287
by Alan Zimmerman at 2025-06-16T20:38:15+01:00
More GHC_CPP diagnostic results
-
f0aa3567
by Alan Zimmerman at 2025-06-16T20:38:15+01:00
WIP on converting error calls to GHC diagnostics in GHC_CPP
-
920f7123
by Alan Zimmerman at 2025-06-16T20:38:15+01:00
Working on CPP diagnostic reporting
-
901f0917
by Alan Zimmerman at 2025-06-16T20:38:15+01:00
Tweak some tests/lint warnings
-
d0248398
by Alan Zimmerman at 2025-06-16T20:38:15+01:00
More error reporting in Macro
-
2c39a131
by Alan Zimmerman at 2025-06-16T20:38:15+01:00
Some cleanups