Skip to content

Commit 9aa78e3

Browse files
committed
Never pass tydesc to functions
My assumption that native generics needed them was wrong, so tydescs can be eliminated from function signatures completely.
1 parent 47f35c9 commit 9aa78e3

File tree

6 files changed

+93
-351
lines changed

6 files changed

+93
-351
lines changed

src/rustc/middle/trans/base.rs

Lines changed: 58 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -865,7 +865,7 @@ fn get_res_dtor(ccx: @crate_ctxt, did: ast::def_id, substs: [ty::t])
865865
maybe_instantiate_inline(ccx, did)
866866
} else { did };
867867
assert did.crate == ast::local_crate;
868-
option::get(monomorphic_fn(ccx, did, substs, none))
868+
monomorphic_fn(ccx, did, substs, none)
869869
}
870870

871871
fn trans_res_drop(bcx: block, rs: ValueRef, did: ast::def_id,
@@ -1951,8 +1951,7 @@ enum callee_env {
19511951
type lval_maybe_callee = {bcx: block,
19521952
val: ValueRef,
19531953
kind: lval_kind,
1954-
env: callee_env,
1955-
tds: option<[ValueRef]>};
1954+
env: callee_env};
19561955

19571956
fn null_env_ptr(bcx: block) -> ValueRef {
19581957
C_null(T_opaque_box_ptr(bcx.ccx()))
@@ -1971,20 +1970,21 @@ fn lval_temp(bcx: block, val: ValueRef) -> lval_result {
19711970

19721971
fn lval_no_env(bcx: block, val: ValueRef, kind: lval_kind)
19731972
-> lval_maybe_callee {
1974-
ret {bcx: bcx, val: val, kind: kind, env: is_closure, tds: none};
1973+
ret {bcx: bcx, val: val, kind: kind, env: is_closure};
19751974
}
19761975

1977-
fn trans_external_path(cx: block, did: ast::def_id,
1978-
tpt: ty::ty_param_bounds_and_ty) -> ValueRef {
1979-
let ccx = cx.fcx.ccx;
1976+
fn trans_external_path(ccx: @crate_ctxt, did: ast::def_id, t: ty::t)
1977+
-> ValueRef {
19801978
let name = csearch::get_symbol(ccx.sess.cstore, did);
1981-
ret get_extern_const(ccx.externs, ccx.llmod, name,
1982-
type_of_ty_param_bounds_and_ty(ccx, tpt));
1979+
let llty = alt ty::get(t).struct {
1980+
ty::ty_fn(_) { type_of_fn_from_ty(ccx, t) }
1981+
_ { type_of(ccx, t) }
1982+
};
1983+
ret get_extern_const(ccx.externs, ccx.llmod, name, llty);
19831984
}
19841985

19851986
fn monomorphic_fn(ccx: @crate_ctxt, fn_id: ast::def_id, substs: [ty::t],
1986-
vtables: option<typeck::vtable_res>)
1987-
-> option<ValueRef> {
1987+
vtables: option<typeck::vtable_res>) -> ValueRef {
19881988
let substs = vec::map(substs, {|t|
19891989
alt ty::get(t).struct {
19901990
ty::ty_box(mt) { ty::mk_opaque_box(ccx.tcx) }
@@ -1996,7 +1996,7 @@ fn monomorphic_fn(ccx: @crate_ctxt, fn_id: ast::def_id, substs: [ty::t],
19961996
none { no_vts }
19971997
}};
19981998
alt ccx.monomorphized.find(hash_id) {
1999-
some(val) { ret some(val); }
1999+
some(val) { ret val; }
20002000
none {}
20012001
}
20022002

@@ -2017,8 +2017,10 @@ fn monomorphic_fn(ccx: @crate_ctxt, fn_id: ast::def_id, substs: [ty::t],
20172017
}
20182018
ast_map::node_variant(v, _, pt) { (pt, v.node.name) }
20192019
ast_map::node_method(m, _, pt) { (pt, m.ident) }
2020-
// We can't monomorphize native functions
2021-
ast_map::node_native_item(_, _, _) { ret none; }
2020+
ast_map::node_native_item(_, _, _) {
2021+
// Natives don't have to be monomorphized.
2022+
ret get_item_val(ccx, fn_id.node);
2023+
}
20222024
ast_map::node_ctor(i) {
20232025
alt check ccx.tcx.items.get(i.id) {
20242026
ast_map::node_item(i, pt) { (pt, i.ident) }
@@ -2027,7 +2029,7 @@ fn monomorphic_fn(ccx: @crate_ctxt, fn_id: ast::def_id, substs: [ty::t],
20272029
_ { fail "unexpected node type"; }
20282030
};
20292031
let mono_ty = ty::substitute_type_params(ccx.tcx, substs, item_ty);
2030-
let llfty = type_of_fn_from_ty(ccx, mono_ty, 0u);
2032+
let llfty = type_of_fn_from_ty(ccx, mono_ty);
20312033

20322034
let pt = *pt + [path_name(ccx.names(name))];
20332035
let s = mangle_exported_name(ccx, pt, mono_ty);
@@ -2071,7 +2073,7 @@ fn monomorphic_fn(ccx: @crate_ctxt, fn_id: ast::def_id, substs: [ty::t],
20712073
}
20722074
}
20732075
}
2074-
some(lldecl)
2076+
lldecl
20752077
}
20762078

20772079
fn maybe_instantiate_inline(ccx: @crate_ctxt, fn_id: ast::def_id)
@@ -2142,39 +2144,18 @@ fn lval_static_fn(bcx: block, fn_id: ast::def_id, id: ast::node_id,
21422144
maybe_instantiate_inline(ccx, fn_id)
21432145
} else { fn_id };
21442146

2145-
// The awkwardness below mostly stems from the fact that we're mixing
2146-
// monomorphized and non-monomorphized functions at the moment. If
2147-
// monomorphizing becomes the only approach, this'll be much simpler.
21482147
if fn_id.crate == ast::local_crate {
2149-
let mono = alt substs {
2150-
some((stys, vtables)) {
2151-
if stys.len() > 0u {
2152-
monomorphic_fn(ccx, fn_id, stys, some(vtables))
2153-
} else { none }
2154-
}
2155-
none {
2156-
alt ccx.maps.vtable_map.find(id) {
2157-
some(vtables) {
2158-
let rvtables = impl::resolve_vtables_in_fn_ctxt(
2159-
bcx.fcx, vtables);
2160-
monomorphic_fn(ccx, fn_id, tys, some(rvtables))
2161-
}
2162-
none {
2163-
if tys.len() == 0u { none }
2164-
else { monomorphic_fn(ccx, fn_id, tys, none) }
2165-
}
2166-
}
2167-
}
2148+
let (tys, vtables) = alt substs {
2149+
some((tys, vts)) { (tys, some(vts)) }
2150+
none { (tys, option::map(ccx.maps.vtable_map.find(id), {|vts|
2151+
impl::resolve_vtables_in_fn_ctxt(bcx.fcx, vts)})) }
21682152
};
2169-
alt mono {
2170-
some(llfn) {
2171-
let cast = PointerCast(bcx, llfn, T_ptr(type_of_fn_from_ty(
2172-
ccx, node_id_type(bcx, id), 0u)));
2153+
if tys.len() > 0u {
2154+
let val = monomorphic_fn(ccx, fn_id, tys, vtables);
2155+
let cast = PointerCast(bcx, val, T_ptr(type_of_fn_from_ty(
2156+
ccx, node_id_type(bcx, id))));
21732157
ret {bcx: bcx, val: cast,
2174-
kind: owned, env: null_env,
2175-
tds: none};
2176-
}
2177-
none {}
2158+
kind: owned, env: null_env};
21782159
}
21792160
}
21802161

@@ -2183,8 +2164,14 @@ fn lval_static_fn(bcx: block, fn_id: ast::def_id, id: ast::node_id,
21832164
get_item_val(ccx, fn_id.node)
21842165
} else {
21852166
// External reference.
2186-
trans_external_path(bcx, fn_id, tpt)
2167+
trans_external_path(ccx, fn_id, tpt.ty)
21872168
};
2169+
if tys.len() > 0u {
2170+
// This is supposed to be an external native function.
2171+
// Unfortunately, I found no easy/cheap way to assert that.
2172+
val = PointerCast(bcx, val, T_ptr(type_of_fn_from_ty(
2173+
ccx, node_id_type(bcx, id))));
2174+
}
21882175

21892176
// FIXME: Need to support external crust functions
21902177
if fn_id.crate == ast::local_crate {
@@ -2198,22 +2185,7 @@ fn lval_static_fn(bcx: block, fn_id: ast::def_id, id: ast::node_id,
21982185
}
21992186
}
22002187

2201-
let tds = none, bcx = bcx;
2202-
// FIXME[mono] ensure this is a native function
2203-
if tys.len() > 0u {
2204-
val = PointerCast(bcx, val, T_ptr(type_of_fn_from_ty(
2205-
ccx, node_id_type(bcx, id), tys.len())));
2206-
let tydescs = [];
2207-
for t in tys {
2208-
let ti = none;
2209-
let td = get_tydesc(bcx, t, ti);
2210-
lazily_emit_all_tydesc_glue(ccx, ti);
2211-
bcx = td.bcx;
2212-
tydescs += [td.val];
2213-
}
2214-
tds = some(tydescs);
2215-
}
2216-
ret {bcx: bcx, val: val, kind: owned, env: null_env, tds: tds};
2188+
ret {bcx: bcx, val: val, kind: owned, env: null_env};
22172189
}
22182190

22192191
fn lookup_discriminant(ccx: @crate_ctxt, vid: ast::def_id) -> ValueRef {
@@ -2313,7 +2285,7 @@ fn trans_var(cx: block, def: ast::def, id: ast::node_id, path: @ast::path)
23132285
ret lval_no_env(cx, get_item_val(ccx, did.node), owned);
23142286
} else {
23152287
let tp = node_id_type(cx, id);
2316-
let val = trans_external_path(cx, did, {bounds: @[], ty: tp});
2288+
let val = trans_external_path(ccx, did, tp);
23172289
ret lval_no_env(cx, load_if_immediate(cx, val, tp), owned_imm);
23182290
}
23192291
}
@@ -2466,8 +2438,7 @@ fn trans_lval(cx: block, e: @ast::expr) -> lval_result {
24662438
}
24672439

24682440
fn lval_maybe_callee_to_lval(c: lval_maybe_callee, ty: ty::t) -> lval_result {
2469-
let must_bind = option::is_some(c.tds) ||
2470-
alt c.env { self_env(_, _) { true } _ { false } };
2441+
let must_bind = alt c.env { self_env(_, _) { true } _ { false } };
24712442
if must_bind {
24722443
let n_args = ty::ty_fn_args(ty).len();
24732444
let args = vec::from_elem(n_args, none);
@@ -2662,12 +2633,10 @@ fn trans_arg_expr(cx: block, arg: ty::arg, lldestty: TypeRef, e: @ast::expr,
26622633
// - create_llargs_for_fn_args.
26632634
// - new_fn_ctxt
26642635
// - trans_args
2665-
fn trans_args(cx: block, llenv: ValueRef,
2666-
tds: option<[ValueRef]>, es: [@ast::expr], fn_ty: ty::t,
2667-
dest: dest)
2668-
-> {bcx: block,
2669-
args: [ValueRef],
2670-
retslot: ValueRef} {
2636+
fn trans_args(cx: block, llenv: ValueRef, es: [@ast::expr], fn_ty: ty::t,
2637+
dest: dest) -> {bcx: block,
2638+
args: [ValueRef],
2639+
retslot: ValueRef} {
26712640

26722641
let temp_cleanups = [];
26732642
let args = ty::ty_fn_args(fn_ty);
@@ -2701,12 +2670,6 @@ fn trans_args(cx: block, llenv: ValueRef,
27012670
// Arg 1: Env (closure-bindings / self value)
27022671
llargs += [llenv];
27032672

2704-
// Args >2: ty_params ...
2705-
alt tds {
2706-
some(tds) { llargs += tds; }
2707-
none {}
2708-
}
2709-
27102673
// ... then explicit args.
27112674

27122675
// First we figure out the caller's view of the types of the arguments.
@@ -2770,8 +2733,7 @@ fn trans_call_inner(in_cx: block, fn_expr_ty: ty::t,
27702733
};
27712734

27722735
let ret_ty = node_id_type(bcx, id);
2773-
let args_res =
2774-
trans_args(bcx, llenv, f_res.tds, args, fn_expr_ty, dest);
2736+
let args_res = trans_args(bcx, llenv, args, fn_expr_ty, dest);
27752737
bcx = args_res.bcx;
27762738
let llargs = args_res.args;
27772739
let llretslot = args_res.retslot;
@@ -3883,7 +3845,7 @@ fn create_llargs_for_fn_args(cx: fn_ctxt,
38833845
args: [ast::arg],
38843846
tps_bounds: [ty::param_bounds]) {
38853847
// Skip the implicit arguments 0, and 1.
3886-
let arg_n = first_tp_arg;
3848+
let arg_n = first_real_arg;
38873849
alt ty_self {
38883850
impl_self(tt) {
38893851
cx.llself = some({v: cx.llenv, t: tt});
@@ -4417,11 +4379,9 @@ fn get_pair_fn_ty(llpairty: TypeRef) -> TypeRef {
44174379
}
44184380

44194381
fn register_fn(ccx: @crate_ctxt, sp: span, path: path, flav: str,
4420-
ty_params: [ast::ty_param], node_id: ast::node_id)
4421-
-> ValueRef {
4382+
node_id: ast::node_id) -> ValueRef {
44224383
let t = ty::node_id_to_type(ccx.tcx, node_id);
4423-
let bnds = param_bounds(ccx, ty_params);
4424-
register_fn_full(ccx, sp, path, flav, bnds, node_id, t)
4384+
register_fn_full(ccx, sp, path, flav, node_id, t)
44254385
}
44264386

44274387
fn param_bounds(ccx: @crate_ctxt, tps: [ast::ty_param])
@@ -4430,9 +4390,8 @@ fn param_bounds(ccx: @crate_ctxt, tps: [ast::ty_param])
44304390
}
44314391

44324392
fn register_fn_full(ccx: @crate_ctxt, sp: span, path: path, flav: str,
4433-
bnds: [ty::param_bounds], node_id: ast::node_id,
4434-
node_type: ty::t) -> ValueRef {
4435-
let llfty = type_of_fn_from_ty(ccx, node_type, bnds.len());
4393+
node_id: ast::node_id, node_type: ty::t) -> ValueRef {
4394+
let llfty = type_of_fn_from_ty(ccx, node_type);
44364395
register_fn_fuller(ccx, sp, path, flav, node_id, node_type,
44374396
lib::llvm::CCallConv, llfty)
44384397
}
@@ -4479,7 +4438,7 @@ fn create_main_wrapper(ccx: @crate_ctxt, sp: span, main_llfn: ValueRef,
44794438
{mode: ast::expl(ast::by_val),
44804439
ty: ty::mk_vec(ccx.tcx, {ty: unit_ty, mutbl: ast::m_imm})};
44814440
let nt = ty::mk_nil(ccx.tcx);
4482-
let llfty = type_of_fn(ccx, [vecarg_ty], nt, 0u);
4441+
let llfty = type_of_fn(ccx, [vecarg_ty], nt);
44834442
let llfdecl = decl_fn(ccx.llmod, "_rust_main",
44844443
lib::llvm::CCallConv, llfty);
44854444

@@ -4575,34 +4534,32 @@ fn get_item_val(ccx: @crate_ctxt, id: ast::node_id) -> ValueRef {
45754534
ccx.item_symbols.insert(i.id, s);
45764535
g
45774536
}
4578-
ast::item_fn(decl, tps, _) {
4537+
ast::item_fn(decl, _, _) {
45794538
let llfn = if decl.purity != ast::crust_fn {
4580-
register_fn(ccx, i.span, my_path, "fn", tps, i.id)
4539+
register_fn(ccx, i.span, my_path, "fn", i.id)
45814540
} else {
45824541
native::register_crust_fn(ccx, i.span, my_path, i.id)
45834542
};
45844543
set_inline_hint_if_appr(i.attrs, llfn);
45854544
llfn
45864545
}
4587-
ast::item_res(_, tps, _, dtor_id, _) {
4546+
ast::item_res(_, _, _, dtor_id, _) {
45884547
// Note that the destructor is associated with the item's id,
45894548
// not the dtor_id. This is a bit counter-intuitive, but
45904549
// simplifies ty_res, which would have to carry around two
45914550
// def_ids otherwise -- one to identify the type, and one to
45924551
// find the dtor symbol.
45934552
let t = ty::node_id_to_type(ccx.tcx, dtor_id);
45944553
register_fn_full(ccx, i.span, my_path + [path_name("dtor")],
4595-
"res_dtor", param_bounds(ccx, tps), i.id, t)
4554+
"res_dtor", i.id, t)
45964555
}
45974556
}
45984557
}
45994558
ast_map::node_method(m, impl_id, pth) {
46004559
let mty = ty::node_id_to_type(ccx.tcx, id);
4601-
let impl_tps = *ty::lookup_item_type(ccx.tcx, impl_id).bounds;
46024560
let pth = *pth + [path_name(int::str(impl_id.node)),
46034561
path_name(m.ident)];
46044562
let llfn = register_fn_full(ccx, m.span, pth, "impl_method",
4605-
impl_tps + param_bounds(ccx, m.tps),
46064563
id, mty);
46074564
set_inline_hint_if_appr(m.attrs, llfn);
46084565
llfn
@@ -4612,24 +4569,24 @@ fn get_item_val(ccx: @crate_ctxt, id: ast::node_id) -> ValueRef {
46124569
}
46134570
ast_map::node_ctor(i) {
46144571
alt check i.node {
4615-
ast::item_res(_, tps, _, _, _) {
4572+
ast::item_res(_, _, _, _, _) {
46164573
let my_path = item_path(ccx, i);
46174574
let llctor = register_fn(ccx, i.span, my_path, "res_ctor",
4618-
tps, id);
4575+
id);
46194576
set_inline_hint(llctor);
46204577
llctor
46214578
}
4622-
ast::item_class(tps, _, ctor) {
4623-
register_fn(ccx, i.span, item_path(ccx, i), "ctor", tps, id)
4579+
ast::item_class(_, _, ctor) {
4580+
register_fn(ccx, i.span, item_path(ccx, i), "ctor", id)
46244581
}
46254582
}
46264583
}
46274584
ast_map::node_variant(v, enm, pth) {
46284585
assert v.node.args.len() != 0u;
46294586
let pth = *pth + [path_name(enm.ident), path_name(v.node.name)];
46304587
let llfn = alt check enm.node {
4631-
ast::item_enum(_, tps) {
4632-
register_fn(ccx, v.span, pth, "enum", tps, id)
4588+
ast::item_enum(_, _) {
4589+
register_fn(ccx, v.span, pth, "enum", id)
46334590
}
46344591
};
46354592
set_inline_hint(llfn);

0 commit comments

Comments
 (0)