Skip to content

Commit b73e613

Browse files
committed
De-duplicate and move adjust_nan to InterpCx
1 parent 8f8bee4 commit b73e613

4 files changed

Lines changed: 19 additions & 23 deletions

File tree

‎compiler/rustc_const_eval/src/interpret/cast.rs‎

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -334,19 +334,6 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
334334
{
335335
use rustc_type_ir::TyKind::*;
336336

337-
fnadjust_nan<
338-
'tcx,
339-
M:Machine<'tcx>,
340-
F1: rustc_apfloat::Float + FloatConvert<F2>,
341-
F2: rustc_apfloat::Float,
342-
>(
343-
ecx:&InterpCx<'tcx,M>,
344-
f1:F1,
345-
f2:F2,
346-
) -> F2{
347-
if f2.is_nan(){M::generate_nan(ecx,&[f1])}else{ f2 }
348-
}
349-
350337
match*dest_ty.kind(){
351338
// float -> uint
352339
Uint(t) => {
@@ -367,11 +354,17 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
367354
}
368355
// float -> float
369356
Float(fty) => match fty {
370-
FloatTy::F16 => Scalar::from_f16(adjust_nan(self, f, f.convert(&mutfalse).value)),
371-
FloatTy::F32 => Scalar::from_f32(adjust_nan(self, f, f.convert(&mutfalse).value)),
372-
FloatTy::F64 => Scalar::from_f64(adjust_nan(self, f, f.convert(&mutfalse).value)),
357+
FloatTy::F16 => {
358+
Scalar::from_f16(self.adjust_nan(f.convert(&mutfalse).value,&[f]))
359+
}
360+
FloatTy::F32 => {
361+
Scalar::from_f32(self.adjust_nan(f.convert(&mutfalse).value,&[f]))
362+
}
363+
FloatTy::F64 => {
364+
Scalar::from_f64(self.adjust_nan(f.convert(&mutfalse).value,&[f]))
365+
}
373366
FloatTy::F128 => {
374-
Scalar::from_f128(adjust_nan(self, f, f.convert(&mutfalse).value))
367+
Scalar::from_f128(self.adjust_nan(f.convert(&mutfalse).value,&[f]))
375368
}
376369
},
377370
// That's it.

‎compiler/rustc_const_eval/src/interpret/eval_context.rs‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,14 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
599599
pubfngenerate_stacktrace(&self) -> Vec<FrameInfo<'tcx>>{
600600
Frame::generate_stacktrace_from_stack(self.stack())
601601
}
602+
603+
pubfnadjust_nan<F1,F2>(&self,f:F2,inputs:&[F1]) -> F2
604+
where
605+
F1: rustc_apfloat::Float + rustc_apfloat::FloatConvert<F2>,
606+
F2: rustc_apfloat::Float,
607+
{
608+
if f.is_nan(){M::generate_nan(self, inputs)}else{ f }
609+
}
602610
}
603611

604612
#[doc(hidden)]

‎compiler/rustc_const_eval/src/interpret/operator.rs‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
6464
use rustc_middle::mir::BinOp::*;
6565

6666
// Performs appropriate non-deterministic adjustments of NaN results.
67-
let adjust_nan =
68-
|f:F| -> F{if f.is_nan(){M::generate_nan(self,&[l, r])}else{ f }};
67+
let adjust_nan = |f:F| -> F{self.adjust_nan(f,&[l, r])};
6968

7069
match bin_op {
7170
Eq => ImmTy::from_bool(l == r,*self.tcx),

‎src/tools/miri/src/operator.rs‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,4 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
115115
nan
116116
}
117117
}
118-
119-
fnadjust_nan<F1:Float + FloatConvert<F2>,F2:Float>(&self,f:F2,inputs:&[F1]) -> F2{
120-
if f.is_nan(){self.generate_nan(inputs)}else{ f }
121-
}
122118
}

0 commit comments

Comments
 (0)