Rodrigo Mesquita pushed to branch wip/romes/async-eval-resume at Glasgow Haskell Compiler / GHC Commits: 3e66b59c by Andrea Vezzosi at 2026-11-23T12:52:30+05:30 test case for #28104 (cherry picked from commit c032076a9cd2a6ce2fea66df98fd5f5c85e81aac) - - - - - d991ab3c by Zubin Duggal at 2026-11-23T14:02:49+05:30 loader: fix #28104 Ensure LoaderState is recorded accurately and consistent in the presence of failures * loadObjects: when resolveObjs fails, unload only the objects freshly loaded and return the old LoaderState. Before this we used to unload every home module with unload_wkr, but then its callers threw inside `modifyLoaderState`, which restored the old state, which contained objects that were already unloaded. The objects loaded by `loadObjects` are also unloaded if loading or resolving fails. * loadName, loadDecls, loadModule: report failure after the transaction has committed, so we don't mangle the loader state by restoring the old state. * unload: Keep track of things that were succefully unloaded on exception and unload each object of a module only once. The foreign stub objects of a bytecode module are recorded in both objs_loaded and bcos_loaded, so with a non-dynamic interpreter unloading such a module called unloadObj twice on the same object and failed. Fixes #28104 - - - - - 19a4dfcd by Zubin Duggal at 2026-11-23T14:02:49+05:30 loader: make crucial sequences uninterruptible Add masks so that we don't observe async exceptions during sequences that can't deal with them. - - - - - 0c095fa9 by Andrea Vezzosi at 2026-11-23T10:39:42+01:00 interp: close Mailbox when exiting sendTHComputation - - - - - 8a15b532 by Andrea Vezzosi at 2026-11-23T10:39:42+01:00 Revert "template-haskell: force arguments of Q primitives up front." This reverts commit 653e4ffcbf807f7a8268d7d0d9f5b710f8d73906. - - - - - 5216cfd0 by Andrea Vezzosi at 2026-11-23T10:39:42+01:00 Revert "Follow `Note [Exceptions in TH]` in `qReport` implementation" This reverts commit 95bf64567e373d9c3607c250469c171fdc876c7b. - - - - - c6c1dbae by Andrea Vezzosi at 2026-11-23T14:16:06+01:00 TH: force arguments of MetaHandlers up front Fixes #28112 - - - - - bad96e95 by Rodrigo Mesquita at 2026-11-23T17:27:00+00:00 Clean up GHCi.Message.Async lower-level interface - - - - - 8267a65b by Andrea Vezzosi at 2026-11-24T16:06:42+01:00 ghc-boot-th: avoid orphan NFData instances we define rnf<Foo> functions instead. Also, ghc-boot-th now exports forceMetaHandlersArgs instead of GHCi.TH. - - - - - 027084d2 by Rodrigo Mesquita at 2026-11-24T16:30:47+00:00 Global break action which uses a per-thread context map Previously, everytime an expression was run in the interpreter (`sandboxIO`): 1) the RTS global variable `rts_breakpoint_io_action`, which is run anytime any thread hits a breakpoint, got set to a new action that: a) Wrote the breakpoint hit by the thread to the `statusMVar` b) Blocked waiting on a newly created MVar `breakMVar` for a `resumeStmt` to signal it. 2) Start the expression evaluation on a new "sandbox" thread 3) Block waiting on `statusMVar` for a breakpoint to be hit, and we'd return the read `EvalBreak` 4) Set the `rts_breakpoint_io_action` to a no-op which prints "Ignored breakpoint..." At some later point, we could `resumeStmt` with the `EvalBreak` context by signaling the `breakMVar` on which the thread that hit the breakpoint is blocked. However, if you consider an expression which forks off threads which hit breakpoints, surprising things may happen: main = do -- the `worker` code has a breakpoint mapM (forkIO . worker) [1..10] forever $ threadDelay 10000000 Interpreting this program, we'll do (1,2,3), and all workers will hit their breakpoint and run `rts_breakpoint_io_action`. Here's a first issue: 1. The first worker succeeds in `putMVar statusMVar` 2. The interpreter will read `takeMVar statusMVar` (3) and then (4) 3. The remaining workers are hitting the breakpoint concurrently: - Some may block trying to `putMVar statusMVar` - Some may run the no-op action which discards the breakpoint Depending on whether the remaining workers hit the breakpoint or (4) happens first, some workers will skip their breakpoint. Now, let's pretend all workers can block on `putMVar statusMVar`. Since the interpreter will take the breakpoints one by one, and resume them one by one, it seemingly works. However, that's only fine when we assume only one expression is evaluated at once. As soon as multiple expressions can be evaluated at once (a desireable property of a debugger, as well as something that can already happen today in some scenarios (see `break049`)), it becomes madness: The second issue comes the global break action being swapped by a second evaluation and threads from the first evaluation running the "wrong" action. Consider: 1. eval `expr_A` installs a break action that puts on `statusMVar_A` 2. `expr_A` forks off a few threads, they're running in the background 3. eval `expr_B` sets the break action to put on `statusMVar_B` 4. the `expr_A` forked threads hit a breakpoint and put `statusMVar_B` 5. `expr_B` returns with a breakpoint of `expr_A`, `resume expr_B` would resume `expr_A`, etc... A third issue with having a single MVar for all threads of an execution is that there is no way to have fine-grained control over which threads are resumed and which are stopped. This is often necessary to debug multi-threaded programs too. Therefore, it is imperative that the global break action does not capture a global single MVar when many expressions with many corresponding threads can be running in the interpreter/debugger at once, if we want to support debugging multi-threaded programs at all. --- This commit fixes these foundational issues by making the global break action truly global (i.e. never modified and never capturing any locals). The global break action is installed once in `sandboxIO` and never removed (`withBreakAciton` and `noBreakAction` were killed). Subsequent runs of `sandboxIO` re-rewrite the same break action (a no-op). When any thread hits the global break action, it looks its `ThreadId` up in the global per-thread context mapping, returning a `ResumeContext` which contains that thread's `breakMVar` (now `resumeBreakVar`) and `statusMVar` (now `resumeEvalStatus`). Each thread blocks on its own MVar and replies on its own TVar. There is no longer one global status nor break MVar. To resume a thread by its `ThreadId`, we can simply fetch its `ResumeContext` and signal the corresponding `resumeBreakMVar` To wait for a result or for a breakpoint in a specific thread, we do `readThreadEvalStatus`. To wait for any breakpoint hit in any thread at all, we have `readAnyThreadEvalBreak`. Some evaluations will only care to look at their own result and breaks (so they run with `readAllBreaks` `= False`); and the main thread of an evaluation should not be read by other evaluations. In short, only threads forked off by the main thread of evaluations get read with `readAnyThreadEvalBreak`. If two evaluations fork off threads in the background, `readAnyThreadEvalBreak` may return threads from any of them. There is no just way to distinguish their "parents" at runtime. For instance, `compileParsedExprRemote` should run an expression until completion without any existing threads interfering with its execution, so it runs with `readAllBreaks = False`. Otherwise, by default, running `main` on the REPL, we'll want to stop at any break any forked thread hits, just like we did before. P.S. Currently, we need to keep track of the "main expression thread" being currently evaluated to fetch its result, but, when `evalStmt` becomes asynchronous by returning the `ThreadId` of the "sandbox" thread, the whole `evaluationMainThreadGlobalVar` hack can be deleted. --- New tests observing behavior that we don't want to break (which I broke at some point while developing this patch): - break032: we don't stop at breakpoints in TH - break033: :continue after -fbreak-on-exception doesn't hit exception breakpoint - break034: test :abandon doesn't hang with -fbreak-on-error - conc033: also run with the external interpreter - ForceInterrupt(Ext): ^C during :force interrupts the forced expression - break043: :continue of a forked thread reads main thread breaks/results too - break046: evaluating expr while stopped doesn't change what :continue resumes - break048: evaluating expr while forked thread is stopped doesn't hit again current breakpoint New tests that failed before this commit: - T3171(ext)nosandbox: T3171 with -fno-ghci-sandbox (T3171extnosandbox still fails) - break050(ext): ^C during :continue of a forked thread interrupts that thread Fixed ext-interp bc. resumeStmt now does unsafeUnmask, just like sandboxIO, so the UserInterrupt reaches the resume. - break049: breakpoints in forked threads don't get mixed up with other evaluations This test demonstrates one way multi-threaded debugging can go wrong bc the global break action used to capture a break MVar for a specific thread that is shared by all threads (described above as "the second issue"). Here is the annotated execution of the test *before this commit*: ```haskell ghci> main Stopped in Main.inMain, break049.hs:30:12-18 _result :: IO () = _ [break049.hs:30:12-18] ghci> :force slow -- ANN: the breakpoint we're ignoring on :force is the worker's -- breakpoint, and it's just discarded *** Ignoring breakpoint [break049.hs:27:14-20] slow = 5 [break049.hs:30:12-18] ghci> :cmd return "" -- ANN: we :continue `main`, but the worker should still be blocked -- so `main` should block. [break049.hs:30:12-18] ghci> :continue -- ANN: however, it completes; recall the worker break was ignored -- instead of stopping there main done -- ANN: after this commit, the worker break wouldn't have been read -- by `:force`, and we'd see it when resuming `:main`, and -- `:continue` here would resume the worker and only then main would -- complete. ghci> :continue -- ANN: bc this is ghci before the commit, we see: not stopped at a breakpoint ghci> ``` - break042: main forks workers and all workers hit a breakpoint This test witnesses "the first issue" described above, where the workers hit breaks after the global break action was already removed and so are lost. Fixes #28124 - - - - - 61f11e2f by Rodrigo Mesquita at 2026-11-24T16:30:47+00:00 disable breakpoints in forked threads to run TH in ext interp and other merge artifacts that do not come from conflict TODO: fix up to either the async rpc or to the global break changes, depending on who lands first the new tests pass; and we even observed that break032 fails without disableThreadBreakpoints - - - - - 91bb01a4 by Rodrigo Mesquita at 2026-11-26T16:04:36+00:00 WIP: Start Async Eval/Resume - - - - - 109 changed files: - + changelog.d/28124 - compiler/GHC/Driver/Config.hs - compiler/GHC/Linker/Loader.hs - compiler/GHC/Runtime/Context.hs - compiler/GHC/Runtime/Eval.hs - compiler/GHC/Runtime/Eval/Types.hs - compiler/GHC/Runtime/Interpreter.hs - compiler/GHC/Runtime/Interpreter/Process.hs - compiler/GHC/Tc/Errors/Types.hs - compiler/GHC/Tc/Gen/Splice.hs - ghc/GHCi/UI/Monad.hs - libraries/ghc-boot-th/GHC/Boot/TH/Monad.hs - libraries/ghc-boot-th/GHC/Boot/TH/Syntax.hs - libraries/ghc-boot-th/ghc-boot-th.cabal.in - libraries/ghc-internal/src/GHC/Internal/TH/Monad.hs - libraries/ghci/GHCi/Message.hs - libraries/ghci/GHCi/Message/Async.hs - libraries/ghci/GHCi/Run.hs - + libraries/ghci/GHCi/Run/Breakpoints.hs - libraries/ghci/GHCi/Server.hs - libraries/ghci/GHCi/Signals.hs - libraries/ghci/GHCi/TH.hs - libraries/ghci/ghci.cabal.in - libraries/template-haskell/Language/Haskell/TH/Syntax.hs - libraries/template-haskell/template-haskell.cabal.in - rts/Interpreter.c - testsuite/tests/concurrent/should_run/all.T - testsuite/tests/ghci.debugger/scripts/Makefile - testsuite/tests/ghci.debugger/scripts/T14690.stdout - testsuite/tests/ghci.debugger/scripts/all.T - testsuite/tests/ghci.debugger/scripts/break024.stdout - + testsuite/tests/ghci.debugger/scripts/break032.hs - + testsuite/tests/ghci.debugger/scripts/break032.script - + testsuite/tests/ghci.debugger/scripts/break032.stdout - + testsuite/tests/ghci.debugger/scripts/break033.hs - + testsuite/tests/ghci.debugger/scripts/break033.script - + testsuite/tests/ghci.debugger/scripts/break033.stdout - + testsuite/tests/ghci.debugger/scripts/break034.hs - + testsuite/tests/ghci.debugger/scripts/break034.script - + testsuite/tests/ghci.debugger/scripts/break034.stdout - + testsuite/tests/ghci.debugger/scripts/break042.hs - + testsuite/tests/ghci.debugger/scripts/break042.script - + testsuite/tests/ghci.debugger/scripts/break042.stderr - + testsuite/tests/ghci.debugger/scripts/break042.stdout - + testsuite/tests/ghci.debugger/scripts/break043.hs - + testsuite/tests/ghci.debugger/scripts/break043.script - + testsuite/tests/ghci.debugger/scripts/break043.stdout - + testsuite/tests/ghci.debugger/scripts/break046.hs - + testsuite/tests/ghci.debugger/scripts/break046.script - + testsuite/tests/ghci.debugger/scripts/break046.stdout - + testsuite/tests/ghci.debugger/scripts/break048.hs - + testsuite/tests/ghci.debugger/scripts/break048.script - + testsuite/tests/ghci.debugger/scripts/break048.stdout - + testsuite/tests/ghci.debugger/scripts/break049.hs - + testsuite/tests/ghci.debugger/scripts/break049.script - + testsuite/tests/ghci.debugger/scripts/break049.stdout - + testsuite/tests/ghci.debugger/scripts/break050.hs - + testsuite/tests/ghci.debugger/scripts/break050.script - + testsuite/tests/ghci.debugger/scripts/break050.stdout - + testsuite/tests/ghci.debugger/scripts/break050ext.stdout - + testsuite/tests/ghci/linking/UnloadWkrA.hs - + testsuite/tests/ghci/linking/UnloadWkrB.hs - testsuite/tests/ghci/linking/all.T - + testsuite/tests/ghci/linking/unload_wkr-throw-ext.stderr - + testsuite/tests/ghci/linking/unload_wkr-throw-ext.stdout - + testsuite/tests/ghci/linking/unload_wkr-throw.script - + testsuite/tests/ghci/linking/unload_wkr-throw.stderr - + testsuite/tests/ghci/linking/unload_wkr-throw.stdout - + testsuite/tests/ghci/should_run/ForceInterrupt.script - + testsuite/tests/ghci/should_run/ForceInterrupt.stdout - + testsuite/tests/ghci/should_run/ForceInterruptExt.stdout - testsuite/tests/ghci/should_run/Makefile - + testsuite/tests/ghci/should_run/T3171extnosandbox.stdout - + testsuite/tests/ghci/should_run/T3171nosandbox.stdout - testsuite/tests/ghci/should_run/all.T - testsuite/tests/interface-stability/template-haskell-exports.stdout - testsuite/tests/plugins/plugins10.stdout - testsuite/tests/th/T8987d.hs - + testsuite/tests/th/T8987d14.stderr - + testsuite/tests/th/T8987d15.stderr - + testsuite/tests/th/T8987d16.stderr - + testsuite/tests/th/T8987d17.stderr - + testsuite/tests/th/T8987d18.stderr - + testsuite/tests/th/T8987d19.stderr - + testsuite/tests/th/T8987d20.stderr - + testsuite/tests/th/T8987d21.stderr - + testsuite/tests/th/T8987d22.stderr - + testsuite/tests/th/T8987d23.stderr - + testsuite/tests/th/T8987d24.stderr - + testsuite/tests/th/T8987d25.stderr - + testsuite/tests/th/T8987d26.stderr - + testsuite/tests/th/T8987d27.stderr - + testsuite/tests/th/T8987d28.stderr - + testsuite/tests/th/T8987d29.stderr - + testsuite/tests/th/T8987d30.stderr - + testsuite/tests/th/T8987d31.stderr - + testsuite/tests/th/T8987d32.stderr - + testsuite/tests/th/T8987d33.stderr - + testsuite/tests/th/T8987d34.stderr - + testsuite/tests/th/T8987d35.stderr - + testsuite/tests/th/T8987d36.stderr - + testsuite/tests/th/T8987d37.stderr - + testsuite/tests/th/T8987d38.stderr - + testsuite/tests/th/T8987d39.stderr - + testsuite/tests/th/T8987d40.stderr - + testsuite/tests/th/T8987d41.stderr - + testsuite/tests/th/T8987d42.stderr - + testsuite/tests/th/T8987d43.stderr - testsuite/tests/th/all.T The diff was not included because it is too large. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/0901ae77c768d2477ac84ffae369809... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/0901ae77c768d2477ac84ffae369809... You're receiving this email because of your account on gitlab.haskell.org. Manage all notifications: https://gitlab.haskell.org/-/profile/notifications | Help: https://gitlab.haskell.org/help
participants (1)
-
Rodrigo Mesquita (@alt-romes)