1010
1111use llvm:: ValueRef ;
1212use rustc:: middle:: ty:: { self , Ty } ;
13- use rustc_front:: hir;
1413use rustc_mir:: repr as mir;
1514
1615use trans:: asm;
@@ -47,6 +46,8 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
4746
4847 mir:: Rvalue :: Cast ( mir:: CastKind :: Unsize , ref operand, cast_ty) => {
4948 if common:: type_is_fat_ptr ( bcx. tcx ( ) , cast_ty) {
49+ // into-coerce of a thin pointer to a fat pointer - just
50+ // use the operand path.
5051 let ( bcx, temp) = self . trans_rvalue_operand ( bcx, rvalue) ;
5152 self . store_operand ( bcx, lldest, temp) ;
5253 return bcx;
@@ -59,8 +60,13 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
5960 let operand = self . trans_operand ( bcx, operand) ;
6061 match operand. val {
6162 OperandValue :: FatPtr ( ..) => unreachable ! ( ) ,
62- OperandValue :: Imm ( llval) => {
63- // ugly alloca.
63+ OperandValue :: Immediate ( llval) => {
64+ // unsize from an immediate structure. We don't
65+ // really need a temporary alloca here, but
66+ // avoiding it would require us to have
67+ // `coerce_unsized_into` use extractvalue to
68+ // index into the struct, and this case isn't
69+ // important enough for it.
6470 debug ! ( "trans_rvalue: creating ugly alloca" ) ;
6571 let lltemp = base:: alloc_ty ( bcx, operand. ty , "__unsize_temp" ) ;
6672 base:: store_ty ( bcx, llval, lltemp, operand. ty ) ;
@@ -165,7 +171,7 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
165171 // and is a no-op at the LLVM level
166172 operand. val
167173 }
168- OperandValue :: Imm ( lldata) => {
174+ OperandValue :: Immediate ( lldata) => {
169175 // "standard" unsize
170176 let ( lldata, llextra) =
171177 base:: unsize_thin_ptr ( bcx, lldata,
@@ -200,7 +206,7 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
200206 // destination effectively creates a reference.
201207 if common:: type_is_sized ( bcx. tcx ( ) , ty) {
202208 ( bcx, OperandRef {
203- val : OperandValue :: Imm ( tr_lvalue. llval ) ,
209+ val : OperandValue :: Immediate ( tr_lvalue. llval ) ,
204210 ty : ref_ty,
205211 } )
206212 } else {
@@ -215,7 +221,7 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
215221 mir:: Rvalue :: Len ( ref lvalue) => {
216222 let tr_lvalue = self . trans_lvalue ( bcx, lvalue) ;
217223 ( bcx, OperandRef {
218- val : OperandValue :: Imm ( self . lvalue_len ( bcx, tr_lvalue) ) ,
224+ val : OperandValue :: Immediate ( self . lvalue_len ( bcx, tr_lvalue) ) ,
219225 ty : bcx. tcx ( ) . types . usize ,
220226 } )
221227 }
@@ -230,7 +236,7 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
230236 base:: compare_fat_ptrs ( bcx,
231237 lhs_addr, lhs_extra,
232238 rhs_addr, rhs_extra,
233- lhs. ty , cmp_to_hir_cmp ( op ) ,
239+ lhs. ty , op . to_hir_binop ( ) ,
234240 DebugLoc :: None )
235241 }
236242 _ => unreachable ! ( )
@@ -242,8 +248,8 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
242248 lhs. ty , DebugLoc :: None )
243249 } ;
244250 ( bcx, OperandRef {
245- val : OperandValue :: Imm ( llresult) ,
246- ty : type_of_binop ( bcx. tcx ( ) , op, lhs. ty , rhs. ty ) ,
251+ val : OperandValue :: Immediate ( llresult) ,
252+ ty : self . mir . binop_ty ( bcx. tcx ( ) , op, lhs. ty , rhs. ty ) ,
247253 } )
248254 }
249255
@@ -261,7 +267,7 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
261267 }
262268 } ;
263269 ( bcx, OperandRef {
264- val : OperandValue :: Imm ( llval) ,
270+ val : OperandValue :: Immediate ( llval) ,
265271 ty : operand. ty ,
266272 } )
267273 }
@@ -281,7 +287,7 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
281287 llalign,
282288 DebugLoc :: None ) ;
283289 ( bcx, OperandRef {
284- val : OperandValue :: Imm ( llval) ,
290+ val : OperandValue :: Immediate ( llval) ,
285291 ty : box_ty,
286292 } )
287293 }
@@ -388,7 +394,7 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
388394 mir:: BinOp :: Eq | mir:: BinOp :: Lt | mir:: BinOp :: Gt |
389395 mir:: BinOp :: Ne | mir:: BinOp :: Le | mir:: BinOp :: Ge => {
390396 base:: compare_scalar_types ( bcx, lhs, rhs, input_ty,
391- cmp_to_hir_cmp ( op ) , debug_loc)
397+ op . to_hir_binop ( ) , debug_loc)
392398 }
393399 }
394400 }
@@ -413,43 +419,3 @@ pub fn rvalue_creates_operand<'tcx>(rvalue: &mir::Rvalue<'tcx>) -> bool {
413419
414420 // (*) this is only true if the type is suitable
415421}
416-
417- fn cmp_to_hir_cmp ( op : mir:: BinOp ) -> hir:: BinOp_ {
418- match op {
419- mir:: BinOp :: Eq => hir:: BiEq ,
420- mir:: BinOp :: Ne => hir:: BiNe ,
421- mir:: BinOp :: Lt => hir:: BiLt ,
422- mir:: BinOp :: Le => hir:: BiLe ,
423- mir:: BinOp :: Gt => hir:: BiGt ,
424- mir:: BinOp :: Ge => hir:: BiGe ,
425- _ => unreachable ! ( )
426- }
427- }
428-
429- /// FIXME(nikomatsakis): I don't think this function should go here
430- fn type_of_binop < ' tcx > (
431- tcx : & ty:: ctxt < ' tcx > ,
432- op : mir:: BinOp ,
433- lhs_ty : Ty < ' tcx > ,
434- rhs_ty : Ty < ' tcx > )
435- -> Ty < ' tcx >
436- {
437- match op {
438- mir:: BinOp :: Add | mir:: BinOp :: Sub |
439- mir:: BinOp :: Mul | mir:: BinOp :: Div | mir:: BinOp :: Rem |
440- mir:: BinOp :: BitXor | mir:: BinOp :: BitAnd | mir:: BinOp :: BitOr => {
441- // these should be integers or floats of the same size. We
442- // probably want to dump all ops in some intrinsics framework
443- // someday.
444- assert_eq ! ( lhs_ty, rhs_ty) ;
445- lhs_ty
446- }
447- mir:: BinOp :: Shl | mir:: BinOp :: Shr => {
448- lhs_ty // lhs_ty can be != rhs_ty
449- }
450- mir:: BinOp :: Eq | mir:: BinOp :: Lt | mir:: BinOp :: Le |
451- mir:: BinOp :: Ne | mir:: BinOp :: Ge | mir:: BinOp :: Gt => {
452- tcx. types . bool
453- }
454- }
455- }
0 commit comments