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

Stack GHCI Loads Only First Module #995

Closed
ruggeri opened this issue Sep 15, 2015 · 13 comments
Closed

Stack GHCI Loads Only First Module #995

ruggeri opened this issue Sep 15, 2015 · 13 comments

Comments

@ruggeri
Copy link

@ruggeri ruggeri commented Sep 15, 2015

When I run stack ghci, it claims to load multiple files:

~/Chess$ stack ghci
Configuring GHCi with the following packages: Chess
GHCi, version 7.10.2: http://www.haskell.org/ghc/  :? for help
[ 1 of 13] Compiling Utils            ( /Users/ruggeri/Chess/src/Utils.hs, interpreted )
[ 2 of 13] Compiling Pos              ( /Users/ruggeri/Chess/src/Pos.hs, interpreted )
[ 3 of 13] Compiling Move             ( /Users/ruggeri/Chess/src/Move.hs, interpreted )
[ 4 of 13] Compiling Color            ( /Users/ruggeri/Chess/src/Color.hs, interpreted )[ 5 of 13] Compiling Piece            ( /Users/ruggeri/Chess/src/Piece.hs, interpreted )
[ 6 of 13] Compiling Board            ( /Users/ruggeri/Chess/src/Board.hs, interpreted )
[ 7 of 13] Compiling PieceMovement    ( /Users/ruggeri/Chess/src/PieceMovement.hs, interpreted )
[ 8 of 13] Compiling Game             ( /Users/ruggeri/Chess/src/Game.hs, interpreted )
[ 9 of 13] Compiling GameIO           ( /Users/ruggeri/Chess/src/GameIO.hs, interpreted )
[10 of 13] Compiling Search           ( /Users/ruggeri/Chess/src/Search.hs, interpreted )
[11 of 13] Compiling TestBoards       ( /Users/ruggeri/Chess/src/TestBoards.hs, interpreted )
[12 of 13] Compiling Abc              ( /Users/ruggeri/Chess/src/Abc.hs, interpreted )[13 of 13] Compiling Lib              ( /Users/ruggeri/Chess/src/Lib.hs, interpreted )
Ok, modules loaded: Lib, Abc, Board, Color, Game, GameIO, Move, Piece, PieceMovement, Pos, Search, TestBoards, Utils.
*Abc>

But as you can see, only the module Abc is in fact loaded. It appears the alphabetically first module of my code ("src/Abc.hs") is the one chosen.

Is there a way to configure the cabl file such that all modules are loaded? Thanks!

@chrisdone
Copy link
Member

@chrisdone chrisdone commented Sep 17, 2015

It did load them, hence why it says so in the message. But only the first is imported. The missing part seems to be having them all imported with :m + A B C. GHCi has never automatically done this, and it's why in haskell-mode I had Emacs itself do this:

<- Ok, modules loaded: Services.Server.Notification, Services.Server.Settings, Services.Server.Foundation, Services.Types, Services.Server.Constants, Services.Server.JSON, Services.Server.Print, Services.Server.Handler.Status.
-> :m + Services.Server.Notification Services.Server.Settings Services.Server.Foundation Services.Types Services.Server.Constants Services.Server.JSON Services.Server.Print Services.Server.Handler.Status

Perhaps we can make stack ghci automatically run this step too.

Loading

@rvion
Copy link
Contributor

@rvion rvion commented Sep 17, 2015

I +1 for stack ghci automatically importing all modules

Loading

@borsboom borsboom added this to the P2: Should milestone Oct 6, 2015
@ruggeri
Copy link
Author

@ruggeri ruggeri commented Oct 7, 2015

Thanks for your replies! I'm not a Haskell power-user by any means, but as a n00b, I think it would be easier if stack ghci either imported all the modules or none. Importing just the first alphabetically feels weird.

Thanks again!

Loading

@chrisdone
Copy link
Member

@chrisdone chrisdone commented Oct 27, 2015

So it's rather a messy business to change our process launching code which now uses things from the unix package, etc. Writing to the stdin of the GHCi process is therefore a messy option. Instead, I've found this handy argument to GHCi called -ghci-script:

