Daily Thought - 2024-08-30
< back to listOkay, so there are cases where call stack reconstruction won't work without further information. These cases can be detected at compile-time, so we can probably rely on the compiler to make sure we get the information we need.
Here's my idea: When the compiler detects such a case, it emits a special instruction that, when executed at runtime, leaves a hint on the call stack. It can't just do so unconditionally, because then we get unbounded stack growth in the presence of recursion. Just what tail call elimination is supposed to avoid in the first place.
So the instruction will have to check the stack first, and only add a hint if one isn't already there. This means there's going to be some performance overhead. I don't want to take this lightly. I want Caterpillar to work for a broad range of use cases, and that means it needs to be fast. But some overhead is acceptable, if it improves developer experience.