@@ -22,7 +22,6 @@ use arena::TypedArena;
22
22
use back:: link;
23
23
use session;
24
24
use llvm:: { self , ValueRef , get_params} ;
25
- use metadata:: csearch;
26
25
use middle:: def;
27
26
use middle:: subst;
28
27
use middle:: subst:: { Subst , Substs } ;
@@ -66,7 +65,7 @@ pub struct MethodData {
66
65
pub enum CalleeData < ' tcx > {
67
66
// Constructor for enum variant/tuple-like-struct
68
67
// i.e. Some, Ok
69
- NamedTupleConstructor ( subst :: Substs < ' tcx > , ty:: Disr ) ,
68
+ NamedTupleConstructor ( ty:: Disr ) ,
70
69
71
70
// Represents a (possibly monomorphized) top-level fn item or method
72
71
// item. Note that this is just the fn-ptr and is not a Rust closure
@@ -81,6 +80,7 @@ pub enum CalleeData<'tcx> {
81
80
pub struct Callee < ' blk , ' tcx : ' blk > {
82
81
pub bcx : Block < ' blk , ' tcx > ,
83
82
pub data : CalleeData < ' tcx > ,
83
+ pub ty : Ty < ' tcx >
84
84
}
85
85
86
86
fn trans < ' blk , ' tcx > ( bcx : Block < ' blk , ' tcx > , expr : & ast:: Expr )
@@ -104,11 +104,11 @@ fn trans<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, expr: &ast::Expr)
104
104
let DatumBlock { bcx, datum, .. } = expr:: trans ( bcx, expr) ;
105
105
match datum. ty . sty {
106
106
ty:: TyBareFn ( ..) => {
107
- let llval = datum. to_llscalarish ( bcx) ;
108
- return Callee {
107
+ Callee {
109
108
bcx : bcx,
110
- data : Fn ( llval) ,
111
- } ;
109
+ ty : datum. ty ,
110
+ data : Fn ( datum. to_llscalarish ( bcx) )
111
+ }
112
112
}
113
113
_ => {
114
114
bcx. tcx ( ) . sess . span_bug (
@@ -119,12 +119,13 @@ fn trans<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, expr: &ast::Expr)
119
119
}
120
120
}
121
121
122
- fn fn_callee < ' blk , ' tcx > ( bcx : Block < ' blk , ' tcx > , llfn : ValueRef )
122
+ fn fn_callee < ' blk , ' tcx > ( bcx : Block < ' blk , ' tcx > , datum : Datum < ' tcx , Rvalue > )
123
123
-> Callee < ' blk , ' tcx > {
124
- return Callee {
124
+ Callee {
125
125
bcx : bcx,
126
- data : Fn ( llfn) ,
127
- } ;
126
+ data : Fn ( datum. val ) ,
127
+ ty : datum. ty
128
+ }
128
129
}
129
130
130
131
fn trans_def < ' blk , ' tcx > ( bcx : Block < ' blk , ' tcx > ,
@@ -143,12 +144,10 @@ fn trans<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, expr: &ast::Expr)
143
144
_ => false
144
145
}
145
146
} => {
146
- let substs = common:: node_id_substs ( bcx. ccx ( ) ,
147
- ExprId ( ref_expr. id ) ,
148
- bcx. fcx . param_substs ) ;
149
147
Callee {
150
148
bcx : bcx,
151
- data : NamedTupleConstructor ( substs, 0 )
149
+ data : NamedTupleConstructor ( 0 ) ,
150
+ ty : expr_ty
152
151
}
153
152
}
154
153
def:: DefFn ( did, _) if match expr_ty. sty {
@@ -159,40 +158,36 @@ fn trans<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, expr: &ast::Expr)
159
158
ExprId ( ref_expr. id ) ,
160
159
bcx. fcx . param_substs ) ;
161
160
let def_id = inline:: maybe_instantiate_inline ( bcx. ccx ( ) , did) ;
162
- Callee { bcx : bcx, data : Intrinsic ( def_id. node , substs) }
161
+ Callee { bcx : bcx, data : Intrinsic ( def_id. node , substs) , ty : expr_ty }
163
162
}
164
163
def:: DefFn ( did, _) | def:: DefMethod ( did, def:: FromImpl ( _) ) => {
165
164
fn_callee ( bcx, trans_fn_ref ( bcx. ccx ( ) , did, ExprId ( ref_expr. id ) ,
166
- bcx. fcx . param_substs ) . val )
165
+ bcx. fcx . param_substs ) )
167
166
}
168
167
def:: DefMethod ( meth_did, def:: FromTrait ( trait_did) ) => {
169
168
fn_callee ( bcx, meth:: trans_static_method_callee ( bcx. ccx ( ) ,
170
169
meth_did,
171
170
trait_did,
172
171
ref_expr. id ,
173
- bcx. fcx . param_substs ) . val )
172
+ bcx. fcx . param_substs ) )
174
173
}
175
174
def:: DefVariant ( tid, vid, _) => {
176
175
let vinfo = bcx. tcx ( ) . enum_variant_with_id ( tid, vid) ;
177
- let substs = common:: node_id_substs ( bcx. ccx ( ) ,
178
- ExprId ( ref_expr. id ) ,
179
- bcx. fcx . param_substs ) ;
180
176
181
177
// Nullary variants are not callable
182
178
assert ! ( !vinfo. args. is_empty( ) ) ;
183
179
184
180
Callee {
185
181
bcx : bcx,
186
- data : NamedTupleConstructor ( substs, vinfo. disr_val )
182
+ data : NamedTupleConstructor ( vinfo. disr_val ) ,
183
+ ty : expr_ty
187
184
}
188
185
}
189
186
def:: DefStruct ( _) => {
190
- let substs = common:: node_id_substs ( bcx. ccx ( ) ,
191
- ExprId ( ref_expr. id ) ,
192
- bcx. fcx . param_substs ) ;
193
187
Callee {
194
188
bcx : bcx,
195
- data : NamedTupleConstructor ( substs, 0 )
189
+ data : NamedTupleConstructor ( 0 ) ,
190
+ ty : expr_ty
196
191
}
197
192
}
198
193
def:: DefStatic ( ..) |
@@ -232,21 +227,6 @@ pub fn trans_fn_ref<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
232
227
trans_fn_ref_with_substs ( ccx, def_id, node, param_substs, substs)
233
228
}
234
229
235
- fn trans_fn_ref_with_substs_to_callee < ' blk , ' tcx > ( bcx : Block < ' blk , ' tcx > ,
236
- def_id : ast:: DefId ,
237
- ref_id : ast:: NodeId ,
238
- substs : subst:: Substs < ' tcx > )
239
- -> Callee < ' blk , ' tcx > {
240
- Callee {
241
- bcx : bcx,
242
- data : Fn ( trans_fn_ref_with_substs ( bcx. ccx ( ) ,
243
- def_id,
244
- ExprId ( ref_id) ,
245
- bcx. fcx . param_substs ,
246
- substs) . val ) ,
247
- }
248
- }
249
-
250
230
/// Translates an adapter that implements the `Fn` trait for a fn
251
231
/// pointer. This is basically the equivalent of something like:
252
232
///
@@ -356,12 +336,13 @@ pub fn trans_fn_pointer_shim<'a, 'tcx>(
356
336
expr:: SaveIn ( fcx. get_ret_slot ( bcx, sig. output , "ret_slot" ) )
357
337
) ;
358
338
359
- bcx = trans_call_inner ( bcx,
360
- DebugLoc :: None ,
361
- bare_fn_ty,
362
- |bcx, _| Callee { bcx : bcx, data : Fn ( llfnpointer) } ,
363
- ArgVals ( & llargs[ ( self_idx + 1 ) ..] ) ,
364
- dest) . bcx ;
339
+ bcx = trans_call_inner ( bcx, DebugLoc :: None , |bcx, _| {
340
+ Callee {
341
+ bcx : bcx,
342
+ data : Fn ( llfnpointer) ,
343
+ ty : bare_fn_ty
344
+ }
345
+ } , ArgVals ( & llargs[ ( self_idx + 1 ) ..] ) , dest) . bcx ;
365
346
366
347
finish_fn ( & fcx, bcx, sig. output , DebugLoc :: None ) ;
367
348
@@ -586,17 +567,16 @@ pub fn trans_fn_ref_with_substs<'a, 'tcx>(
586
567
// ______________________________________________________________________
587
568
// Translating calls
588
569
589
- pub fn trans_call < ' a , ' blk , ' tcx > ( in_cx : Block < ' blk , ' tcx > ,
570
+ pub fn trans_call < ' a , ' blk , ' tcx > ( bcx : Block < ' blk , ' tcx > ,
590
571
call_expr : & ast:: Expr ,
591
572
f : & ast:: Expr ,
592
573
args : CallArgs < ' a , ' tcx > ,
593
574
dest : expr:: Dest )
594
575
-> Block < ' blk , ' tcx > {
595
576
let _icx = push_ctxt ( "trans_call" ) ;
596
- trans_call_inner ( in_cx ,
577
+ trans_call_inner ( bcx ,
597
578
call_expr. debug_loc ( ) ,
598
- common:: expr_ty_adjusted ( in_cx, f) ,
599
- |cx, _| trans ( cx, f) ,
579
+ |bcx, _| trans ( bcx, f) ,
600
580
args,
601
581
Some ( dest) ) . bcx
602
582
}
@@ -610,22 +590,9 @@ pub fn trans_method_call<'a, 'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
610
590
let _icx = push_ctxt ( "trans_method_call" ) ;
611
591
debug ! ( "trans_method_call(call_expr={:?})" , call_expr) ;
612
592
let method_call = MethodCall :: expr ( call_expr. id ) ;
613
- let method_ty = match bcx. tcx ( ) . tables . borrow ( ) . method_map . get ( & method_call) {
614
- Some ( method) => match method. origin {
615
- ty:: MethodOrigin :: Object ( _) => match method. ty . sty {
616
- ty:: TyBareFn ( _, ref fty) => {
617
- bcx. tcx ( ) . mk_fn ( None , meth:: opaque_method_ty ( bcx. tcx ( ) , fty) )
618
- }
619
- _ => method. ty
620
- } ,
621
- _ => method. ty
622
- } ,
623
- None => panic ! ( "method not found in trans_method_call" )
624
- } ;
625
593
trans_call_inner (
626
594
bcx,
627
595
call_expr. debug_loc ( ) ,
628
- common:: monomorphize_type ( bcx, method_ty) ,
629
596
|cx, arg_cleanup_scope| {
630
597
meth:: trans_method_callee ( cx, method_call, Some ( rcvr) , arg_cleanup_scope)
631
598
} ,
@@ -639,22 +606,18 @@ pub fn trans_lang_call<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
639
606
dest : Option < expr:: Dest > ,
640
607
debug_loc : DebugLoc )
641
608
-> Result < ' blk , ' tcx > {
642
- let fty = if did. krate == ast:: LOCAL_CRATE {
643
- bcx. tcx ( ) . node_id_to_type ( did. node )
644
- } else {
645
- csearch:: get_type ( bcx. tcx ( ) , did) . ty
646
- } ;
647
- callee:: trans_call_inner ( bcx,
648
- debug_loc,
649
- fty,
650
- |bcx, _| {
651
- trans_fn_ref_with_substs_to_callee ( bcx,
652
- did,
653
- 0 ,
654
- subst:: Substs :: trans_empty ( ) )
655
- } ,
656
- ArgVals ( args) ,
657
- dest)
609
+ callee:: trans_call_inner ( bcx, debug_loc, |bcx, _| {
610
+ let datum = trans_fn_ref_with_substs ( bcx. ccx ( ) ,
611
+ did,
612
+ ExprId ( 0 ) ,
613
+ bcx. fcx . param_substs ,
614
+ subst:: Substs :: trans_empty ( ) ) ;
615
+ Callee {
616
+ bcx : bcx,
617
+ data : Fn ( datum. val ) ,
618
+ ty : datum. ty
619
+ }
620
+ } , ArgVals ( args) , dest)
658
621
}
659
622
660
623
/// This behemoth of a function translates function calls. Unfortunately, in order to generate more
@@ -669,7 +632,6 @@ pub fn trans_lang_call<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
669
632
/// somewhere. Nonetheless we return the actual return value of the function.
670
633
pub fn trans_call_inner < ' a , ' blk , ' tcx , F > ( bcx : Block < ' blk , ' tcx > ,
671
634
debug_loc : DebugLoc ,
672
- callee_ty : Ty < ' tcx > ,
673
635
get_callee : F ,
674
636
args : CallArgs < ' a , ' tcx > ,
675
637
dest : Option < expr:: Dest > )
@@ -690,7 +652,7 @@ pub fn trans_call_inner<'a, 'blk, 'tcx, F>(bcx: Block<'blk, 'tcx>,
690
652
let callee = get_callee ( bcx, cleanup:: CustomScope ( arg_cleanup_scope) ) ;
691
653
let mut bcx = callee. bcx ;
692
654
693
- let ( abi, ret_ty) = match callee_ty . sty {
655
+ let ( abi, ret_ty) = match callee . ty . sty {
694
656
ty:: TyBareFn ( _, ref f) => {
695
657
let output = bcx. tcx ( ) . erase_late_bound_regions ( & f. sig . output ( ) ) ;
696
658
( f. abi , output)
@@ -716,18 +678,17 @@ pub fn trans_call_inner<'a, 'blk, 'tcx, F>(bcx: Block<'blk, 'tcx>,
716
678
}
717
679
} ;
718
680
719
- return intrinsic:: trans_intrinsic_call ( bcx, node, callee_ty ,
681
+ return intrinsic:: trans_intrinsic_call ( bcx, node, callee . ty ,
720
682
arg_cleanup_scope, args,
721
683
dest. unwrap ( ) , substs,
722
684
call_info) ;
723
685
}
724
- NamedTupleConstructor ( substs , disr) => {
686
+ NamedTupleConstructor ( disr) => {
725
687
assert ! ( dest. is_some( ) ) ;
726
688
fcx. pop_custom_cleanup_scope ( arg_cleanup_scope) ;
727
689
728
- let ctor_ty = callee_ty. subst ( bcx. tcx ( ) , & substs) ;
729
690
return base:: trans_named_tuple_constructor ( bcx,
730
- ctor_ty ,
691
+ callee . ty ,
731
692
disr,
732
693
args,
733
694
dest. unwrap ( ) ,
@@ -802,7 +763,7 @@ pub fn trans_call_inner<'a, 'blk, 'tcx, F>(bcx: Block<'blk, 'tcx>,
802
763
// Push the arguments.
803
764
bcx = trans_args ( bcx,
804
765
args,
805
- callee_ty ,
766
+ callee . ty ,
806
767
& mut llargs,
807
768
cleanup:: CustomScope ( arg_cleanup_scope) ,
808
769
llself. is_some ( ) ,
@@ -814,7 +775,7 @@ pub fn trans_call_inner<'a, 'blk, 'tcx, F>(bcx: Block<'blk, 'tcx>,
814
775
let ( llret, b) = base:: invoke ( bcx,
815
776
llfn,
816
777
& llargs[ ..] ,
817
- callee_ty ,
778
+ callee . ty ,
818
779
debug_loc) ;
819
780
bcx = b;
820
781
llresult = llret;
@@ -843,15 +804,15 @@ pub fn trans_call_inner<'a, 'blk, 'tcx, F>(bcx: Block<'blk, 'tcx>,
843
804
} ;
844
805
bcx = trans_args ( bcx,
845
806
args,
846
- callee_ty ,
807
+ callee . ty ,
847
808
& mut llargs,
848
809
cleanup:: CustomScope ( arg_cleanup_scope) ,
849
810
false ,
850
811
abi) ;
851
812
fcx. scopes . borrow_mut ( ) . last_mut ( ) . unwrap ( ) . drop_non_lifetime_clean ( ) ;
852
813
853
814
bcx = foreign:: trans_native_call ( bcx,
854
- callee_ty ,
815
+ callee . ty ,
855
816
llfn,
856
817
opt_llretslot. unwrap ( ) ,
857
818
& llargs[ ..] ,
0 commit comments