33use cranelift_module:: * ;
44use rustc_data_structures:: fx:: { FxHashMap , FxHashSet } ;
55use 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 ;
78
89use crate :: prelude:: * ;
910
@@ -62,9 +63,9 @@ pub(crate) fn codegen_tls_ref<'tcx>(
6263
6364pub ( crate ) fn eval_mir_constant < ' tcx > (
6465 fx : & FunctionCx < ' _ , ' _ , ' tcx > ,
65- constant : & Constant < ' tcx > ,
66+ constant : & ConstOperand < ' tcx > ,
6667) -> ( ConstValue < ' tcx > , Ty < ' tcx > ) {
67- let cv = fx. monomorphize ( constant. literal ) ;
68+ let cv = fx. monomorphize ( constant. const_ ) ;
6869 // This cannot fail because we checked all required_consts in advance.
6970 let val = cv
7071 . eval ( fx. tcx , ty:: ParamEnv :: reveal_all ( ) , Some ( constant. span ) )
@@ -74,7 +75,7 @@ pub(crate) fn eval_mir_constant<'tcx>(
7475
7576pub ( crate ) fn codegen_constant_operand < ' tcx > (
7677 fx : & mut FunctionCx < ' _ , ' _ , ' tcx > ,
77- constant : & Constant < ' tcx > ,
78+ constant : & ConstOperand < ' tcx > ,
7879) -> CValue < ' tcx > {
7980 let ( const_val, ty) = eval_mir_constant ( fx, constant) ;
8081 codegen_const_value ( fx, const_val, ty)
@@ -182,15 +183,11 @@ pub(crate) fn codegen_const_value<'tcx>(
182183 . offset_i64 ( fx, i64:: try_from ( offset. bytes ( ) ) . unwrap ( ) ) ,
183184 layout,
184185 ) ,
185- ConstValue :: Slice { data, start , end } => {
186+ ConstValue :: Slice { data, meta } => {
186187 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 ( ) ) ;
194191 CValue :: by_val_pair ( ptr, len, layout)
195192 }
196193 }
0 commit comments