Skip to content

Commit 9fb2284

Browse files
committed
rustc: Add a type param ID -> type descriptor mapping to function contexts
1 parent 7bd30f8 commit 9fb2284

File tree

1 file changed

+30
-16
lines changed

1 file changed

+30
-16
lines changed

src/comp/middle/trans.rs

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ state type fn_ctxt = rec(ValueRef llfn,
7777
ValueRef lltaskptr,
7878
hashmap[ast.def_id, ValueRef] llargs,
7979
hashmap[ast.def_id, ValueRef] lllocals,
80+
hashmap[ast.def_id, ValueRef] lltydescs,
8081
@crate_ctxt ccx);
8182

8283
tag cleanup {
@@ -2261,17 +2262,27 @@ fn new_fn_ctxt(@crate_ctxt cx,
22612262

22622263
let hashmap[ast.def_id, ValueRef] lllocals = new_def_hash[ValueRef]();
22632264
let hashmap[ast.def_id, ValueRef] llargs = new_def_hash[ValueRef]();
2265+
let hashmap[ast.def_id, ValueRef] lltydescs = new_def_hash[ValueRef]();
22642266

22652267
ret @rec(llfn=llfndecl,
22662268
lltaskptr=lltaskptr,
22672269
llargs=llargs,
22682270
lllocals=lllocals,
2271+
lltydescs=lltydescs,
22692272
ccx=cx);
22702273
}
22712274

22722275

2273-
fn create_llargs_for_fn_args(@fn_ctxt cx, vec[ast.arg] args) {
2276+
fn create_llargs_for_fn_args(&@fn_ctxt cx, &vec[ast.arg] args,
2277+
&vec[ast.ty_param] ty_params) {
22742278
let uint arg_n = 1u;
2279+
for (ast.ty_param tp in ty_params) {
2280+
auto llarg = llvm.LLVMGetParam(cx.llfn, arg_n);
2281+
check (llarg as int != 0);
2282+
cx.lltydescs.insert(tp.id, llarg);
2283+
arg_n += 1u;
2284+
}
2285+
22752286
for (ast.arg arg in args) {
22762287
auto llarg = llvm.LLVMGetParam(cx.llfn, arg_n);
22772288
check (llarg as int != 0);
@@ -2328,13 +2339,13 @@ fn ret_ty_of_fn(ast.ann ann) -> @typeck.ty {
23282339
}
23292340

23302341
impure fn trans_fn(@crate_ctxt cx, &ast._fn f, ast.def_id fid,
2331-
&ast.ann ann) {
2342+
&vec[ast.ty_param] ty_params, &ast.ann ann) {
23322343

23332344
auto llfndecl = cx.item_ids.get(fid);
23342345
cx.item_names.insert(cx.path, llfndecl);
23352346

23362347
auto fcx = new_fn_ctxt(cx, cx.path, llfndecl);
2337-
create_llargs_for_fn_args(fcx, f.inputs);
2348+
create_llargs_for_fn_args(fcx, f.inputs, ty_params);
23382349

23392350
auto bcx = new_top_block_ctxt(fcx);
23402351

@@ -2348,7 +2359,8 @@ impure fn trans_fn(@crate_ctxt cx, &ast._fn f, ast.def_id fid,
23482359
}
23492360
}
23502361

2351-
impure fn trans_vtbl(@crate_ctxt cx, &ast._obj ob) -> ValueRef {
2362+
impure fn trans_vtbl(@crate_ctxt cx, &ast._obj ob,
2363+
&vec[ast.ty_param] ty_params) -> ValueRef {
23522364
let vec[ValueRef] methods = vec();
23532365
for (@ast.method m in ob.methods) {
23542366

@@ -2357,7 +2369,7 @@ impure fn trans_vtbl(@crate_ctxt cx, &ast._obj ob) -> ValueRef {
23572369
let ValueRef llfn = decl_fastcall_fn(cx.llmod, s, llfnty);
23582370
cx.item_ids.insert(m.node.id, llfn);
23592371

2360-
trans_fn(cx, m.node.meth, m.node.id, m.node.ann);
2372+
trans_fn(cx, m.node.meth, m.node.id, ty_params, m.node.ann);
23612373
methods += llfn;
23622374
}
23632375
auto vtbl = C_struct(methods);
@@ -2370,7 +2382,7 @@ impure fn trans_vtbl(@crate_ctxt cx, &ast._obj ob) -> ValueRef {
23702382
}
23712383

23722384
impure fn trans_obj(@crate_ctxt cx, &ast._obj ob, ast.def_id oid,
2373-
&ast.ann ann) {
2385+
&vec[ast.ty_param] ty_params, &ast.ann ann) {
23742386

23752387
auto llctor_decl = cx.item_ids.get(oid);
23762388
cx.item_names.insert(cx.path, llctor_decl);
@@ -2385,14 +2397,14 @@ impure fn trans_obj(@crate_ctxt cx, &ast._obj ob, ast.def_id oid,
23852397
}
23862398

23872399
auto fcx = new_fn_ctxt(cx, cx.path, llctor_decl);
2388-
create_llargs_for_fn_args(fcx, fn_args);
2400+
create_llargs_for_fn_args(fcx, fn_args, ty_params);
23892401

23902402
auto bcx = new_top_block_ctxt(fcx);
23912403

23922404
copy_args_to_allocas(bcx, fn_args, arg_tys_of_fn(ann));
23932405

23942406
auto pair = bcx.build.Alloca(type_of(cx, ret_ty_of_fn(ann)));
2395-
auto vtbl = trans_vtbl(cx, ob);
2407+
auto vtbl = trans_vtbl(cx, ob, ty_params);
23962408
auto pair_vtbl = bcx.build.GEP(pair,
23972409
vec(C_int(0),
23982410
C_int(abi.obj_field_vtbl)));
@@ -2401,7 +2413,8 @@ impure fn trans_obj(@crate_ctxt cx, &ast._obj ob, ast.def_id oid,
24012413
}
24022414

24032415
fn trans_tag_variant(@crate_ctxt cx, ast.def_id tag_id,
2404-
&ast.variant variant, int index) {
2416+
&ast.variant variant, int index,
2417+
&vec[ast.ty_param] ty_params) {
24052418
if (_vec.len[ast.variant_arg](variant.args) == 0u) {
24062419
ret; // nullary constructors are just constants
24072420
}
@@ -2427,7 +2440,7 @@ fn trans_tag_variant(@crate_ctxt cx, ast.def_id tag_id,
24272440
cx.item_names.insert(cx.path, llfndecl);
24282441

24292442
auto fcx = new_fn_ctxt(cx, cx.path, llfndecl);
2430-
create_llargs_for_fn_args(fcx, fn_args);
2443+
create_llargs_for_fn_args(fcx, fn_args, ty_params);
24312444

24322445
auto bcx = new_top_block_ctxt(fcx);
24332446

@@ -2473,23 +2486,23 @@ fn trans_tag_variant(@crate_ctxt cx, ast.def_id tag_id,
24732486

24742487
impure fn trans_item(@crate_ctxt cx, &ast.item item) {
24752488
alt (item.node) {
2476-
case (ast.item_fn(?name, ?f, _, ?fid, ?ann)) {
2489+
case (ast.item_fn(?name, ?f, ?tps, ?fid, ?ann)) {
24772490
auto sub_cx = @rec(path=cx.path + "." + name with *cx);
2478-
trans_fn(sub_cx, f, fid, ann);
2491+
trans_fn(sub_cx, f, fid, tps, ann);
24792492
}
2480-
case (ast.item_obj(?name, ?ob, _, ?oid, ?ann)) {
2493+
case (ast.item_obj(?name, ?ob, ?tps, ?oid, ?ann)) {
24812494
auto sub_cx = @rec(path=cx.path + "." + name with *cx);
2482-
trans_obj(sub_cx, ob, oid, ann);
2495+
trans_obj(sub_cx, ob, oid, tps, ann);
24832496
}
24842497
case (ast.item_mod(?name, ?m, _)) {
24852498
auto sub_cx = @rec(path=cx.path + "." + name with *cx);
24862499
trans_mod(sub_cx, m);
24872500
}
2488-
case (ast.item_tag(?name, ?variants, _, ?tag_id)) {
2501+
case (ast.item_tag(?name, ?variants, ?tps, ?tag_id)) {
24892502
auto sub_cx = @rec(path=cx.path + "." + name with *cx);
24902503
auto i = 0;
24912504
for (ast.variant variant in variants) {
2492-
trans_tag_variant(sub_cx, tag_id, variant, i);
2505+
trans_tag_variant(sub_cx, tag_id, variant, i, tps);
24932506
i += 1;
24942507
}
24952508
}
@@ -2694,6 +2707,7 @@ fn trans_exit_task_glue(@crate_ctxt cx) {
26942707
lltaskptr=lltaskptr,
26952708
llargs=new_def_hash[ValueRef](),
26962709
lllocals=new_def_hash[ValueRef](),
2710+
lltydescs=new_def_hash[ValueRef](),
26972711
ccx=cx);
26982712

26992713
auto bcx = new_top_block_ctxt(fcx);

0 commit comments

Comments
 (0)