Skip to content

Per-module control of overflow checks? #70358

Open
@RalfJung

Description

@RalfJung

For arithmetic that happens inside Miri, I am quite paranoid that we may have an overflow issue, so I spent a lot of time last week-end to go over every occurrence of +/-/* and replace them all by checked_* operations. That has not made code more readable, and I am worried I might have missed some cases.

I am not sure if enabling overflow checks for all of rustc is realistic, so it would be great if that could be controlled on a per-module level: if I could set something like #![enable_overflow_checks] in the interpreter modules, I could sleep much more soundly as I would be sure we'd not have silently overflowing arithmetic -- and I wouldn't have to make the code unreadable by turning (x * 2) + 1 into x.checked_mul(2).unwrap().checked_add(1).unwrap().

Overflow checks are embedded into MIR, and it seems entirely possible to take module-level attributes into account during MIR building, so I think this is realistic.

(I am not sure if this should go into this repo or the RFC repo, feel free to move around.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-feature-requestCategory: A feature request, i.e: not implemented / a PR.T-langRelevant to the language 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