zig icon indicating copy to clipboard operation
zig copied to clipboard

There should be a way to disable formatting in panic handlers

Open gwenzek opened this issue 3 years ago • 1 comments

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:

  1. remove all formatting code from default panic handler
  2. provide two different set of implementations with/without formatting and allow switching between them with a magic global constant in "root" ( @Vexu idea)
  3. I also thought about letting users directly override panicOutOfBound, panicSentinelMismatch and panicUnwrapError as we allow overriding panic.

@andrewrk you also said you had some ideas on the topic.

gwenzek avatar Oct 15 '22 20:10 gwenzek

I can make a PR for either 1. or 2. Please let me know what you prefer.

gwenzek avatar Oct 19 '22 18:10 gwenzek