@@ -39,6 +39,7 @@ use middle::trans::inline;
39
39
use middle:: trans:: meth;
40
40
use middle:: trans:: monomorphize;
41
41
use middle:: trans:: type_of;
42
+ use middle:: ty:: ty_to_str;
42
43
use middle:: ty;
43
44
use middle:: typeck;
44
45
use util:: common:: indenter;
@@ -94,10 +95,25 @@ pub fn trans(bcx: block, expr: @ast::expr) -> Callee {
94
95
}
95
96
96
97
// any other expressions are closures:
97
- return closure_callee ( & expr:: trans_to_datum ( bcx, expr) ) ;
98
-
99
- fn closure_callee ( db : & DatumBlock ) -> Callee {
100
- return Callee { bcx : db. bcx , data : Closure ( db. datum ) } ;
98
+ return datum_callee ( bcx, expr) ;
99
+
100
+ fn datum_callee ( bcx : block , expr : @ast:: expr ) -> Callee {
101
+ let DatumBlock { bcx, datum} = expr:: trans_to_datum ( bcx, expr) ;
102
+ match ty:: get ( datum. ty ) . sty {
103
+ ty:: ty_bare_fn( * ) => {
104
+ let llval = datum. to_appropriate_llval ( bcx) ;
105
+ return Callee { bcx : bcx, data : Fn ( FnData { llfn : llval} ) } ;
106
+ }
107
+ ty:: ty_closure( * ) => {
108
+ return Callee { bcx : bcx, data : Closure ( datum) } ;
109
+ }
110
+ _ => {
111
+ bcx. tcx ( ) . sess . span_bug (
112
+ expr. span ,
113
+ fmt ! ( "Type of callee is neither bare-fn nor closure: %s" ,
114
+ bcx. ty_to_str( datum. ty) ) ) ;
115
+ }
116
+ }
101
117
}
102
118
103
119
fn fn_callee ( bcx : block , fd : FnData ) -> Callee {
@@ -129,7 +145,7 @@ pub fn trans(bcx: block, expr: @ast::expr) -> Callee {
129
145
ast:: def_binding( * ) |
130
146
ast:: def_upvar( * ) |
131
147
ast:: def_self( * ) => {
132
- closure_callee ( & expr :: trans_to_datum ( bcx, ref_expr) )
148
+ datum_callee ( bcx, ref_expr)
133
149
}
134
150
ast:: def_mod( * ) | ast:: def_foreign_mod( * ) |
135
151
ast:: def_const( * ) | ast:: def_ty( * ) | ast:: def_prim_ty( * ) |
@@ -392,7 +408,6 @@ pub fn trans_lang_call_with_type_params(bcx: block,
392
408
fty) ;
393
409
let mut llfnty = type_of:: type_of ( callee. bcx . ccx ( ) ,
394
410
substituted) ;
395
- llfnty = lib:: llvm:: struct_tys ( llfnty) [ 0 ] ;
396
411
new_llval = PointerCast ( callee. bcx , fn_data. llfn , llfnty) ;
397
412
}
398
413
_ => fail ! ( )
@@ -715,6 +730,8 @@ pub fn trans_arg_expr(bcx: block,
715
730
}
716
731
717
732
ast:: by_copy => {
733
+ debug ! ( "by copy arg with type %s, storing to scratch" ,
734
+ bcx. ty_to_str( arg_datum. ty) ) ;
718
735
let scratch = scratch_datum ( bcx, arg_datum. ty , false ) ;
719
736
720
737
arg_datum. store_to_datum ( bcx, arg_expr. id ,
0 commit comments