Skip to content
This repository was archived by the owner on Sep 12, 2024. It is now read-only.
This repository was archived by the owner on Sep 12, 2024. It is now read-only.

no-panic as a language feature #49

Open
@yaahc

Description

@yaahc

A common request I see is for the ability to require that the compiler prove a function can't ever panic. There are already libraries / tools that provide functionality like this.

As I see it we need to answer the following questions:

  • What are the use cases of no-panic?
  • What are the use cases for which no-panic and rustig are insufficient? (or, How do we benefit by making this a language feature?)
    • ???

As well as resolve the following issues:

  • interaction with optimizations
    • Frequently the codepaths in question that people wish to assert don't panic do have panics present which are removed when the optimizer is able to prove that they're unnecessary. This severely limits how we can implement this feature, since we'd need to check if there are still panics very late in the compilation pipeline. no-panic handles this by using linker shenanigans to produce an error when panics are still compiled in. rustig handles this by analyzing the final generated binary. It's unclear which strategy we'd follow when implementing this as a language feature.
    • Existing implementations don't work at all when panics are set to abort instead of unwind
    • The existing implementations make it so you can no longer compile in debug mode, or that you must enable some optimizations in debug mode.
  • interaction with stability guarantees
    • By making compiler errors depend on optimizations we risk introducing significant stability hazards. Changing a function such that the compiler can no longer prove that it doesn't panic or even introducing a panic would break code that previously successfully asserted that said function does not panic. It may be that we could never make this feature available except on nightly since using it would also effectively be opting into treating existing non-breaking changes as breaking changes.

And here are some previous discussions related to this topic:

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions