Runtime Haskell interpreter

#9Segmentation fault for compiled programs when large module is imported in an interpreted script

I'm not sure if the size of the module is the criteria which triggers the segmentation fault, but I experienced this while loading a .hs file which imported Graphics.XHB (only for types).

The program works fine when run in ghci, but if I build an executable with ghc --make the program will segfault while the interpreter is running.

If necessary, I can try to provide a minimal example.

  • If you are experiencing a segmentation fault then it is most likely that some of the .hs files you are loading is also being used to compile your application and, in particular, that modules define one or more types that are involved in the expression then being interpreted.

    The problem is that this type has two incompatible representations: 1) the one in the compiled code and 2) the one in the interpreted code, and when interpreting the expression that leads to the segmentation fault, the latter is used as if it were the former.

    The rule of thumb is: never make the interpreter run on the directory with the source code of your program! If you want to use in your interpreted code some type that is defined in your program, then put the defining module on a library and make your program depend on that package.

    • status set to closed

    Thank you very much for your hint. After moving the source for the interpreted modules to a different package and installing it as a library, everything works fine now!

    Maybe this could be added somewhere in the documentation as a note for future users of the hint package?

  • I have the same issue and I'm guessing for the same reasons. I'd really like to avoid splitting my code over multiple packages. Is there another way to structure my code to avoid segmentation faults?

  • @sigfpe: not that I know of. You could try to play with ghc arguments to see if you can force it to generate binary code for the interpreted code, so that you get the same representation for the compiled and interpreted version of your types. If you make it work, please shrare