Skip to content

Commit

Permalink
Use the right type for self in methods and remove obsoleted items.
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyb committed Jan 11, 2014
1 parent 7a305f9 commit 08ac616
Show file tree
Hide file tree
Showing 28 changed files with 472 additions and 522 deletions.
1 change: 0 additions & 1 deletion src/librustc/metadata/tydecode.rs
Expand Up @@ -410,7 +410,6 @@ fn parse_ty(st: &mut PState, conv: conv_did) -> ty::t {
let inner = parse_ty(st, |x,y| conv(x,y));
inner
}
'B' => ty::mk_opaque_box(st.tcx),
'a' => {
assert_eq!(next(st), '[');
let did = parse_def(st, NominalType, |x,y| conv(x,y));
Expand Down
1 change: 0 additions & 1 deletion src/librustc/metadata/tyencode.rs
Expand Up @@ -331,7 +331,6 @@ fn enc_sty(w: &mut MemWriter, cx: @ctxt, st: &ty::sty) {
mywrite!(w, "C&");
enc_sigil(w, p);
}
ty::ty_opaque_box => mywrite!(w, "B"),
ty::ty_struct(def, ref substs) => {
mywrite!(w, "a[{}|", (cx.ds)(def));
enc_substs(w, cx, substs);
Expand Down
9 changes: 1 addition & 8 deletions src/librustc/middle/astencode.rs
Expand Up @@ -578,9 +578,6 @@ fn encode_method_map_entry(ecx: &e::EncodeContext,
ebml_w.emit_struct_field("origin", 1u, |ebml_w| {
mme.origin.encode(ebml_w);
});
ebml_w.emit_struct_field("self_mode", 3, |ebml_w| {
mme.self_mode.encode(ebml_w);
});
})
}

Expand All @@ -602,11 +599,7 @@ impl<'a> read_method_map_entry_helper for reader::Decoder<'a> {
let method_origin: method_origin =
Decodable::decode(this);
method_origin.tr(xcx)
}),
self_mode: this.read_struct_field("self_mode", 3, |this| {
let self_mode: ty::SelfMode = Decodable::decode(this);
self_mode
}),
})
}
})
}
Expand Down
93 changes: 51 additions & 42 deletions src/librustc/middle/trans/_match.rs
Expand Up @@ -1392,37 +1392,41 @@ fn insert_lllocals<'a>(
let llval = match binding_info.trmode {
// By value bindings: use the stack slot that we
// copied/moved the value into
TrByValue(lldest) => {
if add_cleans {
add_clean(bcx, lldest, binding_info.ty);
}
TrByValue(lldest) => lldest,
// By ref binding: use the ptr into the matched value
TrByRef => binding_info.llmatch
};

lldest
}
let datum = Datum {
val: llval,
ty: binding_info.ty,
mode: ByRef(ZeroMem)
};

// By ref binding: use the ptr into the matched value
TrByRef => {
binding_info.llmatch
if add_cleans {
match binding_info.trmode {
TrByValue(_) => datum.add_clean(bcx),
_ => {}
}
};
}

{
debug!("binding {:?} to {}",
binding_info.id,
bcx.val_to_str(llval));
let mut llmap = bcx.fcx.lllocals.borrow_mut();
llmap.get().insert(binding_info.id, llval);
llmap.get().insert(binding_info.id, datum);
}

if bcx.sess().opts.extra_debuginfo {
debuginfo::create_match_binding_metadata(bcx,
ident,
binding_info.id,
binding_info.ty,
binding_info.span);
binding_info.span,
datum);
}
}
return bcx;
bcx
}

fn compile_guard<'r,
Expand Down Expand Up @@ -2032,8 +2036,7 @@ pub fn store_local<'a>(
Some(path) => {
return mk_binding_alloca(
bcx, pat.id, path, BindLocal,
|bcx, _, llval| expr::trans_into(bcx, init_expr,
expr::SaveIn(llval)));
|bcx, datum| expr::trans_into(bcx, init_expr, expr::SaveIn(datum.val)));
}

None => {}
Expand Down Expand Up @@ -2067,13 +2070,13 @@ pub fn store_local<'a>(
pat_bindings(tcx.def_map, pat, |_, p_id, _, path| {
bcx = mk_binding_alloca(
bcx, p_id, path, BindLocal,
|bcx, var_ty, llval| { zero_mem(bcx, llval, var_ty); bcx });
|bcx, datum| { datum.cancel_clean(bcx); bcx });
});
bcx
}
}

