Skip to content

fix(mir-lower): support packed AS3 field projections through carrier locals - #1092

Closed
uurl wants to merge 1 commit into
NVIDIA:mainfrom
uurl:fix/packed-as3-local-slots
Closed

uurl wants to merge 1 commit into
NVIDIA:mainfrom
uurl:fix/packed-as3-local-slots

Conversation

@uurl

@uurl uurl commented Aug 20, 2026 •

Copy link
Copy Markdown
Contributor

Closes #1036

Summary

Support local materialization and field projections for the deliberately narrow packed-AS3 shape introduced by the internal device ABI work.

Eligible packed locals now use a target-stable carrier representation:

semantic <{ scalar, p3 }>
        |
        | store coercion
        v
carrier  <{ scalar, p0 }>

Loads reconstruct the semantic value in the opposite direction.

Field projections from those locals are addressed directly through the carrier slots. An AS3 pointer field therefore physically loads/stores as p0 and is explicitly converted between p0 and p3 at the semantic boundary.

Arbitrary packed-AS3 memory remains fail-closed.

Implementation

Local carrier admission

Add a dedicated packed_shared_local_storage_info gate for local storage.

The local-storage gate is intentionally independent of the internal ABI classifier:

  • packed struct root;
  • exactly one direct AS3/shared pointer field;
  • all remaining non-ZST fields scalar;
  • no recursive aggregates;
  • no arrays or vectors;
  • no multiple shared-pointer leaves.

Keeping this gate independent prevents future widening of the internal device ABI classifier from implicitly widening local-storage support.

Local allocation

mir.alloca uses the target-stable carrier type for eligible packed-AS3 locals:

<{ scalar, p3 }>  semantic type
<{ scalar, p0 }>  physical local storage

Whole-value local stores and loads

Stores into compiler-owned carrier locals coerce the semantic packed value to the target-stable storage representation before emitting llvm.store.

Loads use the physical carrier type and reconstruct the semantic packed value after llvm.load.

The existing fail-closed path is preserved for arbitrary packed-AS3 memory.

Field projections

mir.field_addr recognizes an eligible carrier-backed local and emits a typed GEP through the carrier struct.

This keeps field addressing by-slot while preserving the existing rustc byte-offset fallback for ordinary packed aggregates.

For the AS3 field:

projected load:   p0 -> addrspacecast -> p3
projected store:  p3 -> addrspacecast -> p0

The projected load/store path uses operand type history to distinguish the semantic MIR pointee from the physical carrier pointee.

End-to-end regression

Strengthen packed_aggregate_abi so consume_packed_shared actually projects both fields from the returned packed value.

The test now:

  • reads value.tag;
  • reads value.ptr;
  • writes shared memory through the round-tripped value.ptr;
  • observes the mutation through the independently passed raw shared pointer.

This makes broken carrier-to-semantic reconstruction observable at runtime, while the lowering tests independently cover the inverse projected-store conversion.

Tests

Added lowering coverage for:

  • carrier allocation for an eligible packed-AS3 local;
  • whole-value semantic -> carrier store;
  • projected pointer-field p0 -> p3 load;
  • projected pointer-field p3 -> p0 store;
  • carrier pointer storage remaining in generic address space.

Validation performed:

cargo fmt --all -- --check
git diff --check

cargo test -p mir-lower --all-targets
cargo clippy -p mir-lower --all-targets -- -D warnings

cargo oxide run packed_aggregate_abi

Results:

mir-lower unit tests: 254 passed
lowering tests:       117 passed
clippy -D warnings:   pass
packed_aggregate_abi: pass on sm_120a

Out of scope

This PR intentionally does not add support for:

  • kernel-entry ABI changes;
  • device-global packed AS3 storage;
  • arbitrary packed-AS3 memory;
  • recursive or nested AS3 local projections;
  • multiple AS3 pointer leaves;
  • AS3 pointer arrays;
  • AS3 pointer vectors;
  • AS3-containing enums.

Those remain separate work.

@nihalpasham nihalpasham added declined PR intentionally not merged (closed without merging) codegen Device code-generation pipeline (Rust MIR to IR to PTX) IR-lowering Lowering between dialects (dialect-mir to LLVM dialect) miscompile Produces incorrect PTX/IR (wrong generated code) safety Memory safety, soundness, or undefined behavior labels Aug 24, 2026
@nihalpasham

nihalpasham commented Aug 24, 2026 •

Copy link
Copy Markdown
Collaborator

Closing this PR because the packed-AS3 carrier rule is incomplete and can generate wrong code.

  • The change rewrites eligible AS3 storage to an AS0 carrier, but recovers that carrier identity only from a small set of defining operations.
  • Passing the pointer through a call or block argument means carrier recognition can no longer be recovered. A later field projection then treats AS0 carrier storage as AS3 storage.
  • The active Preserve Rust reference kind and exclusivity through MIR import and lowering #413 pointer-contract work supplies the semantic type and layout foundation a replacement must use; it does not itself implement this packed-AS3 fix.

A replacement needs to address the full pointer path and include call, block-argument, cast, and projection controls, consistent with the acceptance criteria announced on Discord.

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

Labels

codegen Device code-generation pipeline (Rust MIR to IR to PTX) declined PR intentionally not merged (closed without merging) IR-lowering Lowering between dialects (dialect-mir to LLVM dialect) miscompile Produces incorrect PTX/IR (wrong generated code) safety Memory safety, soundness, or undefined behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support field projections of packed aggregates containing address-space 3 pointers

2 participants