-
e0f3ff11
by Patrick at 2025-04-17T04:31:12-04:00
Refactor Handling of Multiple Default Declarations
Fixes: #25912, #25914, #25934
Previously, GHC discarded all loaded defaults (tcg_default) when local
defaults were encountered during typechecking. According to the
exportable-named-default proposal (sections 2.4.2 and 2.4.3), local
defaults should be merged into tcg_default, retaining any defaults
already present while overriding where necessary.
Key Changes:
* Introduce DefaultProvenance to track the origin of default declarations
(local, imported, or built-in), replacing the original cd_module
in ClassDefaults with cd_provenance :: DefaultProvenance.
* Rename tcDefaults to tcDefaultDecls, limiting its responsibility to only
converting renamed class defaults into ClassDefaults.
* Add extendDefaultEnvWithLocalDefaults to merge local defaults into the
environment, with proper duplication checks:
- Duplicate local defaults for a class trigger an error.
- Local defaults override imported or built-in defaults.
* Update and add related notes: Note [Builtin class defaults],
Note [DefaultProvenance].
* Add regression tests: T25912, T25914, T25934.
Thanks sam and simon for the help on this patch.
Co-authored-by: sheaf <sam.derbyshire@gmail.com>
-
386f1854
by Teo Camarasu at 2025-04-17T04:31:55-04:00
template-haskell: Remove `addrToByteArrayName` and `addrToByteArray`
These were part of the implementation of the `Lift ByteArray` instance and were errornously exported because this module lacked an explicit export list. They have no usages on Hackage.
Resolves #24782
-
b96e2f77
by Sylvain Henry at 2025-04-18T20:46:33-04:00
RTS: remove target info and fix host info (#24058)
The RTS isn't a compiler, hence it doesn't have a target and we remove
the reported target info displayed by "+RTS --info". We also fix the
host info displayed by "+RTS --info": the host of the RTS is the
RTS-building compiler's target, not the compiler's host (wrong when
doing cross-compilation).
-
6d9965f4
by Sylvain Henry at 2025-04-18T20:46:33-04:00
RTS: remove build info
As per the discussion in !13967, there is no reason to tag the RTS with
information about the build platform.
-
d52e9b3f
by Vladislav Zavialov at 2025-04-18T20:47:15-04:00
Diagnostics: remove the KindMismatch constructor (#25957)
The KindMismatch constructor was only used as an intermediate
representation in pretty-printing.
Its removal addresses a problem detected by the "codes" test case:
[GHC-89223] is untested (constructor = KindMismatch)
In a concious deviation from the usual procedure, the error code
GHC-89223 is removed entirely rather than marked as Outdated.
The reason is that it never was user-facing in the first place.
-
e2f2f9d0
by Vladislav Zavialov at 2025-04-20T10:53:39-04:00
Add name for -Wunusable-unpack-pragmas
This warning had no name or flag and was triggered unconditionally.
Now it is part of -Wdefault.
In GHC.Tc.TyCl.tcTyClGroupsPass's strict mode, we now have to
force-enable this warning to ensure that detection of flawed groups
continues to work even if the user disables the warning with the
-Wno-unusable-unpack-pragmas option. Test case: T3990c
Also, the misnamed BackpackUnpackAbstractType is now called
UnusableUnpackPragma.
-
6caa6508
by Adam Gundry at 2025-04-20T10:54:22-04:00
Fix specialisation of incoherent instances (fixes #25883)
GHC normally assumes that class constraints are canonical, meaning that
the specialiser is allowed to replace one dictionary argument with another
provided that they have the same type. The `-fno-specialise-incoherents`
flag alters INCOHERENT instance definitions so that they will prevent
specialisation in some cases, by inserting `nospec`.
This commit fixes a bug in 7124e4ad76d98f1fc246ada4fd7bf64413ff2f2e, which
treated some INCOHERENT instance matches as if `-fno-specialise-incoherents`
was in effect, thereby unnecessarily preventing specialisation. In addition
it updates the relevant `Note [Rules for instance lookup]` and adds a new
`Note [Canonicity for incoherent matches]`.
-
0426fd6c
by Adam Gundry at 2025-04-20T10:54:23-04:00
Add regression test for #23429
-
eec96527
by Adam Gundry at 2025-04-20T10:54:23-04:00
user's guide: update specification of overlapping/incoherent instances
The description of the instance resolution algorithm in the user's
guide was slightly out of date, because it mentioned in-scope given
constraints only at the end, whereas the implementation checks for
their presence before any of the other steps.
This also adds a warning to the user's guide about the impact of
incoherent instances on specialisation, and more clearly documents
some of the other effects of `-XIncoherentInstances`.
-
a00eeaec
by Matthew Craven at 2025-04-20T10:55:03-04:00
Fix bytecode generation for `tagToEnum# <LITERAL>`
Fixes #25975.
-
ea5fab39
by Alan Zimmerman at 2025-04-21T18:44:33+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
-
e73abe65
by Alan Zimmerman at 2025-04-21T18:44:33+01:00
Tidy up before re-visiting the continuation mechanic
-
496b05a4
by Alan Zimmerman at 2025-04-21T18:44:33+01:00
Switch preprocessor to continuation passing style
Proof of concept, needs tidying up
-
7d770792
by Alan Zimmerman at 2025-04-21T18:44:33+01:00
Small cleanup
-
4436589a
by Alan Zimmerman at 2025-04-21T18:44:33+01:00
Get rid of some cruft
-
703f0997
by Alan Zimmerman at 2025-04-21T18:44:33+01:00
Starting to integrate.
Need to get the pragma recognised and set
-
d41cf158
by Alan Zimmerman at 2025-04-21T18:44:33+01:00
Make cppTokens extend to end of line, and process CPP comments
-
5473a8f8
by Alan Zimmerman at 2025-04-21T18:44:33+01:00
Remove unused ITcppDefined
-
6e761c77
by Alan Zimmerman at 2025-04-21T18:44:33+01:00
Allow spaces between # and keyword for preprocessor directive
-
a963ddf1
by Alan Zimmerman at 2025-04-21T18:44:33+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.
-
a27ddbe1
by Alan Zimmerman at 2025-04-21T18:44:33+01:00
Accumulate CPP continuations, process when ready
Can be simplified further, we only need one CPP token
-
aecedf1a
by Alan Zimmerman at 2025-04-21T18:44:33+01:00
Simplify Lexer interface. Only ITcpp
We transfer directive lines through it, then parse them from scratch
in the preprocessor.
-
a8124788
by Alan Zimmerman at 2025-04-21T18:44:33+01:00
Deal with directive on last line, with no trailing \n
-
07258013
by Alan Zimmerman at 2025-04-21T18:44:33+01:00
Start parsing and processing the directives
-
da41c32b
by Alan Zimmerman at 2025-04-21T18:44:33+01:00
Prepare for processing include files
-
74fc7700
by Alan Zimmerman at 2025-04-21T18:44:33+01:00
Move PpState into PreProcess
And initParserState, initPragState too
-
3629caba
by Alan Zimmerman at 2025-04-21T18:44:33+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
-
30f795fb
by Alan Zimmerman at 2025-04-21T18:44:33+01:00
Split into separate files
-
fce63df8
by Alan Zimmerman at 2025-04-21T18:44:33+01:00
Starting on expression parser.
But it hangs. Time for Text.Parsec.Expr
-
a777ca97
by Alan Zimmerman at 2025-04-21T18:44:33+01:00
Start integrating the ghc-cpp work
From https://github.com/alanz/ghc-cpp
-
053eb592
by Alan Zimmerman at 2025-04-21T18:44:33+01:00
WIP
-
b71ec92e
by Alan Zimmerman at 2025-04-21T18:44:33+01:00
Fixup after rebase
-
e439eaa3
by Alan Zimmerman at 2025-04-21T18:44:33+01:00
WIP
-
c01bf5b6
by Alan Zimmerman at 2025-04-21T18:44:33+01:00
Fixup after rebase, including all tests pass
-
e0ba1ec8
by Alan Zimmerman at 2025-04-21T18:44:33+01:00
Change pragma usage to GHC_CPP from GhcCPP
-
c1b68436
by Alan Zimmerman at 2025-04-21T18:44:33+01:00
Some comments
-
dede9429
by Alan Zimmerman at 2025-04-21T18:44:33+01:00
Reformat
-
4eed4283
by Alan Zimmerman at 2025-04-21T18:44:33+01:00
Delete unused file
-
f2e37212
by Alan Zimmerman at 2025-04-21T18:44:33+01:00
Rename module Parse to ParsePP
-
45457d52
by Alan Zimmerman at 2025-04-21T18:44:33+01:00
Clarify naming in the parser
-
87c77e37
by Alan Zimmerman at 2025-04-21T18:44:33+01:00
WIP. Switching to alex/happy to be able to work in-tree
Since Parsec is not available
-
c529a377
by Alan Zimmerman at 2025-04-21T18:44:33+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
-
ebd2fd33
by Alan Zimmerman at 2025-04-21T18:44:33+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
```
-
8537a9c0
by Alan Zimmerman at 2025-04-21T18:44:33+01:00
Rebase, and all tests pass except whitespace for generated parser
-
1807c3e1
by Alan Zimmerman at 2025-04-21T18:44:33+01:00
More plumbing. Ready for testing tomorrow.
-
d62a7992
by Alan Zimmerman at 2025-04-21T18:44:34+01:00
Proress. Renamed module State from Types
And at first blush it seems to handle preprocessor scopes properly.
-
21d99768
by Alan Zimmerman at 2025-04-21T18:44:34+01:00
Insert basic GHC version macros into parser
__GLASGOW_HASKELL__
__GLASGOW_HASKELL_FULL_VERSION__
__GLASGOW_HASKELL_PATCHLEVEL1__
__GLASGOW_HASKELL_PATCHLEVEL2__
-
a5c97101
by Alan Zimmerman at 2025-04-21T18:44:34+01:00
Re-sync check-cpp for easy ghci work
-
88fbbb68
by Alan Zimmerman at 2025-04-21T18:44:34+01:00
Get rid of warnings
-
159e3f5c
by Alan Zimmerman at 2025-04-21T18:44:34+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
-
26de6c7a
by Alan Zimmerman at 2025-04-21T18:44:34+01:00
WIP. Can crack arguments for #define
Next step it to crack out args in an expansion
-
08a4bc32
by Alan Zimmerman at 2025-04-21T18:44:34+01:00
WIP on arg parsing.
-
e9f20c47
by Alan Zimmerman at 2025-04-21T18:44:34+01:00
Progress. Still screwing up nested parens.
-
2ddc204e
by Alan Zimmerman at 2025-04-21T18:44:34+01:00
Seems to work, but has redundant code
-
39c9fff2
by Alan Zimmerman at 2025-04-21T18:44:34+01:00
Remove redundant code
-
9738906c
by Alan Zimmerman at 2025-04-21T18:44:34+01:00
Reformat
-
8b7bc8fc
by Alan Zimmerman at 2025-04-21T18:44:34+01:00
Expand args, single pass
Still need to repeat until fixpoint
-
faf74e30
by Alan Zimmerman at 2025-04-21T18:44:34+01:00
Fixed point expansion
-
a72b05b6
by Alan Zimmerman at 2025-04-21T18:44:34+01:00
Sync the playground to compiler
-
ed57b7a2
by Alan Zimmerman at 2025-04-21T18:44:34+01:00
Working on dumping the GHC_CPP result
But We need to keep the BufSpan in a comment
-
19fe2968
by Alan Zimmerman at 2025-04-21T18:44:34+01:00
Keep BufSpan in queued comments in GHC.Parser.Lexer
-
f468e163
by Alan Zimmerman at 2025-04-21T18:44:34+01:00
Getting close to being able to print the combined tokens
showing what is in and what is out
-
6fbb06cf
by Alan Zimmerman at 2025-04-21T18:44:34+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
-
6c4ee20f
by Alan Zimmerman at 2025-04-21T18:44:34+01:00
Clean up a bit
-
85d45f08
by Alan Zimmerman at 2025-04-21T18:44:34+01:00
Add -ddump-ghc-cpp option and a test based on it
-
2df9e747
by Alan Zimmerman at 2025-04-21T18:44:34+01:00
Restore Lexer.x rules, we need them for continuation lines
-
06069b87
by Alan Zimmerman at 2025-04-21T18:44:34+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
-
a6f7ba7e
by Alan Zimmerman at 2025-04-21T18:44:34+01:00
Inserts predefined macros. But does not dump properly
Because the cpp tokens have a trailing newline
-
19c9b350
by Alan Zimmerman at 2025-04-21T18:44:34+01:00
Remove unnecessary LExer rules
We *need* the ones that explicitly match to the end of the line.
-
d94b37b7
by Alan Zimmerman at 2025-04-21T18:44:34+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.
-
4a6b9234
by Alan Zimmerman at 2025-04-21T18:44:34+01:00
Reduce duplication in lexer
-
4ee7b8cb
by Alan Zimmerman at 2025-04-21T18:44:34+01:00
Tweaks
-
04d0978c
by Alan Zimmerman at 2025-04-21T18:44:34+01:00
Insert min_version predefined macros into state
The mechanism now works. Still need to flesh out the full set.
-
31c434f2
by Alan Zimmerman at 2025-04-21T18:44:34+01:00
Trying my alternative pragma syntax.
It works, but dumpGhcCpp is broken, I suspect from the ITcpp token
span update.
-
58842a2c
by Alan Zimmerman at 2025-04-21T18:44:34+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
-
d58d5a85
by Alan Zimmerman at 2025-04-21T18:44:34+01:00
Remove some tracing
-
db54555f
by Alan Zimmerman at 2025-04-21T18:44:34+01:00
Fix test exes for changes
-
78aea61f
by Alan Zimmerman at 2025-04-21T18:44:34+01:00
For GHC_CPP tests, normalise config-time-based macros
-
c843e1f6
by Alan Zimmerman at 2025-04-21T18:44:34+01:00
WIP
-
f91a3167
by Alan Zimmerman at 2025-04-21T18:44:34+01:00
WIP again. What is wrong?
-
d9bd7e2d
by Alan Zimmerman at 2025-04-21T18:44:34+01:00
Revert to dynflags for normal not pragma lexing
-
aff258ca
by Alan Zimmerman at 2025-04-21T18:44:34+01:00
Working on getting check-exact to work properly
-
057b2d78
by Alan Zimmerman at 2025-04-21T18:44:34+01:00
Passes CppCommentPlacement test
-
d5f7efa3
by Alan Zimmerman at 2025-04-21T18:44:34+01:00
Starting on exact printing with GHC_CPP
While overriding normal CPP
-
69c1dbeb
by Alan Zimmerman at 2025-04-21T18:44:34+01:00
Correctly store CPP ignored tokens as comments
By populating the lexeme string in it, based on the bufpos
-
2f9ae126
by Alan Zimmerman at 2025-04-21T18:44:34+01:00
WIP
-
6d55843e
by Alan Zimmerman at 2025-04-21T18:44:34+01:00
Simplifying
-
865f357f
by Alan Zimmerman at 2025-04-21T18:44:34+01:00
Update the active state logic
-
95f7764c
by Alan Zimmerman at 2025-04-21T18:44:35+01:00
Work the new logic into the mainline code
-
c4eddc92
by Alan Zimmerman at 2025-04-21T18:44:35+01:00
Process `defined` operator
-
2df85e87
by Alan Zimmerman at 2025-04-21T18:44:35+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.
-
0100b713
by Alan Zimmerman at 2025-04-21T18:44:35+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.
-
073704da
by Alan Zimmerman at 2025-04-21T18:44:35+01:00
Process the ! operator in GHC_CPP expressions
-
0cc4f052
by Alan Zimmerman at 2025-04-21T18:44:35+01:00
Predefine a constant when GHC_CPP is being used.
-
a3a17006
by Alan Zimmerman at 2025-04-21T18:44:35+01:00
WIP
-
384034da
by Alan Zimmerman at 2025-04-21T18:44:35+01:00
Skip lines directly in the lexer when required
-
58f8e94f
by Alan Zimmerman at 2025-04-21T18:44:35+01:00
Properly manage location when accepting tokens again
-
0975166e
by Alan Zimmerman at 2025-04-21T18:44:35+01:00
Seems to be working now, for Example9
-
3a8b34f1
by Alan Zimmerman at 2025-04-21T18:44:35+01:00
Remove tracing
-
f35bf0c3
by Alan Zimmerman at 2025-04-21T18:44:35+01:00
Fix parsing '*' in block comments
Instead of replacing them with '-'
-
430e0c92
by Alan Zimmerman at 2025-04-21T18:44:35+01:00
Keep the trailing backslash in a ITcpp token
-
a15bb515
by Alan Zimmerman at 2025-04-21T18:44:35+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
-
cb88f9a5
by Alan Zimmerman at 2025-04-21T18:44:35+01:00
Replace remaining identifiers with 0 when evaluating
As per the spec
-
1c0d10fc
by Alan Zimmerman at 2025-04-21T18:44:35+01:00
Snapshot before rebase
-
beb2cf2e
by Alan Zimmerman at 2025-04-21T18:44:35+01:00
Skip non-processed lines starting with #
-
4e7fbb22
by Alan Zimmerman at 2025-04-21T18:44:35+01:00
Export generateMacros so we can use it in ghc-exactprint
-
50cdeda7
by Alan Zimmerman at 2025-04-21T18:44:35+01:00
Fix rebase
-
de4a5656
by Alan Zimmerman at 2025-04-21T18:44:35+01:00
Expose initParserStateWithMacrosString
-
faafb98f
by Alan Zimmerman at 2025-04-21T18:44:35+01:00
Fix buggy lexer cppSkip
It was skipping all lines, not just ones prefixed by #
-
abc6dd80
by Alan Zimmerman at 2025-04-21T18:44:35+01:00
Fix evaluation of && to use the correct operator
-
6759b157
by Alan Zimmerman at 2025-04-21T18:44:35+01:00
Deal with closing #-} at the start of a line
-
aaea5fe1
by Alan Zimmerman at 2025-04-21T18:44:35+01:00
Add the MIN_VERSION_GLASGOW_HASKELL predefined macro
-
4725ad9f
by Alan Zimmerman at 2025-04-21T18:44:35+01:00
Include MIN_VERSION_GLASGOW_HASKELL in GhcCpp01.stderr
-
8144afb6
by Alan Zimmerman at 2025-04-21T18:44:35+01:00
Use a strict map for macro defines
-
937902ae
by Alan Zimmerman at 2025-04-21T18:44:35+01:00
Process TIdentifierLParen
Which only matters at the start of #define
-
0b4c36a4
by Alan Zimmerman at 2025-04-21T18:44:35+01:00
Do not provide TIdentifierLParen paren twice
-
e2eef871
by Alan Zimmerman at 2025-04-21T18:44:35+01:00
Handle whitespace between identifier and '(' for directive only