Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Weird behaviour with loading custom GHCI config #7789

Open
georgefst opened this issue Oct 31, 2021 · 3 comments
Open

Weird behaviour with loading custom GHCI config #7789

georgefst opened this issue Oct 31, 2021 · 3 comments

Comments

@georgefst
Copy link

This is with cabal-install 3.6.2.0, GHC 8.10.7, Manjaro Linux.

I have the following in my ~/.ghc/ghci.conf:

:add /home/gthomas/.ghc/ghci.hs
:set -interactive-print ghciInteractivePrint
:set prompt-function ghciPromptFunction

And in ~/.ghc/ghci.hs (obviously this isn't my real config, it's much simplified):

ghciInteractivePrint :: Show a => a -> IO ()
ghciInteractivePrint x = putStrLn "printing..."

ghciPromptFunction :: [String] -> Int -> IO String
ghciPromptFunction modules _lineno = pure "prompt> "

In plain ghci, everything works as expected:

GHCi, version 8.10.7: https://www.haskell.org/ghc/  :? for help
[1 of 1] Compiling Main             ( /home/gthomas/.ghc/ghci.hs, interpreted )
Ok, one module loaded.
Loaded GHCi configuration from /home/gthomas/.ghc/ghci.conf
prompt> 1
printing...
prompt>

Running cabal repl within a cabal project directory, somehow ghciPromptFunction is loaded but not ghciInteractivePrint:

Build profile: -w ghc-8.10.7 -O1
In order, the following will be built (use -v for more details):
 - hello-hs-0.1.0.0 (exe:hello-hs) (file app/Main.hs changed)
Preprocessing executable 'hello-hs' for hello-hs-0.1.0.0..
GHCi, version 8.10.7: https://www.haskell.org/ghc/  :? for help
[1 of 1] Compiling Main             ( /home/gthomas/.ghc/ghci.hs, interpreted )
Ok, one module loaded.
Loaded GHCi configuration from /home/gthomas/.ghc/ghci.conf
[1 of 1] Compiling Main             ( app/Main.hs, interpreted )
Ok, one module loaded.
prompt> 1
1
prompt>

Running cabal repl outside of a project directory, everything fails to load, but there are at least visible errors (possibly only due to setcwd.ghci, which I can't find any mention of anywhere - what's the purpose of it?):

Resolving dependencies...
Build profile: -w ghc-8.10.7 -O1
In order, the following will be built (use -v for more details):
 - fake-package-0 (lib) (first run)
Configuring library for fake-package-0..
Preprocessing library for fake-package-0..
Warning: No exposed modules
GHCi, version 8.10.7: https://www.haskell.org/ghc/  :? for help
[1 of 1] Compiling Main             ( /home/gthomas/.ghc/ghci.hs, interpreted )
Ok, one module loaded.

<interactive>:1:1: error: Not in scope: ‘ghciInteractivePrint’

<interactive>:1:2: error:
    Variable not in scope:
      ghciPromptFunction :: [String] -> Int -> IO String
Loaded GHCi configuration from /home/gthomas/.ghc/ghci.conf
Warning: changing directory causes all loaded modules to be unloaded,
because the search path has changed.
Loaded GHCi configuration from /tmp/cabal-repl.-171000/setcwd.ghci
Prelude> 1
1
Prelude>
@fgaz
Copy link
Member

fgaz commented Nov 1, 2021

Thanks for the bug report.

The second case can be explained by

Warning: changing directory causes all loaded modules to be unloaded,
because the search path has changed.
Loaded GHCi configuration from /tmp/cabal-repl.-171000/setcwd.ghci

setcwd.ghci is a configuration file generated by cabal repl that sets the working directory to a dummy temporary project (related: #6977). it may be that it causes /home/gthomas/.ghc/ghci.hs to be unloaded too.


i get a different but still problematic output in the project case

[...]
[1 of 1] Compiling Main             ( /home/fgaz/.ghc/ghci.hs, interpreted )
Ok, one module loaded.

<interactive>:1:1: error: Not in scope: ‘ghciInteractivePrint’

<interactive>:1:2: error:
    Variable not in scope:
      ghciPromptFunction :: [String] -> Int -> IO String
Loaded GHCi configuration from /home/fgaz/.ghc/ghci.conf
[...]

Weird indeed!

@georgefst
Copy link
Author

georgefst commented Nov 1, 2021

Ah, so presumably without setcwd.ghci, we'd end up in /tmp or something? Oh well, all the more reason to look forward to the removal of fake-package.

The in-project case is the one I'm more interested in anyway.

@jneira
Copy link
Member

jneira commented Jun 25, 2022

#1471 suggested to directly make cabal don load .ghci, but it seems that does not fit all workflows so it would need at least a flag

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants