-
d3e60e97
by Ryan Scott at 2025-06-18T22:29:21-04:00
Deprecate -Wdata-kinds-tc, make DataKinds issues in typechecker become errors
!11314 introduced the `-Wdata-kinds-tc` warning as part of a fix for #22141.
This was a temporary stopgap measure to allow users who were accidentally
relying on code which needed the `DataKinds` extension in order to typecheck
without having to explicitly enable the extension.
Now that some amount of time has passed, this patch deprecates
`-Wdata-kinds-tc` and upgrades any `DataKinds`-related issues in the
typechecker (which were previously warnings) into errors.
-
fd5b5177
by Ryan Hendrickson at 2025-06-18T22:30:06-04:00
haddock: Add redact-type-synonyms pragma
`{-# OPTIONS_HADDOCK redact-type-synonyms #-}` pragma will hide the RHS
of type synonyms, and display the result kind instead, if the RHS
contains any unexported types.
-
15b2b2ec
by Alan Zimmerman at 2025-06-19T19:35:02+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
-
8a890112
by Alan Zimmerman at 2025-06-19T19:35:02+01:00
Tidy up before re-visiting the continuation mechanic
-
b81a1ae0
by Alan Zimmerman at 2025-06-19T19:35:02+01:00
Switch preprocessor to continuation passing style
Proof of concept, needs tidying up
-
cfe778e2
by Alan Zimmerman at 2025-06-19T19:35:02+01:00
Small cleanup
-
56dde4c8
by Alan Zimmerman at 2025-06-19T19:35:02+01:00
Get rid of some cruft
-
19be2264
by Alan Zimmerman at 2025-06-19T19:35:02+01:00
Starting to integrate.
Need to get the pragma recognised and set
-
9d65fbb9
by Alan Zimmerman at 2025-06-19T19:35:02+01:00
Make cppTokens extend to end of line, and process CPP comments
-
aacef8f5
by Alan Zimmerman at 2025-06-19T19:35:02+01:00
Remove unused ITcppDefined
-
9f54aa10
by Alan Zimmerman at 2025-06-19T19:35:02+01:00
Allow spaces between # and keyword for preprocessor directive
-
841e8b19
by Alan Zimmerman at 2025-06-19T19:35:02+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.
-
d0a141b9
by Alan Zimmerman at 2025-06-19T19:35:02+01:00
Accumulate CPP continuations, process when ready
Can be simplified further, we only need one CPP token
-
12c0689b
by Alan Zimmerman at 2025-06-19T19:35:02+01:00
Simplify Lexer interface. Only ITcpp
We transfer directive lines through it, then parse them from scratch
in the preprocessor.
-
30cd0529
by Alan Zimmerman at 2025-06-19T19:35:02+01:00
Deal with directive on last line, with no trailing \n
-
e2d20617
by Alan Zimmerman at 2025-06-19T19:35:02+01:00
Start parsing and processing the directives
-
74955b8e
by Alan Zimmerman at 2025-06-19T19:35:02+01:00
Prepare for processing include files
-
6c2f7197
by Alan Zimmerman at 2025-06-19T19:35:02+01:00
Move PpState into PreProcess
And initParserState, initPragState too
-
b112d95c
by Alan Zimmerman at 2025-06-19T19:35:02+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
-
c62fbc6d
by Alan Zimmerman at 2025-06-19T19:35:02+01:00
Split into separate files
-
5e9b65b6
by Alan Zimmerman at 2025-06-19T19:35:02+01:00
Starting on expression parser.
But it hangs. Time for Text.Parsec.Expr
-
e7233f54
by Alan Zimmerman at 2025-06-19T19:35:02+01:00
Start integrating the ghc-cpp work
From https://github.com/alanz/ghc-cpp
-
d44f73a2
by Alan Zimmerman at 2025-06-19T19:35:02+01:00
WIP
-
3524ce86
by Alan Zimmerman at 2025-06-19T19:35:02+01:00
Fixup after rebase
-
7a0bfc0a
by Alan Zimmerman at 2025-06-19T19:35:03+01:00
WIP
-
b247de57
by Alan Zimmerman at 2025-06-19T19:35:03+01:00
Fixup after rebase, including all tests pass
-
186c6054
by Alan Zimmerman at 2025-06-19T19:35:03+01:00
Change pragma usage to GHC_CPP from GhcCPP
-
b7ed58f2
by Alan Zimmerman at 2025-06-19T19:35:03+01:00
Some comments
-
0a7d82d3
by Alan Zimmerman at 2025-06-19T19:35:03+01:00
Reformat
-
0c126cd1
by Alan Zimmerman at 2025-06-19T19:35:03+01:00
Delete unused file
-
741b5935
by Alan Zimmerman at 2025-06-19T19:35:03+01:00
Rename module Parse to ParsePP
-
db9b5584
by Alan Zimmerman at 2025-06-19T19:35:03+01:00
Clarify naming in the parser
-
ed0e5a41
by Alan Zimmerman at 2025-06-19T19:35:03+01:00
WIP. Switching to alex/happy to be able to work in-tree
Since Parsec is not available
-
e567da0c
by Alan Zimmerman at 2025-06-19T19:35:03+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
-
468cda2a
by Alan Zimmerman at 2025-06-19T19:35:03+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
```
-
6bbc63fb
by Alan Zimmerman at 2025-06-19T19:35:03+01:00
Rebase, and all tests pass except whitespace for generated parser
-
a4ec35ca
by Alan Zimmerman at 2025-06-19T19:35:03+01:00
More plumbing. Ready for testing tomorrow.
-
91c2d89f
by Alan Zimmerman at 2025-06-19T19:35:03+01:00
Proress. Renamed module State from Types
And at first blush it seems to handle preprocessor scopes properly.
-
0c944603
by Alan Zimmerman at 2025-06-19T19:35:03+01:00
Insert basic GHC version macros into parser
__GLASGOW_HASKELL__
__GLASGOW_HASKELL_FULL_VERSION__
__GLASGOW_HASKELL_PATCHLEVEL1__
__GLASGOW_HASKELL_PATCHLEVEL2__
-
668d141e
by Alan Zimmerman at 2025-06-19T19:35:03+01:00
Re-sync check-cpp for easy ghci work
-
4f5b0d0b
by Alan Zimmerman at 2025-06-19T19:35:03+01:00
Get rid of warnings
-
7fdc08bd
by Alan Zimmerman at 2025-06-19T19:35:03+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
-
07814b89
by Alan Zimmerman at 2025-06-19T19:35:03+01:00
WIP. Can crack arguments for #define
Next step it to crack out args in an expansion
-
53e55437
by Alan Zimmerman at 2025-06-19T19:35:03+01:00
WIP on arg parsing.
-
8c04ddfd
by Alan Zimmerman at 2025-06-19T19:35:03+01:00
Progress. Still screwing up nested parens.
-
8e594a84
by Alan Zimmerman at 2025-06-19T19:35:03+01:00
Seems to work, but has redundant code
-
cc21e1d4
by Alan Zimmerman at 2025-06-19T19:35:03+01:00
Remove redundant code
-
6620f57c
by Alan Zimmerman at 2025-06-19T19:35:03+01:00
Reformat
-
694c05ef
by Alan Zimmerman at 2025-06-19T19:35:03+01:00
Expand args, single pass
Still need to repeat until fixpoint
-
a043620f
by Alan Zimmerman at 2025-06-19T19:35:03+01:00
Fixed point expansion
-
750c694f
by Alan Zimmerman at 2025-06-19T19:35:03+01:00
Sync the playground to compiler
-
6c8750c2
by Alan Zimmerman at 2025-06-19T19:35:03+01:00
Working on dumping the GHC_CPP result
But We need to keep the BufSpan in a comment
-
bdb8adf2
by Alan Zimmerman at 2025-06-19T19:35:03+01:00
Keep BufSpan in queued comments in GHC.Parser.Lexer
-
3ae1d536
by Alan Zimmerman at 2025-06-19T19:35:03+01:00
Getting close to being able to print the combined tokens
showing what is in and what is out
-
accff1b5
by Alan Zimmerman at 2025-06-19T19:35:03+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
-
8b9bf22a
by Alan Zimmerman at 2025-06-19T19:35:03+01:00
Clean up a bit
-
2f6ecade
by Alan Zimmerman at 2025-06-19T19:35:03+01:00
Add -ddump-ghc-cpp option and a test based on it
-
365aa02d
by Alan Zimmerman at 2025-06-19T19:35:03+01:00
Restore Lexer.x rules, we need them for continuation lines
-
0f6dfae8
by Alan Zimmerman at 2025-06-19T19:35:03+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
-
9f6aec58
by Alan Zimmerman at 2025-06-19T19:35:03+01:00
Inserts predefined macros. But does not dump properly
Because the cpp tokens have a trailing newline
-
829f75e2
by Alan Zimmerman at 2025-06-19T19:35:03+01:00
Remove unnecessary LExer rules
We *need* the ones that explicitly match to the end of the line.
-
501a2caf
by Alan Zimmerman at 2025-06-19T19:35:03+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.
-
db23d6e9
by Alan Zimmerman at 2025-06-19T19:35:03+01:00
Reduce duplication in lexer
-
047e48f5
by Alan Zimmerman at 2025-06-19T19:35:03+01:00
Tweaks
-
37b47da0
by Alan Zimmerman at 2025-06-19T19:35:03+01:00
Insert min_version predefined macros into state
The mechanism now works. Still need to flesh out the full set.
-
1e045be7
by Alan Zimmerman at 2025-06-19T19:35:03+01:00
Trying my alternative pragma syntax.
It works, but dumpGhcCpp is broken, I suspect from the ITcpp token
span update.
-
9a61360c
by Alan Zimmerman at 2025-06-19T19:35:03+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
-
4f8555c7
by Alan Zimmerman at 2025-06-19T19:35:03+01:00
Remove some tracing
-
8a68e6dc
by Alan Zimmerman at 2025-06-19T19:35:03+01:00
Fix test exes for changes
-
12177e13
by Alan Zimmerman at 2025-06-19T19:35:04+01:00
For GHC_CPP tests, normalise config-time-based macros
-
d442984b
by Alan Zimmerman at 2025-06-19T19:35:04+01:00
WIP
-
5cbb9087
by Alan Zimmerman at 2025-06-19T19:35:04+01:00
WIP again. What is wrong?
-
ff468973
by Alan Zimmerman at 2025-06-19T19:35:04+01:00
Revert to dynflags for normal not pragma lexing
-
00a4da95
by Alan Zimmerman at 2025-06-19T19:35:04+01:00
Working on getting check-exact to work properly
-
04c7e601
by Alan Zimmerman at 2025-06-19T19:35:04+01:00
Passes CppCommentPlacement test
-
0a08e51c
by Alan Zimmerman at 2025-06-19T19:35:04+01:00
Starting on exact printing with GHC_CPP
While overriding normal CPP
-
cebb3403
by Alan Zimmerman at 2025-06-19T19:35:04+01:00
Correctly store CPP ignored tokens as comments
By populating the lexeme string in it, based on the bufpos
-
8aa7e52c
by Alan Zimmerman at 2025-06-19T19:35:04+01:00
WIP
-
373b18ab
by Alan Zimmerman at 2025-06-19T19:35:04+01:00
Simplifying
-
eb25bbc6
by Alan Zimmerman at 2025-06-19T19:35:04+01:00
Update the active state logic
-
0c7a106a
by Alan Zimmerman at 2025-06-19T19:35:04+01:00
Work the new logic into the mainline code
-
22726082
by Alan Zimmerman at 2025-06-19T19:35:04+01:00
Process `defined` operator
-
3725a850
by Alan Zimmerman at 2025-06-19T19:35:04+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.
-
15414093
by Alan Zimmerman at 2025-06-19T19:35:04+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.
-
337dbc7a
by Alan Zimmerman at 2025-06-19T19:35:04+01:00
Process the ! operator in GHC_CPP expressions
-
b79f9bea
by Alan Zimmerman at 2025-06-19T19:35:04+01:00
Predefine a constant when GHC_CPP is being used.
-
052e64b3
by Alan Zimmerman at 2025-06-19T19:35:04+01:00
WIP
-
d996722c
by Alan Zimmerman at 2025-06-19T19:35:04+01:00
Skip lines directly in the lexer when required
-
6d5efd6f
by Alan Zimmerman at 2025-06-19T19:35:04+01:00
Properly manage location when accepting tokens again
-
6edf4195
by Alan Zimmerman at 2025-06-19T19:35:04+01:00
Seems to be working now, for Example9
-
2077e54c
by Alan Zimmerman at 2025-06-19T19:35:04+01:00
Remove tracing
-
83a4d5ab
by Alan Zimmerman at 2025-06-19T19:35:04+01:00
Fix parsing '*' in block comments
Instead of replacing them with '-'
-
097b4235
by Alan Zimmerman at 2025-06-19T19:35:04+01:00
Keep the trailing backslash in a ITcpp token
-
e0e1e90f
by Alan Zimmerman at 2025-06-19T19:35:04+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
-
7151fd24
by Alan Zimmerman at 2025-06-19T19:35:04+01:00
Replace remaining identifiers with 0 when evaluating
As per the spec
-
49cfb7a3
by Alan Zimmerman at 2025-06-19T19:35:04+01:00
Snapshot before rebase
-
4cfce858
by Alan Zimmerman at 2025-06-19T19:35:04+01:00
Skip non-processed lines starting with #
-
c706f25d
by Alan Zimmerman at 2025-06-19T19:35:04+01:00
Export generateMacros so we can use it in ghc-exactprint
-
89b39f49
by Alan Zimmerman at 2025-06-19T19:35:04+01:00
Fix rebase
-
2a346936
by Alan Zimmerman at 2025-06-19T19:35:04+01:00
Expose initParserStateWithMacrosString
-
f12c44db
by Alan Zimmerman at 2025-06-19T19:35:04+01:00
Fix buggy lexer cppSkip
It was skipping all lines, not just ones prefixed by #
-
5f84c0db
by Alan Zimmerman at 2025-06-19T19:35:04+01:00
Fix evaluation of && to use the correct operator
-
2d8bedc7
by Alan Zimmerman at 2025-06-19T19:35:04+01:00
Deal with closing #-} at the start of a line
-
555b7a83
by Alan Zimmerman at 2025-06-19T19:35:04+01:00
Add the MIN_VERSION_GLASGOW_HASKELL predefined macro
-
ba80b032
by Alan Zimmerman at 2025-06-19T19:35:04+01:00
Include MIN_VERSION_GLASGOW_HASKELL in GhcCpp01.stderr
-
edf528f7
by Alan Zimmerman at 2025-06-19T19:35:04+01:00
Use a strict map for macro defines
-
c28cd1b7
by Alan Zimmerman at 2025-06-19T19:35:04+01:00
Process TIdentifierLParen
Which only matters at the start of #define
-
0516c631
by Alan Zimmerman at 2025-06-19T19:35:04+01:00
Do not provide TIdentifierLParen paren twice
-
24e4d45d
by Alan Zimmerman at 2025-06-19T19:35:04+01:00
Handle whitespace between identifier and '(' for directive only
-
4de7275c
by Alan Zimmerman at 2025-06-19T19:35:04+01:00
Expose some Lexer bitmap manipulation helpers
-
6d12ec40
by Alan Zimmerman at 2025-06-19T19:35:04+01:00
Deal with line pragmas as tokens
Blows up for dumpGhcCpp though
-
c682be7a
by Alan Zimmerman at 2025-06-19T19:35:04+01:00
Allow strings delimited by a single quote too
-
1a549ee1
by Alan Zimmerman at 2025-06-19T19:35:04+01:00
Allow leading whitespace on cpp directives
As per https://timsong-cpp.github.io/cppwp/n4140/cpp#1
-
4d2d4de1
by Alan Zimmerman at 2025-06-19T19:35:04+01:00
Implement GHC_CPP undef
-
9533c2d7
by Alan Zimmerman at 2025-06-19T19:35:04+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
-
dbcbb002
by Alan Zimmerman at 2025-06-19T19:35:04+01:00
Fix GhcCpp01 test
The LINE pragma stuff works in ghc-exactprint when specifically
setting flag to emit ITline_pragma tokens
-
8e460807
by Alan Zimmerman at 2025-06-19T19:35:04+01:00
Process comments in CPP directives
-
7103a6b2
by Alan Zimmerman at 2025-06-19T19:35:04+01:00
Correctly lex pragmas with finel #-} on a newline
-
830c79e0
by Alan Zimmerman at 2025-06-19T19:35:04+01:00
Do not process CPP-style comments
-
37a486ec
by Alan Zimmerman at 2025-06-19T19:35:04+01:00
Allow cpp-style comments when GHC_CPP enabled
-
a8a1722b
by Alan Zimmerman at 2025-06-19T19:35:04+01:00
Return other pragmas as cpp ignored when GHC_CPP active
-
789233df
by Alan Zimmerman at 2025-06-19T19:35:05+01:00
Fix exactprinting default decl
-
b3ccee8b
by Alan Zimmerman at 2025-06-19T19:35:05+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.
-
6b84f415
by Alan Zimmerman at 2025-06-19T19:35:05+01:00
Tweak testing
-
a8fcfa4a
by Alan Zimmerman at 2025-06-19T19:35:05+01:00
Only allow unknown cpp pragmas with # in left margin
-
ac95dd60
by Alan Zimmerman at 2025-06-19T19:35:05+01:00
Require # against left margin for all GHC_CPP directives
-
8947e929
by Alan Zimmerman at 2025-06-19T19:35:05+01:00
Fix CPP directives appearing in pragmas
And add a test for error reporting for missing `#if`
-
3c073ceb
by Alan Zimmerman at 2025-06-19T19:35:05+01:00
Starting to report GHC_CPP errors using GHC machinery
-
1ee27ed3
by Alan Zimmerman at 2025-06-19T19:35:05+01:00
More GHC_CPP diagnostic results
-
f70203f8
by Alan Zimmerman at 2025-06-19T19:35:05+01:00
WIP on converting error calls to GHC diagnostics in GHC_CPP
-
b3f8401d
by Alan Zimmerman at 2025-06-19T19:35:05+01:00
Working on CPP diagnostic reporting
-
882e38a6
by Alan Zimmerman at 2025-06-19T19:35:05+01:00
Tweak some tests/lint warnings
-
995e97e4
by Alan Zimmerman at 2025-06-19T19:35:05+01:00
More error reporting in Macro
-
f0477b99
by Alan Zimmerman at 2025-06-19T19:35:05+01:00
Some cleanups