@@ -8,7 +8,7 @@ use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
88use rustc_middle:: mir:: interpret:: {
99 read_target_uint, AllocId , Allocation , ConstValue , ErrorHandled , GlobalAlloc , Pointer , Scalar ,
1010} ;
11- use rustc_middle:: ty:: { Const , ConstKind } ;
11+ use rustc_middle:: ty:: ConstKind ;
1212
1313use cranelift_codegen:: ir:: GlobalValueData ;
1414use cranelift_module:: * ;
@@ -39,7 +39,10 @@ impl ConstantCx {
3939pub ( crate ) fn check_constants ( fx : & mut FunctionCx < ' _ , ' _ , ' _ > ) -> bool {
4040 let mut all_constants_ok = true ;
4141 for constant in & fx. mir . required_consts {
42- let const_ = fx. monomorphize ( constant. literal ) ;
42+ let const_ = match fx. monomorphize ( constant. literal ) {
43+ ConstantKind :: Ty ( ct) => ct,
44+ ConstantKind :: Val ( ..) => continue ,
45+ } ;
4346 match const_. val {
4447 ConstKind :: Value ( _) => { }
4548 ConstKind :: Unevaluated ( def, ref substs, promoted) => {
@@ -115,19 +118,17 @@ pub(crate) fn codegen_constant<'tcx>(
115118 fx : & mut FunctionCx < ' _ , ' _ , ' tcx > ,
116119 constant : & Constant < ' tcx > ,
117120) -> CValue < ' tcx > {
118- let const_ = fx. monomorphize ( constant. literal ) ;
121+ let const_ = match fx. monomorphize ( constant. literal ) {
122+ ConstantKind :: Ty ( ct) => ct,
123+ ConstantKind :: Val ( val, ty) => return codegen_const_value ( fx, val, ty) ,
124+ } ;
119125 let const_val = match const_. val {
120126 ConstKind :: Value ( const_val) => const_val,
121127 ConstKind :: Unevaluated ( def, ref substs, promoted) if fx. tcx . is_static ( def. did ) => {
122128 assert ! ( substs. is_empty( ) ) ;
123129 assert ! ( promoted. is_none( ) ) ;
124130
125- return codegen_static_ref (
126- fx,
127- def. did ,
128- fx. layout_of ( fx. monomorphize ( & constant. literal . ty ) ) ,
129- )
130- . to_cvalue ( fx) ;
131+ return codegen_static_ref ( fx, def. did , fx. layout_of ( const_. ty ) ) . to_cvalue ( fx) ;
131132 }
132133 ConstKind :: Unevaluated ( def, ref substs, promoted) => {
133134 match fx. tcx . const_eval_resolve ( ParamEnv :: reveal_all ( ) , def, substs, promoted, None ) {
@@ -427,11 +428,14 @@ fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut dyn Module, cx: &mut Constant
427428pub ( crate ) fn mir_operand_get_const_val < ' tcx > (
428429 fx : & FunctionCx < ' _ , ' _ , ' tcx > ,
429430 operand : & Operand < ' tcx > ,
430- ) -> Option < & ' tcx Const < ' tcx > > {
431+ ) -> Option < ConstValue < ' tcx > > {
431432 match operand {
432433 Operand :: Copy ( _) | Operand :: Move ( _) => None ,
433- Operand :: Constant ( const_) => {
434- Some ( fx. monomorphize ( const_. literal ) . eval ( fx. tcx , ParamEnv :: reveal_all ( ) ) )
435- }
434+ Operand :: Constant ( const_) => match const_. literal {
435+ ConstantKind :: Ty ( const_) => {
436+ fx. monomorphize ( const_) . eval ( fx. tcx , ParamEnv :: reveal_all ( ) ) . val . try_to_value ( )
437+ }
438+ ConstantKind :: Val ( val, _) => Some ( val) ,
439+ } ,
436440 }
437441}
0 commit comments