Skip to content

Global GHCi configuration interfers with `hadrian/ghci` loading.

This ticket is related to this MR: !4093 (closed)

Context

While trying to load GHC in GHCi, many compilation errors appeared (see compilation logs below). At first I did not understand where they were coming from, but as @RyanGlScott, they were arising from the fact that my personal ~/.ghci configuration file had enabled a couple of extensions in order to create GHCi macros.

~/.ghci
import Data.List (concat)

import GHC.Base ((.), ($), return, (==))

import Data.Monoid ((<>))

import Data.Foldable (concatMap)

import Data.Text (Text)
import qualified Data.Text as Text

:set -XTemplateHaskell
:set -XOverloadedStrings

-- Surround a string in single quotes.
let single_quote s = concat ["'", s, "'"]
 
-- Escape a single quote in the shell. (This mess actually works.)
let escape_single_quote c = if c == '\'' then "'\"'\"'" else [c]
 
-- Simple heuristic to escape shell command arguments.
let simple_shell_escape = single_quote . (concatMap escape_single_quote)

:def hoogle \x -> return $ ":!hoogle --color " <> (simple_shell_escape x)
:def doc \x -> return $ ":!hoogle --info --color " <> (simple_shell_escape x)
:def pf \x -> return $ "!pointfree" <> (simple_shell_escape x)
:set prompt "\ESC[36m\STXλ❯ \ESC[m\STX"

:set +s
:set +t
:set -freverse-errors
compilation logs
/home/hecate/Contrib/GHC/ghc/compiler/GHC/Utils/Misc.hs:1221:22: error:
     Could not deduce (Foldable t0) arising from a use of elem
      from the context: MonadFail m
        bound by the inferred type of
                   readExp :: MonadFail m => [Char] -> m (Int, [Char])
        at /home/hecate/Contrib/GHC/ghc/compiler/GHC/Utils/Misc.hs:(1221,6)-(1222,49)
      The type variable t0 is ambiguous
      These potential instances exist:
        instance Foldable (Either a) -- Defined in ‘Data.Foldable’
        instance Foldable Down -- Defined in ‘Data.Foldable’
        instance Foldable Proxy -- Defined in ‘Data.Foldable’
        ...plus six others
        ...plus 46 instances involving out-of-scope types
        (use -fprint-potential-instances to see them all)
     In the expression: e `elem` "eE"
      In a stmt of a pattern guard for
                     an equation for readExp:
        e `elem` "eE"
      In an equation for readExp:
          readExp (e : s) | e `elem` "eE" = readExp' s
     |
1221 |      readExp (e:s) | e `elem` "eE" = readExp' s
     |                      ^^^^^^^^^^^^^


/home/hecate/Contrib/GHC/ghc/compiler/GHC/Unit/Module/Name.hs:97:55: error:
     Ambiguous type variable t0 arising from a use of elem
      prevents the constraint (Foldable t0) from being solved.
      Probable fix: use a type annotation to specify what t0 should be.
      These potential instances exist:
        instance Foldable (Either a) -- Defined in ‘Data.Foldable’
        instance Foldable Maybe -- Defined in ‘Data.Foldable’
        instance Foldable ((,) a) -- Defined in ‘Data.Foldable’
        ...plus one other
        ...plus 57 instances involving out-of-scope types
        (use -fprint-potential-instances to see them all)
     In the second argument of (||), namely c `elem` "_."
      In the expression: isAlphaNum c || c `elem` "_."
      In the first argument of Parse.munch1, namely
        (\ c -> isAlphaNum c || c `elem` "_.")
   |
97 |                 $ Parse.munch1 (\c -> isAlphaNum c || c `elem` "_.")
   |                                                       ^^^^^^^^^^^^^


/home/hecate/Contrib/GHC/ghc/compiler/GHC/Unit/Parser.hs:33:45: error:
     Ambiguous type variable t0 arising from a use of elem
      prevents the constraint (Foldable t0) from being solved.
      Probable fix: use a type annotation to specify what t0 should be.
      These potential instances exist:
        instance Foldable (Either a) -- Defined in ‘Data.Foldable’
        instance Foldable GenWithIsBoot
          -- Defined at /home/hecate/Contrib/GHC/ghc/compiler/GHC/Unit/Types.hs:661:25
        instance Foldable Maybe -- Defined in ‘Data.Foldable’
        ...plus two others
        ...plus 58 instances involving out-of-scope types
        (use -fprint-potential-instances to see them all)
     In the second argument of (||), namely c `elem` "-_.+"
      In the expression: isAlphaNum c || c `elem` "-_.+"
      In the first argument of Parse.munch1, namely
        (\ c -> isAlphaNum c || c `elem` "-_.+")
   |
33 |    s <- Parse.munch1 (\c -> isAlphaNum c || c `elem` "-_.+")
   |                                             ^^^^^^^^^^^^^^^

Workaround

As a workaround, one can deactivate the loading of ~/.ghci by typing hadrian/ghci -ignore-dot-ghci. This is documented in the wiki.

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information