pub fn store_arg<'a>(mut bcx: &'a Block<'a>, pat: @ast::Pat, llval: ValueRef)
pub fn store_arg<'a>(mut bcx: &'a Block<'a>, pat: @ast::Pat, arg: Datum)
-> &'a Block<'a> {
/*!
* Generates code for argument patterns like `fn foo(<pat>: T)`.
Expand All @@ -2093,13 +2096,12 @@ pub fn store_arg<'a>(mut bcx: &'a Block<'a>, pat: @ast::Pat, llval: ValueRef)
// Note that we cannot do it before for fear of a fn like
// fn getaddr(~ref x: ~uint) -> *uint {....}
// (From test `run-pass/func-arg-ref-pattern.rs`)
let arg_ty = node_id_type(bcx, pat.id);
add_clean(bcx, llval, arg_ty);
arg.add_clean(bcx);

// Debug information (the llvm.dbg.declare intrinsic to be precise) always expects to get an
// alloca, which only is the case on the general path, so lets disable the optimized path when
// debug info is enabled.
let arg_is_alloca = unsafe { llvm::LLVMIsAAllocaInst(llval) != ptr::null() };
let arg_is_alloca = unsafe { llvm::LLVMIsAAllocaInst(arg.val) != ptr::null() };

let fast_path = (arg_is_alloca || !bcx.ccx().sess.opts.extra_debuginfo)
&& simple_identifier(pat).is_some();
Expand All @@ -2109,37 +2111,42 @@ pub fn store_arg<'a>(mut bcx: &'a Block<'a>, pat: @ast::Pat, llval: ValueRef)
// `llval` wholesale as the pointer for `x`, avoiding the
// general logic which may copy out of `llval`.
let mut llargs = bcx.fcx.llargs.borrow_mut();
llargs.get().insert(pat.id, llval);
llargs.get().insert(pat.id, arg);
} else {
// General path. Copy out the values that are used in the
// pattern.
bcx = bind_irrefutable_pat(bcx, pat, llval, BindArgument);
let llptr = arg.to_ref_llval(bcx);
bcx = bind_irrefutable_pat(bcx, pat, llptr, BindArgument);
}

return bcx;
}

fn mk_binding_alloca<'a>(
mut bcx: &'a Block<'a>,
bcx: &'a Block<'a>,
p_id: ast::NodeId,
path: &ast::Path,
binding_mode: IrrefutablePatternBindingMode,
populate: |&'a Block<'a>,
ty::t,
ValueRef|
-> &'a Block<'a>)
populate: |&'a Block<'a>, Datum| -> &'a Block<'a>)
-> &'a Block<'a> {
let var_ty = node_id_type(bcx, p_id);
let ident = ast_util::path_to_ident(path);
let llval = alloc_ty(bcx, var_ty, bcx.ident(ident));
bcx = populate(bcx, var_ty, llval);
let mut llmap = match binding_mode {
BindLocal => bcx.fcx.lllocals.borrow_mut(),
BindArgument => bcx.fcx.llargs.borrow_mut(),
let datum = Datum {
val: llval,
ty: var_ty,
mode: ByRef(ZeroMem)
};
llmap.get().insert(p_id, llval);
add_clean(bcx, llval, var_ty);
return bcx;
{
let mut llmap = match binding_mode {
BindLocal => bcx.fcx.lllocals.borrow_mut(),
BindArgument => bcx.fcx.llargs.borrow_mut()
};
llmap.get().insert(p_id, datum);
}
let bcx = populate(bcx, datum);
datum.add_clean(bcx);
bcx
}

fn bind_irrefutable_pat<'a>(
Expand Down Expand Up @@ -2179,7 +2186,7 @@ fn bind_irrefutable_pat<'a>(

let _indenter = indenter();

let _icx = push_ctxt("alt::bind_irrefutable_pat");
let _icx = push_ctxt("match::bind_irrefutable_pat");
let mut bcx = bcx;
let tcx = bcx.tcx();
let ccx = bcx.ccx();
Expand All @@ -2191,21 +2198,23 @@ fn bind_irrefutable_pat<'a>(
// map.
bcx = mk_binding_alloca(
bcx, pat.id, path, binding_mode,
|bcx, variable_ty, llvariable_val| {
|bcx, var_datum| {
match pat_binding_mode {
ast::BindByValue(_) => {
// By value binding: move the value that `val`
// points at into the binding's stack slot.
let datum = Datum {val: val,
ty: variable_ty,
mode: ByRef(ZeroMem)};
datum.store_to(bcx, INIT, llvariable_val)
let datum = Datum {
val: val,
ty: var_datum.ty,
mode: ByRef(ZeroMem)
};
datum.store_to(bcx, INIT, var_datum.val)
}

ast::BindByRef(_) => {
// By ref binding: the value of the variable
// is the pointer `val` itself.
Store(bcx, val, llvariable_val);
Store(bcx, val, var_datum.val);
bcx
}
}
Expand Down
2 changes: 0 additions & 2 deletions src/librustc/middle/trans/asm.rs
Expand Up @@ -20,7 +20,6 @@ use middle::trans::callee;
use middle::trans::common::*;
use middle::trans::expr::*;
use middle::trans::type_of::*;
use middle::ty;

use middle::trans::type_::Type;

Expand Down Expand Up @@ -56,7 +55,6 @@ pub fn trans_inline_asm<'a>(bcx: &'a Block<'a>, ia: &ast::InlineAsm)
unpack_result!(bcx, {
callee::trans_arg_expr(bcx,
expr_ty(bcx, input),
ty::ByCopy,
input,
&mut cleanups,
callee::DontAutorefArg)
Expand Down

1 comment on commit 08ac616

@huonw
Copy link

@huonw huonw commented on 08ac616 Jan 11, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r=pcwalton

Please sign in to comment.