Re: [Haskell-cafe] HasCallStack - runtime costs?

Eric wrote earlier:
If you import a function with a HasCallStack constraint there's no way to disable the overhead ...
For non-recursive functions like head and tail, the overhead is probably not large enough to be noticeable.
Now I'm confused: should this mean that head and tail are "functions with a HasCallStack constraint"? If I ask ghci for their type, it just says head :: [a] -> a and that's also what's in the source https://downloads.haskell.org/~ghc/8.0.1-rc2/docs/html/libraries/base-4.9.0.... but the Callstack explanation in the user manual does show a different version of head https://downloads.haskell.org/~ghc/8.0.1-rc2/docs/html/users_guide/glasgow_e... I am not particularly concerned about head and tail here but generally about how to find out whether my code is taking a performance penalty. I think the documentation (user manual Section 9.31) is rather brief about the semantics. It speaks about solving "HasCallStack" constraints - but they could also be propagated? There is secondary documentation like https://ghc.haskell.org/trac/ghc/wiki/ExplicitCallStack but it does not tell what is actually implemented, or I don't see it. - J.W.

I think the documentation for HasCallStack is not quite correct. As far as I understood, head and tail are not changed to contain call stacks as this would indeed carry a performance-penalty. Maybe the documentation should call the function myHead to distinguish it from the library function. The user-manual also uses errorWithCallStack, but I think base calls this function just error and adds errorWithoutStackTrace (at least thats what I find in https://downloads.haskell.org/~ghc/8.0.1-rc2/docs/html/libraries/base-4.9.0....). On 03/07/2016 06:21 PM, Johannes Waldmann wrote:
Eric wrote earlier:
If you import a function with a HasCallStack constraint there's no way to disable the overhead ...
For non-recursive functions like head and tail, the overhead is probably not large enough to be noticeable.
Now I'm confused: should this mean that head and tail are "functions with a HasCallStack constraint"? If I ask ghci for their type, it just says head :: [a] -> a and that's also what's in the source https://downloads.haskell.org/~ghc/8.0.1-rc2/docs/html/libraries/base-4.9.0.... but the Callstack explanation in the user manual does show a different version of head https://downloads.haskell.org/~ghc/8.0.1-rc2/docs/html/users_guide/glasgow_e...
I am not particularly concerned about head and tail here but generally about how to find out whether my code is taking a performance penalty.
I think the documentation (user manual Section 9.31) is rather brief about the semantics. It speaks about solving "HasCallStack" constraints - but they could also be propagated? There is secondary documentation like https://ghc.haskell.org/trac/ghc/wiki/ExplicitCallStack but it does not tell what is actually implemented, or I don't see it.
- J.W.
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe

On Mon, Mar 7, 2016, at 09:21, Johannes Waldmann wrote:
Eric wrote earlier:
If you import a function with a HasCallStack constraint there's no way to disable the overhead ...
For non-recursive functions like head and tail, the overhead is probably not large enough to be noticeable.
Now I'm confused: should this mean that head and tail are "functions with a HasCallStack constraint"? If I ask ghci for their type, it just says head :: [a] -> a and that's also what's in the source https://downloads.haskell.org/~ghc/8.0.1-rc2/docs/html/libraries/base-4.9.0.... but the Callstack explanation in the user manual does show a different version of head https://downloads.haskell.org/~ghc/8.0.1-rc2/docs/html/users_guide/glasgow_e...
I am not particularly concerned about head and tail here but generally about how to find out whether my code is taking a performance penalty.
I think the documentation (user manual Section 9.31) is rather brief about the semantics. It speaks about solving "HasCallStack" constraints - but they could also be propagated? There is secondary documentation like https://ghc.haskell.org/trac/ghc/wiki/ExplicitCallStack but it does not tell what is actually implemented, or I don't see it.
I'm sorry for the confusion, to be clear a function only gets a call-stack if it has a HasCallStack constraint in its type. I used head as an example of a function that you might want to give a call-stack, but base *does not* do this at the moment. GHC will infer HasCallStack constraints for functions as it would infer class constraints, but I have a mostly-done patch to disable this inference for top-level functions, it should make it in to the final 8.0 release. I'll try to expand the documentation as well, perhaps some more examples would help? Thanks, Eric
participants (3)
-
Eric Seidel
-
Johannes Waldmann
-
Jonas Scholl