@@ -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+ ConstantSource :: Ty ( ct) => ct,
44+ ConstantSource :: Val ( ..) => continue ,
45+ } ;
4346 match const_. val {
4447 ConstKind :: Value ( _) => { }
4548 ConstKind :: Unevaluated ( def, ref substs, promoted) => {
@@ -113,19 +116,17 @@ pub(crate) fn codegen_constant<'tcx>(
113116 fx : & mut FunctionCx < ' _ , ' _ , ' tcx > ,
114117 constant : & Constant < ' tcx > ,
115118) -> CValue < ' tcx > {
116- let const_ = fx. monomorphize ( constant. literal ) ;
119+ let const_ = match fx. monomorphize ( constant. literal ) {
120+ ConstantSource :: Ty ( ct) => ct,
121+ ConstantSource :: Val ( val, ty) => return codegen_const_value ( fx, val, ty) ,
122+ } ;
117123 let const_val = match const_. val {
118124 ConstKind :: Value ( const_val) => const_val,
119125 ConstKind :: Unevaluated ( def, ref substs, promoted) if fx. tcx . is_static ( def. did ) => {
120126 assert ! ( substs. is_empty( ) ) ;
121127 assert ! ( promoted. is_none( ) ) ;
122128
123- return codegen_static_ref (
124- fx,
125- def. did ,
126- fx. layout_of ( fx. monomorphize ( & constant. literal . ty ) ) ,
127- )
128- . to_cvalue ( fx) ;
129+ return codegen_static_ref ( fx, def. did , fx. layout_of ( const_. ty ) ) . to_cvalue ( fx) ;
129130 }
130131 ConstKind :: Unevaluated ( def, ref substs, promoted) => {
131132 match fx. tcx . const_eval_resolve ( ParamEnv :: reveal_all ( ) , def, substs, promoted, None ) {
@@ -422,11 +423,14 @@ fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut dyn Module, cx: &mut Constant
422423pub ( crate ) fn mir_operand_get_const_val < ' tcx > (
423424 fx : & FunctionCx < ' _ , ' _ , ' tcx > ,
424425 operand : & Operand < ' tcx > ,
425- ) -> Option < & ' tcx Const < ' tcx > > {
426+ ) -> Option < ConstValue < ' tcx > > {
426427 match operand {
427428 Operand :: Copy ( _) | Operand :: Move ( _) => None ,
428- Operand :: Constant ( const_) => {
429- Some ( fx. monomorphize ( const_. literal ) . eval ( fx. tcx , ParamEnv :: reveal_all ( ) ) )
430- }
429+ Operand :: Constant ( const_) => match const_. literal {
430+ ConstantSource :: Ty ( const_) => {
431+ fx. monomorphize ( const_) . eval ( fx. tcx , ParamEnv :: reveal_all ( ) ) . val . try_to_value ( )
432+ }
433+ ConstantSource :: Val ( val, _) => Some ( val) ,
434+ } ,
431435 }
432436}
0 commit comments