Skip to content

There should be a way to disable formatting in panic handlers #13174

@gwenzek

Description

@gwenzek

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 #12807 (comment)

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    acceptedThis proposal is planned.proposalThis issue suggests modifications. If it also has the "accepted" label then it is planned.standard libraryThis issue involves writing Zig code for the standard library.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions