stack ghci recompiles all modules on every startup, even when invoked with "-fobject-code" or "--no-build"

Created on 14 Aug 2017  路  2Comments  路  Source: commercialhaskell/stack

Summary

Running stack ghci appears to trigger a recompilation of all modules on every startup, even when invoked with the -fobject-code option (as documented here) or the --no-build option (as documented here).

Steps to reproduce

  1. Create a new project:
$ stack new example
$ cd example
  1. Build the project
$ stack build
  1. Observe that to begin with, there is no .stack-work/odir directory:
$ ls .stack-work/
dist  install
  1. Start GHCI, enabling -fobject-code, and observe that it compiles all modules:
$ stack ghci --ghc-options -fobject-code
The following GHC options are incompatible with GHCi and have not been passed to it: -threaded
Configuring GHCi with the following packages: example
Using main module: 1. Package `example' component exe:example-exe with main-is file: /home/jsk/example/app/Main.hs
GHCi, version 8.0.2: http://www.haskell.org/ghc/  :? for help
[1 of 1] Compiling Lib              ( /home/jsk/example/src/Lib.hs, /home/jsk/example/.stack-work/odir/Lib.o )
Ok, modules loaded: Lib (/home/jsk/example/.stack-work/odir/Lib.o).
[2 of 2] Compiling Main             ( /home/jsk/example/app/Main.hs, /home/jsk/example/.stack-work/odir/Main.o )
Ok, modules loaded: Lib (/home/jsk/example/.stack-work/odir/Lib.o), Main (/home/jsk/example/.stack-work/odir/Main.o).
Loaded GHCi configuration from /tmp/ghci7387/ghci-script
Prelude Lib Main> 
Leaving GHCi.
  1. Observe that there are now object files within the .stack-work/odir directory:
$ ls .stack-work/
dist  install  odir
$ ls -la --full-time .stack-work/odir/
total 56
drwxrwxr-x 2 jsk jsk 4096 2017-08-15 21:43:15.468485195 +0800 .
drwxrwxr-x 5 jsk jsk 4096 2017-08-15 21:43:15.444485108 +0800 ..
-rw-rw-r-- 1 jsk jsk  823 2017-08-15 21:43:15.448485123 +0800 Lib.hi
-rw-rw-r-- 1 jsk jsk 3176 2017-08-15 21:43:15.456485152 +0800 Lib.o
-rw-rw-r-- 1 jsk jsk  858 2017-08-15 21:43:15.464485181 +0800 Main.hi
-rw-rw-r-- 1 jsk jsk 2800 2017-08-15 21:43:15.468485195 +0800 Main.o
  1. Restart GHCI with the same options, observing that modules are recompiled:
$ stack ghci --ghc-options -fobject-code
The following GHC options are incompatible with GHCi and have not been passed to it: -threaded
Configuring GHCi with the following packages: example
Using main module: 1. Package `example' component exe:example-exe with main-is file: /home/jsk/example/app/Main.hs
GHCi, version 8.0.2: http://www.haskell.org/ghc/  :? for help
[1 of 1] Compiling Lib              ( /home/jsk/example/src/Lib.hs, /home/jsk/example/.stack-work/odir/Lib.o ) [flags changed]
Ok, modules loaded: Lib (/home/jsk/example/.stack-work/odir/Lib.o).
[2 of 2] Compiling Main             ( /home/jsk/example/app/Main.hs, /home/jsk/example/.stack-work/odir/Main.o ) [flags changed]
Ok, modules loaded: Lib (/home/jsk/example/.stack-work/odir/Lib.o), Main (/home/jsk/example/.stack-work/odir/Main.o).
Loaded GHCi configuration from /tmp/ghci7865/ghci-script
Prelude Lib Main> 
Leaving GHCi.
  1. Observe that the timestamps of object files within the .stack-work/odir directory have changed:
