Skip to content

Commit 996ec62

Browse files
committed
Remove spurious by-ref argument to destructors
Destructors were internally declared with an extra (hidden) nil-typed argument that was passed in by-ref mode. This was causing spurious mode warnings. Deleted it. Also some misc. cleanup because I couldn't help myself.
1 parent 656cbea commit 996ec62

File tree

6 files changed

+14
-18
lines changed

6 files changed

+14
-18
lines changed

src/libsyntax/ast_util.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -398,10 +398,8 @@ fn operator_prec(op: ast::binop) -> uint {
398398

399399
fn dtor_dec() -> fn_decl {
400400
let nil_t = @{id: 0, node: ty_nil, span: dummy_sp()};
401-
// dtor has one argument, of type ()
402-
{inputs: ~[{mode: ast::expl(ast::by_ref),
403-
ty: nil_t, ident: parse::token::special_idents::underscore,
404-
id: 0}],
401+
// dtor has no args
402+
{inputs: ~[],
405403
output: nil_t, cf: return_val}
406404
}
407405

src/rustc/middle/trans/base.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ fn get_res_dtor(ccx: @crate_ctxt, did: ast::def_id,
383383
parent_id: ast::def_id, substs: ~[ty::t])
384384
-> ValueRef {
385385
let _icx = ccx.insn_ctxt("trans_res_dtor");
386-
if (substs.len() > 0u) {
386+
if (substs.is_not_empty()) {
387387
let did = if did.crate != ast::local_crate {
388388
inline::maybe_instantiate_inline(ccx, did)
389389
} else { did };
@@ -1496,7 +1496,7 @@ fn copy_args_to_allocas(fcx: fn_ctxt,
14961496

14971497
// For certain mode/type combinations, the raw llarg values are passed
14981498
// by value. However, within the fn body itself, we want to always
1499-
// have all locals and argumenst be by-ref so that we can cancel the
1499+
// have all locals and arguments be by-ref so that we can cancel the
15001500
// cleanup and for better interaction with LLVM's debug info. So, if
15011501
// the argument would be passed by value, we store it into an alloca.
15021502
// This alloca should be optimized away by LLVM's mem-to-reg pass in
@@ -1767,9 +1767,7 @@ fn trans_class_dtor(ccx: @crate_ctxt, path: path,
17671767

17681768
/* The dtor takes a (null) output pointer, and a self argument,
17691769
and returns () */
1770-
let lldty = T_fn(~[T_ptr(type_of(ccx, ty::mk_nil(tcx))),
1771-
T_ptr(type_of(ccx, class_ty))],
1772-
llvm::LLVMVoidType());
1770+
let lldty = type_of_dtor(ccx, class_ty);
17731771

17741772
let s = get_dtor_symbol(ccx, path, dtor_id, psubsts);
17751773

@@ -1833,7 +1831,7 @@ fn trans_item(ccx: @crate_ctxt, item: ast::item) {
18331831
*path,
18341832
~[path_name(item.ident)]),
18351833
decl, body, llfndecl, item.id);
1836-
} else if tps.len() == 0u {
1834+
} else if tps.is_empty() {
18371835
let llfndecl = get_item_val(ccx, item.id);
18381836
trans_fn(ccx,
18391837
vec::append(*path, ~[path_name(item.ident)]),

src/rustc/middle/trans/datum.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ fn appropriate_mode(ty: ty::t) -> DatumMode {
204204
*
205205
* Indicates the "appropriate" mode for this value,
206206
* which is either by ref or by value, depending
207-
* on whether type is iimmediate or what. */
207+
* on whether type is immediate or not. */
208208

209209
if ty::type_is_nil(ty) || ty::type_is_bot(ty) {
210210
ByValue

src/rustc/middle/trans/glue.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -426,8 +426,8 @@ fn trans_class_drop(bcx: block,
426426
// Class dtors have no explicit args, so the params should
427427
// just consist of the output pointer and the environment
428428
// (self)
429-
assert(params.len() == 2u);
430-
let self_arg = PointerCast(bcx, v0, params[1u]);
429+
assert(params.len() == 2);
430+
let self_arg = PointerCast(bcx, v0, params[1]);
431431
let args = ~[bcx.fcx.llretptr, self_arg];
432432
Call(bcx, dtor_addr, args);
433433

@@ -440,7 +440,7 @@ fn trans_class_drop(bcx: block,
440440
bcx = drop_ty(bcx, llfld_a, fld.mt.ty);
441441
}
442442

443-
Store(bcx, C_u8(0u), drop_flag);
443+
Store(bcx, C_u8(0), drop_flag);
444444
bcx
445445
}
446446
}

src/rustc/middle/trans/monomorphize.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,11 @@ fn monomorphic_fn(ccx: @crate_ctxt,
103103
// Random cut-off -- code that needs to instantiate the same function
104104
// recursively more than ten times can probably safely be assumed to be
105105
// causing an infinite expansion.
106-
if depth > 10u {
106+
if depth > 10 {
107107
ccx.sess.span_fatal(
108108
span, ~"overly deep expansion of inlined function");
109109
}
110-
ccx.monomorphizing.insert(fn_id, depth + 1u);
110+
ccx.monomorphizing.insert(fn_id, depth + 1);
111111

112112
let pt = vec::append(*pt,
113113
~[path_name(ccx.names(ccx.sess.str_of(name)))]);

src/rustc/middle/trans/type_of.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,8 @@ fn llvm_type_name(cx: @crate_ctxt,
254254
}
255255

256256
fn type_of_dtor(ccx: @crate_ctxt, self_ty: ty::t) -> TypeRef {
257-
T_fn(~[T_ptr(type_of(ccx, ty::mk_nil(ccx.tcx))),
258-
T_ptr(type_of(ccx, self_ty))],
257+
T_fn(~[T_ptr(type_of(ccx, ty::mk_nil(ccx.tcx))), // output pointer
258+
T_ptr(type_of(ccx, self_ty))], // self arg
259259
llvm::LLVMVoidType())
260260
}
261261

0 commit comments

Comments
 (0)