There should be a way to disable formatting in panic handlers
Currently it's possible to override the default panic handler, but not panicOutOfBound, panicSentinelMismatch
nor panicUnwrapError which are typically calling panic.
The issue I have with this is that those are calling std.fmt.format to provide nice error messages. Even though it's nice in the general case, there are some platform were this has unintended consequences.
On PTX (Nvidia GPU) backend, the GPU driver need to know the memory needed for a given kernel. Since panicOutOfBound calls std.fmt.format which can also panic, there is a "possible" infinite loop which trips up the static analyzer.
The results is that the driver allocates too much memory for a kernel, which means that most non-trivial kernel fail to launch, because they don't have enough memory. Current workaround is using releaseFast, but it would be nice to be allow to run with releaseSafe.
This issue also has been mentioned previously by Andrew in https://github.com/ziglang/zig/pull/12807#issuecomment-1247285968
I'd like to discuss the possible solutions:
- remove all formatting code from default panic handler
- provide two different set of implementations with/without formatting and allow switching between them with a magic global constant in "root" ( @Vexu idea)
- I also thought about letting users directly override
panicOutOfBound,panicSentinelMismatchandpanicUnwrapErroras we allow overridingpanic.
@andrewrk you also said you had some ideas on the topic.
I can make a PR for either 1. or 2. Please let me know what you prefer.