$ ls -la --full-time .stack-work/odir/
total 56
drwxrwxr-x 2 jsk jsk 4096 2017-08-15 21:44:23.392722165 +0800 .
drwxrwxr-x 5 jsk jsk 4096 2017-08-15 21:43:15.444485108 +0800 ..
-rw-rw-r-- 1 jsk jsk  823 2017-08-15 21:44:23.364722071 +0800 Lib.hi
-rw-rw-r-- 1 jsk jsk 3176 2017-08-15 21:44:23.376722112 +0800 Lib.o
-rw-rw-r-- 1 jsk jsk  858 2017-08-15 21:44:23.384722138 +0800 Main.hi
-rw-rw-r-- 1 jsk jsk 2800 2017-08-15 21:44:23.396722179 +0800 Main.o
  1. Restart GHCI with the --no-build option, observing again that modules are recompiled:
$ stack ghci --no-build --ghc-options -fobject-code
The following GHC options are incompatible with GHCi and have not been passed to it: -threaded
Configuring GHCi with the following packages: example
Using main module: 1. Package `example' component exe:example-exe with main-is file: /home/jsk/example/app/Main.hs
GHCi, version 8.0.2: http://www.haskell.org/ghc/  :? for help
[1 of 1] Compiling Lib              ( /home/jsk/example/src/Lib.hs, /home/jsk/example/.stack-work/odir/Lib.o ) [flags changed]
Ok, modules loaded: Lib (/home/jsk/example/.stack-work/odir/Lib.o).
[2 of 2] Compiling Main             ( /home/jsk/example/app/Main.hs, /home/jsk/example/.stack-work/odir/Main.o ) [flags changed]
Ok, modules loaded: Lib (/home/jsk/example/.stack-work/odir/Lib.o), Main (/home/jsk/example/.stack-work/odir/Main.o).
Loaded GHCi configuration from /tmp/ghci7920/ghci-script
Prelude Lib Main> 
Leaving GHCi.
  1. Observe once more that the timestamps of object files within the .stack-work/odir directory have changed:
$ ls -la --full-time .stack-work/odir/
total 56
drwxrwxr-x 2 jsk jsk 4096 2017-08-15 21:46:26.325111175 +0800 .
drwxrwxr-x 5 jsk jsk 4096 2017-08-15 21:43:15.444485108 +0800 ..
-rw-rw-r-- 1 jsk jsk  823 2017-08-15 21:46:26.305111115 +0800 Lib.hi
-rw-rw-r-- 1 jsk jsk 3176 2017-08-15 21:46:26.313111138 +0800 Lib.o
-rw-rw-r-- 1 jsk jsk  858 2017-08-15 21:46:26.321111163 +0800 Main.hi
-rw-rw-r-- 1 jsk jsk 2800 2017-08-15 21:46:26.329111186 +0800 Main.o

Expected

During steps 6 and 8, GHCi reloads _without_ recompiling every module.

Actual

GHCi appears to recompile every module, reporting [flags changed].

Verbose output

See https://gist.github.com/jonathanknowles/fd9616126313c9d3633620114e4d1eac

Stack version

$ stack --version
Version 1.5.1, Git revision 600c1f01435a10d127938709556c1682ecfd694e (4861 commits) x86_64 hpack-0.17.1

Method of installation

$ which stack
/home/user/.local/bin/stack

Question

Is this behaviour by design?

If so, is there another way to get ghci to reload already-compiled modules on startup, when invoked with stack?

Most helpful comment

This behavior is not by design, it was an unintended consequence of using a random tmpdir for generated files. @chrisdone resolved it recently in https://github.com/commercialhaskell/stack/pull/4038 :fireworks:

All 2 comments

This behavior is not by design, it was an unintended consequence of using a random tmpdir for generated files. @chrisdone resolved it recently in https://github.com/commercialhaskell/stack/pull/4038 :fireworks:

@mgsloan Thanks for the update! In that case, I'll definitely give this method of starting ghci another try. Thanks again!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sjakobi picture sjakobi  路  4Comments

Cosmius picture Cosmius  路  3Comments

silky picture silky  路  3Comments

bitemyapp picture bitemyapp  路  3Comments

s5k6 picture s5k6  路  3Comments