Skip to content

Commit ae5ba62

Browse files
committed
rustc: Use the type cache to construct external item references
1 parent cc59cea commit ae5ba62

File tree

1 file changed

+38
-19
lines changed

1 file changed

+38
-19
lines changed

src/comp/middle/trans.rs

Lines changed: 38 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,24 @@ fn type_of_arg(@crate_ctxt cx, &ty.arg arg) -> TypeRef {
764764
ret typ;
765765
}
766766

767+
fn type_of_ty_params_opt_and_ty(@crate_ctxt ccx, ty.ty_params_opt_and_ty tpt)
768+
-> TypeRef {
769+
alt (tpt._1.struct) {
770+
case (ty.ty_fn(?proto, ?inputs, ?output)) {
771+
auto ty_params = option.get[vec[ast.def_id]](tpt._0);
772+
auto ty_param_count = _vec.len[ast.def_id](ty_params);
773+
auto llfnty = type_of_fn(ccx, proto, inputs, output,
774+
ty_param_count);
775+
ret T_fn_pair(ccx.tn, llfnty);
776+
}
777+
case (_) {
778+
// fall through
779+
}
780+
}
781+
ret type_of(ccx, tpt._1);
782+
}
783+
784+
767785
// Name sanitation. LLVM will happily accept identifiers with weird names, but
768786
// gas doesn't!
769787

@@ -3570,14 +3588,30 @@ fn lval_val(@block_ctxt cx, ValueRef val) -> lval_result {
35703588
llobj=none[ValueRef]);
35713589
}
35723590

3591+
fn trans_external_path(@block_ctxt cx, ast.def_id did,
3592+
ty.ty_params_opt_and_ty tpt) -> lval_result {
3593+
auto ccx = cx.fcx.ccx;
3594+
auto name = creader.get_symbol(ccx.sess, did);
3595+
auto v = get_extern_const(ccx.externs, ccx.llmod,
3596+
name, type_of_ty_params_opt_and_ty(ccx, tpt));
3597+
ret lval_val(cx, v);
3598+
}
3599+
35733600
fn lval_generic_fn(@block_ctxt cx,
35743601
ty.ty_params_and_ty tpt,
35753602
ast.def_id fn_id,
35763603
&ast.ann ann)
3577-
-> lval_result {
3578-
3579-
check (cx.fcx.ccx.fn_pairs.contains_key(fn_id));
3580-
auto lv = lval_val(cx, cx.fcx.ccx.fn_pairs.get(fn_id));
3604+
-> lval_result {
3605+
auto lv;
3606+
if (cx.fcx.ccx.sess.get_targ_crate_num() == fn_id._0) {
3607+
// Internal reference.
3608+
check (cx.fcx.ccx.fn_pairs.contains_key(fn_id));
3609+
lv = lval_val(cx, cx.fcx.ccx.fn_pairs.get(fn_id));
3610+
} else {
3611+
// External reference.
3612+
auto tpot = tup(some[vec[ast.def_id]](tpt._0), tpt._1);
3613+
lv = trans_external_path(cx, fn_id, tpot);
3614+
}
35813615

35823616
auto monoty;
35833617
auto tys;
@@ -3609,22 +3643,10 @@ fn lval_generic_fn(@block_ctxt cx,
36093643
ret lv;
36103644
}
36113645

3612-
fn trans_external_path(@block_ctxt cx, &ast.path p,
3613-
ast.def def, ast.ann a) -> lval_result {
3614-
// FIXME: This isn't generic-safe.
3615-
auto ccx = cx.fcx.ccx;
3616-
auto ty = node_ann_type(ccx, a);
3617-
auto name = creader.get_symbol(ccx.sess, ast.def_id_of_def(def));
3618-
auto v = get_extern_const(ccx.externs, ccx.llmod,
3619-
name, type_of(ccx, ty));
3620-
ret lval_mem(cx, v);
3621-
}
3622-
36233646
fn trans_path(@block_ctxt cx, &ast.path p, &option.t[ast.def] dopt,
36243647
&ast.ann ann) -> lval_result {
36253648
alt (dopt) {
36263649
case (some[ast.def](?def)) {
3627-
36283650
alt (def) {
36293651
case (ast.def_arg(?did)) {
36303652
alt (cx.fcx.llargs.find(did)) {
@@ -3657,13 +3679,11 @@ fn trans_path(@block_ctxt cx, &ast.path p, &option.t[ast.def] dopt,
36573679
ret lval_mem(cx, cx.fcx.llobjfields.get(did));
36583680
}
36593681
case (ast.def_fn(?did)) {
3660-
check (cx.fcx.ccx.items.contains_key(did));
36613682
auto tyt = ty.lookup_generic_item_type(cx.fcx.ccx.sess,
36623683
cx.fcx.ccx.type_cache, did);
36633684
ret lval_generic_fn(cx, tyt, did, ann);
36643685
}
36653686
case (ast.def_obj(?did)) {
3666-
check (cx.fcx.ccx.items.contains_key(did));
36673687
auto tyt = ty.lookup_generic_item_type(cx.fcx.ccx.sess,
36683688
cx.fcx.ccx.type_cache, did);
36693689
ret lval_generic_fn(cx, tyt, did, ann);
@@ -3717,7 +3737,6 @@ fn trans_path(@block_ctxt cx, &ast.path p, &option.t[ast.def] dopt,
37173737
ret lval_mem(cx, cx.fcx.ccx.consts.get(did));
37183738
}
37193739
case (ast.def_native_fn(?did)) {
3720-
check (cx.fcx.ccx.native_items.contains_key(did));
37213740
auto tyt = ty.lookup_generic_item_type(cx.fcx.ccx.sess,
37223741
cx.fcx.ccx.type_cache, did);
37233742
ret lval_generic_fn(cx, tyt, did, ann);

0 commit comments

Comments
 (0)