Skip to content

Add primop to annotate the call stack with arbitrary data

Hannes Siebenhandl requested to merge wip/fendor/ann-frame into master

Closes #26218 (closed)

We introduce a new primop annotateStack# which allows us to push arbitrary data onto the call-stack. This allows us to extract the data later when decoding the stack, for example when an exception is thrown, showing more information to the user without having to annotate the full call-stack with HasCallStack constraints.

A new stack frame value is introduced AnnFrame, which consists of nothing but a generic payload.

The primop has a small wrapper API that allows users to annotate their call-stack in programs. There is a pure API and an IO-based one. The former is a little bit dubious, as it affects the evaluation of a program, so use with care. The latter is "safe", as it doesn't change the evaluation of the program.

The stack annotation mechanism is similarly implemented to the ExceptionAnnotation and Exception, there is a typeclass to indicate something can be pushed onto the call-stack and all values are wrapped in the existential SomeStackAnnotation, which recover the type of the annotation payload.

There is currently no builtin way to show the stack annotations when Backtraces are displayed (i.e., when showing stack traces to the user), which we will address in a follow-up MR.

Merge request reports

Loading