Changes between Version 13 and Version 14 of ExplicitCallStack/ImplicitLocations


Ignore:
Timestamp:
Feb 3, 2016 6:04:12 PM (4 years ago)
Author:
gridaphobe
Comment:

add a section about setCallStack, and why we can't implement it in haskell

Legend:

Unmodified
Added
Removed
Modified
  • ExplicitCallStack/ImplicitLocations

    v13 v14  
    224224  return (parseConfig s)
    225225}}}
     226
     227
     228== Generalizing to `setCallStack` ==
     229
     230It would be nice to generalize the rebinding trick above to a function
     231
     232{{{
     233setCallStack :: CallStack -> (HasCallStack => a) -> a
     234}}}
     235
     236that overrides the callstack for the sub-computation.
     237
     238Unfortunately we can't write this function in Haskell (though we could easily write it in Core).. Why? Let's look at the implementation
     239
     240{{{
     241setCallStack :: CallStack -> (HasCallStack => a) -> a
     242setCallStack stk do_this =
     243  let ?callStack = stk in do_this
     244}}}
     245
     246Rebinding `?callStack` works just fine, but the occurrence of `do_this`
     247causes GHC to push an entry onto the stack, which is less than ideal.
     248
     249What does this look like in practice? If we evaluate
     250
     251{{{
     252setCallStack foo (error "die")
     253}}}
     254
     255the resulting stack will be
     256
     257{{{
     258  error
     259  *do_this*
     260  foo
     261}}}
     262
     263The rebinding trick works with `freezeCallStack` precisely because we
     264freeze the CallStack, so the push from `do_this` is ignored.
    226265
    227266= Alternate Proposal =