-
ce616f49
by Simon Peyton Jones at 2025-04-27T21:10:25+01:00
Fix infelicities in the Specialiser
On the way to #23109 (unary classes) I discovered some infelicities
(or maybe tiny bugs, I forget) in the type-class specialiser.
I also tripped over #25965, an outright bug in the rule matcher
Specifically:
* Refactor: I enhanced `wantCallsFor`, whih previously always said
`True`, to discard calls of class-ops, data constructors etc. This is
a bit more efficient; and it means we don't need to worry about
filtering them out later.
* Fix: I tidied up some tricky logic that eliminated redundant
specialisations. It wasn't working correctly. See the expanded
Note [Specialisations already covered], and
(MP3) in Note [Specialising polymorphic dictionaries].
See also the new top-level `alreadyCovered`
function, which now goes via `GHC.Core.Rules.ruleLhsIsMoreSpecific`
I also added a useful Note [The (CI-KEY) invariant]
* Fix #25965: fixed a tricky bug in the `go_fam_fam` in
`GHC.Core.Unify.uVarOrFam`, which allows matching to succeed
without binding all type varibles.
I enhanced Note [Apartness and type families] some more
* #25703. This ticket "just works" with -fpolymorphic-specialisation;
but I was surprised that it worked! In this MR I added documentation
to Note [Interesting dictionary arguments] to explain; and tests to
ensure it stays fixed.
-
22d11fa8
by Simon Peyton Jones at 2025-04-28T18:05:19-04:00
Track rewriter sets more accurately in constraint solving
The key change, which fixed #25440, is to call `recordRewriter` in
GHC.Tc.Solver.Rewrite.rewrite_exact_fam_app. This missing call meant
that we were secretly rewriting a Wanted with a Wanted, but not really
noticing; and that led to a very bad error message, as you can see
in the ticket.
But of course that led me into rabbit hole of other refactoring around
the RewriteSet code:
* Improve Notes [Wanteds rewrite Wanteds]
* Zonk the RewriterSet in `zonkCtEvidence` rather than only in GHC.Tc.Errors.
This is tidier anyway (e.g. de-clutters debug output), and helps with the
next point.
* In GHC.Tc.Solver.Equality.inertsCanDischarge, don't replace a constraint
with no rewriters with an equal constraint that has many. See
See (CE4) in Note [Combining equalities]
* Move zonkRewriterSet and friends from GHC.Tc.Zonk.Type into
GHC.Tc.Zonk.TcType, where they properly belong.
A handful of tests get better error messages.
For some reason T24984 gets 12% less compiler allocation -- good
Metric Decrease:
T24984
-
6467d61e
by Brandon Chinn at 2025-04-29T18:36:03-04:00
Fix lexing "\^\" (#25937)
This broke in the refactor in !13128, where the old code parsed escape
codes and collapsed string gaps at the same time, but the new code
collapsed gaps first, then resolved escape codes. The new code used a
naive heuristic to skip escaped backslashes, but didn't account for
"\^\".
-
99868a86
by Jens Petersen at 2025-04-29T18:36:44-04:00
hadrian: default selftest to disabled
-
aba2a4a5
by Zubin Duggal at 2025-04-30T06:35:59-04:00
get-win32-tarballs.py: List tarball files to be downloaded if we cannot find them
Fixes #25929
-
d99a617b
by Ben Gamari at 2025-04-30T06:36:40-04:00
Move Data ModuleName instance to Language.Haskell.Syntax.Module.Name
Fixes #25968.
-
b5e557d8
by Alan Zimmerman at 2025-04-30T18:27:18+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
-
8571387c
by Alan Zimmerman at 2025-04-30T18:27:18+01:00
Tidy up before re-visiting the continuation mechanic
-
92273c0f
by Alan Zimmerman at 2025-04-30T18:27:18+01:00
Switch preprocessor to continuation passing style
Proof of concept, needs tidying up
-
d8c87361
by Alan Zimmerman at 2025-04-30T18:27:18+01:00
Small cleanup
-
30a1a4e5
by Alan Zimmerman at 2025-04-30T18:27:18+01:00
Get rid of some cruft
-
7dd5d77c
by Alan Zimmerman at 2025-04-30T18:27:18+01:00
Starting to integrate.
Need to get the pragma recognised and set
-
b44b17cf
by Alan Zimmerman at 2025-04-30T18:27:18+01:00
Make cppTokens extend to end of line, and process CPP comments
-
71d19727
by Alan Zimmerman at 2025-04-30T18:27:18+01:00
Remove unused ITcppDefined
-
c326a944
by Alan Zimmerman at 2025-04-30T18:27:18+01:00
Allow spaces between # and keyword for preprocessor directive
-
9dcd821c
by Alan Zimmerman at 2025-04-30T18:27:18+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.
-
873d3c9b
by Alan Zimmerman at 2025-04-30T18:27:18+01:00
Accumulate CPP continuations, process when ready
Can be simplified further, we only need one CPP token
-
1d604a35
by Alan Zimmerman at 2025-04-30T18:27:18+01:00
Simplify Lexer interface. Only ITcpp
We transfer directive lines through it, then parse them from scratch
in the preprocessor.
-
bcd77e8b
by Alan Zimmerman at 2025-04-30T18:27:18+01:00
Deal with directive on last line, with no trailing \n
-
55f1056a
by Alan Zimmerman at 2025-04-30T18:27:18+01:00
Start parsing and processing the directives
-
8f2079a7
by Alan Zimmerman at 2025-04-30T18:27:18+01:00
Prepare for processing include files
-
2407cbed
by Alan Zimmerman at 2025-04-30T18:27:18+01:00
Move PpState into PreProcess
And initParserState, initPragState too
-
8a9008c4
by Alan Zimmerman at 2025-04-30T18:27:18+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
-
24e47f5d
by Alan Zimmerman at 2025-04-30T18:27:18+01:00
Split into separate files
-
ace37ecb
by Alan Zimmerman at 2025-04-30T18:27:18+01:00
Starting on expression parser.
But it hangs. Time for Text.Parsec.Expr
-
d7c05912
by Alan Zimmerman at 2025-04-30T18:27:18+01:00
Start integrating the ghc-cpp work
From https://github.com/alanz/ghc-cpp
-
c96e142b
by Alan Zimmerman at 2025-04-30T18:27:18+01:00
WIP
-
c4cc4cec
by Alan Zimmerman at 2025-04-30T18:27:18+01:00
Fixup after rebase
-
1728a5f9
by Alan Zimmerman at 2025-04-30T18:27:18+01:00
WIP
-
86eb1e35
by Alan Zimmerman at 2025-04-30T18:27:18+01:00
Fixup after rebase, including all tests pass
-
091892a4
by Alan Zimmerman at 2025-04-30T18:27:18+01:00
Change pragma usage to GHC_CPP from GhcCPP
-
fc6e9524
by Alan Zimmerman at 2025-04-30T18:27:19+01:00
Some comments
-
7e907713
by Alan Zimmerman at 2025-04-30T18:27:19+01:00
Reformat
-
9844268f
by Alan Zimmerman at 2025-04-30T18:27:19+01:00
Delete unused file
-
714dec3b
by Alan Zimmerman at 2025-04-30T18:27:19+01:00
Rename module Parse to ParsePP
-
6c09c72a
by Alan Zimmerman at 2025-04-30T18:27:19+01:00
Clarify naming in the parser
-
90f621b0
by Alan Zimmerman at 2025-04-30T18:27:19+01:00
WIP. Switching to alex/happy to be able to work in-tree
Since Parsec is not available
-
cdc19c1d
by Alan Zimmerman at 2025-04-30T18:27:19+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
-
5a95ab9e
by Alan Zimmerman at 2025-04-30T18:27:19+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
```
-
62a44662
by Alan Zimmerman at 2025-04-30T18:27:19+01:00
Rebase, and all tests pass except whitespace for generated parser
-
e390dc29
by Alan Zimmerman at 2025-04-30T18:27:19+01:00
More plumbing. Ready for testing tomorrow.
-
a854d7d1
by Alan Zimmerman at 2025-04-30T18:27:19+01:00
Proress. Renamed module State from Types
And at first blush it seems to handle preprocessor scopes properly.
-
8413c8a1
by Alan Zimmerman at 2025-04-30T18:27:19+01:00
Insert basic GHC version macros into parser
__GLASGOW_HASKELL__
__GLASGOW_HASKELL_FULL_VERSION__
__GLASGOW_HASKELL_PATCHLEVEL1__
__GLASGOW_HASKELL_PATCHLEVEL2__
-
2b2b9228
by Alan Zimmerman at 2025-04-30T18:27:19+01:00
Re-sync check-cpp for easy ghci work
-
430277cc
by Alan Zimmerman at 2025-04-30T18:27:19+01:00
Get rid of warnings
-
56c60aa3
by Alan Zimmerman at 2025-04-30T18:27:19+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
-
ed637dcd
by Alan Zimmerman at 2025-04-30T18:27:19+01:00
WIP. Can crack arguments for #define
Next step it to crack out args in an expansion
-
eb140d03
by Alan Zimmerman at 2025-04-30T18:27:19+01:00
WIP on arg parsing.
-
c93e5c43
by Alan Zimmerman at 2025-04-30T18:27:19+01:00
Progress. Still screwing up nested parens.
-
b01ee9be
by Alan Zimmerman at 2025-04-30T18:27:19+01:00
Seems to work, but has redundant code
-
57e61eb2
by Alan Zimmerman at 2025-04-30T18:27:19+01:00
Remove redundant code
-
53a013e9
by Alan Zimmerman at 2025-04-30T18:27:19+01:00
Reformat
-
ff5d845d
by Alan Zimmerman at 2025-04-30T18:27:19+01:00
Expand args, single pass
Still need to repeat until fixpoint
-
eabfa64f
by Alan Zimmerman at 2025-04-30T18:27:19+01:00
Fixed point expansion
-
76e3c95c
by Alan Zimmerman at 2025-04-30T18:27:19+01:00
Sync the playground to compiler
-
b308b101
by Alan Zimmerman at 2025-04-30T18:27:19+01:00
Working on dumping the GHC_CPP result
But We need to keep the BufSpan in a comment
-
8216dfd9
by Alan Zimmerman at 2025-04-30T18:27:19+01:00
Keep BufSpan in queued comments in GHC.Parser.Lexer
-
4aa75569
by Alan Zimmerman at 2025-04-30T18:27:19+01:00
Getting close to being able to print the combined tokens
showing what is in and what is out
-
621fd6bc
by Alan Zimmerman at 2025-04-30T18:27:19+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
-
38b978bc
by Alan Zimmerman at 2025-04-30T18:27:19+01:00
Clean up a bit
-
5b80b455
by Alan Zimmerman at 2025-04-30T18:27:19+01:00
Add -ddump-ghc-cpp option and a test based on it
-
fddd2454
by Alan Zimmerman at 2025-04-30T18:27:19+01:00
Restore Lexer.x rules, we need them for continuation lines
-
30b3055a
by Alan Zimmerman at 2025-04-30T18:27:19+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
-
fc8d7dc7
by Alan Zimmerman at 2025-04-30T18:27:19+01:00
Inserts predefined macros. But does not dump properly
Because the cpp tokens have a trailing newline
-
b12d9528
by Alan Zimmerman at 2025-04-30T18:27:19+01:00
Remove unnecessary LExer rules
We *need* the ones that explicitly match to the end of the line.
-
95da0848
by Alan Zimmerman at 2025-04-30T18:27:19+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.
-
a89c12e4
by Alan Zimmerman at 2025-04-30T18:27:19+01:00
Reduce duplication in lexer
-
c072ea30
by Alan Zimmerman at 2025-04-30T18:27:19+01:00
Tweaks
-
ff1e169e
by Alan Zimmerman at 2025-04-30T18:27:19+01:00
Insert min_version predefined macros into state
The mechanism now works. Still need to flesh out the full set.
-
77b2fb0b
by Alan Zimmerman at 2025-04-30T18:27:19+01:00
Trying my alternative pragma syntax.
It works, but dumpGhcCpp is broken, I suspect from the ITcpp token
span update.
-
946fcffe
by Alan Zimmerman at 2025-04-30T18:27:19+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
-
ea220ec5
by Alan Zimmerman at 2025-04-30T18:27:19+01:00
Remove some tracing
-
77e29d38
by Alan Zimmerman at 2025-04-30T18:27:19+01:00
Fix test exes for changes
-
a05c2b54
by Alan Zimmerman at 2025-04-30T18:27:19+01:00
For GHC_CPP tests, normalise config-time-based macros
-
b872a140
by Alan Zimmerman at 2025-04-30T18:27:19+01:00
WIP
-
171744b2
by Alan Zimmerman at 2025-04-30T18:27:19+01:00
WIP again. What is wrong?
-
66b3d2b5
by Alan Zimmerman at 2025-04-30T18:27:19+01:00
Revert to dynflags for normal not pragma lexing
-
7c9b44a3
by Alan Zimmerman at 2025-04-30T18:27:19+01:00
Working on getting check-exact to work properly
-
614ea6a0
by Alan Zimmerman at 2025-04-30T18:27:19+01:00
Passes CppCommentPlacement test
-
eb13851f
by Alan Zimmerman at 2025-04-30T18:27:19+01:00
Starting on exact printing with GHC_CPP
While overriding normal CPP
-
25842766
by Alan Zimmerman at 2025-04-30T18:27:19+01:00
Correctly store CPP ignored tokens as comments
By populating the lexeme string in it, based on the bufpos
-
c7c62d60
by Alan Zimmerman at 2025-04-30T18:27:20+01:00
WIP
-
950201a7
by Alan Zimmerman at 2025-04-30T18:27:20+01:00
Simplifying
-
71e2e916
by Alan Zimmerman at 2025-04-30T18:27:20+01:00
Update the active state logic
-
1f85f1fd
by Alan Zimmerman at 2025-04-30T18:27:20+01:00
Work the new logic into the mainline code
-
44385d18
by Alan Zimmerman at 2025-04-30T18:27:20+01:00
Process `defined` operator
-
bd22d304
by Alan Zimmerman at 2025-04-30T18:27:20+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.
-
e967f92b
by Alan Zimmerman at 2025-04-30T18:27:20+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.
-
69b1c666
by Alan Zimmerman at 2025-04-30T18:27:20+01:00
Process the ! operator in GHC_CPP expressions
-
589bf9fb
by Alan Zimmerman at 2025-04-30T18:27:20+01:00
Predefine a constant when GHC_CPP is being used.
-
e5080cfb
by Alan Zimmerman at 2025-04-30T18:27:20+01:00
WIP
-
46b58f7c
by Alan Zimmerman at 2025-04-30T18:27:20+01:00
Skip lines directly in the lexer when required
-
51db8d2f
by Alan Zimmerman at 2025-04-30T18:27:20+01:00
Properly manage location when accepting tokens again
-
f7851788
by Alan Zimmerman at 2025-04-30T18:27:20+01:00
Seems to be working now, for Example9
-
23ca6470
by Alan Zimmerman at 2025-04-30T18:27:20+01:00
Remove tracing
-
b5c3c800
by Alan Zimmerman at 2025-04-30T18:27:20+01:00
Fix parsing '*' in block comments
Instead of replacing them with '-'
-
34952423
by Alan Zimmerman at 2025-04-30T18:27:20+01:00
Keep the trailing backslash in a ITcpp token
-
967699fe
by Alan Zimmerman at 2025-04-30T18:27:20+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
-
7496a89d
by Alan Zimmerman at 2025-04-30T18:27:20+01:00
Replace remaining identifiers with 0 when evaluating
As per the spec
-
7d8ae8e0
by Alan Zimmerman at 2025-04-30T18:27:20+01:00
Snapshot before rebase
-
cbaef129
by Alan Zimmerman at 2025-04-30T18:27:20+01:00
Skip non-processed lines starting with #
-
dbbf4975
by Alan Zimmerman at 2025-04-30T18:27:20+01:00
Export generateMacros so we can use it in ghc-exactprint
-
89e62cfd
by Alan Zimmerman at 2025-04-30T18:27:20+01:00
Fix rebase
-
922d6f93
by Alan Zimmerman at 2025-04-30T18:27:20+01:00
Expose initParserStateWithMacrosString
-
0591e754
by Alan Zimmerman at 2025-04-30T18:27:20+01:00
Fix buggy lexer cppSkip
It was skipping all lines, not just ones prefixed by #
-
d1437795
by Alan Zimmerman at 2025-04-30T18:27:20+01:00
Fix evaluation of && to use the correct operator
-
6f1b578d
by Alan Zimmerman at 2025-04-30T18:27:20+01:00
Deal with closing #-} at the start of a line
-
b323cddc
by Alan Zimmerman at 2025-04-30T18:27:20+01:00
Add the MIN_VERSION_GLASGOW_HASKELL predefined macro
-
a95937c9
by Alan Zimmerman at 2025-04-30T18:27:20+01:00
Include MIN_VERSION_GLASGOW_HASKELL in GhcCpp01.stderr
-
8d808fb3
by Alan Zimmerman at 2025-04-30T18:27:20+01:00
Use a strict map for macro defines
-
7b305c1f
by Alan Zimmerman at 2025-04-30T18:27:20+01:00
Process TIdentifierLParen
Which only matters at the start of #define
-
93e98895
by Alan Zimmerman at 2025-04-30T18:27:20+01:00
Do not provide TIdentifierLParen paren twice
-
6c1cc903
by Alan Zimmerman at 2025-04-30T18:27:20+01:00
Handle whitespace between identifier and '(' for directive only
-
f6bc6402
by Alan Zimmerman at 2025-04-30T18:27:20+01:00
Expose some Lexer bitmap manipulation helpers
-
9c0c7d3a
by Alan Zimmerman at 2025-04-30T18:27:20+01:00
Deal with line pragmas as tokens
Blows up for dumpGhcCpp though
-
91877c57
by Alan Zimmerman at 2025-04-30T18:27:20+01:00
Allow strings delimited by a single quote too
-
a35d6cc1
by Alan Zimmerman at 2025-04-30T18:27:20+01:00
Allow leading whitespace on cpp directives
As per https://timsong-cpp.github.io/cppwp/n4140/cpp#1
-
e271da2f
by Alan Zimmerman at 2025-04-30T18:27:20+01:00
Implement GHC_CPP undef
-
da493772
by Alan Zimmerman at 2025-04-30T18:27:20+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