Skip to content

Unroll factor in #[unroll] attributes should accept any const expr, not just literals #158161

Description

@Kmeakin

Related to the #![feature(loop_hints)] attributes: #156874

It would be nice if the N in #[unroll(N)] could take an arbitrary const expression, not just an integer literal:

fn foo<const UNROLL_FACTOR: usize>() {
    #[unroll(UNROLL_FACTOR)]
    loop {
        ...
    }
}

If that's not possible for technical reasons, another possibility would be a std::hint::unroll function which takes a const parameter and a closure:

fn foo<const UNROLL_FACTOR: usize>() {
    std::hint::unroll::<UNROLL_FACTOR>(|| loop {
        ...
    });
}

This would make it easier to experiment with different unroll factors without having to duplicate the same function for each unroll factor

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-attributesArea: Attributes (`#[…]`, `#![…]`)C-feature-requestCategory: A feature request, i.e: not implemented / a PR.F-loop-hints`#![feature(loop_hints)]`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