@@ -8,7 +8,7 @@ use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
8
8
use rustc_middle:: mir:: interpret:: {
9
9
read_target_uint, AllocId , Allocation , ConstValue , ErrorHandled , GlobalAlloc , Pointer , Scalar ,
10
10
} ;
11
- use rustc_middle:: ty:: { Const , ConstKind } ;
11
+ use rustc_middle:: ty:: ConstKind ;
12
12
13
13
use cranelift_codegen:: ir:: GlobalValueData ;
14
14
use cranelift_module:: * ;
@@ -39,7 +39,10 @@ impl ConstantCx {
39
39
pub ( crate ) fn check_constants ( fx : & mut FunctionCx < ' _ , ' _ , ' _ > ) -> bool {
40
40
let mut all_constants_ok = true ;
41
41
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
+ } ;
43
46
match const_. val {
44
47
ConstKind :: Value ( _) => { }
45
48
ConstKind :: Unevaluated ( def, ref substs, promoted) => {
@@ -113,19 +116,17 @@ pub(crate) fn codegen_constant<'tcx>(
113
116
fx : & mut FunctionCx < ' _ , ' _ , ' tcx > ,
114
117
constant : & Constant < ' tcx > ,
115
118
) -> 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
+ } ;
117
123
let const_val = match const_. val {
118
124
ConstKind :: Value ( const_val) => const_val,
119
125
ConstKind :: Unevaluated ( def, ref substs, promoted) if fx. tcx . is_static ( def. did ) => {
120
126
assert ! ( substs. is_empty( ) ) ;
121
127
assert ! ( promoted. is_none( ) ) ;
122
128
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) ;
129
130
}
130
131
ConstKind :: Unevaluated ( def, ref substs, promoted) => {
131
132
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
422
423
pub ( crate ) fn mir_operand_get_const_val < ' tcx > (
423
424
fx : & FunctionCx < ' _ , ' _ , ' tcx > ,
424
425
operand : & Operand < ' tcx > ,
425
- ) -> Option < & ' tcx Const < ' tcx > > {
426
+ ) -> Option < ConstValue < ' tcx > > {
426
427
match operand {
427
428
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
+ } ,
431
435
}
432
436
}
0 commit comments