Skip to content

Commit 8124846

Browse files
committed
Get rid of taskpointer-passing throughout the compiler
Only intrinsics still take a dummy taskptr. We'll have to do some makefile stunts to snapshot a version without taskptrs-in-intrinsics. Issue #466
1 parent 457683c commit 8124846

11 files changed

+52
-80
lines changed

Diff for: src/comp/back/upcall.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ type upcalls =
3131
rust_personality: ValueRef};
3232

3333
fn declare_upcalls(_tn: type_names, tydesc_type: TypeRef,
34-
taskptr_type: TypeRef, llmod: ModuleRef) -> @upcalls {
34+
llmod: ModuleRef) -> @upcalls {
3535
fn decl(llmod: ModuleRef, name: str, tys: [TypeRef], rv: TypeRef) ->
3636
ValueRef {
3737
let arg_tys: [TypeRef] = [];
@@ -63,7 +63,7 @@ fn declare_upcalls(_tn: type_names, tydesc_type: TypeRef,
6363
T_ptr(T_i8())]),
6464
cmp_type:
6565
dv("cmp_type",
66-
[T_ptr(T_i1()), taskptr_type, T_ptr(tydesc_type),
66+
[T_ptr(T_i1()), T_ptr(tydesc_type),
6767
T_ptr(T_ptr(tydesc_type)), T_ptr(T_i8()), T_ptr(T_i8()),
6868
T_i8()]),
6969
log_type:

Diff for: src/comp/middle/trans.rs

+26-51
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,7 @@ fn type_of_fn(cx: @crate_ctxt, sp: span, proto: ast::proto,
9292
let out_ty = T_ptr(type_of_inner(cx, sp, output));
9393
atys += [ret_ref ? T_ptr(out_ty) : out_ty];
9494

95-
// Arg 1: task pointer.
96-
atys += [T_taskptr(*cx)];
97-
98-
// Arg 2: Env (closure-bindings / self-obj)
95+
// Arg 1: Env (closure-bindings / self-obj)
9996
if is_method {
10097
atys += [T_ptr(cx.rust_object_type)];
10198
} else {
@@ -109,7 +106,7 @@ fn type_of_fn(cx: @crate_ctxt, sp: span, proto: ast::proto,
109106
}
110107
}
111108

112-
// Args >3: ty params, if not acquired via capture...
109+
// Args >2: ty params, if not acquired via capture...
113110
if !is_method {
114111
let i = 0u;
115112
while i < ty_param_count { atys += [T_ptr(cx.tydesc_type)]; i += 1u; }
@@ -349,10 +346,6 @@ fn decl_internal_cdecl_fn(llmod: ModuleRef, name: str, llty: TypeRef) ->
349346
ret llfn;
350347
}
351348

352-
fn decl_glue(llmod: ModuleRef, cx: crate_ctxt, s: str) -> ValueRef {
353-
ret decl_cdecl_fn(llmod, s, T_fn([T_taskptr(cx)], T_void()));
354-
}
355-
356349
fn get_extern_fn(externs: hashmap<str, ValueRef>, llmod: ModuleRef, name: str,
357350
cc: uint, ty: TypeRef) -> ValueRef {
358351
if externs.contains_key(name) { ret externs.get(name); }
@@ -1217,7 +1210,7 @@ fn make_generic_glue_inner(cx: @local_ctxt, sp: span, t: ty::t,
12171210
} else { T_ptr(T_i8()) };
12181211

12191212
let ty_param_count = std::vec::len::<uint>(ty_params);
1220-
let lltyparams = llvm::LLVMGetParam(llfn, 3u);
1213+
let lltyparams = llvm::LLVMGetParam(llfn, 2u);
12211214
let load_env_bcx = new_raw_block_ctxt(fcx, fcx.llloadenv);
12221215
let lltydescs = [mutable];
12231216
let p = 0u;
@@ -1235,12 +1228,12 @@ fn make_generic_glue_inner(cx: @local_ctxt, sp: span, t: ty::t,
12351228

12361229
let bcx = new_top_block_ctxt(fcx);
12371230
let lltop = bcx.llbb;
1238-
let llrawptr0 = llvm::LLVMGetParam(llfn, 4u);
1231+
let llrawptr0 = llvm::LLVMGetParam(llfn, 3u);
12391232
let llval0 = BitCast(bcx, llrawptr0, llty);
12401233
alt helper {
12411234
default_helper(helper) { helper(bcx, llval0, t); }
12421235
copy_helper(helper) {
1243-
let llrawptr1 = llvm::LLVMGetParam(llfn, 5u);
1236+
let llrawptr1 = llvm::LLVMGetParam(llfn, 4u);
12441237
let llval1 = BitCast(bcx, llrawptr1, llty);
12451238
helper(bcx, llval0, llval1, t);
12461239
}
@@ -1463,7 +1456,7 @@ fn trans_res_drop(cx: @block_ctxt, rs: ValueRef, did: ast::def_id,
14631456
cx = val.bcx;
14641457
// Find and call the actual destructor.
14651458
let dtor_addr = trans_common::get_res_dtor(ccx, cx.sp, did, inner_t);
1466-
let args = [cx.fcx.llretptr, cx.fcx.lltaskptr, null_env_ptr(cx)];
1459+
let args = [cx.fcx.llretptr, null_env_ptr(cx)];
14671460
for tp: ty::t in tps {
14681461
let ti: option::t<@tydesc_info> = none;
14691462
let td = get_tydesc(cx, tp, false, tps_normal, ti).result;
@@ -1888,9 +1881,8 @@ fn call_tydesc_glue_full(cx: @block_ctxt, v: ValueRef, tydesc: ValueRef,
18881881
some(sgf) { llfn = sgf; }
18891882
}
18901883

1891-
Call(cx, llfn,
1892-
[C_null(T_ptr(T_nil())), cx.fcx.lltaskptr, C_null(T_ptr(T_nil())),
1893-
lltydescs, llrawptr]);
1884+
Call(cx, llfn, [C_null(T_ptr(T_nil())), C_null(T_ptr(T_nil())),
1885+
lltydescs, llrawptr]);
18941886
}
18951887

18961888
fn call_tydesc_glue(cx: @block_ctxt, v: ValueRef, t: ty::t, field: int) ->
@@ -1937,7 +1929,7 @@ fn call_cmp_glue(cx: @block_ctxt, lhs: ValueRef, rhs: ValueRef, t: ty::t,
19371929
}
19381930

19391931
let llcmpresultptr = alloca(bcx, T_i1());
1940-
Call(bcx, llfn, [llcmpresultptr, bcx.fcx.lltaskptr, lltydesc, lltydescs,
1932+
Call(bcx, llfn, [llcmpresultptr, lltydesc, lltydescs,
19411933
llrawlhsptr, llrawrhsptr, llop]);
19421934
ret rslt(bcx, Load(bcx, llcmpresultptr));
19431935
}
@@ -2921,7 +2913,7 @@ fn trans_for_each(cx: @block_ctxt, local: @ast::local, seq: @ast::expr,
29212913
let bcx = new_top_block_ctxt(fcx);
29222914
// Add bindings for the loop variable alias.
29232915
bcx = trans_alt::bind_irrefutable_pat(bcx, local.node.pat,
2924-
llvm::LLVMGetParam(fcx.llfn, 3u),
2916+
llvm::LLVMGetParam(fcx.llfn, 2u),
29252917
false);
29262918
let lltop = bcx.llbb;
29272919
bcx = trans_block(bcx, body);
@@ -3560,10 +3552,10 @@ fn trans_bind_thunk(cx: @local_ctxt, sp: span, incoming_fty: ty::t,
35603552
let llargs: [ValueRef] = alt ty::ty_fn_proto(ccx.tcx, outgoing_fty) {
35613553
ast::proto_bare. {
35623554
// Bare functions don't take an environment
3563-
[llretptr, fcx.lltaskptr]
3555+
[llretptr]
35643556
}
35653557
_ {
3566-
[llretptr, fcx.lltaskptr, lltargetenv]
3558+
[llretptr, lltargetenv]
35673559
}
35683560
};
35693561

@@ -3583,7 +3575,7 @@ fn trans_bind_thunk(cx: @local_ctxt, sp: span, incoming_fty: ty::t,
35833575
i += 1u;
35843576
}
35853577

3586-
let a: uint = 3u; // retptr, task ptr, env come first
3578+
let a: uint = 2u; // retptr, env come first
35873579
let b: int = starting_idx;
35883580
let outgoing_arg_index: uint = 0u;
35893581
let llout_arg_tys: [TypeRef] =
@@ -3847,18 +3839,15 @@ fn trans_args(cx: @block_ctxt, outer_cx: @block_ctxt, llenv: ValueRef,
38473839
llargs += [PointerCast(cx, llretslot, llretty)];
38483840
} else { llargs += [llretslot]; }
38493841

3850-
// Arg 1: task pointer.
3851-
llargs += [bcx.fcx.lltaskptr];
3852-
3853-
// Arg 2: Env (closure-bindings / self-obj)
3842+
// Arg 1: Env (closure-bindings / self-obj)
38543843
alt ty::ty_fn_proto(tcx, fn_ty) {
38553844
ast::proto_bare. { }
38563845
_ {
38573846
llargs += [llenv];
38583847
}
38593848
}
38603849

3861-
// Args >3: ty_params ...
3850+
// Args >2: ty_params ...
38623851
llargs += lltydescs;
38633852

38643853
// ... then possibly an lliterbody argument.
@@ -4639,7 +4628,7 @@ fn trans_put(in_cx: @block_ctxt, e: option::t<@ast::expr>) -> @block_ctxt {
46394628
}
46404629
let bcx = cx;
46414630
let dummy_retslot = alloca(bcx, T_nil());
4642-
let llargs: [ValueRef] = [dummy_retslot, cx.fcx.lltaskptr, llenv];
4631+
let llargs: [ValueRef] = [dummy_retslot, llenv];
46434632
alt e {
46444633
none. {
46454634
llargs += [C_null(T_ptr(T_nil()))];
@@ -5110,8 +5099,7 @@ fn new_fn_ctxt_w_id(cx: @local_ctxt, sp: span, llfndecl: ValueRef,
51105099
let llbbs = mk_standard_basic_blocks(llfndecl);
51115100
// FIXME: llenv is not correct for bare functions
51125101
ret @{llfn: llfndecl,
5113-
lltaskptr: llvm::LLVMGetParam(llfndecl, 1u),
5114-
llenv: llvm::LLVMGetParam(llfndecl, 2u),
5102+
llenv: llvm::LLVMGetParam(llfndecl, 1u),
51155103
llretptr: llvm::LLVMGetParam(llfndecl, 0u),
51165104
mutable llstaticallocas: llbbs.sa,
51175105
mutable llloadenv: llbbs.ca,
@@ -5141,8 +5129,8 @@ fn new_fn_ctxt(cx: @local_ctxt, sp: span, llfndecl: ValueRef) -> @fn_ctxt {
51415129

51425130
fn implicit_args_for_fn(proto: ast::proto) -> uint {
51435131
alt proto {
5144-
ast::proto_bare. { 2u }
5145-
_ { 3u }
5132+
ast::proto_bare. { 1u }
5133+
_ { 2u }
51465134
}
51475135
}
51485136

@@ -5666,10 +5654,9 @@ fn create_main_wrapper(ccx: @crate_ctxt, sp: span, main_llfn: ValueRef,
56665654
let lltop = bcx.llbb;
56675655

56685656
let lloutputarg = llvm::LLVMGetParam(llfdecl, 0u);
5669-
let lltaskarg = llvm::LLVMGetParam(llfdecl, 1u);
5670-
let llenvarg = llvm::LLVMGetParam(llfdecl, 2u);
5671-
let args = [lloutputarg, lltaskarg, llenvarg];
5672-
if takes_argv { args += [llvm::LLVMGetParam(llfdecl, 3u)]; }
5657+
let llenvarg = llvm::LLVMGetParam(llfdecl, 1u);
5658+
let args = [lloutputarg, llenvarg];
5659+
if takes_argv { args += [llvm::LLVMGetParam(llfdecl, 2u)]; }
56735660
Call(bcx, main_llfn, args);
56745661
build_return(bcx);
56755662

@@ -5825,16 +5812,11 @@ fn register_native_fn(ccx: @crate_ctxt, sp: span, path: [str], name: str,
58255812
let rty = ty::ty_fn_ret(ccx.tcx, fn_type);
58265813
let rty_is_nil = ty::type_is_nil(ccx.tcx, rty);
58275814

5828-
let lltaskptr;
5829-
if cast_to_i32 {
5830-
lltaskptr = vp2i(bcx, fcx.lltaskptr);
5831-
} else { lltaskptr = fcx.lltaskptr; }
5832-
58335815
let call_args: [ValueRef] = [];
5834-
if pass_task { call_args += [lltaskptr]; }
5816+
if pass_task { call_args += [C_null(T_ptr(ccx.task_type))]; }
58355817
if uses_retptr { call_args += [bcx.fcx.llretptr]; }
58365818

5837-
let arg_n = 3u;
5819+
let arg_n = 2u;
58385820
for each i: uint in uint::range(0u, num_ty_param) {
58395821
let llarg = llvm::LLVMGetParam(fcx.llfn, arg_n);
58405822
fcx.lltydescs += [llarg];
@@ -6144,11 +6126,6 @@ fn trap(bcx: @block_ctxt) {
61446126
}
61456127
}
61466128

6147-
fn decl_no_op_type_glue(llmod: ModuleRef, taskptr_type: TypeRef) -> ValueRef {
6148-
let ty = T_fn([taskptr_type, T_ptr(T_i8())], T_void());
6149-
ret decl_cdecl_fn(llmod, abi::no_op_type_glue_name(), ty);
6150-
}
6151-
61526129
fn create_module_map(ccx: @crate_ctxt) -> ValueRef {
61536130
let elttype = T_struct([T_int(), T_int()]);
61546131
let maptype = T_array(elttype, ccx.module_data.size() + 1u);
@@ -6255,9 +6232,7 @@ fn trans_crate(sess: session::session, crate: @ast::crate, tcx: ty::ctxt,
62556232
let tn = mk_type_names();
62566233
let intrinsics = declare_intrinsics(llmod);
62576234
let task_type = T_task();
6258-
let taskptr_type = T_ptr(task_type);
6259-
tn.associate("taskptr", taskptr_type);
6260-
let tydesc_type = T_tydesc(taskptr_type);
6235+
let tydesc_type = T_tydesc();
62616236
tn.associate("tydesc", tydesc_type);
62626237
let hasher = ty::hash_ty;
62636238
let eqer = ty::eq_ty;
@@ -6302,7 +6277,7 @@ fn trans_crate(sess: session::session, crate: @ast::crate, tcx: ty::ctxt,
63026277
mutable n_real_glues: 0u,
63036278
fn_times: @mutable []},
63046279
upcalls:
6305-
upcall::declare_upcalls(tn, tydesc_type, taskptr_type, llmod),
6280+
upcall::declare_upcalls(tn, tydesc_type, llmod),
63066281
rust_object_type: T_rust_object(),
63076282
tydesc_type: tydesc_type,
63086283
task_type: task_type,

Diff for: src/comp/middle/trans_common.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,6 @@ type fn_ctxt =
234234

235235
// This function's enclosing local context.
236236
{llfn: ValueRef,
237-
lltaskptr: ValueRef,
238237
llenv: ValueRef,
239238
llretptr: ValueRef,
240239
mutable llstaticallocas: BasicBlockRef,
@@ -605,15 +604,15 @@ fn T_cmp_glue_fn(cx: crate_ctxt) -> TypeRef {
605604
ret t;
606605
}
607606

608-
fn T_tydesc(taskptr_type: TypeRef) -> TypeRef {
607+
fn T_tydesc() -> TypeRef {
609608
let tydesc = T_named_struct("tydesc");
610609
let tydescpp = T_ptr(T_ptr(tydesc));
611610
let pvoid = T_ptr(T_i8());
612611
let glue_fn_ty =
613-
T_ptr(T_fn([T_ptr(T_nil()), taskptr_type, T_ptr(T_nil()), tydescpp,
612+
T_ptr(T_fn([T_ptr(T_nil()), T_ptr(T_nil()), tydescpp,
614613
pvoid], T_void()));
615614
let cmp_glue_fn_ty =
616-
T_ptr(T_fn([T_ptr(T_i1()), taskptr_type, T_ptr(tydesc), tydescpp,
615+
T_ptr(T_fn([T_ptr(T_i1()), T_ptr(tydesc), tydescpp,
617616
pvoid, pvoid, T_i8()], T_void()));
618617

619618
let elems =

Diff for: src/comp/middle/trans_objects.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -680,13 +680,12 @@ fn process_bkwding_mthd(cx: @local_ctxt, sp: span, m: @ty::method,
680680

681681
// Set up the three implicit arguments to the outer method we'll need to
682682
// call.
683-
let llouter_mthd_args: [ValueRef] = [llretptr, fcx.lltaskptr,
684-
llself_obj_ptr];
683+
let llouter_mthd_args: [ValueRef] = [llretptr, llself_obj_ptr];
685684

686685
// Copy the explicit arguments that are being passed into the forwarding
687686
// function (they're in fcx.llargs) to llouter_mthd_args.
688687

689-
let a: uint = 3u; // retptr, task ptr, env come first
688+
let a: uint = 2u; // retptr, env come first
690689
for arg: ty::arg in m.inputs {
691690
llouter_mthd_args += [llvm::LLVMGetParam(llbackwarding_fn, a)];
692691
a += 1u;
@@ -833,12 +832,12 @@ fn process_fwding_mthd(cx: @local_ctxt, sp: span, m: @ty::method,
833832

834833
// Set up the three implicit arguments to the original method we'll need
835834
// to call.
836-
let llorig_mthd_args: [ValueRef] = [llretptr, fcx.lltaskptr, self_stack];
835+
let llorig_mthd_args: [ValueRef] = [llretptr, self_stack];
837836

838837
// Copy the explicit arguments that are being passed into the forwarding
839838
// function (they're in fcx.llargs) to llorig_mthd_args.
840839

841-
let a: uint = 3u; // retptr, task ptr, env come first
840+
let a: uint = 2u; // retptr, env come first
842841
for arg: ty::arg in m.inputs {
843842
llorig_mthd_args += [llvm::LLVMGetParam(llforwarding_fn, a)];
844843
a += 1u;

Diff for: src/rt/intrinsics/intrinsics.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ rust_intrinsic_cast(rust_task *task, void *retptr, type_desc *t1,
2828
type_desc *t2, void *src)
2929
{
3030
if (t1->size != t2->size) {
31-
upcall_fail(task, "attempt to cast values of differing sizes",
31+
upcall_fail("attempt to cast values of differing sizes",
3232
__FILE__, __LINE__);
3333
return;
3434
}
@@ -45,6 +45,6 @@ rust_intrinsic_addr_of(rust_task *task, void **retptr, type_desc *ty,
4545
extern "C" void
4646
rust_intrinsic_recv(rust_task *task, void **retptr, type_desc *ty,
4747
rust_port *port) {
48-
port_recv(task, (uintptr_t*)retptr, port);
48+
port_recv((uintptr_t*)retptr, port);
4949
}
5050

Diff for: src/rt/intrinsics/intrinsics.ll.in

+4-4
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ entry:
8383
br i1 %cmp, label %if.end, label %if.then
8484

8585
if.then: ; preds = %entry
86-
tail call void @upcall_fail(%struct.rust_task* %task, i8* getelementptr inbounds ([42 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([15 x i8]* @.str1, i32 0, i32 0), i32 45)
86+
tail call void @upcall_fail(i8* getelementptr inbounds ([42 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([15 x i8]* @.str1, i32 0, i32 0), i32 45)
8787
br label %return
8888

8989
if.end: ; preds = %entry
@@ -94,7 +94,7 @@ return: ; preds = %if.end, %if.then
9494
ret void
9595
}
9696

97-
declare void @upcall_fail(%struct.rust_task*, i8*, i8*, i32)
97+
declare void @upcall_fail(i8*, i8*, i32)
9898

9999
declare void @llvm.memmove.p0i8.p0i8.i32(i8* nocapture, i8* nocapture, i32, i32, i1) nounwind
100100

@@ -107,11 +107,11 @@ entry:
107107
define linkonce_odr void @rust_intrinsic_recv(%struct.rust_task* %task, i8** %retptr, %struct.type_desc* nocapture %ty, %class.rust_port* %port) {
108108
entry:
109109
%0 = bitcast i8** %retptr to i32*
110-
tail call void @port_recv(%struct.rust_task* %task, i32* %0, %class.rust_port* %port)
110+
tail call void @port_recv(i32* %0, %class.rust_port* %port)
111111
ret void
112112
}
113113

114-
declare void @port_recv(%struct.rust_task*, i32*, %class.rust_port*)
114+
declare void @port_recv(i32*, %class.rust_port*)
115115

116116
!0 = metadata !{metadata !"long", metadata !1}
117117
!1 = metadata !{metadata !"omnipotent char", metadata !2}

Diff for: src/rt/rust_builtin.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -452,9 +452,9 @@ struct fn_env_pair {
452452

453453
// FIXME This is probably not needed at all anymore. Have to rearrange some
454454
// argument passing to remove it.
455-
void rust_spawn_wrapper(void* retptr, rust_task* taskptr, void* envptr,
456-
void(*func)(void*, rust_task*, void*)) {
457-
func(retptr, taskptr, envptr);
455+
void rust_spawn_wrapper(void* retptr, void* envptr,
456+
void(*func)(void*, void*)) {
457+
func(retptr, envptr);
458458
}
459459

460460
extern "C" CDECL void

Diff for: src/rt/rust_internal.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -245,9 +245,9 @@ struct rust_timer {
245245

246246
#include "rust_util.h"
247247

248-
typedef void CDECL (glue_fn)(void *, rust_task *, void *,
248+
typedef void CDECL (glue_fn)(void *, void *,
249249
const type_desc **, void *);
250-
typedef void CDECL (cmp_glue_fn)(void *, rust_task *, void *,
250+
typedef void CDECL (cmp_glue_fn)(void *, void *,
251251
const type_desc **,
252252
void *, void *, int8_t);
253253

Diff for: src/rt/rust_shape.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -530,9 +530,10 @@ log::walk_res(const rust_fn *dtor, unsigned n_params,
530530
} // end namespace shape
531531

532532
extern "C" void
533-
upcall_cmp_type(int8_t *result, rust_task *task, const type_desc *tydesc,
533+
upcall_cmp_type(int8_t *result, const type_desc *tydesc,
534534
const type_desc **subtydescs, uint8_t *data_0,
535535
uint8_t *data_1, uint8_t cmp_type) {
536+
rust_task *task = rust_scheduler::get_task();
536537
shape::arena arena;
537538

538539
// FIXME: This may well be broken when comparing two closures or objects

0 commit comments

Comments
 (0)