CallStack naming
Eric Seidel
eric at seidel.io
Wed Jan 27 18:16:14 UTC 2016
On Thu, Jan 21, 2016, at 04:07, Simon Peyton Jones wrote:
> | It’d probably need a built-in function
> |
> | setCallStack :: CallStack -> (AppendsCallStack => a) -> a
>
> Correct. This is easy to write in Core but not in Haskell.
Ugh, I just realized that we can't write setCallStack (with implicit
parameters) in Haskell either. Well, we can, but it adds an entry to the
stack.. Why? Let's look at the implementation
setCallStack :: CallStack -> (HasCallStack => a) -> a
setCallStack stk do_this =
let ?callStack = stk in do_this
Rebinding ?callStack works just fine, but the occurrence of do_this
causes GHC to push an entry onto the stack, which is less than ideal.
What does this look like in practice? If we evaluate
setCallStack foo (error "die")
the resulting stack will be
error
*do_this*
foo
The rebinding trick works for withFrozenCallStack precisely because we
freeze the CallStack, so the push from do_this is ignored.
So, long story short, I'm not convinced of the utility of setCallStack.
I think perhaps we should not provide it, and just do the rebinding
trick inside withFrozenCallStack (which was the only use-case for
setCallStack to begin with).
More information about the ghc-devs
mailing list