Virtual stack-trace of function applications
We want to keep track of a 'virtual' stack trace so that we can give the current trace if we encounter an error during run-time.
We return the arguments or return values to avoid code-reordering from messing with the location of these stack pushes and pops.
x1', .., xn' = _virtual_stack_push_ (x1, .., xn, "foo signature");
res1, .., resm = foo (x1', .., xn');
res1', .., resm' = _virtual_stack_pop_ (res1, .., resm);
Optionally, we might also be able to use this notation to construct a stack trace for compile time errors. But that is something we should figure out in the future, first we must investigate whether this will even work as intended.
We might consider multiple tracing levels:
- No stack trace; used for performance-critical applications
- Trace user-defined function applications (even inlined ones); used for printing the stack trace of e.g. type checking, ecc, or type pattern errors
- Trace all function applications (even generated ones); useful for people debugging the compiler
For the two new function we might be able to reuse NUMVARIABLERETS
and CONTEXTSTRING
from the guard primitive.