Skip to content

Range<usize>::next should fully MIR-inline #130590

Closed
@scottmcm

Description

@scottmcm

If you compile this to optimized MIR:

// @compile-flags: -O -C debuginfo=0 --emit=mir -Z inline-mir-threshold=9999 -Z inline-mir-hint-threshold=9999
use std::ops::Range;
#[no_mangle]
pub fn demo(num: &mut Range<usize>) -> Option<usize> {
    num.next()
}

https://rust.godbolt.org/z/zsh6b6Y8n

You'll see that it still contains a call to forward_unchecked:

    bb1: {
        _3 = copy ((*_1).0: usize);
        StorageLive(_4);
        _4 = <usize as Step>::forward_unchecked(copy _3, const 1_usize) -> [return: bb2, unwind continue];
    }

That's pretty unfortunate, because forward_unchecked(a, 1) is just AddUnchecked(a, 1), a single MIR operator.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-MIRArea: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.htmlA-mir-opt-inliningArea: MIR inliningC-optimizationCategory: An issue highlighting optimization opportunities or PRs implementing suchT-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