-
e64b3f16
by ARATA Mizuki at 2025-06-17T10:13:42+09:00
MachRegs.h: Don't define NO_ARG_REGS when a XMM register is defined
On i386, MAX_REAL_VANILLA_REG is 1, but MAX_REAL_XMM_REG is 4.
If we define NO_ARG_REGS on i386, programs that use SIMD vectors may segfault.
Closes #25985
A couple of notes on the BROKEN_TESTS field:
* This fixes the segfault from T25062_V16.
* The failure from T22187_run was fixed in an earlier commit (see #25561),
but BROKEN_TESTS was missed at that time. Now should be a good time to
mark it fixed.
-
3e7c6b4d
by Matthew Pickering at 2025-06-18T15:34:04-04:00
Improve error messages when implicit lifting fails
This patch concerns programs which automatically try to fix level errors
by inserting `Lift`. For example:
```
foo x = [| x |]
~>
foo x = [| $(lift x) |]
```
Before, there were two problems with the message.
1. (#26031), the location of the error was reported as the whole
quotation.
2. (#26035), the message just mentions there is no Lift instance, but
gives no indicate why the user program needed a Lift instance in the
first place.
This problem is especially bad when you disable
`ImplicitStagePersistence`, so you just end up with a confusing "No
instance for" message rather than an error message about levels
This patch fixes both these issues.
Firstly, `PendingRnSplice` differentiates between a user-written splice
and an implicit lift. Then, the Lift instance is precisely requested
with a specific origin in the typechecker. If the instance fails to be
solved, the message is reported using the `TcRnBadlyLevelled`
constructor (like a normal level error).
Fixes #26031, #26035
-
44b8cee2
by Cheng Shao at 2025-06-18T15:34:46-04:00
testsuite: add T26120 marked as broken
-
894a04f3
by Cheng Shao at 2025-06-18T15:34:46-04:00
compiler: fix GHC.SysTools.Ar archive member size writing logic
This patch fixes a long-standing bug in `GHC.SysTools.Ar` that emits
the wrong archive member size in each archive header. It should encode
the exact length of the member payload, excluding any padding byte,
otherwise malformed archive that extracts a broken object with an
extra trailing byte could be created.
Apart from the in-tree `T26120` test, I've also created an out-of-tree
testsuite at https://github.com/TerrorJack/ghc-ar-quickcheck that
contains QuickCheck roundtrip tests for `GHC.SysTools.Ar`. With this
fix, simple roundtrip tests and `writeGNUAr`/GNU `ar` roundtrip test
passes. There might be more bugs lurking in here, but this patch is
still a critical bugfix already.
Fixes #26120 #22586.
Co-authored-by: Codex <codex@openai.com>
-
f677ab5f
by Lauren Yim at 2025-06-18T15:35:37-04:00
fix some typos in the warnings page in the user guide
-
b968e1c1
by Rodrigo Mesquita at 2025-06-18T15:36:18-04:00
Add a frozen callstack to throwGhcException
Fixes #25956
-
a5e0c3a3
by fendor at 2025-06-18T15:36:59-04:00
Update using.rst to advertise full mhu support for GHCi
-
889b8815
by Alan Zimmerman at 2025-06-18T21:22:34+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
-
4ebf2101
by Alan Zimmerman at 2025-06-18T21:22:34+01:00
Tidy up before re-visiting the continuation mechanic
-
f0dd0257
by Alan Zimmerman at 2025-06-18T21:22:34+01:00
Switch preprocessor to continuation passing style
Proof of concept, needs tidying up
-
604d1a13
by Alan Zimmerman at 2025-06-18T21:22:34+01:00
Small cleanup
-
fb58338d
by Alan Zimmerman at 2025-06-18T21:22:34+01:00
Get rid of some cruft
-
778123da
by Alan Zimmerman at 2025-06-18T21:22:34+01:00
Starting to integrate.
Need to get the pragma recognised and set
-
946016da
by Alan Zimmerman at 2025-06-18T21:22:34+01:00
Make cppTokens extend to end of line, and process CPP comments
-
c8b03ee1
by Alan Zimmerman at 2025-06-18T21:22:34+01:00
Remove unused ITcppDefined
-
1de0f0e3
by Alan Zimmerman at 2025-06-18T21:22:34+01:00
Allow spaces between # and keyword for preprocessor directive
-
088fcc53
by Alan Zimmerman at 2025-06-18T21:22:34+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.
-
9fe0f67a
by Alan Zimmerman at 2025-06-18T21:22:34+01:00
Accumulate CPP continuations, process when ready
Can be simplified further, we only need one CPP token
-
bcb05807
by Alan Zimmerman at 2025-06-18T21:22:34+01:00
Simplify Lexer interface. Only ITcpp
We transfer directive lines through it, then parse them from scratch
in the preprocessor.
-
18cce45b
by Alan Zimmerman at 2025-06-18T21:22:34+01:00
Deal with directive on last line, with no trailing \n
-
01804178
by Alan Zimmerman at 2025-06-18T21:22:35+01:00
Start parsing and processing the directives
-
9369dfeb
by Alan Zimmerman at 2025-06-18T21:22:35+01:00
Prepare for processing include files
-
2c498ca4
by Alan Zimmerman at 2025-06-18T21:22:35+01:00
Move PpState into PreProcess
And initParserState, initPragState too
-
08dc4d62
by Alan Zimmerman at 2025-06-18T21:22:35+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
-
9b8af447
by Alan Zimmerman at 2025-06-18T21:22:35+01:00
Split into separate files
-
462d0b45
by Alan Zimmerman at 2025-06-18T21:22:35+01:00
Starting on expression parser.
But it hangs. Time for Text.Parsec.Expr
-
9a0bb0ac
by Alan Zimmerman at 2025-06-18T21:22:35+01:00
Start integrating the ghc-cpp work
From https://github.com/alanz/ghc-cpp
-
3d703f19
by Alan Zimmerman at 2025-06-18T21:22:35+01:00
WIP
-
8c8ab9de
by Alan Zimmerman at 2025-06-18T21:22:35+01:00
Fixup after rebase
-
292f6173
by Alan Zimmerman at 2025-06-18T21:22:35+01:00
WIP
-
aa1d4f99
by Alan Zimmerman at 2025-06-18T21:22:35+01:00
Fixup after rebase, including all tests pass
-
5b20ff87
by Alan Zimmerman at 2025-06-18T21:22:35+01:00
Change pragma usage to GHC_CPP from GhcCPP
-
3d2e444d
by Alan Zimmerman at 2025-06-18T21:22:35+01:00
Some comments
-
9bbf6ba8
by Alan Zimmerman at 2025-06-18T21:22:35+01:00
Reformat
-
f470c7b5
by Alan Zimmerman at 2025-06-18T21:22:35+01:00
Delete unused file
-
eff62de5
by Alan Zimmerman at 2025-06-18T21:22:35+01:00
Rename module Parse to ParsePP
-
e66be481
by Alan Zimmerman at 2025-06-18T21:22:35+01:00
Clarify naming in the parser
-
a0224ad1
by Alan Zimmerman at 2025-06-18T21:22:35+01:00
WIP. Switching to alex/happy to be able to work in-tree
Since Parsec is not available
-
2cef2273
by Alan Zimmerman at 2025-06-18T21:22:35+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
-
9878bce6
by Alan Zimmerman at 2025-06-18T21:22:35+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
```
-
411767d9
by Alan Zimmerman at 2025-06-18T21:22:35+01:00
Rebase, and all tests pass except whitespace for generated parser
-
2a92b35c
by Alan Zimmerman at 2025-06-18T21:22:35+01:00
More plumbing. Ready for testing tomorrow.
-
53d2399c
by Alan Zimmerman at 2025-06-18T21:22:35+01:00
Proress. Renamed module State from Types
And at first blush it seems to handle preprocessor scopes properly.
-
5703c1a9
by Alan Zimmerman at 2025-06-18T21:22:35+01:00
Insert basic GHC version macros into parser
__GLASGOW_HASKELL__
__GLASGOW_HASKELL_FULL_VERSION__
__GLASGOW_HASKELL_PATCHLEVEL1__
__GLASGOW_HASKELL_PATCHLEVEL2__
-
914c0931
by Alan Zimmerman at 2025-06-18T21:22:35+01:00
Re-sync check-cpp for easy ghci work
-
3f227991
by Alan Zimmerman at 2025-06-18T21:22:35+01:00
Get rid of warnings
-
5e878d93
by Alan Zimmerman at 2025-06-18T21:22:35+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
-
e7bdaaa4
by Alan Zimmerman at 2025-06-18T21:22:35+01:00
WIP. Can crack arguments for #define
Next step it to crack out args in an expansion
-
373f9916
by Alan Zimmerman at 2025-06-18T21:22:35+01:00
WIP on arg parsing.
-
d8d130c5
by Alan Zimmerman at 2025-06-18T21:22:35+01:00
Progress. Still screwing up nested parens.
-
0080df4a
by Alan Zimmerman at 2025-06-18T21:22:35+01:00
Seems to work, but has redundant code
-
686084ca
by Alan Zimmerman at 2025-06-18T21:22:35+01:00
Remove redundant code
-
b378b0e9
by Alan Zimmerman at 2025-06-18T21:22:35+01:00
Reformat
-
9be9de1f
by Alan Zimmerman at 2025-06-18T21:22:35+01:00
Expand args, single pass
Still need to repeat until fixpoint
-
4fe1d38e
by Alan Zimmerman at 2025-06-18T21:22:35+01:00
Fixed point expansion
-
2c868e15
by Alan Zimmerman at 2025-06-18T21:22:35+01:00
Sync the playground to compiler
-
65e5a420
by Alan Zimmerman at 2025-06-18T21:22:35+01:00
Working on dumping the GHC_CPP result
But We need to keep the BufSpan in a comment
-
305ffb14
by Alan Zimmerman at 2025-06-18T21:22:35+01:00
Keep BufSpan in queued comments in GHC.Parser.Lexer
-
54a1c9ff
by Alan Zimmerman at 2025-06-18T21:22:36+01:00
Getting close to being able to print the combined tokens
showing what is in and what is out
-
e6924494
by Alan Zimmerman at 2025-06-18T21:22:36+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
-
6c893315
by Alan Zimmerman at 2025-06-18T21:22:36+01:00
Clean up a bit
-
89e1cd84
by Alan Zimmerman at 2025-06-18T21:22:36+01:00
Add -ddump-ghc-cpp option and a test based on it
-
13daa03f
by Alan Zimmerman at 2025-06-18T21:22:36+01:00
Restore Lexer.x rules, we need them for continuation lines
-
bc439ea3
by Alan Zimmerman at 2025-06-18T21:22:36+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
-
332ddab7
by Alan Zimmerman at 2025-06-18T21:22:36+01:00
Inserts predefined macros. But does not dump properly
Because the cpp tokens have a trailing newline
-
50f40f1f
by Alan Zimmerman at 2025-06-18T21:22:36+01:00
Remove unnecessary LExer rules
We *need* the ones that explicitly match to the end of the line.
-
b5a9732b
by Alan Zimmerman at 2025-06-18T21:22:36+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.
-
6307a622
by Alan Zimmerman at 2025-06-18T21:22:36+01:00
Reduce duplication in lexer
-
ae9cb89a
by Alan Zimmerman at 2025-06-18T21:22:36+01:00
Tweaks
-
74f31b10
by Alan Zimmerman at 2025-06-18T21:22:36+01:00
Insert min_version predefined macros into state
The mechanism now works. Still need to flesh out the full set.
-
cd087f21
by Alan Zimmerman at 2025-06-18T21:22:36+01:00
Trying my alternative pragma syntax.
It works, but dumpGhcCpp is broken, I suspect from the ITcpp token
span update.
-
eaeefb34
by Alan Zimmerman at 2025-06-18T21:22:36+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
-
fe4d273e
by Alan Zimmerman at 2025-06-18T21:22:36+01:00
Remove some tracing
-
35f675b0
by Alan Zimmerman at 2025-06-18T21:22:36+01:00
Fix test exes for changes
-
d4500988
by Alan Zimmerman at 2025-06-18T21:22:36+01:00
For GHC_CPP tests, normalise config-time-based macros
-
2f99928b
by Alan Zimmerman at 2025-06-18T21:22:36+01:00
WIP
-
64bd6a23
by Alan Zimmerman at 2025-06-18T21:22:36+01:00
WIP again. What is wrong?
-
1f2a83b4
by Alan Zimmerman at 2025-06-18T21:22:36+01:00
Revert to dynflags for normal not pragma lexing
-
2225db35
by Alan Zimmerman at 2025-06-18T21:22:36+01:00
Working on getting check-exact to work properly
-
30aa16de
by Alan Zimmerman at 2025-06-18T21:22:36+01:00
Passes CppCommentPlacement test
-
408b4722
by Alan Zimmerman at 2025-06-18T21:22:36+01:00
Starting on exact printing with GHC_CPP
While overriding normal CPP
-
420548f5
by Alan Zimmerman at 2025-06-18T21:22:36+01:00
Correctly store CPP ignored tokens as comments
By populating the lexeme string in it, based on the bufpos
-
4a1a04ef
by Alan Zimmerman at 2025-06-18T21:22:36+01:00
WIP
-
279e41d4
by Alan Zimmerman at 2025-06-18T21:22:36+01:00
Simplifying
-
2f0d4d97
by Alan Zimmerman at 2025-06-18T21:22:36+01:00
Update the active state logic
-
9ef48795
by Alan Zimmerman at 2025-06-18T21:22:36+01:00
Work the new logic into the mainline code
-
80428aaa
by Alan Zimmerman at 2025-06-18T21:22:36+01:00
Process `defined` operator
-
f65a0d9d
by Alan Zimmerman at 2025-06-18T21:22:36+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.
-
2f12dffd
by Alan Zimmerman at 2025-06-18T21:22:36+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.
-
0fff4ce8
by Alan Zimmerman at 2025-06-18T21:22:36+01:00
Process the ! operator in GHC_CPP expressions
-
7245df41
by Alan Zimmerman at 2025-06-18T21:22:36+01:00
Predefine a constant when GHC_CPP is being used.
-
c32f169a
by Alan Zimmerman at 2025-06-18T21:22:36+01:00
WIP
-
f79d8ae6
by Alan Zimmerman at 2025-06-18T21:22:36+01:00
Skip lines directly in the lexer when required
-
eacc502e
by Alan Zimmerman at 2025-06-18T21:22:36+01:00
Properly manage location when accepting tokens again
-
46fc9d13
by Alan Zimmerman at 2025-06-18T21:22:36+01:00
Seems to be working now, for Example9
-
7189e97c
by Alan Zimmerman at 2025-06-18T21:22:36+01:00
Remove tracing
-
99eafc55
by Alan Zimmerman at 2025-06-18T21:22:36+01:00
Fix parsing '*' in block comments
Instead of replacing them with '-'
-
2ccb3354
by Alan Zimmerman at 2025-06-18T21:22:36+01:00
Keep the trailing backslash in a ITcpp token
-
96c0b70e
by Alan Zimmerman at 2025-06-18T21:22:36+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
-
5270f370
by Alan Zimmerman at 2025-06-18T21:22:36+01:00
Replace remaining identifiers with 0 when evaluating
As per the spec
-
e35ede33
by Alan Zimmerman at 2025-06-18T21:22:36+01:00
Snapshot before rebase
-
bc8081ae
by Alan Zimmerman at 2025-06-18T21:22:36+01:00
Skip non-processed lines starting with #
-
37947b7e
by Alan Zimmerman at 2025-06-18T21:22:36+01:00
Export generateMacros so we can use it in ghc-exactprint
-
aec471b4
by Alan Zimmerman at 2025-06-18T21:22:36+01:00
Fix rebase
-
5b166f2a
by Alan Zimmerman at 2025-06-18T21:22:37+01:00
Expose initParserStateWithMacrosString
-
82accba8
by Alan Zimmerman at 2025-06-18T21:22:37+01:00
Fix buggy lexer cppSkip
It was skipping all lines, not just ones prefixed by #
-
015d27a7
by Alan Zimmerman at 2025-06-18T21:22:37+01:00
Fix evaluation of && to use the correct operator
-
fb7038b5
by Alan Zimmerman at 2025-06-18T21:22:37+01:00
Deal with closing #-} at the start of a line
-
28047dc8
by Alan Zimmerman at 2025-06-18T21:22:37+01:00
Add the MIN_VERSION_GLASGOW_HASKELL predefined macro
-
cd298351
by Alan Zimmerman at 2025-06-18T21:22:37+01:00
Include MIN_VERSION_GLASGOW_HASKELL in GhcCpp01.stderr
-
59fc66d0
by Alan Zimmerman at 2025-06-18T21:22:37+01:00
Use a strict map for macro defines
-
abc3d948
by Alan Zimmerman at 2025-06-18T21:22:37+01:00
Process TIdentifierLParen
Which only matters at the start of #define
-
4e145cd2
by Alan Zimmerman at 2025-06-18T21:22:37+01:00
Do not provide TIdentifierLParen paren twice
-
6dd33444
by Alan Zimmerman at 2025-06-18T21:22:37+01:00
Handle whitespace between identifier and '(' for directive only
-
d83ddd88
by Alan Zimmerman at 2025-06-18T21:22:37+01:00
Expose some Lexer bitmap manipulation helpers
-
2b4ae10c
by Alan Zimmerman at 2025-06-18T21:22:37+01:00
Deal with line pragmas as tokens
Blows up for dumpGhcCpp though
-
95ef50f2
by Alan Zimmerman at 2025-06-18T21:22:37+01:00
Allow strings delimited by a single quote too
-
d420e107
by Alan Zimmerman at 2025-06-18T21:22:37+01:00
Allow leading whitespace on cpp directives
As per https://timsong-cpp.github.io/cppwp/n4140/cpp#1
-
b36cc1ef
by Alan Zimmerman at 2025-06-18T21:22:37+01:00
Implement GHC_CPP undef
-
81286cbd
by Alan Zimmerman at 2025-06-18T21:22:37+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
-
775b9e53
by Alan Zimmerman at 2025-06-18T21:22:37+01:00
Fix GhcCpp01 test
The LINE pragma stuff works in ghc-exactprint when specifically
setting flag to emit ITline_pragma tokens
-
d0e96edd
by Alan Zimmerman at 2025-06-18T21:22:37+01:00
Process comments in CPP directives
-
23856d4d
by Alan Zimmerman at 2025-06-18T21:22:37+01:00
Correctly lex pragmas with finel #-} on a newline
-
6bd11f3d
by Alan Zimmerman at 2025-06-18T21:22:37+01:00
Do not process CPP-style comments
-
d502ce75
by Alan Zimmerman at 2025-06-18T21:22:37+01:00
Allow cpp-style comments when GHC_CPP enabled
-
3296c832
by Alan Zimmerman at 2025-06-18T21:22:37+01:00
Return other pragmas as cpp ignored when GHC_CPP active
-
a8f4a2a2
by Alan Zimmerman at 2025-06-18T21:22:37+01:00
Fix exactprinting default decl
-
0bf34347
by Alan Zimmerman at 2025-06-18T21:22:37+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.
-
f5697190
by Alan Zimmerman at 2025-06-18T21:22:37+01:00
Tweak testing
-
72664c05
by Alan Zimmerman at 2025-06-18T21:22:37+01:00
Only allow unknown cpp pragmas with # in left margin
-
bb3524d9
by Alan Zimmerman at 2025-06-18T21:22:37+01:00
Require # against left margin for all GHC_CPP directives
-
1657e0cd
by Alan Zimmerman at 2025-06-18T21:22:37+01:00
Fix CPP directives appearing in pragmas
And add a test for error reporting for missing `#if`
-
1be508ef
by Alan Zimmerman at 2025-06-18T21:22:37+01:00
Starting to report GHC_CPP errors using GHC machinery
-
591b330e
by Alan Zimmerman at 2025-06-18T21:22:37+01:00
More GHC_CPP diagnostic results
-
7d9e12b1
by Alan Zimmerman at 2025-06-18T21:22:37+01:00
WIP on converting error calls to GHC diagnostics in GHC_CPP
-
5ed5378f
by Alan Zimmerman at 2025-06-18T21:22:37+01:00
Working on CPP diagnostic reporting
-
b64fea57
by Alan Zimmerman at 2025-06-18T21:22:37+01:00
Tweak some tests/lint warnings
-
9d91ca3e
by Alan Zimmerman at 2025-06-18T21:22:37+01:00
More error reporting in Macro
-
ad20e507
by Alan Zimmerman at 2025-06-18T21:22:37+01:00
Some cleanups