Skip to content

Commit 0827870

Browse files
committed
---
yaml --- r: 5356 b: refs/heads/master c: eafb678 h: refs/heads/master v: v3
1 parent 7186120 commit 0827870

File tree

4 files changed

+44
-87
lines changed

4 files changed

+44
-87
lines changed

[refs]

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 8640e67e3ff97f64ab5afdf6c788d335e491696e
2+
refs/heads/master: eafb6789a288ee7203b6d554cce7e53f61b261d8

trunk/src/comp/middle/trans.rs

+40-82
Original file line numberDiff line numberDiff line change
@@ -244,10 +244,9 @@ fn type_of_ty_param_kinds_and_ty(lcx: @local_ctxt, sp: span,
244244
let cx = lcx.ccx;
245245
let t = tpt.ty;
246246
alt ty::struct(cx.tcx, t) {
247-
ty::ty_fn(_, _, _, _, _) {
247+
ty::ty_fn(_, _, _, _, _) | ty::ty_native_fn(_, _, _) {
248248
check returns_non_ty_var(cx, t);
249-
let llfnty = type_of_fn_from_ty(cx, sp, t, std::vec::len(tpt.kinds));
250-
ret T_fn_pair(*cx, llfnty);
249+
ret type_of_fn_from_ty(cx, sp, t, std::vec::len(tpt.kinds));
251250
}
252251
_ {
253252
// fall through
@@ -328,10 +327,9 @@ fn decl_fastcall_fn(llmod: ModuleRef, name: str, llty: TypeRef) -> ValueRef {
328327
// not valid to simply declare a function as internal.
329328
fn decl_internal_fastcall_fn(llmod: ModuleRef, name: str, llty: TypeRef) ->
330329
ValueRef {
331-
let llfn = decl_fn(llmod, name, lib::llvm::LLVMFastCallConv, llty);
330+
let llfn = decl_fastcall_fn(llmod, name, llty);
332331
llvm::LLVMSetLinkage(llfn,
333332
lib::llvm::LLVMInternalLinkage as llvm::Linkage);
334-
let _: () = str::as_buf("rust", {|buf| llvm::LLVMSetGC(llfn, buf) });
335333
ret llfn;
336334
}
337335

@@ -1418,12 +1416,8 @@ fn trans_res_drop(cx: @block_ctxt, rs: ValueRef, did: ast::def_id,
14181416
let val = GEP_tup_like(cx, tup_ty, rs, [0, 1]);
14191417
cx = val.bcx;
14201418
// Find and call the actual destructor.
1421-
let dtor_pair = trans_common::get_res_dtor(ccx, cx.sp, did, inner_t);
1422-
let dtor_addr =
1423-
Load(cx, GEP(cx, dtor_pair, [C_int(0), C_int(abi::fn_field_code)]));
1424-
let dtor_env =
1425-
Load(cx, GEP(cx, dtor_pair, [C_int(0), C_int(abi::fn_field_box)]));
1426-
let args = [cx.fcx.llretptr, cx.fcx.lltaskptr, dtor_env];
1419+
let dtor_addr = trans_common::get_res_dtor(ccx, cx.sp, did, inner_t);
1420+
let args = [cx.fcx.llretptr, cx.fcx.lltaskptr, null_env_ptr(cx)];
14271421
for tp: ty::t in tps {
14281422
let ti: option::t<@tydesc_info> = none;
14291423
let td = get_tydesc(cx, tp, false, tps_normal, ti).result;
@@ -2842,6 +2836,10 @@ type lval_maybe_callee = {bcx: @block_ctxt,
28422836
env: callee_env,
28432837
generic: option::t<generic_info>};
28442838

2839+
fn null_env_ptr(bcx: @block_ctxt) -> ValueRef {
2840+
C_null(T_opaque_closure_ptr(*bcx_ccx(bcx)))
2841+
}
2842+
28452843
fn lval_mem(bcx: @block_ctxt, val: ValueRef) -> lval_result {
28462844
ret {bcx: bcx, val: val, is_mem: true};
28472845
}
@@ -2866,8 +2864,8 @@ fn lval_static_fn(bcx: @block_ctxt, tpt: ty::ty_param_kinds_and_ty,
28662864
fn_id: ast::def_id, id: ast::node_id) -> lval_maybe_callee {
28672865
let val = if fn_id.crate == ast::local_crate {
28682866
// Internal reference.
2869-
assert (bcx_ccx(bcx).fn_pairs.contains_key(fn_id.node));
2870-
bcx_ccx(bcx).fn_pairs.get(fn_id.node)
2867+
assert (bcx_ccx(bcx).item_ids.contains_key(fn_id.node));
2868+
bcx_ccx(bcx).item_ids.get(fn_id.node)
28712869
} else {
28722870
// External reference.
28732871
trans_external_path(bcx, fn_id, tpt)
@@ -2886,7 +2884,7 @@ fn lval_static_fn(bcx: @block_ctxt, tpt: ty::ty_param_kinds_and_ty,
28862884
}
28872885
gen = some({item_type: tpt.ty, static_tis: tis, tydescs: tydescs});
28882886
}
2889-
ret {bcx: bcx, val: val, is_mem: true, env: is_closure, generic: gen};
2887+
ret {bcx: bcx, val: val, is_mem: true, env: null_env, generic: gen};
28902888
}
28912889

28922890
fn lookup_discriminant(lcx: @local_ctxt, vid: ast::def_id) -> ValueRef {
@@ -3176,7 +3174,7 @@ fn maybe_add_env(bcx: @block_ctxt, c: lval_maybe_callee)
31763174
(c.is_mem, c.val)
31773175
} else {
31783176
let env = alt c.env {
3179-
null_env. { C_null(T_opaque_closure_ptr(*bcx_ccx(bcx))) }
3177+
null_env. { null_env_ptr(bcx) }
31803178
some_env(e) { e }
31813179
};
31823180
let llfnty = llvm::LLVMGetElementType(val_ty(c.val));
@@ -3353,8 +3351,7 @@ fn trans_bind_thunk(cx: @local_ctxt, sp: span, incoming_fty: ty::t,
33533351
// out the pointer to the target function from the environment. The
33543352
// target function lives in the first binding spot.
33553353
let (lltargetfn, lltargetenv, starting_idx) = alt target_fn {
3356-
some(fptr) {
3357-
(fptr, C_null(T_opaque_closure_ptr(*bcx_ccx(bcx))), 0)
3354+
some(fptr) { (fptr, null_env_ptr(bcx), 0)
33583355
}
33593356
none. {
33603357
// Silly check
@@ -3747,7 +3744,7 @@ fn trans_call(in_cx: @block_ctxt, f: @ast::expr,
37473744
let faddr = f_res.val;
37483745
let llenv;
37493746
alt f_res.env {
3750-
null_env. { llenv = C_null(T_opaque_closure_ptr(*bcx_ccx(cx))); }
3747+
null_env. { llenv = null_env_ptr(cx); }
37513748
some_env(e) { llenv = e; }
37523749
is_closure. {
37533750
// It's a closure. Have to fetch the elements
@@ -4054,7 +4051,8 @@ fn trans_expr_out(cx: @block_ctxt, e: @ast::expr, output: out_method) ->
40544051
alt fn_res {
40554052
some(fn_pair) { fn_pair }
40564053
none. {
4057-
{fn_pair: create_fn_pair(ccx, s, llfnty, llfn, false),
4054+
{fn_pair: create_real_fn_pair(cx, llfnty, llfn,
4055+
null_env_ptr(cx)),
40584056
bcx: cx}
40594057
}
40604058
};
@@ -5488,17 +5486,17 @@ fn get_pair_fn_ty(llpairty: TypeRef) -> TypeRef {
54885486
ret struct_elt(llpairty, 0u);
54895487
}
54905488

5491-
fn decl_fn_and_pair(ccx: @crate_ctxt, sp: span, path: [str], flav: str,
5492-
ty_params: [ast::ty_param], node_id: ast::node_id) {
5489+
fn register_fn(ccx: @crate_ctxt, sp: span, path: [str], flav: str,
5490+
ty_params: [ast::ty_param], node_id: ast::node_id) {
54935491
// FIXME: pull this out
54945492
let t = node_id_type(ccx, node_id);
54955493
check returns_non_ty_var(ccx, t);
5496-
decl_fn_and_pair_full(ccx, sp, path, flav, ty_params, node_id, t);
5494+
register_fn_full(ccx, sp, path, flav, ty_params, node_id, t);
54975495
}
54985496

5499-
fn decl_fn_and_pair_full(ccx: @crate_ctxt, sp: span, path: [str], _flav: str,
5500-
ty_params: [ast::ty_param], node_id: ast::node_id,
5501-
node_type: ty::t)
5497+
fn register_fn_full(ccx: @crate_ctxt, sp: span, path: [str], _flav: str,
5498+
ty_params: [ast::ty_param], node_id: ast::node_id,
5499+
node_type: ty::t)
55025500
: returns_non_ty_var(ccx, node_type) {
55035501
let path = path;
55045502
let llfty =
@@ -5510,14 +5508,12 @@ fn decl_fn_and_pair_full(ccx: @crate_ctxt, sp: span, path: [str], _flav: str,
55105508
ast_util::ret_by_ref(rs), inputs, output,
55115509
vec::len(ty_params));
55125510
}
5513-
_ { ccx.sess.bug("decl_fn_and_pair(): fn item doesn't have fn type!"); }
5511+
_ { ccx.sess.bug("register_fn(): fn item doesn't have fn type!"); }
55145512
}
5515-
let s: str = mangle_internal_name_by_path(ccx, path);
5516-
let llfn: ValueRef = decl_internal_fastcall_fn(ccx.llmod, s, llfty);
5517-
// Declare the global constant pair that points to it.
5518-
55195513
let ps: str = mangle_exported_name(ccx, path, node_type);
5520-
register_fn_pair(ccx, ps, llfty, llfn, node_id);
5514+
let llfn: ValueRef = decl_fastcall_fn(ccx.llmod, ps, llfty);
5515+
ccx.item_ids.insert(node_id, llfn);
5516+
ccx.item_symbols.insert(node_id, ps);
55215517

55225518
let is_main: bool = is_main_name(path) && !ccx.sess.get_opts().library;
55235519
if is_main { create_main_wrapper(ccx, sp, llfn, node_type); }
@@ -5580,28 +5576,6 @@ fn create_main_wrapper(ccx: @crate_ctxt, sp: span, main_llfn: ValueRef,
55805576
}
55815577
}
55825578

5583-
5584-
// Create a closure: a pair containing (1) a ValueRef, pointing to where the
5585-
// fn's definition is in the executable we're creating, and (2) a pointer to
5586-
// space for the function's environment.
5587-
fn create_fn_pair(cx: @crate_ctxt, ps: str, llfnty: TypeRef, llfn: ValueRef,
5588-
external: bool) -> ValueRef {
5589-
let gvar =
5590-
str::as_buf(ps,
5591-
{|buf|
5592-
llvm::LLVMAddGlobal(cx.llmod, T_fn_pair(*cx, llfnty),
5593-
buf)
5594-
});
5595-
let pair = C_struct([llfn, C_null(T_opaque_closure_ptr(*cx))]);
5596-
llvm::LLVMSetInitializer(gvar, pair);
5597-
llvm::LLVMSetGlobalConstant(gvar, True);
5598-
if !external {
5599-
llvm::LLVMSetLinkage(gvar,
5600-
lib::llvm::LLVMInternalLinkage as llvm::Linkage);
5601-
}
5602-
ret gvar;
5603-
}
5604-
56055579
// Create a /real/ closure: this is like create_fn_pair, but creates a
56065580
// a fn value on the stack with a specified environment (which need not be
56075581
// on the stack).
@@ -5619,26 +5593,14 @@ fn create_real_fn_pair(cx: @block_ctxt, llfnty: TypeRef, llfn: ValueRef,
56195593
ret pair;
56205594
}
56215595

5622-
fn register_fn_pair(cx: @crate_ctxt, ps: str, llfnty: TypeRef, llfn: ValueRef,
5623-
id: ast::node_id) {
5624-
// FIXME: We should also hide the unexported pairs in crates.
5625-
5626-
let gvar =
5627-
create_fn_pair(cx, ps, llfnty, llfn, cx.sess.get_opts().library);
5628-
cx.item_ids.insert(id, llfn);
5629-
cx.item_symbols.insert(id, ps);
5630-
cx.fn_pairs.insert(id, gvar);
5631-
}
5632-
5633-
56345596
// Returns the number of type parameters that the given native function has.
56355597
fn native_fn_ty_param_count(cx: @crate_ctxt, id: ast::node_id) -> uint {
56365598
let count;
56375599
let native_item =
56385600
alt cx.ast_map.find(id) { some(ast_map::node_native_item(i)) { i } };
56395601
alt native_item.node {
56405602
ast::native_item_ty. {
5641-
cx.sess.bug("decl_native_fn_and_pair(): native fn isn't \
5603+
cx.sess.bug("register_native_fn(): native fn isn't \
56425604
actually a fn");
56435605
}
56445606
ast::native_item_fn(_, _, tps) {
@@ -5659,23 +5621,20 @@ fn native_fn_wrapper_type(cx: @crate_ctxt, sp: span, ty_param_count: uint,
56595621
}
56605622
}
56615623

5662-
fn decl_native_fn_and_pair(ccx: @crate_ctxt, sp: span, path: [str], name: str,
5624+
fn register_native_fn(ccx: @crate_ctxt, sp: span, path: [str], name: str,
56635625
id: ast::node_id) {
56645626
let path = path;
56655627
let num_ty_param = native_fn_ty_param_count(ccx, id);
56665628
// Declare the wrapper.
56675629

56685630
let t = node_id_type(ccx, id);
56695631
let wrapper_type = native_fn_wrapper_type(ccx, sp, num_ty_param, t);
5670-
let s: str = mangle_internal_name_by_path(ccx, path);
5671-
let wrapper_fn: ValueRef =
5672-
decl_internal_fastcall_fn(ccx.llmod, s, wrapper_type);
5673-
// Declare the global constant pair that points to it.
5674-
56755632
let ps: str = mangle_exported_name(ccx, path, node_id_type(ccx, id));
5676-
register_fn_pair(ccx, ps, wrapper_type, wrapper_fn, id);
5677-
// Build the wrapper.
5633+
let wrapper_fn = decl_fastcall_fn(ccx.llmod, ps, wrapper_type);
5634+
ccx.item_ids.insert(id, wrapper_fn);
5635+
ccx.item_symbols.insert(id, ps);
56785636

5637+
// Build the wrapper.
56795638
let fcx = new_fn_ctxt(new_local_ctxt(ccx), sp, wrapper_fn);
56805639
let bcx = new_top_block_ctxt(fcx);
56815640
let lltop = bcx.llbb;
@@ -5858,7 +5817,7 @@ fn collect_native_item(ccx: @crate_ctxt, i: @ast::native_item, pt: [str],
58585817
alt i.node {
58595818
ast::native_item_fn(_, _, _) {
58605819
if !ccx.obj_methods.contains_key(i.id) {
5861-
decl_native_fn_and_pair(ccx, i.span, pt, i.ident, i.id);
5820+
register_native_fn(ccx, i.span, pt, i.ident, i.id);
58625821
}
58635822
}
58645823
_ { }
@@ -5892,25 +5851,25 @@ fn collect_item_2(ccx: @crate_ctxt, i: @ast::item, pt: [str], v: vt<[str]>) {
58925851
alt i.node {
58935852
ast::item_fn(f, tps) {
58945853
if !ccx.obj_methods.contains_key(i.id) {
5895-
decl_fn_and_pair(ccx, i.span, new_pt, "fn", tps, i.id);
5854+
register_fn(ccx, i.span, new_pt, "fn", tps, i.id);
58965855
}
58975856
}
58985857
ast::item_obj(ob, tps, ctor_id) {
5899-
decl_fn_and_pair(ccx, i.span, new_pt, "obj_ctor", tps, ctor_id);
5858+
register_fn(ccx, i.span, new_pt, "obj_ctor", tps, ctor_id);
59005859
for m: @ast::method in ob.methods {
59015860
ccx.obj_methods.insert(m.node.id, ());
59025861
}
59035862
}
59045863
ast::item_res(_, dtor_id, tps, ctor_id) {
5905-
decl_fn_and_pair(ccx, i.span, new_pt, "res_ctor", tps, ctor_id);
5864+
register_fn(ccx, i.span, new_pt, "res_ctor", tps, ctor_id);
59065865
// Note that the destructor is associated with the item's id, not
59075866
// the dtor_id. This is a bit counter-intuitive, but simplifies
59085867
// ty_res, which would have to carry around two def_ids otherwise
59095868
// -- one to identify the type, and one to find the dtor symbol.
59105869
let t = node_id_type(ccx, dtor_id);
59115870
// FIXME: how to get rid of this check?
59125871
check returns_non_ty_var(ccx, t);
5913-
decl_fn_and_pair_full(ccx, i.span, new_pt, "res_dtor", tps, i.id, t);
5872+
register_fn_full(ccx, i.span, new_pt, "res_dtor", tps, i.id, t);
59145873
}
59155874
_ { }
59165875
}
@@ -5935,8 +5894,8 @@ fn collect_tag_ctor(ccx: @crate_ctxt, i: @ast::item, pt: [str],
59355894
ast::item_tag(variants, tps) {
59365895
for variant: ast::variant in variants {
59375896
if std::vec::len(variant.node.args) != 0u {
5938-
decl_fn_and_pair(ccx, i.span, new_pt + [variant.node.name],
5939-
"tag", tps, variant.node.id);
5897+
register_fn(ccx, i.span, new_pt + [variant.node.name],
5898+
"tag", tps, variant.node.id);
59405899
}
59415900
}
59425901
}
@@ -6209,7 +6168,6 @@ fn trans_crate(sess: session::session, crate: @ast::crate, tcx: ty::ctxt,
62096168
tag_sizes: tag_sizes,
62106169
discrims: new_int_hash::<ValueRef>(),
62116170
discrim_symbols: new_int_hash::<str>(),
6212-
fn_pairs: new_int_hash::<ValueRef>(),
62136171
consts: new_int_hash::<ValueRef>(),
62146172
obj_methods: new_int_hash::<()>(),
62156173
tydescs: tydescs,

trunk/src/comp/middle/trans_common.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ type crate_ctxt =
105105
tag_sizes: hashmap<ty::t, uint>,
106106
discrims: hashmap<ast::node_id, ValueRef>,
107107
discrim_symbols: hashmap<ast::node_id, str>,
108-
fn_pairs: hashmap<ast::node_id, ValueRef>,
109108
consts: hashmap<ast::node_id, ValueRef>,
110109
obj_methods: hashmap<ast::node_id, ()>,
111110
tydescs: hashmap<ty::t, @tydesc_info>,
@@ -328,7 +327,7 @@ fn revoke_clean(cx: @block_ctxt, val: ValueRef, t: ty::t) -> @block_ctxt {
328327
fn get_res_dtor(ccx: @crate_ctxt, sp: span, did: ast::def_id, inner_t: ty::t)
329328
-> ValueRef {
330329
if did.crate == ast::local_crate {
331-
alt ccx.fn_pairs.find(did.node) {
330+
alt ccx.item_ids.find(did.node) {
332331
some(x) { ret x; }
333332
_ { ccx.tcx.sess.bug("get_res_dtor: can't find resource dtor!"); }
334333
}
@@ -343,8 +342,7 @@ fn get_res_dtor(ccx: @crate_ctxt, sp: span, did: ast::def_id, inner_t: ty::t)
343342
nil_res, params);
344343
ret trans::get_extern_const(ccx.externs, ccx.llmod,
345344
csearch::get_symbol(ccx.sess.get_cstore(),
346-
did),
347-
T_fn_pair(*ccx, f_t));
345+
did), f_t);
348346
}
349347

350348
tag block_kind {

trunk/src/comp/middle/ty.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1586,6 +1586,7 @@ fn ty_fn_args(cx: ctxt, fty: t) -> [arg] {
15861586
fn ty_fn_proto(cx: ctxt, fty: t) -> ast::proto {
15871587
alt struct(cx, fty) {
15881588
ty::ty_fn(p, _, _, _, _) { ret p; }
1589+
ty::ty_native_fn(_, _, _) { ret ast::proto_fn; }
15891590
_ { cx.sess.bug("ty_fn_proto() called on non-fn type"); }
15901591
}
15911592
}

0 commit comments

Comments
 (0)