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 build/test/bench --profile should recompile if previous compile was without --profile #2984

Closed
juliapath opened this issue Feb 5, 2017 · 4 comments · Fixed by #3046

Comments

@juliapath
Copy link

juliapath commented Feb 5, 2017

If you build without --profile and then with stack doesn't recompile the second time to create a binary with profiling options if no files have changed. This is in opposition to ghc behaviour. If you build without -prof and then with, ghc will recompile the second time even if no files changed.

Steps to reproduce

For example:

  1. Run command stack clean && stack build.
  2. Run command stack build --profile.

Expected

Stack builds two times, first without profiling options and then another time with.

Actual

Stack builds only once without profiling. It ignores the second build instruction because no files changed.

Stack version

$ stack --version
Version 1.3.2 x86_64

Method of installation

  • ArchLinux package community/stack.
@juliapath juliapath changed the title stack build/test/bench --profile should recompile if previous compile was without --profile stack build/test/bench --profile should recompile if previous compile was without --profile Feb 5, 2017
@mgsloan
Copy link
Contributor

mgsloan commented Feb 23, 2017

Hmm, I can't reproduce the issue:

mgsloan@computer:~/fpco/test-stack$ stack new issue2984
...
mgsloan@computer:~/fpco/test-stack$ cd issue2984
mgsloan@computer:~/fpco/test-stack/issue2984$ stack build --system-ghc
Warning: File listed in issue2984.cabal file does not exist: README.md
[1 of 2] Compiling Main             ( /home/mgsloan/.stack/setup-exe-src/setup-mPHDZzAJ.hs, /home/mgsloan/.stack/setup-exe-src/setup-mPHDZzAJ.o )
[2 of 2] Compiling StackSetupShim   ( /home/mgsloan/.stack/setup-exe-src/setup-shim-mPHDZzAJ.hs, /home/mgsloan/.stack/setup-exe-src/setup-shim-mPHDZzAJ.o )
Linking /home/mgsloan/.stack/setup-exe-cache/x86_64-linux/tmp-Cabal-simple_mPHDZzAJ_1.24.2.0_ghc-8.0.2 ...
issue2984-0.1.0.0: configure (lib + exe)
Configuring issue2984-0.1.0.0...
issue2984-0.1.0.0: build (lib + exe)
Preprocessing library issue2984-0.1.0.0...
[1 of 1] Compiling Lib              ( src/Lib.hs, .stack-work/dist/x86_64-linux/Cabal-1.24.2.0/build/Lib.o )
Preprocessing executable 'issue2984-exe' for issue2984-0.1.0.0...
[1 of 1] Compiling Main             ( app/Main.hs, .stack-work/dist/x86_64-linux/Cabal-1.24.2.0/build/issue2984-exe/issue2984-exe-tmp/Main.o )
Linking .stack-work/dist/x86_64-linux/Cabal-1.24.2.0/build/issue2984-exe/issue2984-exe ...
Warning: File listed in issue2984.cabal file does not exist: README.md
issue2984-0.1.0.0: copy/register
Installing library in
/home/mgsloan/fpco/test-stack/issue2984/.stack-work/install/x86_64-linux/lts-8.2/8.0.2/lib/x86_64-linux-ghc-8.0.2/issue2984-0.1.0.0-LbeuxtjKWiO4EQdGgWKmQI
Installing executable(s) in
/home/mgsloan/fpco/test-stack/issue2984/.stack-work/install/x86_64-linux/lts-8.2/8.0.2/bin
Registering issue2984-0.1.0.0...
mgsloan@computer:~/fpco/test-stack/issue2984$ stack build --system-ghc --profile
Warning: File listed in issue2984.cabal file does not exist: README.md
issue2984-0.1.0.0: unregistering
issue2984-0.1.0.0: configure (lib + exe)
Configuring issue2984-0.1.0.0...
issue2984-0.1.0.0: build (lib + exe)
Preprocessing library issue2984-0.1.0.0...
[1 of 1] Compiling Lib              ( src/Lib.hs, .stack-work/dist/x86_64-linux/Cabal-1.24.2.0/build/Lib.p_o )
Preprocessing executable 'issue2984-exe' for issue2984-0.1.0.0...
[1 of 1] Compiling Main             ( app/Main.hs, .stack-work/dist/x86_64-linux/Cabal-1.24.2.0/build/issue2984-exe/issue2984-exe-tmp/Main.p_o )
Linking .stack-work/dist/x86_64-linux/Cabal-1.24.2.0/build/issue2984-exe/issue2984-exe ...
Warning: File listed in issue2984.cabal file does not exist: README.md
issue2984-0.1.0.0: copy/register
Installing library in
/home/mgsloan/fpco/test-stack/issue2984/.stack-work/install/x86_64-linux/lts-8.2/8.0.2/lib/x86_64-linux-ghc-8.0.2/issue2984-0.1.0.0-LbeuxtjKWiO4EQdGgWKmQI
Installing executable(s) in
/home/mgsloan/fpco/test-stack/issue2984/.stack-work/install/x86_64-linux/lts-8.2/8.0.2/bin
Registering issue2984-0.1.0.0...
mgsloan@computer:~/fpco/test-stack/issue2984$ 

