Skip to content

Profiling executables which use Template Haskell fails #5961

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

Open
snoyberg opened this issue Mar 25, 2019 · 6 comments
Open

Profiling executables which use Template Haskell fails #5961

snoyberg opened this issue Mar 25, 2019 · 6 comments

Comments

@snoyberg
Copy link
Collaborator

Repro:

$ cat EmbedString.hs 
module EmbedString (embedStr) where

import Language.Haskell.TH
import Language.Haskell.TH.Syntax (lift)

embedStr :: IO String -> ExpQ
embedStr readStr = lift =<< runIO readStr
$ cat Main.hs 
{-# LANGUAGE TemplateHaskell #-}

import EmbedString (embedStr)

main :: IO ()
main = putStr $(embedStr (readFile "Setup.hs"))
$ cat profth.cabal
cabal-version: 2.0
name:           profth
version:        0.1.0.0
build-type:     Simple

executable profth
  main-is: Main.hs
  other-modules: EmbedString
  build-depends: base, template-haskell
  default-language: Haskell2010
$ cabal new-build --enable-profiling
Resolving dependencies...
Build profile: -w ghc-8.6.4 -O1
In order, the following will be built (use -v for more details):
 - profth-0.1.0.0 (exe:profth) --enable-profiling (first run)
Configuring executable 'profth' for profth-0.1.0.0..
Preprocessing executable 'profth' for profth-0.1.0.0..
Building executable 'profth' for profth-0.1.0.0..
[1 of 2] Compiling EmbedString      ( EmbedString.hs, /Users/michael/Desktop/profth/dist-newstyle/build/x86_64-osx/ghc-8.6.4/profth-0.1.0.0/x/profth/build/profth/profth-tmp/EmbedString.p_o )
[2 of 2] Compiling Main             ( Main.hs, /Users/michael/Desktop/profth/dist-newstyle/build/x86_64-osx/ghc-8.6.4/profth-0.1.0.0/x/profth/build/profth/profth-tmp/Main.p_o )
Main.hs:6:15: fatal:
    cannot find object file ‘/Users/michael/Desktop/profth/dist-newstyle/build/x86_64-osx/ghc-8.6.4/profth-0.1.0.0/x/profth/build/profth/profth-tmp/EmbedString.dyn_o’
    while linking an interpreted expression
$ cabal --version
cabal-install version 2.4.1.0
compiled using version 2.4.1.0 of the Cabal library 
$ ghc --version
The Glorious Glasgow Haskell Compilation System, version 8.6.4
@snoyberg
Copy link
Collaborator Author

And I just remembered that this is caused by a missing other-extensions: TemplateHaskell, which fixes this problem. It would be nice to get better documentation of this, but closing.

@flip111
Copy link

flip111 commented Mar 25, 2019

Maybe some message like "did you forget to put TemplateHaskell in other-extensions" would be nice when the fatal error occurs.

@23Skidoo
Copy link
Member

Related: #4746, #1562.

@recursion-ninja
Copy link
Contributor

recursion-ninja commented Oct 24, 2019

Why do I need TemplateHaskell in the other-extensions of the .cabal file in order to build with profiling when my actual source files that use template Haskell enables TemplateHaskell via the language extension pragma?

I don't want TemplateHaskell enabled in every module of my project, only the modules that use it.
Having it enabled produces much, much worse parse error messages involving single quotes (').

@23Skidoo
Copy link
Member

23Skidoo commented Feb 7, 2020

Cabal has no knowledge of LANGUAGE pragmas used by the package, and other-extensions (unlike default-extensions) doesn't enable the extension globally, it just informs Cabal that you used it somewhere.

timds pushed a commit to SupercedeTech/yesod-auth-simple that referenced this issue Feb 2, 2021
@tomsmeding
Copy link
Collaborator

I just ran into this, trying to profile an executable with template haskell and getting the same fatal error as in the OP. The fix (adding other-extensions: TemplateHaskell) indeed works, but I would never have thought of this, because nothing in the documentation of other-extensions mentions anything related to changed semantics: it only says anything about checking GHC support, and even alludes to other-extensions being "informational". Hence, when I read the documentation for this cabal file key, I simply discarded it as not useful to me, because I use bounds on base to constrain GHC versions.

It would be great if not only the other-extensions documentation is updated to reflect its apparently fairly significant effect on what cabal does, and furthermore to detect the situation where the user specified --enable-profiling but is also using TemplateHaskell somehow. Because as a user, I have absolutely no clue how to go from "I'm using profiling and TemplateHaskell and GHC cannot find a .dyn_o file" to "let's use other-extensions", apart from using a search engine and hopefully finding this issue.

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

No branches or pull requests

6 participants