Description
Although TLS is fast, it's not that fast on Windows and we shouldn't be hitting it on the fast path for catch_unwind
. Right now all we do this for is to reset the panic counter back to 0.
The purpose of this is to allow code like this to work, but thinking more about that I believe that's actually undefined behavior on MSVC. Basically once a panic is initiated you can't initiate another panic for... "reasons". (I'm not 100% clear myself). This definitely seems like a sketchy pattern as well!
So if we don't want to enable that pattern, I think we can get away with different management of the panic counter:
- When a panic starts, bump the panic counter. If this indicates a double panic, abort.
- When a
catch_unwind
returns from catching a panic, decrease the panic counter. (maybe assert it's 0?)
This way the normal usage of catch_unwind
where nothing panics should never hit TLS, and we should still be able to use panics as we do today.