Skip to content

Commit 4778fe8

Browse files
committed
---
yaml --- r: 10616 b: refs/heads/snap-stage3 c: b021729 h: refs/heads/master v: v3
1 parent db2d6eb commit 4778fe8

File tree

4 files changed

+42
-14
lines changed

4 files changed

+42
-14
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
refs/heads/master: 2898dcc5d97da9427ac367542382b6239d9c0bbf
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 00171165205a1d5222563d0e2bdf7f970758b388
4+
refs/heads/snap-stage3: b02172971fa658f2e6d3cdb3cbf3bf663801d656
55
refs/heads/try: 2898dcc5d97da9427ac367542382b6239d9c0bbf
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105

branches/snap-stage3/src/rustc/middle/trans/base.rs

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,8 @@ fn trans_class_drop(bcx: block, v0: ValueRef, dtor_did: ast::def_id,
754754
// We have to cast v0
755755
let classptr = GEPi(bcx, v0, [0u, 1u]);
756756
// Find and call the actual destructor
757-
let dtor_addr = get_res_dtor(bcx.ccx(), dtor_did, substs.tps);
757+
let dtor_addr = get_res_dtor(bcx.ccx(), dtor_did, some(class_did),
758+
substs.tps);
758759
// The second argument is the "self" argument for drop
759760
let params = lib::llvm::fn_ty_param_tys
760761
(llvm::LLVMGetElementType
@@ -829,7 +830,11 @@ fn make_drop_glue(bcx: block, v0: ValueRef, t: ty::t) {
829830
build_return(bcx);
830831
}
831832

832-
fn get_res_dtor(ccx: @crate_ctxt, did: ast::def_id, substs: [ty::t])
833+
fn get_res_dtor(ccx: @crate_ctxt, did: ast::def_id,
834+
// Parent ID is an option because resources don't
835+
// have one. We can make this a def_id when
836+
// resources get removed.
837+
opt_id: option<ast::def_id>, substs: [ty::t])
833838
-> ValueRef {
834839
let _icx = ccx.insn_ctxt("trans_res_dtor");
835840
if (substs.len() > 0u) {
@@ -841,14 +846,27 @@ fn get_res_dtor(ccx: @crate_ctxt, did: ast::def_id, substs: [ty::t])
841846
} else if did.crate == ast::local_crate {
842847
get_item_val(ccx, did.node)
843848
} else {
844-
let fty = ty::mk_fn(ccx.tcx, {purity: ast::impure_fn,
845-
proto: ast::proto_bare,
846-
inputs: [{mode: ast::expl(ast::by_ref),
849+
alt opt_id {
850+
some(parent_id) {
851+
let tcx = ccx.tcx;
852+
let name = csearch::get_symbol(ccx.sess.cstore, did);
853+
let class_ty = ty::subst_tps(tcx, substs,
854+
ty::lookup_item_type(tcx, parent_id).ty);
855+
let llty = type_of_dtor(ccx, class_ty);
856+
get_extern_fn(ccx.externs, ccx.llmod, name, lib::llvm::CCallConv,
857+
llty)
858+
}
859+
none {
860+
let fty = ty::mk_fn(ccx.tcx, {purity: ast::impure_fn,
861+
proto: ast::proto_bare,
862+
inputs: [{mode: ast::expl(ast::by_ref),
847863
ty: ty::mk_nil_ptr(ccx.tcx)}],
848864
output: ty::mk_nil(ccx.tcx),
849865
ret_style: ast::return_val,
850866
constraints: []});
851-
trans_external_path(ccx, did, fty)
867+
trans_external_path(ccx, did, fty)
868+
}
869+
}
852870
}
853871
}
854872

@@ -862,7 +880,7 @@ fn trans_res_drop(bcx: block, rs: ValueRef, did: ast::def_id,
862880
with_cond(bcx, IsNotNull(bcx, Load(bcx, drop_flag))) {|bcx|
863881
let valptr = GEPi(bcx, rs, [0u, 1u]);
864882
// Find and call the actual destructor.
865-
let dtor_addr = get_res_dtor(ccx, did, tps);
883+
let dtor_addr = get_res_dtor(ccx, did, none, tps);
866884
let args = [bcx.fcx.llretptr, null_env_ptr(bcx)];
867885
// Kludge to work around the fact that we know the precise type of the
868886
// value here, but the dtor expects a type that might have opaque

branches/snap-stage3/src/rustc/middle/trans/shape.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,14 @@ import std::map::hashmap;
2121

2222
import ty_ctxt = middle::ty::ctxt;
2323

24-
type nominal_id = @{did: ast::def_id, tps: [ty::t]};
24+
type nominal_id = @{did: ast::def_id, parent_id: option<ast::def_id>,
25+
tps: [ty::t]};
2526

2627
fn mk_nominal_id(tcx: ty::ctxt, did: ast::def_id,
28+
parent_id: option<ast::def_id>,
2729
tps: [ty::t]) -> nominal_id {
2830
let tps_norm = tps.map { |t| ty::normalize_ty(tcx, t) };
29-
@{did: did, tps: tps_norm}
31+
@{did: did, parent_id: parent_id, tps: tps_norm}
3032
}
3133

3234
fn hash_nominal_id(&&ri: nominal_id) -> uint {
@@ -233,7 +235,7 @@ fn shape_of(ccx: @crate_ctxt, t: ty::t) -> [u8] {
233235
tk_enum { [s_variant_enum_t(ccx.tcx)] }
234236
tk_newtype | tk_complex {
235237
let mut s = [shape_enum], id;
236-
let nom_id = mk_nominal_id(ccx.tcx, did, substs.tps);
238+
let nom_id = mk_nominal_id(ccx.tcx, did, none, substs.tps);
237239
alt ccx.shape_cx.tag_id_to_index.find(nom_id) {
238240
none {
239241
id = ccx.shape_cx.next_tag_id;
@@ -335,7 +337,7 @@ fn shape_of(ccx: @crate_ctxt, t: ty::t) -> [u8] {
335337
else { [shape_struct] };
336338
let mut sub = [];
337339
option::iter(m_dtor_did) {|dtor_did|
338-
let ri = @{did: dtor_did, tps: tps};
340+
let ri = @{did: dtor_did, parent_id: some(did), tps: tps};
339341
let id = interner::intern(ccx.shape_cx.resources, ri);
340342
add_u16(s, id as u16);
341343

@@ -362,7 +364,7 @@ fn shape_of(ccx: @crate_ctxt, t: ty::t) -> [u8] {
362364
for substs.tps.each() {|t| assert !ty::type_has_params(t); }
363365
let subt = ty::subst(ccx.tcx, substs, raw_subt);
364366
let tps = substs.tps;
365-
let ri = @{did: did, tps: tps};
367+
let ri = @{did: did, parent_id: none, tps: tps};
366368
let id = interner::intern(ccx.shape_cx.resources, ri);
367369

368370
let mut s = [shape_res];
@@ -597,7 +599,8 @@ fn gen_resource_shapes(ccx: @crate_ctxt) -> ValueRef {
597599
for uint::range(0u, len) {|i|
598600
let ri = interner::get(ccx.shape_cx.resources, i);
599601
for ri.tps.each() {|s| assert !ty::type_has_params(s); }
600-
dtors += [trans::base::get_res_dtor(ccx, ri.did, ri.tps)];
602+
dtors += [trans::base::get_res_dtor(ccx, ri.did, ri.parent_id,
603+
ri.tps)];
601604
}
602605
ret mk_global(ccx, "resource_shapes", C_struct(dtors), true);
603606
}

branches/snap-stage3/src/rustc/middle/trans/type_of.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import std::map::hashmap;
88
import ty::*;
99

1010
export type_of;
11+
export type_of_dtor;
1112
export type_of_explicit_args;
1213
export type_of_fn_from_ty;
1314
export type_of_fn;
@@ -251,3 +252,9 @@ fn llvm_type_name(cx: @crate_ctxt, t: ty::t) -> str {
251252
);
252253
}
253254

255+
fn type_of_dtor(ccx: @crate_ctxt, self_ty: ty::t) -> TypeRef {
256+
T_fn([T_ptr(type_of(ccx, ty::mk_nil(ccx.tcx))),
257+
T_ptr(type_of(ccx, self_ty))],
258+
llvm::LLVMVoidType())
259+
}
260+

0 commit comments

Comments
 (0)