-
fe6ed8d9
by Sylvain Henry at 2025-04-24T18:04:12-04:00
Doc: add doc for JS interruptible calling convention (#24444)
-
6111c5e4
by Ben Gamari at 2025-04-24T18:04:53-04:00
compiler: Ensure that Panic.Plain.assertPanic' provides callstack
In 36cddd2ce1a3bc62ea8a1307d8bc6006d54109cf @alt-romes removed CallStack
output from `GHC.Utils.Panic.Plain.assertPanic'`. While this output is
redundant due to the exception backtrace proposal, we may be
bootstrapping with a compiler which does not yet include this machinery.
Reintroduce the output for now.
Fixes #25898.
-
217caad1
by Matthew Pickering at 2025-04-25T18:58:42+01:00
Implement Explicit Level Imports for Template Haskell
This commit introduces the `ExplicitLevelImports` and
`ImplicitStagePersistence` language extensions as proposed in GHC
Proposal #682.
Key Features
------------
- `ExplicitLevelImports` adds two new import modifiers - `splice` and
`quote` - allowing precise control over the level at which imported
identifiers are available
- `ImplicitStagePersistence` (enabled by default) preserves existing
path-based cross-stage persistence behavior
- `NoImplicitStagePersistence` disables implicit cross-stage
persistence, requiring explicit level imports
Benefits
--------
- Improved compilation performance by reducing unnecessary code generation
- Enhanced IDE experience with faster feedback in `-fno-code` mode
- Better dependency tracking by distinguishing compile-time and runtime dependencies
- Foundation for future cross-compilation improvements
This implementation enables the separation of modules needed at
compile-time from those needed at runtime, allowing for more efficient
compilation pipelines and clearer code organization in projects using
Template Haskell.
Implementation Notes
--------------------
The level which a name is availble at is stored in the 'GRE', in the normal
GlobalRdrEnv. The function `greLevels` returns the levels which a specific GRE
is imported at. The level information for a 'Name' is computed by `getCurrentAndBindLevel`.
The level validity is checked by `checkCrossLevelLifting`.
Instances are checked by `checkWellLevelledDFun`, which computes the level an
instance by calling `checkWellLevelledInstanceWhat`, which sees what is
available at by looking at the module graph.
Modifications to downsweep
--------------------------
Code generation is now only enabled for modules which are needed at
compile time.
See the Note [-fno-code mode] for more information.
Uniform error messages for level errors
---------------------------------------
All error messages to do with levels are now reported uniformly using
the `TcRnBadlyStaged` constructor.
Error messages are uniformly reported in terms of levels.
0 - top-level
1 - quote level
-1 - splice level
The only level hard-coded into the compiler is the top-level in
GHC.Types.ThLevelIndex.topLevelIndex.
Uniformly refer to levels and stages
------------------------------------
There was much confusion about levels vs stages in the compiler.
A level is a semantic concept, used by the typechecker to ensure a
program can be evaluated in a well-staged manner.
A stage is an operational construct, program evaluation proceeds in
stages.
Deprecate -Wbadly-staged-types
------------------------------
`-Wbadly-staged-types` is deprecated in favour of `-Wbadly-levelled-types`.
Lift derivation changed
-----------------------
Derived lift instances will now not generate code with expression
quotations.
Before:
```
data A = A Int deriving Lift
=>
lift (A x) = [| A $(lift x) |]
```
After:
```
lift (A x) = conE 'A `appE` (lift x)
```
This is because if you attempt to derive `Lift` in a module where
`NoImplicitStagePersistence` is enabled, you would get an infinite loop
where a constructor was attempted to be persisted using the instance you
are currently defining.
GHC API Changes
---------------
The ModuleGraph now contains additional information about the type of
the edges (normal, quote or splice) between modules. This is abstracted
using the `ModuleGraphEdge` data type.
Fixes #25828
-------------------------
Metric Increase:
MultiLayerModulesTH_Make
-------------------------
-
7641a74a
by Simon Peyton Jones at 2025-04-26T22:05:19-04:00
Get a decent MatchContext for pattern synonym bindings
In particular when we have a pattern binding
K p1 .. pn = rhs
where K is a pattern synonym. (It might be nested.)
This small MR fixes #25995. It's a tiny fix, to an error message,
removing an always-dubious `unkSkol`.
The bug report was in the context of horde-ad, a big program,
and I didn't manage to make a small repro case quickly. I decided
not to bother further.
-
cd6cd9d3
by Alan Zimmerman at 2025-04-27T09:42: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
-
42fbb8d8
by Alan Zimmerman at 2025-04-27T09:42:37+01:00
Tidy up before re-visiting the continuation mechanic
-
406d80a0
by Alan Zimmerman at 2025-04-27T09:42:37+01:00
Switch preprocessor to continuation passing style
Proof of concept, needs tidying up
-
479e2847
by Alan Zimmerman at 2025-04-27T09:42:37+01:00
Small cleanup
-
7c8d33f0
by Alan Zimmerman at 2025-04-27T09:42:37+01:00
Get rid of some cruft
-
987dc05b
by Alan Zimmerman at 2025-04-27T09:42:37+01:00
Starting to integrate.
Need to get the pragma recognised and set
-
8c1b61a9
by Alan Zimmerman at 2025-04-27T09:42:37+01:00
Make cppTokens extend to end of line, and process CPP comments
-
d520ffa6
by Alan Zimmerman at 2025-04-27T09:42:37+01:00
Remove unused ITcppDefined
-
2a402d8a
by Alan Zimmerman at 2025-04-27T09:42:37+01:00
Allow spaces between # and keyword for preprocessor directive
-
5ac9db4b
by Alan Zimmerman at 2025-04-27T09:42:37+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.
-
d6c6f169
by Alan Zimmerman at 2025-04-27T09:42:37+01:00
Accumulate CPP continuations, process when ready
Can be simplified further, we only need one CPP token
-
c39d12e1
by Alan Zimmerman at 2025-04-27T09:42:37+01:00
Simplify Lexer interface. Only ITcpp
We transfer directive lines through it, then parse them from scratch
in the preprocessor.
-
e1b6dc62
by Alan Zimmerman at 2025-04-27T09:42:37+01:00
Deal with directive on last line, with no trailing \n
-
bd137110
by Alan Zimmerman at 2025-04-27T09:42:37+01:00
Start parsing and processing the directives
-
b4e92dac
by Alan Zimmerman at 2025-04-27T09:42:37+01:00
Prepare for processing include files
-
1ad6ec4e
by Alan Zimmerman at 2025-04-27T09:43:51+01:00
Move PpState into PreProcess
And initParserState, initPragState too
-
e7ec1320
by Alan Zimmerman at 2025-04-27T09:43:53+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
-
2a02f630
by Alan Zimmerman at 2025-04-27T09:43:53+01:00
Split into separate files
-
f9c13601
by Alan Zimmerman at 2025-04-27T09:43:53+01:00
Starting on expression parser.
But it hangs. Time for Text.Parsec.Expr
-
5d21a660
by Alan Zimmerman at 2025-04-27T09:43:53+01:00
Start integrating the ghc-cpp work
From https://github.com/alanz/ghc-cpp
-
f17c82b8
by Alan Zimmerman at 2025-04-27T09:43:54+01:00
WIP
-
2b7e8616
by Alan Zimmerman at 2025-04-27T09:44:33+01:00
Fixup after rebase
-
2bad789d
by Alan Zimmerman at 2025-04-27T09:44:36+01:00
WIP
-
446f656e
by Alan Zimmerman at 2025-04-27T09:44:36+01:00
Fixup after rebase, including all tests pass
-
a36ba3a6
by Alan Zimmerman at 2025-04-27T09:44:36+01:00
Change pragma usage to GHC_CPP from GhcCPP
-
2227185e
by Alan Zimmerman at 2025-04-27T09:44:36+01:00
Some comments
-
ebbefb31
by Alan Zimmerman at 2025-04-27T09:44:36+01:00
Reformat
-
a76f409b
by Alan Zimmerman at 2025-04-27T09:44:36+01:00
Delete unused file
-
75f1b629
by Alan Zimmerman at 2025-04-27T09:44:36+01:00
Rename module Parse to ParsePP
-
914c8ed2
by Alan Zimmerman at 2025-04-27T09:44:36+01:00
Clarify naming in the parser
-
f79218ae
by Alan Zimmerman at 2025-04-27T09:44:36+01:00
WIP. Switching to alex/happy to be able to work in-tree
Since Parsec is not available
-
1201a517
by Alan Zimmerman at 2025-04-27T09:44:36+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
-
2fdf808f
by Alan Zimmerman at 2025-04-27T09:44:36+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
```
-
7b56ff52
by Alan Zimmerman at 2025-04-27T09:44:36+01:00
Rebase, and all tests pass except whitespace for generated parser
-
0be8ae74
by Alan Zimmerman at 2025-04-27T09:44:36+01:00
More plumbing. Ready for testing tomorrow.
-
da4c51eb
by Alan Zimmerman at 2025-04-27T09:44:36+01:00
Proress. Renamed module State from Types
And at first blush it seems to handle preprocessor scopes properly.
-
22065fab
by Alan Zimmerman at 2025-04-27T09:45:37+01:00
Insert basic GHC version macros into parser
__GLASGOW_HASKELL__
__GLASGOW_HASKELL_FULL_VERSION__
__GLASGOW_HASKELL_PATCHLEVEL1__
__GLASGOW_HASKELL_PATCHLEVEL2__
-
fc538156
by Alan Zimmerman at 2025-04-27T09:45:43+01:00
Re-sync check-cpp for easy ghci work
-
6f4b8e0a
by Alan Zimmerman at 2025-04-27T09:45:43+01:00
Get rid of warnings
-
e8a868b4
by Alan Zimmerman at 2025-04-27T09:45:43+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
-
da7b4bd7
by Alan Zimmerman at 2025-04-27T09:45:43+01:00
WIP. Can crack arguments for #define
Next step it to crack out args in an expansion
-
2cb5187f
by Alan Zimmerman at 2025-04-27T09:45:43+01:00
WIP on arg parsing.
-
fd6219ba
by Alan Zimmerman at 2025-04-27T09:45:43+01:00
Progress. Still screwing up nested parens.
-
a185cf05
by Alan Zimmerman at 2025-04-27T09:45:43+01:00
Seems to work, but has redundant code
-
add511d8
by Alan Zimmerman at 2025-04-27T09:45:43+01:00
Remove redundant code
-
92e3fb7b
by Alan Zimmerman at 2025-04-27T09:45:44+01:00
Reformat
-
053762fa
by Alan Zimmerman at 2025-04-27T09:45:44+01:00
Expand args, single pass
Still need to repeat until fixpoint
-
d6ba6e1c
by Alan Zimmerman at 2025-04-27T09:45:44+01:00
Fixed point expansion
-
998a3449
by Alan Zimmerman at 2025-04-27T09:45:44+01:00
Sync the playground to compiler
-
49229bdb
by Alan Zimmerman at 2025-04-27T09:45:44+01:00
Working on dumping the GHC_CPP result
But We need to keep the BufSpan in a comment
-
4af70371
by Alan Zimmerman at 2025-04-27T09:45:44+01:00
Keep BufSpan in queued comments in GHC.Parser.Lexer
-
74c76e32
by Alan Zimmerman at 2025-04-27T09:45:44+01:00
Getting close to being able to print the combined tokens
showing what is in and what is out
-
73131f6b
by Alan Zimmerman at 2025-04-27T09:45:44+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
-
6486091b
by Alan Zimmerman at 2025-04-27T09:45:44+01:00
Clean up a bit
-
0e0b1812
by Alan Zimmerman at 2025-04-27T09:45:44+01:00
Add -ddump-ghc-cpp option and a test based on it
-
e6567926
by Alan Zimmerman at 2025-04-27T09:45:44+01:00
Restore Lexer.x rules, we need them for continuation lines
-
39204055
by Alan Zimmerman at 2025-04-27T09:45:44+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
-
ee2ff3f9
by Alan Zimmerman at 2025-04-27T09:46:38+01:00
Inserts predefined macros. But does not dump properly
Because the cpp tokens have a trailing newline
-
112c7c67
by Alan Zimmerman at 2025-04-27T09:46:40+01:00
Remove unnecessary LExer rules
We *need* the ones that explicitly match to the end of the line.
-
ed24feed
by Alan Zimmerman at 2025-04-27T09:46:40+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.
-
7f963a43
by Alan Zimmerman at 2025-04-27T09:46:40+01:00
Reduce duplication in lexer
-
8d543de7
by Alan Zimmerman at 2025-04-27T09:46:40+01:00
Tweaks
-
aaa0c03e
by Alan Zimmerman at 2025-04-27T09:46:40+01:00
Insert min_version predefined macros into state
The mechanism now works. Still need to flesh out the full set.
-
06342391
by Alan Zimmerman at 2025-04-27T09:46:40+01:00
Trying my alternative pragma syntax.
It works, but dumpGhcCpp is broken, I suspect from the ITcpp token
span update.
-
0e507bdb
by Alan Zimmerman at 2025-04-27T09:46:40+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
-
057bdfdb
by Alan Zimmerman at 2025-04-27T09:46:40+01:00
Remove some tracing
-
d1c11ee8
by Alan Zimmerman at 2025-04-27T09:46:40+01:00
Fix test exes for changes
-
36192a2e
by Alan Zimmerman at 2025-04-27T09:46:40+01:00
For GHC_CPP tests, normalise config-time-based macros
-
1570daca
by Alan Zimmerman at 2025-04-27T09:46:40+01:00
WIP
-
72a9d4de
by Alan Zimmerman at 2025-04-27T09:46:40+01:00
WIP again. What is wrong?
-
f6f73963
by Alan Zimmerman at 2025-04-27T09:46:40+01:00
Revert to dynflags for normal not pragma lexing
-
ddabab27
by Alan Zimmerman at 2025-04-27T09:46:41+01:00
Working on getting check-exact to work properly
-
db52fe62
by Alan Zimmerman at 2025-04-27T09:46:41+01:00
Passes CppCommentPlacement test
-
d4f4516c
by Alan Zimmerman at 2025-04-27T09:46:41+01:00
Starting on exact printing with GHC_CPP
While overriding normal CPP
-
e60c902c
by Alan Zimmerman at 2025-04-27T09:46:41+01:00
Correctly store CPP ignored tokens as comments
By populating the lexeme string in it, based on the bufpos
-
b89da516
by Alan Zimmerman at 2025-04-27T09:46:41+01:00
WIP
-
6cb6e97a
by Alan Zimmerman at 2025-04-27T09:46:41+01:00
Simplifying
-
8c4cfec3
by Alan Zimmerman at 2025-04-27T09:46:41+01:00
Update the active state logic
-
b43896b3
by Alan Zimmerman at 2025-04-27T09:46:41+01:00
Work the new logic into the mainline code
-
1e38cea0
by Alan Zimmerman at 2025-04-27T09:46:41+01:00
Process `defined` operator
-
3ff7742a
by Alan Zimmerman at 2025-04-27T09:46:41+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.
-
1f895269
by Alan Zimmerman at 2025-04-27T09:46:41+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.
-
99a485e0
by Alan Zimmerman at 2025-04-27T09:46:41+01:00
Process the ! operator in GHC_CPP expressions
-
2ea031c9
by Alan Zimmerman at 2025-04-27T09:46:41+01:00
Predefine a constant when GHC_CPP is being used.
-
6dd75f13
by Alan Zimmerman at 2025-04-27T09:46:41+01:00
WIP
-
55e84bc4
by Alan Zimmerman at 2025-04-27T09:46:41+01:00
Skip lines directly in the lexer when required
-
0d7ece26
by Alan Zimmerman at 2025-04-27T09:46:41+01:00
Properly manage location when accepting tokens again
-
bb5d5425
by Alan Zimmerman at 2025-04-27T09:46:41+01:00
Seems to be working now, for Example9
-
21dfdb8c
by Alan Zimmerman at 2025-04-27T09:46:41+01:00
Remove tracing
-
33df63ea
by Alan Zimmerman at 2025-04-27T09:46:41+01:00
Fix parsing '*' in block comments
Instead of replacing them with '-'
-
2348cf1d
by Alan Zimmerman at 2025-04-27T09:46:41+01:00
Keep the trailing backslash in a ITcpp token
-
0e6359a2
by Alan Zimmerman at 2025-04-27T09:46:41+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
-
03135712
by Alan Zimmerman at 2025-04-27T09:46:41+01:00
Replace remaining identifiers with 0 when evaluating
As per the spec
-
e7598666
by Alan Zimmerman at 2025-04-27T09:46:41+01:00
Snapshot before rebase
-
e6403756
by Alan Zimmerman at 2025-04-27T09:46:41+01:00
Skip non-processed lines starting with #
-
e397240c
by Alan Zimmerman at 2025-04-27T09:46:41+01:00
Export generateMacros so we can use it in ghc-exactprint
-
4d68adb0
by Alan Zimmerman at 2025-04-27T09:46:41+01:00
Fix rebase
-
5ab88d91
by Alan Zimmerman at 2025-04-27T09:46:41+01:00
Expose initParserStateWithMacrosString
-
59cb7936
by Alan Zimmerman at 2025-04-27T09:46:41+01:00
Fix buggy lexer cppSkip
It was skipping all lines, not just ones prefixed by #
-
cc59ad68
by Alan Zimmerman at 2025-04-27T09:46:41+01:00
Fix evaluation of && to use the correct operator
-
3286f84a
by Alan Zimmerman at 2025-04-27T09:46:41+01:00
Deal with closing #-} at the start of a line
-
1ce0abad
by Alan Zimmerman at 2025-04-27T09:46:41+01:00
Add the MIN_VERSION_GLASGOW_HASKELL predefined macro
-
a15043e4
by Alan Zimmerman at 2025-04-27T09:46:41+01:00
Include MIN_VERSION_GLASGOW_HASKELL in GhcCpp01.stderr
-
a44dbcaa
by Alan Zimmerman at 2025-04-27T09:46:41+01:00
Use a strict map for macro defines
-
22aa503a
by Alan Zimmerman at 2025-04-27T09:46:41+01:00
Process TIdentifierLParen
Which only matters at the start of #define
-
a27faeab
by Alan Zimmerman at 2025-04-27T09:46:41+01:00
Do not provide TIdentifierLParen paren twice
-
8e22cba6
by Alan Zimmerman at 2025-04-27T09:46:41+01:00
Handle whitespace between identifier and '(' for directive only
-
9bc48c1e
by Alan Zimmerman at 2025-04-27T09:46:41+01:00
Expose some Lexer bitmap manipulation helpers
-
236800a6
by Alan Zimmerman at 2025-04-27T09:46:41+01:00
Deal with line pragmas as tokens
Blows up for dumpGhcCpp though
-
8f6ebfc0
by Alan Zimmerman at 2025-04-27T09:46:41+01:00
Allow strings delimited by a single quote too
-
9dbc3f96
by Alan Zimmerman at 2025-04-27T10:51:22+01:00
Allow leading whitespace on cpp directives
As per https://timsong-cpp.github.io/cppwp/n4140/cpp#1