Running GHC in GHCi
Hi all, Today I verified that with Luite's recent work on the interpreter it is now possible to run GHC entirely within GHCi (when bootstrapping from GHC 9.2). Behold: ``` $ # First we must remove -fno-code from hadrian/ghci $ git apply <<EOF diff --git a/hadrian/ghci-cabal.in b/hadrian/ghci-cabal.in index 2a97b371802..f96919d91e1 100755 --- a/hadrian/ghci-cabal.in +++ b/hadrian/ghci-cabal.in @@ -6,4 +6,4 @@ set -e # Replace newlines with spaces, as these otherwise break the ghci invocation on windows. GHC_FLAGS="$GHC_FLAGS $(TERM=dumb CABFLAGS=-v0 "hadrian/build-cabal" tool:ghc/Main.hs -q --build-root=.hadrian_ghci --flavour=ghc-in-ghci $HADRIAN_ARGS | tr '\n\r' ' ')" -@WithGhc@ --interactive $GHC_FLAGS $@ -fno-code -fwrite-interface -hidir=.hadrian_ghci/interface -O0 +RTS -A128m +@WithGhc@ --interactive $GHC_FLAGS $@ -fwrite-interface -hidir=.hadrian_ghci/interface -O0 +RTS -A128m $ ./boot $ ./configure GHC=ghc-9.2 . . . $ hadrian/ghci GHCi, version 9.2.1: https://www.haskell.org/ghc/ :? for help [ 1 of 668] Compiling GHC.Iface.Type[boot] ( /opt/exp/ghc/ghc-landing/compiler/GHC/Iface/Type.hs-boot, interpreted ) [ 2 of 668] Compiling GHC.Platform.Constants ( /opt/exp/ghc/ghc-landing/.hadrian_ghci/stage0/compiler/build/GHC/Platform/Constants.hs, interpreted ) . . . [668 of 668] Compiling Main ( ghc/Main.hs, interpreted ) Ok, 668 modules loaded. λ> import Main λ> :set args -B/opt/exp/ghc/ghc-landing/_build/stage1/lib --version λ> :trace main The Glorious Glasgow Haskell Compilation System, version 9.3.20211027 λ> :set args -B/opt/exp/ghc/ghc-landing/_build/stage1/lib HelloWorld.hs λ> main [1 of 1] Compiling Main ( HelloWorld.hs, HelloWorld.o ) Linking HelloWorld ... λ> :! ./HelloWorld "Hello World!" ``` Surprisingly, performance isn't even horrible, taking only a few seconds to compile "hello world". Sadly, `:trace` doesn't quite work yet on `main`: ``` λ> :trace main *** Exception: ModBreaks.modBreaks_array not initialised CallStack (from HasCallStack): error, called at compiler/GHC/ByteCode/Types.hs:231:24 in ghc:GHC.ByteCode.Types ``` I've opened #20570 to track this issue. Fixing it would allow breakpoints and the like to be used on GHC. Anyways, I found this quite exciting. Perhaps this will spur more contributors to take an interest in GHCi. Cheers, - Ben
Ben Gamari <ben@well-typed.com> writes:
Hi all,
Today I verified that with Luite's recent work on the interpreter it is now possible to run GHC entirely within GHCi (when bootstrapping from GHC 9.2).
...
I have fixed the break-array issue noted in the above message in !6848. It is now possible to use `:trace` on GHC itself: $ hadrian/ghci GHCi, version 9.2.1: https://www.haskell.org/ghc/ :? for help . . . λ> import Main λ> :set args -B/opt/exp/ghc/ghc-landing/_build/stage1/lib Hi.hs -v3 -fforce-recomp λ> :set -fbreak-on-error λ> :trace main Glasgow Haskell Compiler, Version 9.3.20211027, stage 1 booted by GHC version 9.2.1 ^CStopped in <exception thrown>, <unknown> _exception :: e = _ [<unknown>] λ> :hist -1 : fromException (/opt/exp/ghc/ghc-landing/compiler/GHC/Utils/Panic.hs:114:19-24) -2 : uniq (/opt/exp/ghc/ghc-landing/compiler/GHC/Data/FastString.hs:205:7-10) -3 : moduleNameFS (/opt/exp/ghc/ghc-landing/compiler/GHC/Unit/Module/Name.hs:72:33-35) -4 : stableModuleNameCmp (/opt/exp/ghc/ghc-landing/compiler/GHC/Unit/Module/Name.hs:62:64-78) -5 : lexicalCompareFS (/opt/exp/ghc/ghc-landing/compiler/GHC/Data/FastString.hs:252:18-25) -6 : uniq (/opt/exp/ghc/ghc-landing/compiler/GHC/Data/FastString.hs:205:7-10) -7 : moduleNameFS (/opt/exp/ghc/ghc-landing/compiler/GHC/Unit/Module/Name.hs:72:33-35) -8 : stableModuleNameCmp (/opt/exp/ghc/ghc-landing/compiler/GHC/Unit/Module/Name.hs:62:29-43) -9 : lexicalCompareFS (/opt/exp/ghc/ghc-landing/compiler/GHC/Data/FastString.hs:252:6-13) -10 : lexicalCompareFS (/opt/exp/ghc/ghc-landing/compiler/GHC/Data/FastString.hs:252:6-25) -11 : lexicalCompareFS (/opt/exp/ghc/ghc-landing/compiler/GHC/Data/FastString.hs:(252,3)-(253,54)) -12 : stableModuleNameCmp (/opt/exp/ghc/ghc-landing/compiler/GHC/Unit/Module/Name.hs:62:29-78) -13 : compare (/opt/exp/ghc/ghc-landing/compiler/GHC/Unit/Module/Name.hs:42:23-49) -14 : fs_sbs (/opt/exp/ghc/ghc-landing/compiler/GHC/Data/FastString.hs:207:7-12) -15 : lexicalCompareFS (/opt/exp/ghc/ghc-landing/compiler/GHC/Data/FastString.hs:253:44-53) -16 : fs_sbs (/opt/exp/ghc/ghc-landing/compiler/GHC/Data/FastString.hs:207:7-12) -17 : lexicalCompareFS (/opt/exp/ghc/ghc-landing/compiler/GHC/Data/FastString.hs:253:31-40) -18 : lexicalCompareFS (/opt/exp/ghc/ghc-landing/compiler/GHC/Data/FastString.hs:253:3-54) -19 : uniq (/opt/exp/ghc/ghc-landing/compiler/GHC/Data/FastString.hs:205:7-10) -20 : moduleNameFS (/opt/exp/ghc/ghc-landing/compiler/GHC/Unit/Module/Name.hs:72:33-35) ... [<unknown>] λ> :back Logged breakpoint at /opt/exp/ghc/ghc-landing/compiler/GHC/Utils/Panic.hs:114:19-24 _result :: Maybe GHC.Utils.Panic.Plain.PlainGhcException e :: SomeAsyncException [-1: /opt/exp/ghc/ghc-landing/compiler/GHC/Utils/Panic.hs:114:19-24] λ> :back Logged breakpoint at /opt/exp/ghc/ghc-landing/compiler/GHC/Data/FastString.hs:205:7-10 _result :: Int uniq :: Int [-2: /opt/exp/ghc/ghc-landing/compiler/GHC/Data/FastString.hs:205:7-10] λ> uniq 603980920 [-2: /opt/exp/ghc/ghc-landing/compiler/GHC/Data/FastString.hs:205:7-10] λ> :back Logged breakpoint at /opt/exp/ghc/ghc-landing/compiler/GHC/Unit/Module/Name.hs:72:33-35 _result :: ModuleName mod :: ModuleName [-3: /opt/exp/ghc/ghc-landing/compiler/GHC/Unit/Module/Name.hs:72:33-35] λ> mod ModuleName "GHC.Tc.Solver.Canonical" et cetera
That's very exciting! On Thu, 28 Oct 2021, 3.08 Ben Gamari, <ben@well-typed.com> wrote:
Ben Gamari <ben@well-typed.com> writes:
Hi all,
Today I verified that with Luite's recent work on the interpreter it is now possible to run GHC entirely within GHCi (when bootstrapping from GHC 9.2).
...
I have fixed the break-array issue noted in the above message in !6848. It is now possible to use `:trace` on GHC itself:
$ hadrian/ghci GHCi, version 9.2.1: https://www.haskell.org/ghc/ :? for help . . . λ> import Main λ> :set args -B/opt/exp/ghc/ghc-landing/_build/stage1/lib Hi.hs -v3 -fforce-recomp λ> :set -fbreak-on-error λ> :trace main Glasgow Haskell Compiler, Version 9.3.20211027, stage 1 booted by GHC version 9.2.1 ^CStopped in <exception thrown>, <unknown> _exception :: e = _ [<unknown>] λ> :hist -1 : fromException (/opt/exp/ghc/ghc-landing/compiler/GHC/Utils/Panic.hs:114:19-24) -2 : uniq (/opt/exp/ghc/ghc-landing/compiler/GHC/Data/FastString.hs:205:7-10) -3 : moduleNameFS (/opt/exp/ghc/ghc-landing/compiler/GHC/Unit/Module/Name.hs:72:33-35) -4 : stableModuleNameCmp (/opt/exp/ghc/ghc-landing/compiler/GHC/Unit/Module/Name.hs:62:64-78) -5 : lexicalCompareFS (/opt/exp/ghc/ghc-landing/compiler/GHC/Data/FastString.hs:252:18-25) -6 : uniq (/opt/exp/ghc/ghc-landing/compiler/GHC/Data/FastString.hs:205:7-10) -7 : moduleNameFS (/opt/exp/ghc/ghc-landing/compiler/GHC/Unit/Module/Name.hs:72:33-35) -8 : stableModuleNameCmp (/opt/exp/ghc/ghc-landing/compiler/GHC/Unit/Module/Name.hs:62:29-43) -9 : lexicalCompareFS (/opt/exp/ghc/ghc-landing/compiler/GHC/Data/FastString.hs:252:6-13) -10 : lexicalCompareFS (/opt/exp/ghc/ghc-landing/compiler/GHC/Data/FastString.hs:252:6-25) -11 : lexicalCompareFS (/opt/exp/ghc/ghc-landing/compiler/GHC/Data/FastString.hs:(252,3)-(253,54)) -12 : stableModuleNameCmp (/opt/exp/ghc/ghc-landing/compiler/GHC/Unit/Module/Name.hs:62:29-78) -13 : compare (/opt/exp/ghc/ghc-landing/compiler/GHC/Unit/Module/Name.hs:42:23-49) -14 : fs_sbs (/opt/exp/ghc/ghc-landing/compiler/GHC/Data/FastString.hs:207:7-12) -15 : lexicalCompareFS (/opt/exp/ghc/ghc-landing/compiler/GHC/Data/FastString.hs:253:44-53) -16 : fs_sbs (/opt/exp/ghc/ghc-landing/compiler/GHC/Data/FastString.hs:207:7-12) -17 : lexicalCompareFS (/opt/exp/ghc/ghc-landing/compiler/GHC/Data/FastString.hs:253:31-40) -18 : lexicalCompareFS (/opt/exp/ghc/ghc-landing/compiler/GHC/Data/FastString.hs:253:3-54) -19 : uniq (/opt/exp/ghc/ghc-landing/compiler/GHC/Data/FastString.hs:205:7-10) -20 : moduleNameFS (/opt/exp/ghc/ghc-landing/compiler/GHC/Unit/Module/Name.hs:72:33-35) ... [<unknown>] λ> :back Logged breakpoint at /opt/exp/ghc/ghc-landing/compiler/GHC/Utils/Panic.hs:114:19-24 _result :: Maybe GHC.Utils.Panic.Plain.PlainGhcException e :: SomeAsyncException [-1: /opt/exp/ghc/ghc-landing/compiler/GHC/Utils/Panic.hs:114:19-24] λ> :back Logged breakpoint at /opt/exp/ghc/ghc-landing/compiler/GHC/Data/FastString.hs:205:7-10 _result :: Int uniq :: Int [-2: /opt/exp/ghc/ghc-landing/compiler/GHC/Data/FastString.hs:205:7-10] λ> uniq 603980920 [-2: /opt/exp/ghc/ghc-landing/compiler/GHC/Data/FastString.hs:205:7-10] λ> :back Logged breakpoint at /opt/exp/ghc/ghc-landing/compiler/GHC/Unit/Module/Name.hs:72:33-35 _result :: ModuleName mod :: ModuleName [-3: /opt/exp/ghc/ghc-landing/compiler/GHC/Unit/Module/Name.hs:72:33-35] λ> mod ModuleName "GHC.Tc.Solver.Canonical"
et cetera _______________________________________________ ghc-devs mailing list ghc-devs@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs
Looks good Ben. Would it be good to add a target to hadrian which builds just the right dependencies for this to work? and then deals with setting options such as -B as well. Matt On Thu, Oct 28, 2021 at 5:26 AM Bryan Richter <b@chreekat.net> wrote:
That's very exciting!
On Thu, 28 Oct 2021, 3.08 Ben Gamari, <ben@well-typed.com> wrote:
Ben Gamari <ben@well-typed.com> writes:
Hi all,
Today I verified that with Luite's recent work on the interpreter it is now possible to run GHC entirely within GHCi (when bootstrapping from GHC 9.2).
...
I have fixed the break-array issue noted in the above message in !6848. It is now possible to use `:trace` on GHC itself:
$ hadrian/ghci GHCi, version 9.2.1: https://www.haskell.org/ghc/ :? for help . . . λ> import Main λ> :set args -B/opt/exp/ghc/ghc-landing/_build/stage1/lib Hi.hs -v3 -fforce-recomp λ> :set -fbreak-on-error λ> :trace main Glasgow Haskell Compiler, Version 9.3.20211027, stage 1 booted by GHC version 9.2.1 ^CStopped in <exception thrown>, <unknown> _exception :: e = _ [<unknown>] λ> :hist -1 : fromException (/opt/exp/ghc/ghc-landing/compiler/GHC/Utils/Panic.hs:114:19-24) -2 : uniq (/opt/exp/ghc/ghc-landing/compiler/GHC/Data/FastString.hs:205:7-10) -3 : moduleNameFS (/opt/exp/ghc/ghc-landing/compiler/GHC/Unit/Module/Name.hs:72:33-35) -4 : stableModuleNameCmp (/opt/exp/ghc/ghc-landing/compiler/GHC/Unit/Module/Name.hs:62:64-78) -5 : lexicalCompareFS (/opt/exp/ghc/ghc-landing/compiler/GHC/Data/FastString.hs:252:18-25) -6 : uniq (/opt/exp/ghc/ghc-landing/compiler/GHC/Data/FastString.hs:205:7-10) -7 : moduleNameFS (/opt/exp/ghc/ghc-landing/compiler/GHC/Unit/Module/Name.hs:72:33-35) -8 : stableModuleNameCmp (/opt/exp/ghc/ghc-landing/compiler/GHC/Unit/Module/Name.hs:62:29-43) -9 : lexicalCompareFS (/opt/exp/ghc/ghc-landing/compiler/GHC/Data/FastString.hs:252:6-13) -10 : lexicalCompareFS (/opt/exp/ghc/ghc-landing/compiler/GHC/Data/FastString.hs:252:6-25) -11 : lexicalCompareFS (/opt/exp/ghc/ghc-landing/compiler/GHC/Data/FastString.hs:(252,3)-(253,54)) -12 : stableModuleNameCmp (/opt/exp/ghc/ghc-landing/compiler/GHC/Unit/Module/Name.hs:62:29-78) -13 : compare (/opt/exp/ghc/ghc-landing/compiler/GHC/Unit/Module/Name.hs:42:23-49) -14 : fs_sbs (/opt/exp/ghc/ghc-landing/compiler/GHC/Data/FastString.hs:207:7-12) -15 : lexicalCompareFS (/opt/exp/ghc/ghc-landing/compiler/GHC/Data/FastString.hs:253:44-53) -16 : fs_sbs (/opt/exp/ghc/ghc-landing/compiler/GHC/Data/FastString.hs:207:7-12) -17 : lexicalCompareFS (/opt/exp/ghc/ghc-landing/compiler/GHC/Data/FastString.hs:253:31-40) -18 : lexicalCompareFS (/opt/exp/ghc/ghc-landing/compiler/GHC/Data/FastString.hs:253:3-54) -19 : uniq (/opt/exp/ghc/ghc-landing/compiler/GHC/Data/FastString.hs:205:7-10) -20 : moduleNameFS (/opt/exp/ghc/ghc-landing/compiler/GHC/Unit/Module/Name.hs:72:33-35) ... [<unknown>] λ> :back Logged breakpoint at /opt/exp/ghc/ghc-landing/compiler/GHC/Utils/Panic.hs:114:19-24 _result :: Maybe GHC.Utils.Panic.Plain.PlainGhcException e :: SomeAsyncException [-1: /opt/exp/ghc/ghc-landing/compiler/GHC/Utils/Panic.hs:114:19-24] λ> :back Logged breakpoint at /opt/exp/ghc/ghc-landing/compiler/GHC/Data/FastString.hs:205:7-10 _result :: Int uniq :: Int [-2: /opt/exp/ghc/ghc-landing/compiler/GHC/Data/FastString.hs:205:7-10] λ> uniq 603980920 [-2: /opt/exp/ghc/ghc-landing/compiler/GHC/Data/FastString.hs:205:7-10] λ> :back Logged breakpoint at /opt/exp/ghc/ghc-landing/compiler/GHC/Unit/Module/Name.hs:72:33-35 _result :: ModuleName mod :: ModuleName [-3: /opt/exp/ghc/ghc-landing/compiler/GHC/Unit/Module/Name.hs:72:33-35] λ> mod ModuleName "GHC.Tc.Solver.Canonical"
et cetera _______________________________________________ ghc-devs mailing list ghc-devs@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs
_______________________________________________ ghc-devs mailing list ghc-devs@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs
participants (3)
-
Ben Gamari -
Bryan Richter -
Matthew Pickering