Skip to content

Commit

Permalink
Remove spurious by-ref argument to destructors
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
catamorphism committed Sep 27, 2012
1 parent 656cbea commit 996ec62
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 18 deletions.
6 changes: 2 additions & 4 deletions src/libsyntax/ast_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,10 +398,8 @@ fn operator_prec(op: ast::binop) -> uint {

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

Expand Down
10 changes: 4 additions & 6 deletions src/rustc/middle/trans/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ fn get_res_dtor(ccx: @crate_ctxt, did: ast::def_id,
parent_id: ast::def_id, substs: ~[ty::t])
-> ValueRef {
let _icx = ccx.insn_ctxt("trans_res_dtor");
if (substs.len() > 0u) {
if (substs.is_not_empty()) {
let did = if did.crate != ast::local_crate {
inline::maybe_instantiate_inline(ccx, did)
} else { did };
Expand Down Expand Up @@ -1496,7 +1496,7 @@ fn copy_args_to_allocas(fcx: fn_ctxt,

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

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

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

Expand Down Expand Up @@ -1833,7 +1831,7 @@ fn trans_item(ccx: @crate_ctxt, item: ast::item) {
*path,
~[path_name(item.ident)]),
decl, body, llfndecl, item.id);
} else if tps.len() == 0u {
} else if tps.is_empty() {
let llfndecl = get_item_val(ccx, item.id);
trans_fn(ccx,
vec::append(*path, ~[path_name(item.ident)]),
Expand Down
2 changes: 1 addition & 1 deletion src/rustc/middle/trans/datum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ fn appropriate_mode(ty: ty::t) -> DatumMode {
*
* Indicates the "appropriate" mode for this value,
* which is either by ref or by value, depending
* on whether type is iimmediate or what. */
* on whether type is immediate or not. */

if ty::type_is_nil(ty) || ty::type_is_bot(ty) {
ByValue
Expand Down
6 changes: 3 additions & 3 deletions src/rustc/middle/trans/glue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,8 +426,8 @@ fn trans_class_drop(bcx: block,
// Class dtors have no explicit args, so the params should
// just consist of the output pointer and the environment
// (self)
assert(params.len() == 2u);
let self_arg = PointerCast(bcx, v0, params[1u]);
assert(params.len() == 2);
let self_arg = PointerCast(bcx, v0, params[1]);
let args = ~[bcx.fcx.llretptr, self_arg];
Call(bcx, dtor_addr, args);

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

Store(bcx, C_u8(0u), drop_flag);
Store(bcx, C_u8(0), drop_flag);
bcx
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/rustc/middle/trans/monomorphize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,11 @@ fn monomorphic_fn(ccx: @crate_ctxt,
// Random cut-off -- code that needs to instantiate the same function
// recursively more than ten times can probably safely be assumed to be
// causing an infinite expansion.
if depth > 10u {
if depth > 10 {
ccx.sess.span_fatal(
span, ~"overly deep expansion of inlined function");
}
ccx.monomorphizing.insert(fn_id, depth + 1u);
ccx.monomorphizing.insert(fn_id, depth + 1);

let pt = vec::append(*pt,
~[path_name(ccx.names(ccx.sess.str_of(name)))]);
Expand Down
4 changes: 2 additions & 2 deletions src/rustc/middle/trans/type_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,8 @@ fn llvm_type_name(cx: @crate_ctxt,
}

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

Expand Down

0 comments on commit 996ec62

Please sign in to comment.