@@ -82,7 +82,6 @@ use util::ppaux::Repr;
82
82
use trans:: machine:: { llsize_of, llsize_of_alloc} ;
83
83
use trans:: type_:: Type ;
84
84
85
- use syntax:: abi as synabi;
86
85
use syntax:: { ast, ast_util, codemap} ;
87
86
use syntax:: parse:: token:: InternedString ;
88
87
use syntax:: ptr:: P ;
@@ -580,42 +579,7 @@ fn trans_unadjusted<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
580
579
581
580
debuginfo:: set_source_location ( bcx. fcx , expr. id , expr. span ) ;
582
581
583
- match expr. node {
584
- ast:: ExprCall ( ref f, ref args) if !bcx. tcx ( ) . is_method_call ( expr. id ) => {
585
- if let ast:: ExprPath ( ..) = f. node {
586
- let fn_ty = expr_ty_adjusted ( bcx, f) ;
587
- let ( fty, ret_ty) = match fn_ty. sty {
588
- ty:: TyBareFn ( _, ref fty) => {
589
- ( fty, ty:: erase_late_bound_regions ( bcx. tcx ( ) , & fty. sig . output ( ) ) )
590
- }
591
- _ => panic ! ( "Not calling a function?!" )
592
- } ;
593
-
594
- if let ty:: FnConverging ( ret_ty) = ret_ty {
595
- let is_rust_fn = fty. abi == synabi:: Rust ||
596
- fty. abi == synabi:: RustIntrinsic ;
597
-
598
- let needs_drop = type_needs_drop ( bcx. tcx ( ) , ret_ty) ;
599
- let uses_output = type_of:: return_uses_outptr ( bcx. ccx ( ) , ret_ty) ;
600
-
601
- if is_rust_fn && !uses_output && !needs_drop {
602
- let args = callee:: ArgExprs ( & args[ ..] ) ;
603
- let result = callee:: trans_call_inner ( bcx,
604
- expr. debug_loc ( ) ,
605
- fn_ty,
606
- |cx, _| callee:: trans ( cx, f) ,
607
- args, Some ( Ignore ) ) ;
608
-
609
- return immediate_rvalue_bcx ( result. bcx , result. val , ret_ty)
610
- . to_expr_datumblock ( ) ;
611
- }
612
- }
613
- }
614
- }
615
- _ => { }
616
- }
617
-
618
- return match ty:: expr_kind ( bcx. tcx ( ) , expr) {
582
+ return match expr_kind ( bcx, expr) {
619
583
ty:: LvalueExpr | ty:: RvalueDatumExpr => {
620
584
let datum = unpack_datum ! ( bcx, {
621
585
trans_datum_unadjusted( bcx, expr)
@@ -664,6 +628,39 @@ fn trans_unadjusted<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
664
628
}
665
629
}
666
630
631
+ // Get the appropriate expression kind for the expression. Most of the time this just uses
632
+ // ty::expr_kind, but `ExprCall`s can be treated as `RvalueDatumExpr`s in some cases.
633
+ fn expr_kind < ' blk , ' tcx > ( bcx : Block < ' blk , ' tcx > , expr : & ast:: Expr ) -> ty:: ExprKind {
634
+ match expr. node {
635
+ ast:: ExprCall ( ref f, _) if !bcx. tcx ( ) . is_method_call ( expr. id ) => {
636
+ if let ast:: ExprPath ( ..) = f. node {
637
+ let fn_ty = expr_ty_adjusted ( bcx, f) ;
638
+
639
+ let ret_ty = match fn_ty. sty {
640
+ ty:: TyBareFn ( _, ref fty) =>
641
+ ty:: erase_late_bound_regions ( bcx. tcx ( ) , & fty. sig . output ( ) ) ,
642
+ _ => bcx. tcx ( ) . sess . bug ( "Not calling a function?" )
643
+ } ;
644
+
645
+ let is_datum = if let ty:: FnConverging ( output) = ret_ty {
646
+ !type_of:: return_uses_outptr ( bcx. ccx ( ) , output) &&
647
+ !bcx. fcx . type_needs_drop ( output)
648
+ } else {
649
+ true
650
+ } ;
651
+
652
+
653
+ if is_datum {
654
+ return ty:: RvalueDatumExpr ;
655
+ }
656
+ }
657
+ }
658
+ _ => ( )
659
+ }
660
+
661
+ return ty:: expr_kind ( bcx. tcx ( ) , expr) ;
662
+ }
663
+
667
664
fn trans_datum_unadjusted < ' blk , ' tcx > ( bcx : Block < ' blk , ' tcx > ,
668
665
expr : & ast:: Expr )
669
666
-> DatumBlock < ' blk , ' tcx , Expr > {
@@ -731,6 +728,35 @@ fn trans_datum_unadjusted<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
731
728
// Datum output mode means this is a scalar cast:
732
729
trans_imm_cast ( bcx, & * * val, expr. id )
733
730
}
731
+ ast:: ExprCall ( ref f, ref args) => {
732
+ let fn_ty = expr_ty_adjusted ( bcx, f) ;
733
+
734
+ let ret_ty = match fn_ty. sty {
735
+ ty:: TyBareFn ( _, ref fty) => {
736
+ ty:: erase_late_bound_regions ( bcx. tcx ( ) , & fty. sig . output ( ) )
737
+ }
738
+ _ => panic ! ( "Not calling a function?!" )
739
+ } ;
740
+
741
+ let args = callee:: ArgExprs ( & args[ ..] ) ;
742
+ let result = callee:: trans_call_inner ( bcx,
743
+ expr. debug_loc ( ) ,
744
+ fn_ty,
745
+ |cx, _| callee:: trans ( cx, f) ,
746
+ args, Some ( Ignore ) ) ;
747
+
748
+ if let ty:: FnConverging ( ret_ty) = ret_ty {
749
+ immediate_rvalue_bcx ( result. bcx , result. val , ret_ty)
750
+ . to_expr_datumblock ( )
751
+ } else {
752
+ // We called a diverging function, generate an undef value of the appropriate
753
+ // type.
754
+ let ty = expr_ty ( bcx, expr) ;
755
+ let llval = C_undef ( type_of:: arg_type_of ( bcx. ccx ( ) , ty) ) ;
756
+ let datum = immediate_rvalue ( llval, ty) ;
757
+ DatumBlock :: new ( bcx, datum. to_expr_datum ( ) )
758
+ }
759
+ }
734
760
_ => {
735
761
bcx. tcx ( ) . sess . span_bug (
736
762
expr. span ,
0 commit comments