Skip to content

Revise semantics and implementation of #[rustc_inherit_overflow_checks]. #35310

Closed
@eddyb

Description

@eddyb

As of #35300, two places in MIR trans look for overflowing operations used when overflow checks are off.
Such operations are then assumed not to overflow, effectively changing semantics on-the-fly.

This is done so that the functions marked #[rustc_inherit_overflow_checks] in libcore can be used cross-crate (e.g. generics over arithmetic traits like Add) and use the overflow checks only when enabled.

A better approach would be to run a pass on the inlined MIR itself to remove these operations.
This would let alternative backends get away without reproducing all of the logic to elide overflow checks.

There's also the possibility of distributing multiple libstd versions, one with overflow checks enabled, and one without, or build such versions on demand, but that is longer-term (cc @rust-lang/infra).

cc @rust-lang/compiler

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-MIRArea: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.htmlC-cleanupCategory: PRs that clean code up or issues documenting cleanup.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions