Repository navigation
Closed
Labels
IR-loweringLowering between dialects (dialect-mir to LLVM dialect)QoL-improvementQuality-of-life improvement; not a correctness fixcodegenDevice code-generation pipeline (Rust MIR to IR to PTX)testsAdds or improves test coveragetrackingUmbrella tracking issue
Description
Summary
There are existing TODOs requesting unit test coverage for MIR to LLVM conversion code paths. This issue tracks correcting those TODOs by adding focused regression tests for conversion behavior that is currently implemented but not explicitly covered.
Scope
Add unit tests for:
-
Constant conversion
- Integer constants preserve their bit pattern.
- Integer constants lower to signless LLVM integer types.
f32andf64constants preserve their floating-point attributes.- MIR-specific
f16attributes are rewritten to the LLVM half attribute representation.
-
Aggregate conversion
- Slice construction lowers to the canonical
{ ptr, len }aggregate layout. - Struct construction respects explicit layout slots and skips zero-sized fields.
- ZST field extraction does not emit
llvm.extractvalue. - Enum construction uses the declared discriminant value rather than the variant index.
- Slice construction lowers to the canonical
-
Cast conversion
- Signed integer widening lowers to
llvm.sext. - Unsigned integer widening lowers to
llvm.zext. - Integer narrowing lowers to
llvm.trunc. - Unsigned integer to float lowers to
llvm.uitofp. - Float to signed integer lowers through the saturating intrinsic.
- Pointer address exposure lowers to
llvm.ptrtoint.
- Signed integer widening lowers to
Motivation
These tests make the lowering behavior explicit and protect several nontrivial semantic details:
- Rust/MIR signedness should not leak incorrectly into lowered LLVM integer constants.
- Explicit struct layout and padding must be preserved.
- Zero-sized types should not produce storage-based extract operations.
- Enum discriminants must use their declared bit-pattern values.
- Cast lowering must select the correct LLVM operation or intrinsic based on source and destination types.
Acceptance criteria
- The TODOs for constant, aggregate, and cast conversion tests are resolved.
- The new tests pass with
cargo test. - The tests validate observable lowered LLVM operations and attributes rather than only checking that lowering succeeds.
Metadata
Metadata
Assignees
Labels
IR-loweringLowering between dialects (dialect-mir to LLVM dialect)QoL-improvementQuality-of-life improvement; not a correctness fixcodegenDevice code-generation pipeline (Rust MIR to IR to PTX)testsAdds or improves test coveragetrackingUmbrella tracking issue
Activity
honeyspoon commentedon Jul 24, 2026
All items in the scope section appear to be covered by tests on
main:convert_integer_preserves_bits_and_makes_type_signlessconstants.rs:242convert_f16_constant_rewrites_mir_attr_to_builtin_half_attrconstants.rs:312convert_f32_constant_preserves_float_attr,convert_f64_...constants.rs:255, 283construct_slice_lowers_to_ptr_len_insert_valuesaggregate.rs:1578extract_field_from_zst_does_not_emit_extractvalueaggregate.rs:1703construct_enum_uses_declared_discriminant_not_variant_indexaggregate.rs:1766int_to_int_signed_widen_lowers_to_s_extcast.rs:1189int_to_int_unsigned_widen_lowers_to_z_extcast.rs:1200int_to_int_narrow_lowers_to_trunccast.rs:1211int_to_float_unsigned_lowers_to_ui_to_fpcast.rs:1222float_to_int_signed_lowers_to_saturating_intrinsic_callcast.rs:1233cast.rs:1250cast.rs:1250These tests are in
crates/mir-lower/src/convert/ops/{constants,aggregate,cast}.rsand validate observable lowered LLVM operations and attributes as described in the acceptance criteria. This issue may be closable.nihalpasham commentedon Sep 3, 2026
Every item in the scope table has a test on main (constants.rs, cast.rs, aggregate/{construct,fields,enums}.rs) and no TODO is left in mir-lower. Closing as completed.
doc: add DGX Spark tutorial and refine book prose (NVIDIA#303)