Skip to content

Add representative unit tests for MIR cast lowering #301

Closed

Description

@uurl

Problem

crates/mir-lower/src/convert/ops/cast.rs still has a TODO for unit tests around cast conversion.

Cast lowering has many semantic branches and high combinatorial surface area, so this issue should not attempt exhaustive coverage of every source/destination type pair. The goal is to resolve the TODO by adding a small set of representative unit tests that lock down the most important dispatch paths.

Scope

Add focused unit tests for representative mir.cast lowering cases, including:

  • signed integer widening -> llvm.sext
  • unsigned integer widening -> llvm.zext
  • integer narrowing -> llvm.trunc
  • unsigned integer to float -> llvm.uitofp
  • signed float to integer -> saturating llvm.fptosi.sat.* intrinsic call
  • pointer expose address -> llvm.ptrtoint

Non-goals

  • Do not attempt to cover the full cast matrix.
  • Do not add niche-encoding or transmute aggregate coverage in this issue.
  • Do not add unsize/fat-pointer tests in this issue.

Those paths are more specialized and should be tested in separate PRs.

Acceptance criteria

  • The TODO in cast.rs is replaced with concrete unit tests.
  • Tests follow the existing convert::ops::test_util pattern: build a minimal MIR module, run lower_mir_to_llvm, and inspect emitted LLVM ops.
  • Tests verify representative dispatch behavior without expanding into exhaustive combinatorial coverage.
  • cargo test -p mir-lower cast::tests --lib passes.

Activity

  1. added
    QoL-improvement
    IR-lowering
    tests
    on Jun 29, 2026
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

    IR-loweringQoL-improvementtests

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions