|
2 | 2 |
|
3 | 3 | use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
4 | 4 | use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
|
5 |
| -use rustc_middle::mir::interpret::{ |
6 |
| - read_target_uint, AllocId, ConstValue, ErrorHandled, GlobalAlloc, Scalar, |
7 |
| -}; |
| 5 | +use rustc_middle::mir::interpret::{read_target_uint, AllocId, ConstValue, GlobalAlloc, Scalar}; |
8 | 6 |
|
9 | 7 | use cranelift_module::*;
|
10 | 8 |
|
@@ -33,16 +31,6 @@ impl ConstantCx {
|
33 | 31 | }
|
34 | 32 | }
|
35 | 33 |
|
36 |
| -pub(crate) fn check_constants(fx: &mut FunctionCx<'_, '_, '_>) -> bool { |
37 |
| - let mut all_constants_ok = true; |
38 |
| - for constant in &fx.mir.required_consts { |
39 |
| - if eval_mir_constant(fx, constant).is_none() { |
40 |
| - all_constants_ok = false; |
41 |
| - } |
42 |
| - } |
43 |
| - all_constants_ok |
44 |
| -} |
45 |
| - |
46 | 34 | pub(crate) fn codegen_static(tcx: TyCtxt<'_>, module: &mut dyn Module, def_id: DefId) {
|
47 | 35 | let mut constants_cx = ConstantCx::new();
|
48 | 36 | constants_cx.todo.push(TodoItem::Static(def_id));
|
@@ -76,30 +64,20 @@ pub(crate) fn codegen_tls_ref<'tcx>(
|
76 | 64 | pub(crate) fn eval_mir_constant<'tcx>(
|
77 | 65 | fx: &FunctionCx<'_, '_, 'tcx>,
|
78 | 66 | constant: &Constant<'tcx>,
|
79 |
| -) -> Option<(ConstValue<'tcx>, Ty<'tcx>)> { |
| 67 | +) -> (ConstValue<'tcx>, Ty<'tcx>) { |
80 | 68 | let cv = fx.monomorphize(constant.literal);
|
| 69 | + // This cannot fail because we checked all required_consts in advance. |
81 | 70 | let val = cv
|
82 | 71 | .eval(fx.tcx, ty::ParamEnv::reveal_all(), Some(constant.span))
|
83 |
| - .map_err(|err| match err { |
84 |
| - ErrorHandled::Reported(_) => { |
85 |
| - fx.tcx.sess.span_err(constant.span, "erroneous constant encountered"); |
86 |
| - } |
87 |
| - ErrorHandled::TooGeneric => { |
88 |
| - span_bug!(constant.span, "codegen encountered polymorphic constant: {:?}", err); |
89 |
| - } |
90 |
| - }) |
91 |
| - .ok(); |
92 |
| - val.map(|val| (val, cv.ty())) |
| 72 | + .expect("erroneous constant not captured by required_consts"); |
| 73 | + (val, cv.ty()) |
93 | 74 | }
|
94 | 75 |
|
95 | 76 | pub(crate) fn codegen_constant_operand<'tcx>(
|
96 | 77 | fx: &mut FunctionCx<'_, '_, 'tcx>,
|
97 | 78 | constant: &Constant<'tcx>,
|
98 | 79 | ) -> CValue<'tcx> {
|
99 |
| - let (const_val, ty) = eval_mir_constant(fx, constant).unwrap_or_else(|| { |
100 |
| - span_bug!(constant.span, "erroneous constant not captured by required_consts") |
101 |
| - }); |
102 |
| - |
| 80 | + let (const_val, ty) = eval_mir_constant(fx, constant); |
103 | 81 | codegen_const_value(fx, const_val, ty)
|
104 | 82 | }
|
105 | 83 |
|
@@ -459,7 +437,7 @@ pub(crate) fn mir_operand_get_const_val<'tcx>(
|
459 | 437 | operand: &Operand<'tcx>,
|
460 | 438 | ) -> Option<ConstValue<'tcx>> {
|
461 | 439 | match operand {
|
462 |
| - Operand::Constant(const_) => Some(eval_mir_constant(fx, const_).unwrap().0), |
| 440 | + Operand::Constant(const_) => Some(eval_mir_constant(fx, const_).0), |
463 | 441 | // FIXME(rust-lang/rust#85105): Casts like `IMM8 as u32` result in the const being stored
|
464 | 442 | // inside a temporary before being passed to the intrinsic requiring the const argument.
|
465 | 443 | // This code tries to find a single constant defining definition of the referenced local.
|
|
0 commit comments