Skip to content

fix(rustlantis): validate place projections against LocalDecls - #1263

Merged
nihalpasham merged 2 commits into
NVIDIA:mainfrom
sachinsharma3191:fix/1160-rustlantis-place-validation
Sep 18, 2026
Merged

nihalpasham merged 2 commits into
NVIDIA:mainfrom
sachinsharma3191:fix/1160-rustlantis-place-validation

Conversation

@sachinsharma3191

@sachinsharma3191 sachinsharma3191 commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

What this adds

Rustlantis now checks projection chains when it constructs a place. An invalid array index or field path is reported by the generator, before it can become a misleading backend compilation failure.

before: arr[index_i32] becomes custom MIR and fails in rustc
after:  place construction reports NonUsizeIndexLocal

This is defensive hardening. No existing generated seed has been shown to require it.

What changed

  • Construction uses the current body's LocalDecls, including the existence and usize type of index locals.
  • One type-projection implementation checks pointers, tuple/struct fields, array constant indices and enum variant fields.
  • Failed extensions leave the original place intact. Generator graph paths use the checked constructor.
  • I rebased and signed the contributor commits, preserving authorship and sign-offs. The first commit is shared with fix(rustlantis): drop the removed box_patterns feature gate #1262.

Verification

Checked at 21d460fe:

  • All 38 tests in the affected Rustlantis workspace packages pass; formatting is clean.
  • Disabling just index-local validation makes both real-generator-path rejection tests fail. The valid usize control passes with validation enabled.
  • Generated output is byte-identical before/after for seeds 0–199 under both the tiny adapter config and the full example config.
  • Hosted CI also passes on this head.

The workspace test run excludes difftest, whose external compiler/Miri configurations are separate. Existing vendored Clippy and rustdoc warnings remain; strict Clippy stops in unchanged abi/src/size.rs.

Closes #1160 as defensive construction validation. Depends on #1262.

nightly-2026-08-28, pinned in NVIDIA#1201, removed the `box_patterns` feature,
so the vendored `mir` crate fails with E0557 and neither `generate` nor
`tools/mir_generator.py` builds. Nothing in the crate uses box patterns.
The rustlantis workspace is not built in CI, so the break went unnoticed.

Signed-off-by: sachin <sachinsharma3191@gmail.com>
`Place::from_projected` and `Place::project` now validate against the
body's `LocalDecls` and return a `ProjectionError`, so a malformed chain
fails where the generator builds it rather than in the emitted custom MIR,
where rustc rejects it (or ICEs on a bad downcast) and `run_seed.py`
records a backend COMPILE_FAIL.

- `Index` must name a declared `usize` local.
- Projection type rules live in `TyId::project_one`, shared by
  `projected_ty` and construction: deref of a pointer, tuple/struct field
  bounds, `Field` only on structs, array (constant) indexing, and
  `DowncastField` variant/field bounds and stored field type.
- `PlacePath::to_place` and `PlaceSelector::into_iter_place` take the
  current body's `LocalDecls`; `to_place` panics on an invalid path.
- `project` leaves the place unchanged on error.

Generated programs are byte-identical to before for the sampled seeds.
Tests cover the `to_place` path (non-usize and undeclared index locals,
plus a valid control) and each rejection in `mir`.

Signed-off-by: sachin <sachinsharma3191@gmail.com>
@nihalpasham
nihalpasham force-pushed the fix/1160-rustlantis-place-validation branch from 47efb61 to 21d460f Compare September 18, 2026 03:49
@nihalpasham nihalpasham added enhancement New feature or request Depends Blocked on another PR/issue or an upstream dependency tests Adds or improves test coverage fuzzer Fuzzing infrastructure (rustlantis, difftest) labels Sep 18, 2026

@nihalpasham nihalpasham left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kept the validation against the body's actual local declarations and rebased and signed the contributor commits.

The projection rules have one owner, and a failed extension leaves the original place unchanged. All 38 affected workspace tests pass; disabling index-local validation makes both generator-path regressions fail. Seeds 0–199 also stay byte-identical under both configs. Existing vendored lint warnings remain.

This addresses #1160 as defensive validation: it catches malformed generator state earlier, without claiming an existing generated miscompile. #1262 is the build prerequisite.

Checked at 21d460fe. Hosted CI also passes on this head.

@nihalpasham
nihalpasham merged commit 0cb2814 into NVIDIA:main Sep 18, 2026
54 checks passed
@nihalpasham nihalpasham removed the Depends Blocked on another PR/issue or an upstream dependency label Sep 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request fuzzer Fuzzing infrastructure (rustlantis, difftest) tests Adds or improves test coverage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

rustlantis: validate projection chains when constructing places

2 participants