Modifications to support loading GHC into GHCi
ClosedPublic

Authored by mgsloan on Jul 19 2018, 12:20 AM.

Details

Summary

This change was previously part of D4904,
but is being split off to aid in getting this reviewed and merged.

  • The compiler code is built with NoImplicitPrelude, but GHCi's modules are incompatible with it. So, this adds the pragma to all GHCi modules that didn't have it, and adds imports of Prelude.
  • In order to run GHC within itself, a call of 'initGCStatistics needed to be skipped. This uses CPP to skip it when -DGHC_LOADED_INTO_GHCI is set.
  • There is an environment variable workaround suggested by Ben Gamari [1], where _GHC_TOP_DIR can be used to specify GHC's top dir if -B isn't provided. This can be used to solve a problem where the GHC being run within GHCi attempts to look in inplace/lib/lib/ instead of inplace/lib/.

[1]: https://phabricator.haskell.org/D4904#135438

Diff Detail

Repository
rGHC Glasgow Haskell Compiler
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
mgsloan created this revision.Jul 19 2018, 12:20 AM
mgsloan updated this revision to Diff 17387.Jul 19 2018, 12:38 AM

Remove unnecessary change to System.Directory import in SysTools.BaseDir

lelf added a subscriber: lelf.Jul 21 2018, 12:07 PM

@bgamari @alpmestan Please let me know if there is anything I can do to help get this merged!

Maybe I'm not seeing it because I'm tired, but how come you needed to add all those NoImplicitPreludes and import Preludes ?

mgsloan updated this revision to Diff 17448.Jul 25 2018, 3:29 AM

Add default-extensions: NoImplicitPrelude to some cabal files, remove use of pragmas

Maybe I'm not seeing it because I'm tired, but how come you needed to add all those NoImplicitPreludes and import Preludes ?

Most ghc code is built with -XNoImplicitPrelude, indeed, it's the only extension set in the script in D4904. However, beyond just loading the GHC library into GHCi, I also want to run the GHC program within GHCi, which means loading ghc/Main.hs.

It *is* weird to add {-# LANGUAGE NoImplicitPrelude #-}. My reasoning was that this would make it less likely that people that don't use GHCi would remove the import Prelude. I should have poked around the build system more, though - I didn't realize there were cabal files! So, instead now this adds NoImplicitPrelude as a default extension to ghc-bin.cabal and template-haskell.cabal

How's that look?

alpmestan requested changes to this revision.Jul 25 2018, 4:10 AM

Looks great, except for the typos in the extension's name =)

I'm not sure I understand why the import Prelude were needed, especially in modules that are otherwise not changing with this patch, since this is in theory just a matter of setting the right options/extensions to mimic what's done when we actually build GHC. But let's perhaps not make that hold the patch back. Once the typo is fixed I think we can merge this.

ghc/ghc-bin.cabal.in
91

Typo in the extension name

libraries/template-haskell/template-haskell.cabal
67

Typo in the extension name.

This revision now requires changes to proceed.Jul 25 2018, 4:10 AM

Ah good catch! That's what I get for only testing this in ghci ;)

One way to look at why this is necessary, is that we are effectively loading multiple cabal packages into ghci, and https://ghc.haskell.org/trac/ghc/ticket/10827 is not yet implemented.

mgsloan updated this revision to Diff 17449.Jul 25 2018, 4:15 AM

Update spelling of NoImplicitPrelude

I believe that should fix it, though I must admit I haven't run it through a full make yet. Perhaps I can leave that up to harbormaster? Not familiar with whether I can rely on CI or not.

alpmestan requested changes to this revision.Jul 25 2018, 4:19 AM

One last typo and we're good. OK for the Prelude imports, I see the reasoning.

ghc/ghc-bin.cabal.in
91

I'm really sorry, but there still is a typo, we want NoImplicitPrelude. =)

This revision now requires changes to proceed.Jul 25 2018, 4:19 AM

And CI will indeed tell us whether a full make succeeds.

mgsloan updated this revision to Diff 17450.Jul 25 2018, 4:21 AM

Fix another 2 AM typo...

Lol.. That's what I get for trying to do too many things at once late at night.

This is why I like static checking so much. Especially rapid feedback static checking. make takes too long for me, hence my enthusiasm for a ghci based workflow

alpmestan accepted this revision.Jul 26 2018, 4:04 AM
This revision is now accepted and ready to land.Jul 26 2018, 4:04 AM
This revision was automatically updated to reflect the committed changes.

Woohoo!! Thanks for merging, @bgamari!