Profiling TH splices with stack (aka: GHC env files from stack ?)

I need to benchmark some functions generated with template-haskell.

Luckily I found this guide by @bgamari that uses cabal : Profiling Template Haskell splices - Well-Typed: The Haskell Consultants

Part of the trick relies on getting cabal to output environment files (package names, versions/hashes) with the `–write-ghc-environment-files=always` flag. I cannot find an equivalent flag in stack. Is there a workaround?

Did anyone face this rather specific problem before? Thanks in advance

2 Likes

An alternative to using the environment file is just passing all the flags that stack would manually. Run stack with a higher verbosity and that should print out the ghc invocations. Then, you can use the same flags needed to compile your module with the additional options Ben described. Perhaps add -fforce-recomp too, to be sure :wink:

1 Like

It seems that you want to profile the generated program? If so, you can compile with -fprof-late and use normal profiling methods.

2 Likes

Ah well caught. Ben’s method is for profiling the execution of the splice itself, not for profiling the execution of the expression produced by executing the splice

Ah, yes of course. Thank you and apologies for the confusion!

One day I might be also interested in profiling the compilation itself, it’s a little compiler inside a QuasiQuoter, but for now I care only about the generated programs.

1 Like

I looked at the output of stack runghc -- Setup.hs configure --help and stack runghc -- Setup.hs build --help (with Cabal-3.12.1.0 - GHC 9.10.3), and can’t see that Cabal (the library) provides a documented --write-ghc-environment-files option. As Stack builds with Cabal, Cabal support may be a prerequisite for Stack support.