Skip to content

Commit 1f56fba

Browse files
dtcxzywclaude
andcommitted
refactor(rustc_codegen_tuffy): replace silent skip with unimplemented!() for unsupported MIR
Change MIR-to-IR translation to panic with unimplemented!() instead of silently returning None/false when encountering unsupported constructs: - Unsupported rvalue kinds (catch-all and PtrMetadata) - Unsupported place projections (OpaqueCast, UnwrapUnsafeBinder) - Unhandled intrinsics and memory intrinsics - Unhandled terminator and statement kinds Also fix coerce_to_ptr missing function body in ctx.rs and a partial move error for float_ty in rvalue.rs. Update README.md with the error policy. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 5acfa96 commit 1f56fba

6 files changed

Lines changed: 27 additions & 17 deletions

File tree

rustc_codegen_tuffy/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ The downstream crates (`tuffy_ir`, `tuffy_opt`, `tuffy_target`, `tuffy_target_x8
5151
- Handles i128/u128 types through annotation-based legalization rather than type splitting at the IR level.
5252
- Supports `dump-ir` via `-C llvm-args=dump-ir` for debugging IR output.
5353

54+
## Error Policy
55+
56+
Unsupported MIR constructs (rvalue kinds, statement kinds, terminator kinds, intrinsics, place projections) must **not** be silently skipped. Use `unimplemented!()` with a descriptive message so the missing support is immediately visible. When an `unimplemented!()` is hit, the correct response is to add a concrete implementation for that construct — not to suppress the error.
57+
5458
## Dependencies
5559

5660
- `tuffy_ir` — IR definitions

rustc_codegen_tuffy/src/mir_to_ir/ctx.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,11 @@ impl<'a, 'tcx> TranslationCtx<'a, 'tcx> {
183183

184184
/// If `val` is an Int, insert inttoptr to coerce it to Ptr.
185185
pub(super) fn coerce_to_ptr(&mut self, val: ValueRef) -> ValueRef {
186+
match self.builder.value_type(val) {
187+
Some(Type::Int) => self.builder.inttoptr(val.into(), 0, Origin::synthetic()),
188+
_ => val,
189+
}
190+
}
186191

187192
/// Create a static `&Location` for a `#[track_caller]` call site.
188193
///

rustc_codegen_tuffy/src/mir_to_ir/intrinsic.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -429,8 +429,8 @@ pub(super) fn translate_intrinsic<'tcx>(
429429
true
430430
}
431431

432-
// Unhandled intrinsics fall through to normal call path.
433-
_ => false,
432+
// Unhandled intrinsics must be reported.
433+
_ => unimplemented!("MIR intrinsic: {}", name),
434434
}
435435
}
436436

@@ -892,7 +892,7 @@ pub(super) fn translate_memory_intrinsic<'tcx>(
892892
Some(new_mem)
893893
}
894894

895-
_ => None,
895+
_ => unimplemented!("MIR memory intrinsic: {}", name),
896896
}
897897
}
898898

rustc_codegen_tuffy/src/mir_to_ir/rvalue.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -264,8 +264,7 @@ impl<'a, 'tcx> TranslationCtx<'a, 'tcx> {
264264
};
265265
}
266266
_ => {
267-
// OpaqueCast, UnwrapUnsafeBinder — not yet handled.
268-
return None;
267+
unimplemented!("MIR place projection: {:?}", elem);
269268
}
270269
}
271270
}
@@ -838,7 +837,7 @@ impl<'a, 'tcx> TranslationCtx<'a, 'tcx> {
838837
};
839838

840839
// Float arithmetic: bitcast Int→Float, dispatch to fadd/fsub/fmul/fdiv, bitcast back.
841-
if let Some(fty) = float_ty {
840+
if let Some(ref fty) = float_ty {
842841
if matches!(
843842
op,
844843
BinOp::Add
@@ -868,35 +867,35 @@ impl<'a, 'tcx> TranslationCtx<'a, 'tcx> {
868867
l_f.into(),
869868
r_f.into(),
870869
flags,
871-
fty,
870+
fty.clone(),
872871
Origin::synthetic(),
873872
),
874873
BinOp::Sub | BinOp::SubUnchecked => self.builder.fsub(
875874
l_f.into(),
876875
r_f.into(),
877876
flags,
878-
fty,
877+
fty.clone(),
879878
Origin::synthetic(),
880879
),
881880
BinOp::Mul | BinOp::MulUnchecked => self.builder.fmul(
882881
l_f.into(),
883882
r_f.into(),
884883
flags,
885-
fty,
884+
fty.clone(),
886885
Origin::synthetic(),
887886
),
888887
BinOp::Rem => self.builder.frem(
889888
l_f.into(),
890889
r_f.into(),
891890
flags,
892-
fty,
891+
fty.clone(),
893892
Origin::synthetic(),
894893
),
895894
_ => self.builder.fdiv(
896895
l_f.into(),
897896
r_f.into(),
898897
flags,
899-
fty,
898+
fty.clone(),
900899
Origin::synthetic(),
901900
),
902901
};
@@ -1922,7 +1921,9 @@ impl<'a, 'tcx> TranslationCtx<'a, 'tcx> {
19221921
}
19231922
None
19241923
}
1925-
Rvalue::UnaryOp(mir::UnOp::PtrMetadata, _) => None,
1924+
Rvalue::UnaryOp(mir::UnOp::PtrMetadata, _) => {
1925+
unimplemented!("MIR rvalue: UnaryOp::PtrMetadata")
1926+
}
19261927
Rvalue::UnaryOp(mir::UnOp::Neg, operand) => {
19271928
let v = self.translate_operand(operand)?;
19281929
let neg_ann = match operand {
@@ -2058,7 +2059,7 @@ impl<'a, 'tcx> TranslationCtx<'a, 'tcx> {
20582059
self.stack_locals.mark(dest_place.local);
20592060
Some(slot)
20602061
}
2061-
_ => None,
2062+
_ => unimplemented!("MIR rvalue: {:?}", rvalue),
20622063
}
20632064
}
20642065

rustc_codegen_tuffy/src/mir_to_ir/statement.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -924,7 +924,9 @@ impl<'a, 'tcx> TranslationCtx<'a, 'tcx> {
924924
}
925925
}
926926
}
927-
_ => {}
927+
_ => {
928+
unimplemented!("MIR statement: {:?}", stmt.kind);
929+
}
928930
}
929931
}
930932

rustc_codegen_tuffy/src/mir_to_ir/terminator.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -440,9 +440,7 @@ impl<'a, 'tcx> TranslationCtx<'a, 'tcx> {
440440
}
441441
}
442442
_ => {
443-
// Unhandled terminator kind — emit unreachable so the block
444-
// is never empty and the IR verifier stays happy.
445-
self.builder.unreachable(Origin::synthetic());
443+
unimplemented!("MIR terminator: {:?}", term.kind);
446444
}
447445
}
448446
}

0 commit comments

Comments
 (0)