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 doesn't see preprocessed (e.g. c2hs) files, and doesn't error #498

Closed
mtolly opened this issue Jul 3, 2015 · 6 comments
Closed

Comments

@mtolly
Copy link
Contributor

mtolly commented Jul 3, 2015

Steps to reproduce:

$ stack --version
Version 0.1.1.0, Git revision bf086c6d5f8e86e95f161c38c596a6dae571ab65

pkg-a.cabal:

name:                pkg-a
version:             0.1.0.0
build-type:          Simple
cabal-version:       >= 1.10

library
  exposed-modules:     A
  build-depends:       base >= 4.7 && < 5
  default-language:    Haskell2010

A.chs:

module A where

stack.yaml:

flags: {}
packages:
- '.'
extra-deps: []
resolver: nightly-2015-06-28

Expected:

Running stack ghci builds and loads module A (after preprocessing with c2hs).

Actual:

$ stack ghci
Configuring GHCi with the following packages: pkg-a
GHCi, version 7.10.1: http://www.haskell.org/ghc/  :? for help
Prelude λ import A

<no location info>:
    Could not find module ‘A’
    It is not a module in the current program, or in any known package.
Prelude λ

# ok, let's install it into stack work
$ stack build
pkg-a-0.1.0.0: build
Building pkg-a-0.1.0.0...
Preprocessing library pkg-a-0.1.0.0...
[1 of 1] Compiling A                ( .stack-work/dist/x86_64-osx/Cabal-1.22.2.0/build/A.hs, .stack-work/dist/x86_64-osx/Cabal-1.22.2.0/build/A.o )
In-place registering pkg-a-0.1.0.0...
pkg-a-0.1.0.0: install
Installing library in
/Users/mtolly/git/stackbugs/.stack-work/install/x86_64-osx/nightly-2015-06-28/7.10.1/lib/x86_64-osx-ghc-7.10.1/pkga_9rCkBC6ycwY3RIqsB0Qe80
Registering pkg-a-0.1.0.0...

$ stack ghci
Configuring GHCi with the following packages: pkg-a
GHCi, version 7.10.1: http://www.haskell.org/ghc/  :? for help
Prelude λ import A

<no location info>:
    Could not find module ‘A’
    It is a member of the hidden package ‘pkg-a-0.1.0.0@pkga_9rCkBC6ycwY3RIqsB0Qe80’.
Prelude λ

# this loads the installed (in stack work) package, not the current source
$ stack ghci --ghc-options "-package pkg-a"
Configuring GHCi with the following packages: pkg-a
GHCi, version 7.10.1: http://www.haskell.org/ghc/  :? for help
Prelude λ import A
Prelude A λ
Leaving GHCi.

Actually you'll get this result if the A file is named anything other than A.hs (like A.foobar), or even if it doesn't exist at all.

So there are 2 bugs:

  1. Module A is not loaded when it's a non-.hs extension
  2. The fact that module A wasn't found while supposedly loading pkg-a does not cause an error
@snoyberg snoyberg added this to the 0.3.0.0 milestone Jul 3, 2015
@snoyberg snoyberg modified the milestones: 0.3.0.0, GHCi Jul 13, 2015
@ntc2
Copy link
Contributor

ntc2 commented Jul 15, 2015

I might be running into something similar: stack ghci is failing to find files generated by Alex and Happy in a dependency package, elf:

[...]
Loading package elf-0.28 ... linking ... done.
[...]
Loading package flexdis86-0.1.1 ... linking ... done.
[...]

/home/conathan/cfar/reopt.git/deps/elf/src/Data/Elf/TH.hs:3:8:
    Could not find module ‘Data.Elf.Lexer’
    it is a hidden module in the package ‘elf-0.28’
    Use -v to see a list of the files searched for.

/home/conathan/cfar/reopt.git/deps/elf/src/Data/Elf/TH.hs:4:8:
    Could not find module ‘Data.Elf.Parser’
    it is a hidden module in the package ‘elf-0.28’
    Use -v to see a list of the files searched for.

The modules Data.Elf.Lexer and Data.Elf.Parser are generated from Data/Elf/Lexer.x and Data/Elf/Parser.y. Moving Data.Elf.Lexer and Data.Elf.Parser from extra-modules to exposed-modules in elf.cabal fixes this problem, as the error message indicates it might, but I don't think that's the right solution.

With the exposed-modules hack in place, I then get a probably unrelated error from stack ghci:

/home/conathan/cfar/reopt.git/deps/flexdis86/src/Flexdis86/DefaultParser.hs:25:5:
    Exception when trying to run compile-time code:
      data/optable.xml: openBinaryFile: does not exist (No such file or directory)
    Code: do { let AbsBinds [] []
                     {Exports: [path <= path
                                  <>]
                      Exported types: path :: [Char]
                                      [LclId, Str=DmdType]
                      Binds: ...};
               qAddDependentFile path;
               contents <- ($) qRunIO BS.readFile path;
               .... }
    In the splice:
      $(do { let path = ...;
             qAddDependentFile path;
             contents <- qRunIO $ BS.readFile path;
             .... })

My best guess for a workaround was to mention data/optable.xml in the flexdis86.cabal file:

extra-source-files: data/optable.xml
data-files: data/optable.xml