bash-3.2$ echo ":m + Data.List" > /tmp/ghci-script
bash-3.2$ stack ghci --ghc-options="-ghci-script /tmp/ghci-script"
Warning: Location of non-project configuration file at '/Users/chris/.stack/stack.yaml' is deprecated; rename it to '/Users/chris/.stack/config.yaml' instead
The following GHC options are incompatible with GHCi and have not been passed to it: -threaded
* * * * * * * *
The main module to load is ambiguous. Candidates are: 
Package `stack' component exe:stack with main-is file: /Users/chris/Work/stack/src/main/Main.hs
Package `stack' component test:stack-integration-test with main-is file: /Users/chris/Work/stack/test/integration/IntegrationSpec.hs
Package `stack' component test:stack-test with main-is file: /Users/chris/Work/stack/src/test/Test.hs
None will be loaded. You can specify which one to pick by: 
 1) Specifying targets to stack ghci e.g. stack ghci stack:exe:stack
 2) Specifying what the main is e.g. stack ghci --main-is stack:exe:stack
* * * * * * * *
Configuring GHCi with the following packages: stack
GHCi, version 7.10.2: http://www.haskell.org/ghc/  :? for help
unknown option: 'c'
[66 of 82] Compiling Stack.Build.ExecuteSpec ( /Users/chris/Work/stack/src/test/Stack/Build/ExecuteSpec.hs, interpreted )
[67 of 82] Compiling Network.HTTP.Download.VerifiedSpec ( /Users/chris/Work/stack/src/test/Network/HTTP/Download/VerifiedSpec.hs, interpreted )
[68 of 82] Compiling Data.Set.Monad   ( /Users/chris/Work/stack/src/Data/Set/Monad.hs, interpreted )
[69 of 82] Compiling Stack.ArgsSpec   ( /Users/chris/Work/stack/src/test/Stack/ArgsSpec.hs, interpreted )
[70 of 82] Compiling Stack.Build.TargetSpec ( /Users/chris/Work/stack/src/test/Stack/Build/TargetSpec.hs, interpreted )
[71 of 82] Compiling Stack.PackageDumpSpec ( /Users/chris/Work/stack/src/test/Stack/PackageDumpSpec.hs, interpreted )
[72 of 82] Compiling Stack.Exec       ( /Users/chris/Work/stack/src/Stack/Exec.hs, interpreted )
[73 of 82] Compiling Stack.BuildPlanSpec ( /Users/chris/Work/stack/src/test/Stack/BuildPlanSpec.hs, interpreted )
[74 of 82] Compiling Stack.ConfigSpec ( /Users/chris/Work/stack/src/test/Stack/ConfigSpec.hs, interpreted )
[75 of 82] Compiling Stack.Setup      ( /Users/chris/Work/stack/src/Stack/Setup.hs, interpreted )
[76 of 82] Compiling Stack.Docker     ( /Users/chris/Work/stack/src/Stack/Docker.hs, interpreted )
[77 of 82] Compiling Stack.DotSpec    ( /Users/chris/Work/stack/src/test/Stack/DotSpec.hs, interpreted )
[78 of 82] Compiling Spec             ( /Users/chris/Work/stack/src/test/Spec.hs, interpreted )
[79 of 82] Compiling Stack.Ghci       ( /Users/chris/Work/stack/src/Stack/Ghci.hs, interpreted )
[80 of 82] Compiling Stack.Ide        ( /Users/chris/Work/stack/src/Stack/Ide.hs, interpreted )
[81 of 82] Compiling Stack.Options    ( /Users/chris/Work/stack/src/Stack/Options.hs, interpreted )
[82 of 82] Compiling Stack.Upgrade    ( /Users/chris/Work/stack/src/Stack/Upgrade.hs, interpreted )
Ok, modules loaded: Control.Concurrent.Execute, Stack.Types, Data.Aeson.Extended, Data.Attoparsec.Args, Data.Attoparsec.Combinators, Data.Binary.VersionTagged, Data.IORef.RunOnce, Data.Maybe.Extra, Data.Set.Monad, Distribution.Version.Extra, Network.HTTP.Download, Network.HTTP.Download.Verified, Network.HTTP.Download.VerifiedSpec, Path.IO, Options.Applicative.Args, Options.Applicative.Builder.Extra, Path.Extra, Path.Find, Paths_stack, Spec, Stack.ArgsSpec, Stack.Build, Stack.Build.ExecuteSpec, Stack.Build.TargetSpec, Stack.BuildPlanSpec, Stack.ConfigSpec, Stack.DotSpec, Stack.PackageDumpSpec, Stack.Build.ConstructPlan, Stack.Build.Execute, Stack.Build.Haddock, Stack.Build.Installed, Stack.Build.Source, Stack.Build.Target, Stack.Constants, Stack.Fetch, Stack.GhcPkg, Stack.Package, Stack.Types.Internal, Stack.Build.Cache, Stack.Types.Build, Stack.BuildPlan, Stack.PackageDump, Stack.PackageIndex, Stack.Coverage, Stack.Types.StackT, System.Process.Read, System.Process.Run, System.Process.Log, Stack.Types.Version, Stack.Config, Stack.Config.Docker, Stack.Image, Stack.Init, Stack.ConfigCmd, Stack.Types.Config, Stack.Types.PackageIdentifier, Stack.Types.PackageName, Stack.Docker, Stack.Docker.GlobalDB, Stack.Setup, System.Process.PagerEditor, Stack.Types.Docker, Stack.Dot, Stack.Exec, Stack.FileWatch, Stack.Ghci, Stack.Ide, Stack.Solver, Stack.New, Stack.Types.TemplateName, Stack.Options, Stack.SDist, Stack.Setup.Installed, Stack.Types.BuildPlan, Stack.Types.FlagName, Stack.Types.GhcPkgId, Stack.Types.Image, Stack.Types.Package, Stack.Types.Compiler, Stack.Upgrade, Stack.Upload.
Prelude Data.List Control.Concurrent.Execute> 

Note the Data.List in the module list at the bottom. So I can just go ahead and write a temporary GHCi script for this session and import all modules for the project like this.

Loading

@chrisdone
Copy link
Member

@chrisdone chrisdone commented Oct 27, 2015

Pushed this change in b758296. @ruggeri Can you confirm and close?

Loading

@mgsloan
Copy link
Contributor

@mgsloan mgsloan commented Nov 5, 2015

No response + it's been working for me. Closing!

Loading

@mgsloan mgsloan closed this Nov 5, 2015
dysinger added a commit that referenced this issue Nov 13, 2015
* master: (106 commits)
  Fix ghci -package-id for lib dep from test #1222
  Fix passing of include dirs to GHCI #1222
  Minor change to some local var naming
  Fix a copy-o which breaks ghci test targets #1222
  Only ask for commit count once when compiling
  Move Windows installers above manual download
  Import all modules after loading them (#995)
  replace if then else with case matching (multiway if)
  Control/Concurrent/Execute.hs : redundant do
  Use stack setup so you can ignore most of the output
  Don't cache the GHC folder
  Strip -static before passing to GHCi (#1094)
  Fix: unlisted files in tests and benchmarks trigger extraneous second build (fixes #838)
  Don't fail when registering/looking up library for executable-only packages #1232
  Fix help for default true bool flag's enable hint
  Rebuild when cabal file is changed
  watched command: show files, not directories
  Update changelog
  Fix: Haddocks not copied for dependencies (fixes #1105)
  Remove redundant Version from InstalledMap
  ...
@erikkaplun
Copy link
Contributor

@erikkaplun erikkaplun commented Dec 3, 2015

Can stack ghci now auto-import all modules? Or possibly a configurable set of modules?

I also tried a .ghci file in the directory where I sta rstack ghci, with :module Foo Bar Baz in it, but stack ghci still gives me a prompt with only Main imported. And apparently, the contents of .ghci is evaluated before the modules are auto-loaded, so that's why putting any imports there won't work.

Loading

@mgsloan
Copy link
Contributor

@mgsloan mgsloan commented Dec 3, 2015

Yes, by default stack ghci now auto-imports all modules. Use --no-load to suppress this.

with :module Foo Bar Baz in it, but stack ghci still gives me a prompt with only Main imported

Are you getting an error like *** WARNING: /home/mgsloan/fpco/stack/.ghci is writable by someone else, IGNORING! as this indicates ghci is ignoring your .ghci file. In my experiments, it seems that .ghci gets loaded before the -ghci-script which is used to load + auto-import everything.

Loading

@erikkaplun
Copy link
Contributor

@erikkaplun erikkaplun commented Dec 7, 2015

I'm not getting any errors really, it just only imports Main...

Loading

@mgsloan
Copy link
Contributor

@mgsloan mgsloan commented Dec 7, 2015

@eallik Can you please open up an issue with steps to reproduce the issue?

Loading

@erikkaplun
Copy link
Contributor

@erikkaplun erikkaplun commented Dec 9, 2015

Well I created a new stack project from new-template and --resolver ghc-7.10.2, added a new module Foo, registered it in the .cabal file and then fired off stack ghci, but only Main/Lib showed up in the prompt and not Foo. I will have to go through this once more to confirm though.

Loading

@mgsloan
Copy link
Contributor

@mgsloan mgsloan commented Dec 10, 2015

Did you add Foo to the library stanza, or some other stanza? It works for me:

mgsloan@computer:~/fpco/test-stack/test995$ stack ghci
Using main module: Package `test995' component exe:test995-exe with main-is file: /home/mgsloan/fpco/test-stack/test995/app/Main.hs
The following GHC options are incompatible with GHCi and have not been passed to it: -threaded
Configuring GHCi with the following packages: test995
GHCi, version 7.10.2: http://www.haskell.org/ghc/  :? for help
unknown option: 'c'
[1 of 3] Compiling Foo              ( /home/mgsloan/fpco/test-stack/test995/src/Foo.hs, interpreted )
[2 of 3] Compiling Lib              ( /home/mgsloan/fpco/test-stack/test995/src/Lib.hs, interpreted )
[3 of 3] Compiling Main             ( /home/mgsloan/fpco/test-stack/test995/app/Main.hs, interpreted )
Ok, modules loaded: Lib, Foo, Main.
*Main Foo Lib> :quit
mgsloan@computer:~/fpco/test-stack/test995$ stack --version
Version 0.1.11.0, Git revision 0a47828fe062d7a4e00398c5a7533bcf67040cb8 (dirty) (2805 commits) x86_64

Loading

@erikkaplun
Copy link
Contributor

@erikkaplun erikkaplun commented Dec 13, 2015

Probably something in how I set up Stack then, so let's leave it I guess — if I come back to this and still can't get it to import everything by default, I'll post another comment here.

Loading

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

Successfully merging a pull request may close this issue.

None yet
7 participants