@@ -98,7 +98,16 @@ fn type_of_fn(cx: @crate_ctxt, sp: span, proto: ast::proto,
98
98
// Arg 2: Env (closure-bindings / self-obj)
99
99
if is_method {
100
100
atys += [ T_ptr ( cx. rust_object_type ) ] ;
101
- } else { atys += [ T_opaque_closure_ptr ( * cx) ] ; }
101
+ } else {
102
+ alt proto {
103
+ ast : : proto_bare. {
104
+ // Bare functions have no environment
105
+ }
106
+ _ {
107
+ atys += [ T_opaque_closure_ptr ( * cx) ] ;
108
+ }
109
+ }
110
+ }
102
111
103
112
// Args >3: ty params, if not acquired via capture...
104
113
if !is_method {
@@ -3559,7 +3568,15 @@ fn trans_bind_thunk(cx: @local_ctxt, sp: span, incoming_fty: ty::t,
3559
3568
}
3560
3569
3561
3570
// Set up the three implicit arguments to the thunk.
3562
- let llargs: [ ValueRef ] = [ llretptr, fcx. lltaskptr , lltargetenv] ;
3571
+ let llargs: [ ValueRef ] = alt ty:: ty_fn_proto ( ccx. tcx , outgoing_fty) {
3572
+ ast:: proto_bare. {
3573
+ // Bare functions don't take an environment
3574
+ [ llretptr, fcx. lltaskptr ]
3575
+ }
3576
+ _ {
3577
+ [ llretptr, fcx. lltaskptr, lltargetenv]
3578
+ }
3579
+ } ;
3563
3580
3564
3581
// Copy in the type parameters.
3565
3582
let i: uint = 0 u;
@@ -3845,7 +3862,12 @@ fn trans_args(cx: @block_ctxt, outer_cx: @block_ctxt, llenv: ValueRef,
3845
3862
llargs += [ bcx. fcx . lltaskptr ] ;
3846
3863
3847
3864
// Arg 2: Env (closure-bindings / self-obj)
3848
- llargs += [ llenv] ;
3865
+ alt ty:: ty_fn_proto ( tcx, fn_ty) {
3866
+ ast:: proto_bare. { }
3867
+ _ {
3868
+ llargs += [ llenv] ;
3869
+ }
3870
+ }
3849
3871
3850
3872
// Args >3: ty_params ...
3851
3873
llargs += lltydescs;
@@ -5098,6 +5120,7 @@ fn new_fn_ctxt_w_id(cx: @local_ctxt, sp: span, llfndecl: ValueRef,
5098
5120
id : ast:: node_id , rstyle : ast:: ret_style )
5099
5121
-> @fn_ctxt {
5100
5122
let llbbs = mk_standard_basic_blocks ( llfndecl) ;
5123
+ // FIXME: llenv is not correct for bare functions
5101
5124
ret @{ llfn : llfndecl,
5102
5125
lltaskptr : llvm:: LLVMGetParam ( llfndecl, 1 u) ,
5103
5126
llenv : llvm:: LLVMGetParam ( llfndecl, 2 u) ,
@@ -5128,6 +5151,13 @@ fn new_fn_ctxt(cx: @local_ctxt, sp: span, llfndecl: ValueRef) -> @fn_ctxt {
5128
5151
ret new_fn_ctxt_w_id ( cx, sp, llfndecl, -1 , ast:: return_val) ;
5129
5152
}
5130
5153
5154
+ fn implicit_args_for_fn ( proto : ast:: proto ) -> uint {
5155
+ alt proto {
5156
+ ast : : proto_bare. { 2 u }
5157
+ _ { 3 u }
5158
+ }
5159
+ }
5160
+
5131
5161
// NB: must keep 4 fns in sync:
5132
5162
//
5133
5163
// - type_of_fn
@@ -5145,10 +5175,8 @@ fn new_fn_ctxt(cx: @local_ctxt, sp: span, llfndecl: ValueRef) -> @fn_ctxt {
5145
5175
fn create_llargs_for_fn_args ( cx : @fn_ctxt , proto : ast:: proto ,
5146
5176
ty_self : option:: t < ty:: t > , ret_ty : ty:: t ,
5147
5177
args : [ ast:: arg ] , ty_params : [ ast:: ty_param ] ) {
5148
- // Skip the implicit arguments 0, 1, and 2. TODO: Pull out 3u and define
5149
- // it as a constant, since we're using it in several places in trans this
5150
- // way.
5151
- let arg_n = 3 u;
5178
+ // Skip the implicit arguments
5179
+ let arg_n = implicit_args_for_fn ( proto) ;
5152
5180
alt ty_self {
5153
5181
some( tt) { cx. llself = some :: < val_self_pair > ( { v: cx. llenv , t: tt} ) ; }
5154
5182
none. {
0 commit comments