@mgsloan mgsloan added this to the Support milestone Feb 23, 2017
@juliapath
Copy link
Author

juliapath commented Feb 25, 2017

It seems that it works only the first time. Try this:

$ stack new issue2984
...

$ cd issue2984

$ stack build
Warning: File listed in issue2984.cabal file does not exist: README.md
issue2984-0.1.0.0: configure (lib + exe)
Configuring issue2984-0.1.0.0...
issue2984-0.1.0.0: build (lib + exe)
Preprocessing library issue2984-0.1.0.0...
[1 of 1] Compiling Lib              ( src/Lib.hs, .stack-work/dist/x86_64-linux-tinfo6/Cabal-1.24.2.0/build/Lib.o )
Preprocessing executable 'issue2984-exe' for issue2984-0.1.0.0...
[1 of 1] Compiling Main             ( app/Main.hs, .stack-work/dist/x86_64-linux-tinfo6/Cabal-1.24.2.0/build/issue2984-exe/issue2984-exe-tmp/Main.o )
Linking .stack-work/dist/x86_64-linux-tinfo6/Cabal-1.24.2.0/build/issue2984-exe/issue2984-exe ...
Warning: File listed in issue2984.cabal file does not exist: README.md
issue2984-0.1.0.0: copy/register
Installing library in
/tmp/jan/issue2984/.stack-work/install/x86_64-linux-tinfo6/lts-8.2/8.0.2/lib/x86_64-linux-ghc-8.0.2/issue2984-0.1.0.0-LbeuxtjKWiO4EQdGgWKmQI
Installing executable(s) in
/tmp/jan/issue2984/.stack-work/install/x86_64-linux-tinfo6/lts-8.2/8.0.2/bin
Registering issue2984-0.1.0.0...

$ stack build # Doesn't build again because nothing has changed.
Warning: File listed in issue2984.cabal file does not exist: README.md

$ stack build --profile # With --profile it does, as expected.
Warning: File listed in issue2984.cabal file does not exist: README.md
issue2984-0.1.0.0: unregistering
issue2984-0.1.0.0: configure (lib + exe)
Configuring issue2984-0.1.0.0...
issue2984-0.1.0.0: build (lib + exe)
Preprocessing library issue2984-0.1.0.0...
[1 of 1] Compiling Lib              ( src/Lib.hs, .stack-work/dist/x86_64-linux-tinfo6/Cabal-1.24.2.0/build/Lib.p_o )
Preprocessing executable 'issue2984-exe' for issue2984-0.1.0.0...
[1 of 1] Compiling Main             ( app/Main.hs, .stack-work/dist/x86_64-linux-tinfo6/Cabal-1.24.2.0/build/issue2984-exe/issue2984-exe-tmp/Main.p_o )
Linking .stack-work/dist/x86_64-linux-tinfo6/Cabal-1.24.2.0/build/issue2984-exe/issue2984-exe ...
Warning: File listed in issue2984.cabal file does not exist: README.md
issue2984-0.1.0.0: copy/register
Installing library in
/tmp/jan/issue2984/.stack-work/install/x86_64-linux-tinfo6/lts-8.2/8.0.2/lib/x86_64-linux-ghc-8.0.2/issue2984-0.1.0.0-LbeuxtjKWiO4EQdGgWKmQI
Installing executable(s) in
/tmp/jan/issue2984/.stack-work/install/x86_64-linux-tinfo6/lts-8.2/8.0.2/bin
Registering issue2984-0.1.0.0...

