3
3
use cranelift_module:: * ;
4
4
use rustc_data_structures:: fx:: { FxHashMap , FxHashSet } ;
5
5
use rustc_middle:: middle:: codegen_fn_attrs:: CodegenFnAttrFlags ;
6
- use rustc_middle:: mir:: interpret:: { read_target_uint, AllocId , ConstValue , GlobalAlloc , Scalar } ;
6
+ use rustc_middle:: mir:: interpret:: { read_target_uint, AllocId , GlobalAlloc , Scalar } ;
7
+ use rustc_middle:: mir:: ConstValue ;
7
8
8
9
use crate :: prelude:: * ;
9
10
@@ -62,9 +63,9 @@ pub(crate) fn codegen_tls_ref<'tcx>(
62
63
63
64
pub ( crate ) fn eval_mir_constant < ' tcx > (
64
65
fx : & FunctionCx < ' _ , ' _ , ' tcx > ,
65
- constant : & Constant < ' tcx > ,
66
+ constant : & ConstOperand < ' tcx > ,
66
67
) -> ( ConstValue < ' tcx > , Ty < ' tcx > ) {
67
- let cv = fx. monomorphize ( constant. literal ) ;
68
+ let cv = fx. monomorphize ( constant. const_ ) ;
68
69
// This cannot fail because we checked all required_consts in advance.
69
70
let val = cv
70
71
. eval ( fx. tcx , ty:: ParamEnv :: reveal_all ( ) , Some ( constant. span ) )
@@ -74,7 +75,7 @@ pub(crate) fn eval_mir_constant<'tcx>(
74
75
75
76
pub ( crate ) fn codegen_constant_operand < ' tcx > (
76
77
fx : & mut FunctionCx < ' _ , ' _ , ' tcx > ,
77
- constant : & Constant < ' tcx > ,
78
+ constant : & ConstOperand < ' tcx > ,
78
79
) -> CValue < ' tcx > {
79
80
let ( const_val, ty) = eval_mir_constant ( fx, constant) ;
80
81
codegen_const_value ( fx, const_val, ty)
@@ -182,15 +183,11 @@ pub(crate) fn codegen_const_value<'tcx>(
182
183
. offset_i64 ( fx, i64:: try_from ( offset. bytes ( ) ) . unwrap ( ) ) ,
183
184
layout,
184
185
) ,
185
- ConstValue :: Slice { data, start , end } => {
186
+ ConstValue :: Slice { data, meta } => {
186
187
let alloc_id = fx. tcx . reserve_and_set_memory_alloc ( data) ;
187
- let ptr = pointer_for_allocation ( fx, alloc_id)
188
- . offset_i64 ( fx, i64:: try_from ( start) . unwrap ( ) )
189
- . get_addr ( fx) ;
190
- let len = fx
191
- . bcx
192
- . ins ( )
193
- . iconst ( fx. pointer_type , i64:: try_from ( end. checked_sub ( start) . unwrap ( ) ) . unwrap ( ) ) ;
188
+ let ptr = pointer_for_allocation ( fx, alloc_id) . get_addr ( fx) ;
189
+ // FIXME: the `try_from` here can actually fail, e.g. for very long ZST slices.
190
+ let len = fx. bcx . ins ( ) . iconst ( fx. pointer_type , i64:: try_from ( meta) . unwrap ( ) ) ;
194
191
CValue :: by_val_pair ( ptr, len, layout)
195
192
}
196
193
}
0 commit comments