-
91564daf
by Matthew Pickering at 2025-04-24T00:29:02-04:00
ghci: Use loadInterfaceForModule rather than loadSrcInterface in mkTopLevEnv
loadSrcInterface takes a user given `ModuleName` and resolves it to the
module which needs to be loaded (taking into account module
renaming/visibility etc).
loadInterfaceForModule takes a specific module and loads it.
The modules in `ImpDeclSpec` have already been resolved to the actual
module to get the information from during renaming. Therefore we just
need to fetch the precise interface from disk (and not attempt to rename
it again).
Fixes #25951
-
2e0c07ab
by Simon Peyton Jones at 2025-04-24T00:29:43-04:00
Test for #23298
-
0eef99b0
by Sven Tennie at 2025-04-24T07:34:36-04:00
RV64: Introduce J instruction (non-local jumps) and don't deallocate stack slots for J_TBL (#25738)
J_TBL result in local jumps, there should not deallocate stack slots
(see Note [extra spill slots].)
J is for non-local jumps, these may need to deallocate stack slots.
-
1bd3d13e
by fendor at 2025-04-24T07:35:17-04:00
Add `UnitId` to `EvalBreakpoint`
The `EvalBreakpoint` is used to communicate that a breakpoint was
encountered during code evaluation.
This `EvalBreakpoint` needs to be converted to an `InternalBreakpointId`
which stores a `Module` to uniquely find the correct `Module` in the
Home Package Table.
The `EvalBreakpoint` used to store only a `ModuleName` which is then
converted to a `Module` based on the currently active home unit.
This is incorrect in the face of multiple home units, the break point
could be in an entirely other home unit!
To fix this, we additionally store the `UnitId` of the `Module` in
`EvalBreakpoint` to later reconstruct the correct `Module`
All of the changes are the consequence of extending `EvalBreakpoint`
with the additional `ShortByteString` of the `UnitId`.
For performance reasons, we store the `ShortByteString` backing the
`UnitId` directly, avoiding marshalling overhead.
-
0fc630f6
by Alan Zimmerman at 2025-04-24T18:16:55+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
-
7b9e88bc
by Alan Zimmerman at 2025-04-24T18:16:55+01:00
Tidy up before re-visiting the continuation mechanic
-
3122938c
by Alan Zimmerman at 2025-04-24T18:16:55+01:00
Switch preprocessor to continuation passing style
Proof of concept, needs tidying up
-
681bef59
by Alan Zimmerman at 2025-04-24T18:16:55+01:00
Small cleanup
-
b440e634
by Alan Zimmerman at 2025-04-24T18:16:55+01:00
Get rid of some cruft
-
2b346c2a
by Alan Zimmerman at 2025-04-24T18:16:56+01:00
Starting to integrate.
Need to get the pragma recognised and set
-
6abe3815
by Alan Zimmerman at 2025-04-24T18:16:56+01:00
Make cppTokens extend to end of line, and process CPP comments
-
d31157a8
by Alan Zimmerman at 2025-04-24T18:16:56+01:00
Remove unused ITcppDefined
-
639208c3
by Alan Zimmerman at 2025-04-24T18:16:56+01:00
Allow spaces between # and keyword for preprocessor directive
-
854374dc
by Alan Zimmerman at 2025-04-24T18:16:56+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.
-
04450a85
by Alan Zimmerman at 2025-04-24T18:16:56+01:00
Accumulate CPP continuations, process when ready
Can be simplified further, we only need one CPP token
-
089bb023
by Alan Zimmerman at 2025-04-24T18:16:56+01:00
Simplify Lexer interface. Only ITcpp
We transfer directive lines through it, then parse them from scratch
in the preprocessor.
-
6f9a6183
by Alan Zimmerman at 2025-04-24T18:16:56+01:00
Deal with directive on last line, with no trailing \n
-
c392bba5
by Alan Zimmerman at 2025-04-24T18:16:56+01:00
Start parsing and processing the directives
-
13e86d1f
by Alan Zimmerman at 2025-04-24T18:16:56+01:00
Prepare for processing include files
-
757b978b
by Alan Zimmerman at 2025-04-24T18:16:56+01:00
Move PpState into PreProcess
And initParserState, initPragState too
-
2aba7f93
by Alan Zimmerman at 2025-04-24T18:16:56+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
-
d545db1d
by Alan Zimmerman at 2025-04-24T18:16:56+01:00
Split into separate files
-
5869fc35
by Alan Zimmerman at 2025-04-24T18:16:56+01:00
Starting on expression parser.
But it hangs. Time for Text.Parsec.Expr
-
370fff2e
by Alan Zimmerman at 2025-04-24T18:16:56+01:00
Start integrating the ghc-cpp work
From https://github.com/alanz/ghc-cpp
-
c85df867
by Alan Zimmerman at 2025-04-24T18:16:56+01:00
WIP
-
b8896b47
by Alan Zimmerman at 2025-04-24T18:16:56+01:00
Fixup after rebase
-
fef967e6
by Alan Zimmerman at 2025-04-24T18:16:56+01:00
WIP
-
847dd6b3
by Alan Zimmerman at 2025-04-24T18:16:56+01:00
Fixup after rebase, including all tests pass
-
fdc130da
by Alan Zimmerman at 2025-04-24T18:16:56+01:00
Change pragma usage to GHC_CPP from GhcCPP
-
bf805566
by Alan Zimmerman at 2025-04-24T18:16:56+01:00
Some comments
-
4965a6cb
by Alan Zimmerman at 2025-04-24T18:16:56+01:00
Reformat
-
0b135bc4
by Alan Zimmerman at 2025-04-24T18:16:56+01:00
Delete unused file
-
368f0bac
by Alan Zimmerman at 2025-04-24T18:16:56+01:00
Rename module Parse to ParsePP
-
272b2ee6
by Alan Zimmerman at 2025-04-24T18:16:56+01:00
Clarify naming in the parser
-
77cc824f
by Alan Zimmerman at 2025-04-24T18:16:56+01:00
WIP. Switching to alex/happy to be able to work in-tree
Since Parsec is not available
-
f8260f59
by Alan Zimmerman at 2025-04-24T18:16:56+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
-
bcf6df38
by Alan Zimmerman at 2025-04-24T18:16:56+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
```
-
e21ff624
by Alan Zimmerman at 2025-04-24T18:16:56+01:00
Rebase, and all tests pass except whitespace for generated parser
-
d3b4779a
by Alan Zimmerman at 2025-04-24T18:16:56+01:00
More plumbing. Ready for testing tomorrow.
-
cbce7b1d
by Alan Zimmerman at 2025-04-24T18:16:56+01:00
Proress. Renamed module State from Types
And at first blush it seems to handle preprocessor scopes properly.
-
4a3bc468
by Alan Zimmerman at 2025-04-24T18:16:56+01:00
Insert basic GHC version macros into parser
__GLASGOW_HASKELL__
__GLASGOW_HASKELL_FULL_VERSION__
__GLASGOW_HASKELL_PATCHLEVEL1__
__GLASGOW_HASKELL_PATCHLEVEL2__
-
302b8058
by Alan Zimmerman at 2025-04-24T18:16:56+01:00
Re-sync check-cpp for easy ghci work
-
ea0417b6
by Alan Zimmerman at 2025-04-24T18:16:56+01:00
Get rid of warnings
-
7614e4a2
by Alan Zimmerman at 2025-04-24T18:16:56+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
-
68c7ed44
by Alan Zimmerman at 2025-04-24T18:16:56+01:00
WIP. Can crack arguments for #define
Next step it to crack out args in an expansion
-
dadcdb3a
by Alan Zimmerman at 2025-04-24T18:16:56+01:00
WIP on arg parsing.
-
c7edf420
by Alan Zimmerman at 2025-04-24T18:16:56+01:00
Progress. Still screwing up nested parens.
-
375ed9f2
by Alan Zimmerman at 2025-04-24T18:16:56+01:00
Seems to work, but has redundant code
-
268a487d
by Alan Zimmerman at 2025-04-24T18:16:56+01:00
Remove redundant code
-
df6e5699
by Alan Zimmerman at 2025-04-24T18:16:57+01:00
Reformat
-
cd62f2c6
by Alan Zimmerman at 2025-04-24T18:16:57+01:00
Expand args, single pass
Still need to repeat until fixpoint
-
45ed9b02
by Alan Zimmerman at 2025-04-24T18:16:57+01:00
Fixed point expansion
-
9dc92747
by Alan Zimmerman at 2025-04-24T18:16:57+01:00
Sync the playground to compiler
-
161cc1c8
by Alan Zimmerman at 2025-04-24T18:16:57+01:00
Working on dumping the GHC_CPP result
But We need to keep the BufSpan in a comment
-
f1cd7c0a
by Alan Zimmerman at 2025-04-24T18:16:57+01:00
Keep BufSpan in queued comments in GHC.Parser.Lexer
-
aa3cde3f
by Alan Zimmerman at 2025-04-24T18:16:57+01:00
Getting close to being able to print the combined tokens
showing what is in and what is out
-
be2beb8d
by Alan Zimmerman at 2025-04-24T18:16:57+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
-
89a8f51e
by Alan Zimmerman at 2025-04-24T18:16:57+01:00
Clean up a bit
-
9437ebfb
by Alan Zimmerman at 2025-04-24T18:16:57+01:00
Add -ddump-ghc-cpp option and a test based on it
-
46818aef
by Alan Zimmerman at 2025-04-24T18:16:57+01:00
Restore Lexer.x rules, we need them for continuation lines
-
40e38ca8
by Alan Zimmerman at 2025-04-24T18:16:57+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
-
77c1e125
by Alan Zimmerman at 2025-04-24T18:16:57+01:00
Inserts predefined macros. But does not dump properly
Because the cpp tokens have a trailing newline
-
e89df978
by Alan Zimmerman at 2025-04-24T18:16:57+01:00
Remove unnecessary LExer rules
We *need* the ones that explicitly match to the end of the line.
-
409ab214
by Alan Zimmerman at 2025-04-24T18:16:57+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.
-
3e4b1f7a
by Alan Zimmerman at 2025-04-24T18:16:57+01:00
Reduce duplication in lexer
-
79f76357
by Alan Zimmerman at 2025-04-24T18:16:57+01:00
Tweaks
-
d2565e5c
by Alan Zimmerman at 2025-04-24T18:16:57+01:00
Insert min_version predefined macros into state
The mechanism now works. Still need to flesh out the full set.
-
46aa4cc8
by Alan Zimmerman at 2025-04-24T18:16:57+01:00
Trying my alternative pragma syntax.
It works, but dumpGhcCpp is broken, I suspect from the ITcpp token
span update.
-
5d0a14c3
by Alan Zimmerman at 2025-04-24T18:16:57+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
-
da76d922
by Alan Zimmerman at 2025-04-24T18:16:57+01:00
Remove some tracing
-
4f2d0896
by Alan Zimmerman at 2025-04-24T18:16:57+01:00
Fix test exes for changes
-
8341fabd
by Alan Zimmerman at 2025-04-24T18:16:57+01:00
For GHC_CPP tests, normalise config-time-based macros
-
4bd8826c
by Alan Zimmerman at 2025-04-24T18:16:57+01:00
WIP
-
ac7411f9
by Alan Zimmerman at 2025-04-24T18:16:57+01:00
WIP again. What is wrong?
-
bcc8bb13
by Alan Zimmerman at 2025-04-24T18:16:57+01:00
Revert to dynflags for normal not pragma lexing
-
e5b3514b
by Alan Zimmerman at 2025-04-24T18:16:57+01:00
Working on getting check-exact to work properly
-
f80cdcd2
by Alan Zimmerman at 2025-04-24T18:16:57+01:00
Passes CppCommentPlacement test
-
eafa436e
by Alan Zimmerman at 2025-04-24T18:16:57+01:00
Starting on exact printing with GHC_CPP
While overriding normal CPP
-
636ca98d
by Alan Zimmerman at 2025-04-24T18:16:57+01:00
Correctly store CPP ignored tokens as comments
By populating the lexeme string in it, based on the bufpos
-
fe0dc499
by Alan Zimmerman at 2025-04-24T18:16:57+01:00
WIP
-
037cc151
by Alan Zimmerman at 2025-04-24T18:16:57+01:00
Simplifying
-
6bd2cedb
by Alan Zimmerman at 2025-04-24T18:16:57+01:00
Update the active state logic
-
bf9af1e4
by Alan Zimmerman at 2025-04-24T18:16:57+01:00
Work the new logic into the mainline code
-
2975b9f1
by Alan Zimmerman at 2025-04-24T18:16:57+01:00
Process `defined` operator
-
83e8470a
by Alan Zimmerman at 2025-04-24T18:16:57+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.
-
d960022a
by Alan Zimmerman at 2025-04-24T18:16:57+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.
-
a64e1ac7
by Alan Zimmerman at 2025-04-24T18:16:57+01:00
Process the ! operator in GHC_CPP expressions
-
20b34726
by Alan Zimmerman at 2025-04-24T18:16:57+01:00
Predefine a constant when GHC_CPP is being used.
-
0a1e66ca
by Alan Zimmerman at 2025-04-24T18:16:57+01:00
WIP
-
dd94a679
by Alan Zimmerman at 2025-04-24T18:16:57+01:00
Skip lines directly in the lexer when required
-
1ec6f204
by Alan Zimmerman at 2025-04-24T18:16:57+01:00
Properly manage location when accepting tokens again
-
20a6be64
by Alan Zimmerman at 2025-04-24T18:16:57+01:00
Seems to be working now, for Example9
-
ac8b516b
by Alan Zimmerman at 2025-04-24T18:16:58+01:00
Remove tracing
-
9966dff9
by Alan Zimmerman at 2025-04-24T18:16:58+01:00
Fix parsing '*' in block comments
Instead of replacing them with '-'
-
654e4220
by Alan Zimmerman at 2025-04-24T18:16:58+01:00
Keep the trailing backslash in a ITcpp token
-
2b198253
by Alan Zimmerman at 2025-04-24T18:16:58+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
-
a0ceda9d
by Alan Zimmerman at 2025-04-24T18:16:58+01:00
Replace remaining identifiers with 0 when evaluating
As per the spec
-
7ab22a44
by Alan Zimmerman at 2025-04-24T18:16:58+01:00
Snapshot before rebase
-
d6dba815
by Alan Zimmerman at 2025-04-24T18:16:58+01:00
Skip non-processed lines starting with #
-
fdda605f
by Alan Zimmerman at 2025-04-24T18:16:58+01:00
Export generateMacros so we can use it in ghc-exactprint
-
31b6e62b
by Alan Zimmerman at 2025-04-24T18:16:58+01:00
Fix rebase
-
050470d3
by Alan Zimmerman at 2025-04-24T18:16:58+01:00
Expose initParserStateWithMacrosString
-
d8b13d8b
by Alan Zimmerman at 2025-04-24T18:16:58+01:00
Fix buggy lexer cppSkip
It was skipping all lines, not just ones prefixed by #
-
e5927330
by Alan Zimmerman at 2025-04-24T18:16:58+01:00
Fix evaluation of && to use the correct operator
-
b3234fc5
by Alan Zimmerman at 2025-04-24T18:16:58+01:00
Deal with closing #-} at the start of a line
-
385e99fc
by Alan Zimmerman at 2025-04-24T18:16:58+01:00
Add the MIN_VERSION_GLASGOW_HASKELL predefined macro
-
eb2b6350
by Alan Zimmerman at 2025-04-24T18:16:58+01:00
Include MIN_VERSION_GLASGOW_HASKELL in GhcCpp01.stderr
-
f006682e
by Alan Zimmerman at 2025-04-24T18:16:58+01:00
Use a strict map for macro defines
-
6f80071d
by Alan Zimmerman at 2025-04-24T18:16:58+01:00
Process TIdentifierLParen
Which only matters at the start of #define
-
be43707c
by Alan Zimmerman at 2025-04-24T18:16:58+01:00
Do not provide TIdentifierLParen paren twice
-
032f1174
by Alan Zimmerman at 2025-04-24T18:16:58+01:00
Handle whitespace between identifier and '(' for directive only
-
a821b36d
by Alan Zimmerman at 2025-04-24T18:16:58+01:00
Expose some Lexer bitmap manipulation helpers
-
ae6f6b39
by Alan Zimmerman at 2025-04-24T18:16:58+01:00
Deal with line pragmas as tokens
Blows up for dumpGhcCpp though
-
cb0c0ee9
by Alan Zimmerman at 2025-04-24T21:41:38+01:00
Allow strings delimited by a single quote too