On 4/29/21 5:39 PM, Edward Catmur via Std-Proposals wrote:
> On Thu, 29 Apr 2021 at 13:28, Andrey Semashev via Std-Proposals
> Presumably, someone has to tell the runtime to collect the stacktrace,
> and, if I understood you right, that someone is supposed to be the
> compiler, which sees a std::current_exception_stacktrace call in the
> catch block.
>
> Yes? That sounds entirely feasible.
No, it doesn't sound feasible at all. At least, not with current
compiler technology. And in case if you bring up link-time code
generation, no, it is not the answer. As any other optimization, it is
entirely optional and must not affect the program behavior.
Quick sketch: the compiler sets a directive at the catch site to request stacktrace, which the personality routine observes and allocates a stacktrace array reachable via the __cxa_exception, then when it is called again in unwind phase it populates. What's wrong with this technique? Obviously you need a new directive (or bit flag on an existing directive) which the compiler can emit and the runtime recognize, but they're supplied by the same vendor so I can't see that as an obstacle.
Also, the argument of "let's make exceptions slower because they're slow
anyway" doesn't work. Clearly, people care about their performance, and
a non-trivial amount of effort was spent to optimize them, even though
most of the time they are not on the hot path.
My understanding is that effort has been spent to optimize the non-exceptional path.