$ stack exec -- issue2984-exe +RTS -xc # Profiling works as expected
someFunc

$ stack clean && stack build # Build again
Warning: File listed in issue2984.cabal file does not exist: README.md
issue2984-0.1.0.0: unregistering (local file changes: app/Main.hs issue2984.cabal src/Lib.hs test/Spec.hs)
issue2984-0.1.0.0: configure (lib + exe)
Configuring issue2984-0.1.0.0...
issue2984-0.1.0.0: build (lib + exe)
Preprocessing library issue2984-0.1.0.0...
[1 of 1] Compiling Lib              ( src/Lib.hs, .stack-work/dist/x86_64-linux-tinfo6/Cabal-1.24.2.0/build/Lib.o )
Preprocessing executable 'issue2984-exe' for issue2984-0.1.0.0...
[1 of 1] Compiling Main             ( app/Main.hs, .stack-work/dist/x86_64-linux-tinfo6/Cabal-1.24.2.0/build/issue2984-exe/issue2984-exe-tmp/Main.o )
Linking .stack-work/dist/x86_64-linux-tinfo6/Cabal-1.24.2.0/build/issue2984-exe/issue2984-exe ...
Warning: File listed in issue2984.cabal file does not exist: README.md
issue2984-0.1.0.0: copy/register
Installing library in
/tmp/jan/issue2984/.stack-work/install/x86_64-linux-tinfo6/lts-8.2/8.0.2/lib/x86_64-linux-ghc-8.0.2/issue2984-0.1.0.0-LbeuxtjKWiO4EQdGgWKmQI
Installing executable(s) in
/tmp/jan/issue2984/.stack-work/install/x86_64-linux-tinfo6/lts-8.2/8.0.2/bin
Registering issue2984-0.1.0.0...

$ stack build --profile # Now suddenly --profile doesn't prompt it to rebuild
Warning: File listed in issue2984.cabal file does not exist: README.md

$ stack exec -- issue2984-exe +RTS -xc # Profiling is indeed not working
issue2984-exe: the flag -xc requires the program to be built with -prof
...

@mgsloan
Copy link
Contributor

mgsloan commented Mar 7, 2017

I believe the issue here is that the library can be built / installed with both profiling and non-profiling versions. However, when it comes to executables / test-suites / benchmarks, there can only be one at a time. Stack doesn't realize that the executable was most recently built without profiling, and so it needs to rebuild the executable.

I think a fix to this would look something like:

  1. When executables get copied, write out a file which indicates which package it comes from, and whether it was built with profiling or not
  2. When determining if a package should be rebuilt, check which executable stanzas we're building, and load up the files corresponding to each executable. If there's a mismatch with the package name or "built with profiling" flag, then the package is considered dirty. As a little optimization, this check could only be done when the package is otherwise clean.

I'm going to try doing something like this, hopefully it goes smoothly. It feels a little strange to special case profiling this way, but I think it's only necessary because it gets special cased elsewhere.

This would also help with another situation, where you build both pkg-a and pkg-b, and they have executables with the same name. This would allow you to do a subsequent build of pkg-a to ensure its executable takes precedence.

@mgsloan
Copy link
Contributor

mgsloan commented Mar 7, 2017

This actually gets rather tricky when you consider that it needs to apply to tests / benchmarks (located in .stack-work/dist/...) in addition to executables (located in .stack-work/install/...)

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

Successfully merging a pull request may close this issue.

2 participants