Skip to content

Recognize range-based for loops in #[unroll] (start with 0..const) #557

Closed

Description

@Ayush7614

Summary

#[unroll] / #[unroll(N)] are shipped and macros already inject markers on `for` loops, but `mir-transforms` only recognizes counted `while` shapes. Idiomatic `#[unroll] for i in 0..N` is therefore a silent no-op (warn + skip) after Range desugars to Option / discriminant exits.

Proposed scope

  1. Canonicalize or extend induction so post-import `for i in 0..CONST` (exclusive Range, step +1) is recognized as a counted loop.
  2. Reuse existing full-unroll path once `LoopRecurrences` is filled.
  3. Unit tests in `mir-transforms` (fixtures + unroll e2e); update pass docs.
  4. Prefer warning clearly when a `for` is annotated but still unrecognized.

Acceptance criteria

  • `mir-transforms` tests: `0..const` for-shaped (or canonicalized) loop fully unrolls
  • Existing while unroll tests still pass
  • Docs no longer claim for-loops are never recognized (for the shipped subset)

Out of scope

`step_by`, inclusive `..=`, arbitrary iterators, runtime-only bounds without partial unroll follow-up.

Activity

  1. nihalpasham commented on Jul 30, 2026

    @nihalpasham
    Collaborator

    Closing - refer to #559

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions