GHC 9.3 API panics with "No home unit"; need advice on what next

All, I tried Alfredo's suggestion of building with the stage1 compiler. (Sticking with the bootstrap compiler for HLS support, which seems to be working OK.) I've gotten a bit further. I have a small app that loads .hs files, translates to STG, and dumps the results. It also dumps the `ModSummary` for each module in the graph. The code worked in the 9.0 API, but using the 9.3 API causes a panic: nr@homedog ~/a/sandbox> cabal v1-build Resolving dependencies... Configuring sandbox-0.1.0.0... Preprocessing executable 'sandbox' for sandbox-0.1.0.0.. Building executable 'sandbox' for sandbox-0.1.0.0.. [1 of 1] Compiling Main ( app/Main.hs, dist/build/sandbox/sandbox-tmp/Main.o ) [Source file changed] Linking dist/build/sandbox/sandbox ... nr@homedog ~/a/sandbox> ./dist/build/sandbox/sandbox programs/Church.hs libdir == /home/nr/asterius/ghc/_build/stage1/lib ModSummary { ms_hs_hash = 8ed607a72dd3968f1e65123b865b8572 ms_mod = Church, ms_textual_imps = [(Nothing, Prelude)] ms_srcimps = [] } .............. sandbox: panic! (the 'impossible' happened) GHC version 9.3.20210918: unsafeGetHomeUnit: No home unit Please report this as a GHC bug: https://www.haskell.org/ghc/reportabug I poked around, but I expected the home unit to be set by `setSessionDynFlags`, and I don't know why it isn't. Everything needed to reproduce the problem can be found (I hope!) at https://github.com/nrnrnr/ghc-api-sandbox I'm a bit reluctant to simply report a bug as I'm afraid I might be doing something wacky. What should I look at next? Norman

Followup: I managed to get things configured to work with `cabal v2-build`, and with this build, the app dumps STG code as expected. I am unblocked! Norman
nr@homedog ~/a/sandbox> cabal v1-build Resolving dependencies... Configuring sandbox-0.1.0.0... Preprocessing executable 'sandbox' for sandbox-0.1.0.0.. Building executable 'sandbox' for sandbox-0.1.0.0.. [1 of 1] Compiling Main ( app/Main.hs, dist/build/sandbox/sandbox-tmp/Main.o ) [Source file changed] Linking dist/build/sandbox/sandbox ... nr@homedog ~/a/sandbox> ./dist/build/sandbox/sandbox programs/Church.hs libdir == /home/nr/asterius/ghc/_build/stage1/lib ModSummary { ms_hs_hash = 8ed607a72dd3968f1e65123b865b8572 ms_mod = Church, ms_textual_imps = [(Nothing, Prelude)] ms_srcimps = [] } .............. sandbox: panic! (the 'impossible' happened) GHC version 9.3.20210918: unsafeGetHomeUnit: No home unit
Please report this as a GHC bug: https://www.haskell.org/ghc/reportabug

The code worked in the 9.0 API, but using the 9.3 API causes a panic:
sandbox: panic! (the 'impossible' happened) GHC version 9.3.20210918: unsafeGetHomeUnit: No home unit
SOLVED: I was getting an `HscEnv` by using `newHscEnv` with a `DynFlags`. Turns out I'm not supposed to do that; using `getSession` instead solved the problem. Thanks to Cheng Shao for the diagnosis! If there is something I can read to help me avoid similar mistakes in the future, please point me in its direction! Norman

Norman,
I'm glad you are unstuck.
We badly need a bird's eye view of the GHC API, with chapters about specific bits. It shouldn't be a question of trial an error. But it evolved rather than being designed, and since then everyone's shortest path to completion is simply to find a way through and execute on it.
If you felt able to write down what you have learned, we could make it part of GHC's user manual, and improve it incrementally. I know that's not on your shortest path to completion either, but you have particularly superior writing skills, and I think you might find that others join in if you took the lead.
Also then you could say "but why do you need to do getSession not newHscEnv, and we might be able to fill in some of the rationale rather than just write down cookbook recipes. And it might lead to design changes too, I hope.
Posting here in the hope that others say "oh yes, I'd love to help with that"!
Simon
PS: I am leaving Microsoft at the end of November 2021, at which point simonpj@microsoft.com will cease to work. Use simon.peytonjones@gmail.com instead. (For now, it just forwards to simonpj@microsoft.com.)
| -----Original Message-----
| From: ghc-devs
participants (2)
-
Norman Ramsey
-
Simon Peyton Jones