@@ -41,24 +41,24 @@ use super::MirContext;
4141/// The LLVM type might not be the same for a single Rust type,
4242/// e.g. each enum variant would have its own LLVM struct type.
4343#[ derive( Copy , Clone ) ]
44- struct Const < ' tcx > {
45- llval : ValueRef ,
46- ty : Ty < ' tcx >
44+ pub struct Const < ' tcx > {
45+ pub llval : ValueRef ,
46+ pub ty : Ty < ' tcx >
4747}
4848
4949impl < ' tcx > Const < ' tcx > {
50- fn new ( llval : ValueRef , ty : Ty < ' tcx > ) -> Const < ' tcx > {
50+ pub fn new ( llval : ValueRef , ty : Ty < ' tcx > ) -> Const < ' tcx > {
5151 Const {
5252 llval : llval,
5353 ty : ty
5454 }
5555 }
5656
5757 /// Translate ConstVal into a LLVM constant value.
58- fn from_constval < ' a > ( ccx : & CrateContext < ' a , ' tcx > ,
59- cv : ConstVal ,
60- ty : Ty < ' tcx > )
61- -> Const < ' tcx > {
58+ pub fn from_constval < ' a > ( ccx : & CrateContext < ' a , ' tcx > ,
59+ cv : ConstVal ,
60+ ty : Ty < ' tcx > )
61+ -> Const < ' tcx > {
6262 let llty = type_of:: type_of ( ccx, ty) ;
6363 let val = match cv {
6464 ConstVal :: Float ( v) => C_floating_f64 ( v, llty) ,
@@ -110,7 +110,7 @@ impl<'tcx> Const<'tcx> {
110110 }
111111 }
112112
113- fn to_operand < ' a > ( & self , ccx : & CrateContext < ' a , ' tcx > ) -> OperandRef < ' tcx > {
113+ pub fn to_operand < ' a > ( & self , ccx : & CrateContext < ' a , ' tcx > ) -> OperandRef < ' tcx > {
114114 let llty = type_of:: immediate_type_of ( ccx, self . ty ) ;
115115 let llvalty = val_ty ( self . llval ) ;
116116
@@ -799,7 +799,7 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
799799 pub fn trans_constant ( & mut self ,
800800 bcx : & BlockAndBuilder < ' bcx , ' tcx > ,
801801 constant : & mir:: Constant < ' tcx > )
802- -> OperandRef < ' tcx >
802+ -> Const < ' tcx >
803803 {
804804 let ty = bcx. monomorphize ( & constant. ty ) ;
805805 let result = match constant. literal . clone ( ) {
@@ -808,10 +808,7 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
808808 // types, which would not work with MirConstContext.
809809 if common:: type_is_zero_size ( bcx. ccx ( ) , ty) {
810810 let llty = type_of:: type_of ( bcx. ccx ( ) , ty) ;
811- return OperandRef {
812- val : OperandValue :: Immediate ( C_null ( llty) ) ,
813- ty : ty
814- } ;
811+ return Const :: new ( C_null ( llty) , ty) ;
815812 }
816813
817814 let substs = bcx. tcx ( ) . mk_substs ( bcx. monomorphize ( substs) ) ;
@@ -827,7 +824,7 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
827824 }
828825 } ;
829826
830- let val = match result {
827+ match result {
831828 Ok ( v) => v,
832829 Err ( ConstEvalFailure :: Compiletime ( _) ) => {
833830 // We've errored, so we don't have to produce working code.
@@ -839,14 +836,6 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
839836 "MIR constant {:?} results in runtime panic: {}" ,
840837 constant, err. description( ) )
841838 }
842- } ;
843-
844- let operand = val. to_operand ( bcx. ccx ( ) ) ;
845- if let OperandValue :: Ref ( ptr) = operand. val {
846- // If this is a OperandValue::Ref to an immediate constant, load it.
847- self . trans_load ( bcx, ptr, operand. ty )
848- } else {
849- operand
850839 }
851840 }
852841}
0 commit comments