Revert "Remove the environment argument from bare functions"

This reverts commit 1b0f1f0b79.
This commit is contained in:
Brian Anderson 2011-10-14 15:16:44 -07:00
parent 070c39ca1d
commit 3bb020aaf8

View File

@ -95,16 +95,7 @@ fn type_of_fn(cx: @crate_ctxt, sp: span, proto: ast::proto,
// Arg 1: Env (closure-bindings / self-obj)
if is_method {
atys += [T_ptr(cx.rust_object_type)];
} else {
alt proto {
ast::proto_bare. {
// Bare functions have no environment
}
_ {
atys += [T_opaque_closure_ptr(*cx)];
}
}
}
} else { atys += [T_opaque_closure_ptr(*cx)]; }
// Args >2: ty params, if not acquired via capture...
if !is_method {
@ -3549,15 +3540,7 @@ fn trans_bind_thunk(cx: @local_ctxt, sp: span, incoming_fty: ty::t,
}
// Set up the three implicit arguments to the thunk.
let llargs: [ValueRef] = alt ty::ty_fn_proto(ccx.tcx, outgoing_fty) {
ast::proto_bare. {
// Bare functions don't take an environment
[llretptr]
}
_ {
[llretptr, lltargetenv]
}
};
let llargs: [ValueRef] = [llretptr, lltargetenv];
// Copy in the type parameters.
let i: uint = 0u;
@ -3840,12 +3823,7 @@ fn trans_args(cx: @block_ctxt, outer_cx: @block_ctxt, llenv: ValueRef,
} else { llargs += [llretslot]; }
// Arg 1: Env (closure-bindings / self-obj)
alt ty::ty_fn_proto(tcx, fn_ty) {
ast::proto_bare. { }
_ {
llargs += [llenv];
}
}
llargs += [llenv];
// Args >2: ty_params ...
llargs += lltydescs;
@ -5097,7 +5075,6 @@ fn new_fn_ctxt_w_id(cx: @local_ctxt, sp: span, llfndecl: ValueRef,
id: ast::node_id, rstyle: ast::ret_style)
-> @fn_ctxt {
let llbbs = mk_standard_basic_blocks(llfndecl);
// FIXME: llenv is not correct for bare functions
ret @{llfn: llfndecl,
llenv: llvm::LLVMGetParam(llfndecl, 1u),
llretptr: llvm::LLVMGetParam(llfndecl, 0u),
@ -5127,13 +5104,6 @@ fn new_fn_ctxt(cx: @local_ctxt, sp: span, llfndecl: ValueRef) -> @fn_ctxt {
ret new_fn_ctxt_w_id(cx, sp, llfndecl, -1, ast::return_val);
}
fn implicit_args_for_fn(proto: ast::proto) -> uint {
alt proto {
ast::proto_bare. { 1u }
_ { 2u }
}
}
// NB: must keep 4 fns in sync:
//
// - type_of_fn
@ -5151,8 +5121,10 @@ fn implicit_args_for_fn(proto: ast::proto) -> uint {
fn create_llargs_for_fn_args(cx: @fn_ctxt, proto: ast::proto,
ty_self: option::t<ty::t>, ret_ty: ty::t,
args: [ast::arg], ty_params: [ast::ty_param]) {
// Skip the implicit arguments
let arg_n = implicit_args_for_fn(proto);
// Skip the implicit arguments 0, and 1. TODO: Pull out 2u and define
// it as a constant, since we're using it in several places in trans this
// way.
let arg_n = 2u;
alt ty_self {
some(tt) { cx.llself = some::<val_self_pair>({v: cx.llenv, t: tt}); }
none. {