Yeah unfortunately even the cost of fluid-binding a handler and releasing it on scope boundaries is considered intolerable by many users, never mind the cost of invocation (same complaint surfaces around SJ/LJ and SEH, there's just no pleasing people!)
Conversation
I think that a big part of the problem is the platform's insistence on there being a single stack (ie "THE stack") as opposed to multiple independent stacks that usually, but not always!, work in lockstep.
1
Not sure I agree. Implementation-wise we put the fluid-bound handlers in their own lists (in TLS) but those are pushed/popped on boundaries of control frames that establish handlers; dunno how to avoid that coupling.
1
1
(The way "zero cost" handlers work is to emit a static handler map, and then drive a binary search for each pc through that map while unwinding; which could also be done here, but it's much heavier engineering since it'd involve bypassing LLVM's abstraction over DW2 unwind.)
1
2
If handlers are always addressed with a symbolic selector, you can have a struct of stacks, one per handler stack. No unwinding search necessary: just lookup the field in that struct by offset of that selector.
2
1
You can also switch the execution call/return stack independently from the handler stack, enabling you to run a handler without unwinding, and you can run with whicher handler stack is more appropriate.
1
I think we're speaking across purposes here, possibly about different stacks. I'm not talking about a control stack that a handler's code runs on; I am talking about just tracking the entry and exit of the main thread from program contexts in which any given handler is active.
1
Those entry/exit events push and pop a handler-pointer from a stack of handler-pointers. Those push/pops are considered too expensive to be in the main path, by some people. Same kind of folks who object to frame pointers existing at all.
2
1
I see. Well, I'm venturing out past my toy experiments in to "real compiler" talk, where I just don't know yet. More experience necessary, I guess :)
1
Yeah, would be super interesting to see how much can be shaven off, and if that stuff actually makes a difference.
1
Been having similar discussions over here:
Quote Tweet
Replying to @brendanzab @_wilfredh and 5 others
I still wish we could figure out an almost zero-cost effect/handler system - I want this for the Next Systems Language™.


