Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

viewing core when compiling with cabal

Tags:

haskell

ghc

cabal

When building my application, I would like cabal to automatically output the intermediate core to a file. I can add the -ddump-simpl flag to the cabal file's ghc-options field, but this prints everything to stdout. Is there a way I can get cabal to redirect all of this to a file?

like image 528
Mike Izbicki Avatar asked Jul 12 '14 21:07

Mike Izbicki


2 Answers

You can use -ddump-to-file and GHC will write to files with names like foo.dump-simpl, etc for the other debugging options. If you put it in your cabal file I believe it will dump them at the top level of your project.

like image 57
jberryman Avatar answered Oct 30 '22 10:10

jberryman


Since this question was written, cabal has changed quite a lot, with the biggest change being the switch to nix-style builds. The directory structure for nix-style builds is very different (and much more deeply nested) from the old structure. The structure also isn't intended to be part of the API, and so may change at any time. Below I describe the structure for current cabals (around version 3.4), but probably the right way to get this information is to add a feature to cabal itself that will tell you the right path. (An example of this kind of feature is the list-bin command for finding a particular executable within dist-newstyle.)

Anyway, after you add ghc-options: -ddump-simpl -ddump-to-file to an executable or library stanza in a cabal file, here's where you want to look for named components:

dist-newstyle/build/<arch>-<os>/<compiler>/<this package>-<version>/<component type>/<component name>/build/<dumped package>/<don't know what this one is>

And here's where you want to look for the main library component:

dist-newstyle/build/<arch>-<os>/<compiler>/<this package>-<version>/build

The directory structure in those locations will mimic the directory structure in the dumped package, with dumped files being named things like ModuleName.dump-simpl. (If you use other -ddumps than -ddump-simpl they will of course be in files with appropriately modified names.)

The name components I referred to above explained:

arch: The architecture of the computer you are building on. (Dunno what happens in cross compilation -- any source divers want to take a stab?) For most people, this will be x86_64.
os: The operating system of the computer you are building on. For me this is linux.
(For the above two components, the vast majority of the time there will be just one directory there anyway, so tab-completion should get you where you need to go.)
compiler: This is the fully-version-expanded name of the executable, e.g. ghc-8.10.4.
this package: The name of the package you are currently building.
version: The version of the package you are currently building.
component type: This is x for executables, l for libraries, or t for test suites.
component name: The name of the executable, library, or test suite.
dumped package: The name of the package whose cabal file you modified to add -ddump flags. Usually this is the same as this package.
don't know what this one is: In my very simple tests, this was always the same as the component name, and there was only ever one directory at this level. But I don't know what could cause that to change.

like image 29
Daniel Wagner Avatar answered Oct 30 '22 11:10

Daniel Wagner