How can I get GHC Core output via stack? - haskell

How do I get a stack build command to dump the GHC Core?
I've tried this, to no avail:
stack build :hello_world --ghc-options '-ddump-simpl'

Make sure to clean before, or force recompilation via the stack option --force-dirty and ghc option -fforce-recomp.
The files are dumped somewhere around .stack-work/dist/.../build/hello_world/hello_world-tmp/.

Related

global GHC from Stack?

I have happily installed Stack, and run my code with stack ghci or stack exec and whatnot.
I would like to use vscode-haskell, and that requires a ghc available in the PATH.
Is it possible to create a ghc command available globally using stack? (e.g. some suitable commans in my powershell/bash profile)
ps. Close duplicates that did not help me are
Using stack ghc as replacement of ghc but only talks about makefiles
Haskell Stack doesn't use system Ghc is about making Stack use a system GHC if it is available which is not the case for me
Haskell stack with global ghc which is close to a dupplicate of [2]

Is there a way for `stack --nix` to allow newer versions of ghc to be used?

I'm running stack --nix init for a new project (xmonad config) and getting error: attribute 'ghc863' missing, at (string):1:43; I have ghc 8.6.5 in the environment, and stack --version reports: 2.1.3.1 x86_64 hpack-0.32.0. My project is roughly following this blog post for building XMonad (with exceptions made to do things using Nix where possible), and so far only consists of cloning the three repos into .xmonad and running stack --nix init; the three repos are: xmobar, xmonad-contrib, xmonad.
Is there a way for stack --nix to allow newer versions of ghc to be used? Or are there other possible causes for the issue?
I saw stack --nix build complains about ghc version mismatch but felt this didn't really illuminate the issue, though it does suggest possibly alternatives using cabal/nix.

Passing RTS-opts to `stack test`

How can I pass RTS options to the test-suite of my project using stack?
stack exec allows for passing options to the executable, but since stack test is a synonym for stack build --test I can't see how to accomplish this.
I'm trying to generate some JSON-formatted profiler output for my test-suite using the RTS option -pj (GHC user guide).
I can see where stack places the regular executables, but not the executables for the test-suite.

Can you have different compilers and resolvers on Stack?

I have a Stack project that can build both GHCJS and GHC binaries. How can I specify on stack.yaml that builds should use both compilers?
I think you have to either
use two different files, say ghc.yaml and ghcjs.yaml, you can then use stack --stack-yaml ghc.yaml or stack --stack-yaml ghcjs.yaml to use those
you can set the compiler ghc or ghcjs by setting the resolver (see haskellstack.org/config#resolver)
or there is a compiler option (see haskellstack.org/config#compiler)
or directly use the commandline option --compiler

Using stack for profiling

I'm trying to do some profiling using stack --enable-profiling and I'm a bit confused about what's happening exactly.
Do I need to use also --enable-library ?.
Also, is it build in a separate directory ?What happend next I build it, will remember that am I in profiling mode or do I have to use the --enable-profiling all the time.
It is generally recommended to profile in conjonction with the -O2 option. Does --enable-profiling set it automatically ?
Stack support for enabling profiling works great, example:
stack build --profile --executable-profiling --library-profiling
stack exec -- example <your prog args> +RTS -p
Then see example.prof for the default output.
Update: the stack support pointed me to the right correct for exec, see https://github.com/commercialhaskell/stack/issues/1655

Resources