11use crate :: mir:: operand:: OperandRef ;
22use crate :: traits:: * ;
33use rustc:: mir;
4- use rustc:: mir:: interpret:: ErrorHandled ;
4+ use rustc:: mir:: interpret:: { ConstValue , ErrorHandled } ;
55use rustc:: ty:: layout:: { self , HasTyCtxt } ;
66use rustc:: ty:: { self , Ty } ;
77use rustc_index:: vec:: Idx ;
@@ -30,27 +30,21 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
3030 }
3131 _ => {
3232 let val = self . eval_mir_constant ( constant) ?;
33- Ok ( OperandRef :: from_const ( bx, & val) )
33+ Ok ( OperandRef :: from_const ( bx, val. clone ( ) , constant . literal . ty ) )
3434 }
3535 }
3636 }
3737
3838 pub fn eval_mir_constant (
3939 & mut self ,
4040 constant : & mir:: Constant < ' tcx > ,
41- ) -> Result < & ' tcx ty :: Const < ' tcx > , ErrorHandled > {
41+ ) -> Result < ConstValue < ' tcx > , ErrorHandled > {
4242 match constant. literal . val {
4343 ty:: ConstKind :: Unevaluated ( def_id, substs, promoted) => {
4444 let substs = self . monomorphize ( & substs) ;
4545 self . cx
4646 . tcx ( )
4747 . const_eval_resolve ( ty:: ParamEnv :: reveal_all ( ) , def_id, substs, promoted, None )
48- . map ( |val| {
49- self . cx . tcx ( ) . mk_const ( ty:: Const {
50- val : ty:: ConstKind :: Value ( val) ,
51- ty : constant. literal . ty ,
52- } )
53- } )
5448 . map_err ( |err| {
5549 if promoted. is_none ( ) {
5650 self . cx
@@ -61,7 +55,15 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
6155 err
6256 } )
6357 }
64- _ => Ok ( self . monomorphize ( & constant. literal ) ) ,
58+ ty:: ConstKind :: Value ( value) => Ok ( value) ,
59+ _ => {
60+ let const_ = self . monomorphize ( & constant. literal ) ;
61+ if let ty:: ConstKind :: Value ( value) = const_. val {
62+ Ok ( value)
63+ } else {
64+ bug ! ( "encountered bad ConstKind in codegen" ) ;
65+ }
66+ }
6567 }
6668 }
6769
@@ -71,21 +73,22 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
7173 bx : & Bx ,
7274 span : Span ,
7375 ty : Ty < ' tcx > ,
74- constant : Result < & ' tcx ty :: Const < ' tcx > , ErrorHandled > ,
76+ constant : Result < ConstValue < ' tcx > , ErrorHandled > ,
7577 ) -> ( Bx :: Value , Ty < ' tcx > ) {
7678 constant
77- . map ( |c | {
78- let field_ty = c . ty . builtin_index ( ) . unwrap ( ) ;
79- let fields = match c . ty . kind {
79+ . map ( |val | {
80+ let field_ty = ty. builtin_index ( ) . unwrap ( ) ;
81+ let fields = match ty. kind {
8082 ty:: Array ( _, n) => n. eval_usize ( bx. tcx ( ) , ty:: ParamEnv :: reveal_all ( ) ) ,
81- _ => bug ! ( "invalid simd shuffle type: {}" , c . ty) ,
83+ _ => bug ! ( "invalid simd shuffle type: {}" , ty) ,
8284 } ;
85+ let c = bx. tcx ( ) . mk_const ( ty:: Const { val : ty:: ConstKind :: Value ( val) , ty } ) ;
8386 let values: Vec < _ > = ( 0 ..fields)
8487 . map ( |field| {
8588 let field = bx. tcx ( ) . const_field (
8689 ty:: ParamEnv :: reveal_all ( ) . and ( ( & c, mir:: Field :: new ( field as usize ) ) ) ,
8790 ) ;
88- if let Some ( prim) = field. val . try_to_scalar ( ) {
91+ if let Some ( prim) = field. try_to_scalar ( ) {
8992 let layout = bx. layout_of ( field_ty) ;
9093 let scalar = match layout. abi {
9194 layout:: Abi :: Scalar ( ref x) => x,
0 commit comments