But that does not help Stack.

In contrast, cabal repl has neither of these problems and starts up without issue.

@mwm
Copy link

mwm commented Jul 23, 2015

I think I also have a similar problem - files auto-generated by cabal aren't available from stack ghci or similar. If I do the following:

  1. stack new
  2. Rename the cabal file to "foobar", changing all occurrences of new-template to foobar in it.
  3. add "import Paths_foobar" to app/Main.hs
  4. stack exec ghci
  5. :load app/Main.hs

This fails to load because "Could not find module 'Paths_foobar'".

Note that "stack ghci" works properly; I just used ghci in the above to illustrate the problem.

@chrisdone
Copy link
Member

It now loads like:

chris@retina:~/issue-498$ stack ghci
pkg-a-0.1.0.0: configure
Configuring pkg-a-0.1.0.0...
pkg-a-0.1.0.0: build
Building pkg-a-0.1.0.0...
Preprocessing library pkg-a-0.1.0.0...
[1 of 1] Compiling A                ( .stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build/A.hs, .stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build/A.o )
In-place registering pkg-a-0.1.0.0...
pkg-a-0.1.0.0: install
Installing library in
/home/chris/issue-498/.stack-work/install/x86_64-linux/nightly-2015-06-28/7.10.2/lib/x86_64-linux-ghc-7.10.2/pkg-a-0.1.0.0-KK15ZBdmKl1FvB9hdtPBH4
Registering pkg-a-0.1.0.0...
Configuring GHCi with the following packages: pkg-a
GHCi, version 7.10.2: http://www.haskell.org/ghc/  :? for help
Warning: ignoring unrecognised input `/home/chris/issue-498/A.chs'

I think this needs to launch GHC with A as an argument instead of A.chs, otherwise it doesn't work.

@chrisdone
Copy link
Member

Fixed in de397f0, f5a8a7f and 2f725c0.

@mtolly Please confirm.

@ntc2
Copy link
Contributor

ntc2 commented Aug 14, 2015

For me, the Alex and Happy generated dependencies problem is now gone; thanks! I still have the second problem, but I think it's unrelated:

$ stack ghci
[...]
/home/conathan/cfar/reopt.git/deps/flexdis86/src/Flexdis86/DefaultParser.hs:25:5:
    Exception when trying to run compile-time code:
      data/optable.xml: openBinaryFile: does not exist (No such file or directory)
    Code: do { let AbsBinds [] []
                     {Exports: [path <= path
                                  <>]
                      Exported types: path :: [Char]
                                      [LclId, Str=DmdType]
                      Binds: ...};
               qAddDependentFile path;
               contents <- ($) qRunIO BS.readFile path;
               .... }
    In the splice:
      $(do { let path = ...;
             qAddDependentFile path;
             contents <- qRunIO $ BS.readFile path;
             .... })

Again, stack build still works here.

@mtolly
Copy link
Contributor Author

mtolly commented Aug 16, 2015

It seems I do still have to run stack build before stack ghci in a fresh work directory or whenever a new non-.hs module is added; see the transcript below. But it does seem to be working correctly (in that it compiles and loads the current version, not the version installed in .stack-work).

╭─mtolly@mbp1440  ~/g/stacktest
╰─$ stack --version
Version 0.1.3.0, Git revision 01a628264ff5cac96109d91d9e3cdc3c58b1cac4
╭─mtolly@mbp1440  ~/g/stacktest
╰─$ rm -rf .stack-work/
╭─mtolly@mbp1440  ~/g/stacktest
╰─$ stack ghci
Configuring GHCi with the following packages: pkg-a
GHCi, version 7.10.1: http://www.haskell.org/ghc/  :? for help

<command line>:
    Could not find module ‘A’
    Use -v to see a list of the files searched for.
Failed, modules loaded: none.
Prelude λ
Leaving GHCi.
╭─mtolly@mbp1440  ~/g/stacktest
╰─$ stack build
pkg-a-0.1.0.0: configure
Configuring pkg-a-0.1.0.0...
pkg-a-0.1.0.0: build
Building pkg-a-0.1.0.0...
Preprocessing library pkg-a-0.1.0.0...
[1 of 1] Compiling A                ( .stack-work/dist/x86_64-osx/Cabal-1.22.2.0/build/A.hs, .stack-work/dist/x86_64-osx/Cabal-1.22.2.0/build/A.o )
In-place registering pkg-a-0.1.0.0...
pkg-a-0.1.0.0: install
Installing library in
/Users/mtolly/git/stacktest/.stack-work/install/x86_64-osx/nightly-2015-06-28/7.10.1/lib/x86_64-osx-ghc-7.10.1/pkga_9rCkBC6ycwY3RIqsB0Qe80
Registering pkg-a-0.1.0.0...
╭─mtolly@mbp1440  ~/g/stacktest
╰─$ stack ghci
Configuring GHCi with the following packages: pkg-a
GHCi, version 7.10.1: http://www.haskell.org/ghc/  :? for help
[1 of 1] Compiling A                ( /Users/mtolly/git/stacktest/.stack-work/dist/x86_64-osx/Cabal-1.22.2.0/build/A.hs, interpreted )
Ok, modules loaded: A.
*A λ

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

6 participants