Skip to content

Commit 08ac616

Browse files
committed
Use the right type for self in methods and remove obsoleted items.
Fixes #7411, #10615.
1 parent 7a305f9 commit 08ac616

28 files changed

+472
-522
lines changed

src/librustc/metadata/tydecode.rs

-1
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,6 @@ fn parse_ty(st: &mut PState, conv: conv_did) -> ty::t {
410410
let inner = parse_ty(st, |x,y| conv(x,y));
411411
inner
412412
}
413-
'B' => ty::mk_opaque_box(st.tcx),
414413
'a' => {
415414
assert_eq!(next(st), '[');
416415
let did = parse_def(st, NominalType, |x,y| conv(x,y));

src/librustc/metadata/tyencode.rs

-1
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,6 @@ fn enc_sty(w: &mut MemWriter, cx: @ctxt, st: &ty::sty) {
331331
mywrite!(w, "C&");
332332
enc_sigil(w, p);
333333
}
334-
ty::ty_opaque_box => mywrite!(w, "B"),
335334
ty::ty_struct(def, ref substs) => {
336335
mywrite!(w, "a[{}|", (cx.ds)(def));
337336
enc_substs(w, cx, substs);

src/librustc/middle/astencode.rs

+1-8
Original file line numberDiff line numberDiff line change
@@ -578,9 +578,6 @@ fn encode_method_map_entry(ecx: &e::EncodeContext,
578578
ebml_w.emit_struct_field("origin", 1u, |ebml_w| {
579579
mme.origin.encode(ebml_w);
580580
});
581-
ebml_w.emit_struct_field("self_mode", 3, |ebml_w| {
582-
mme.self_mode.encode(ebml_w);
583-
});
584581
})
585582
}
586583

@@ -602,11 +599,7 @@ impl<'a> read_method_map_entry_helper for reader::Decoder<'a> {
602599
let method_origin: method_origin =
603600
Decodable::decode(this);
604601
method_origin.tr(xcx)
605-
}),
606-
self_mode: this.read_struct_field("self_mode", 3, |this| {
607-
let self_mode: ty::SelfMode = Decodable::decode(this);
608-
self_mode
609-
}),
602+
})
610603
}
611604
})
612605
}

src/librustc/middle/trans/_match.rs

+51-42
Original file line numberDiff line numberDiff line change
@@ -1392,37 +1392,41 @@ fn insert_lllocals<'a>(
13921392
let llval = match binding_info.trmode {
13931393
// By value bindings: use the stack slot that we
13941394
// copied/moved the value into
1395-
TrByValue(lldest) => {
1396-
if add_cleans {
1397-
add_clean(bcx, lldest, binding_info.ty);
1398-
}
1395+
TrByValue(lldest) => lldest,
1396+
// By ref binding: use the ptr into the matched value
1397+
TrByRef => binding_info.llmatch
1398+
};
13991399

1400-
lldest
1401-
}
1400+
let datum = Datum {
1401+
val: llval,
1402+
ty: binding_info.ty,
1403+
mode: ByRef(ZeroMem)
1404+
};
14021405

1403-
// By ref binding: use the ptr into the matched value
1404-
TrByRef => {
1405-
binding_info.llmatch
1406+
if add_cleans {
1407+
match binding_info.trmode {
1408+
TrByValue(_) => datum.add_clean(bcx),
1409+
_ => {}
14061410
}
1407-
};
1411+
}
14081412

14091413
{
14101414
debug!("binding {:?} to {}",
14111415
binding_info.id,
14121416
bcx.val_to_str(llval));
14131417
let mut llmap = bcx.fcx.lllocals.borrow_mut();
1414-
llmap.get().insert(binding_info.id, llval);
1418+
llmap.get().insert(binding_info.id, datum);
14151419
}
14161420

14171421
if bcx.sess().opts.extra_debuginfo {
14181422
debuginfo::create_match_binding_metadata(bcx,
14191423
ident,
14201424
binding_info.id,
1421-
binding_info.ty,
1422-
binding_info.span);
1425+
binding_info.span,
1426+
datum);
14231427
}
14241428
}
1425-
return bcx;
1429+
bcx
14261430
}
14271431

14281432
fn compile_guard<'r,
@@ -2032,8 +2036,7 @@ pub fn store_local<'a>(
20322036
Some(path) => {
20332037
return mk_binding_alloca(
20342038
bcx, pat.id, path, BindLocal,
2035-
|bcx, _, llval| expr::trans_into(bcx, init_expr,
2036-
expr::SaveIn(llval)));
2039+
|bcx, datum| expr::trans_into(bcx, init_expr, expr::SaveIn(datum.val)));
20372040
}
20382041

20392042
None => {}
@@ -2067,13 +2070,13 @@ pub fn store_local<'a>(
20672070
pat_bindings(tcx.def_map, pat, |_, p_id, _, path| {
20682071
bcx = mk_binding_alloca(
20692072
bcx, p_id, path, BindLocal,
2070-
|bcx, var_ty, llval| { zero_mem(bcx, llval, var_ty); bcx });
2073+
|bcx, datum| { datum.cancel_clean(bcx); bcx });
20712074
});
20722075
bcx
20732076
}
20742077
}
20752078

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

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

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

21192122
return bcx;
21202123
}
21212124

21222125
fn mk_binding_alloca<'a>(
2123-
mut bcx: &'a Block<'a>,
2126+
bcx: &'a Block<'a>,
21242127
p_id: ast::NodeId,
21252128
path: &ast::Path,
21262129
binding_mode: IrrefutablePatternBindingMode,
2127-
populate: |&'a Block<'a>,
2128-
ty::t,
2129-
ValueRef|
2130-
-> &'a Block<'a>)
2130+
populate: |&'a Block<'a>, Datum| -> &'a Block<'a>)
21312131
-> &'a Block<'a> {
21322132
let var_ty = node_id_type(bcx, p_id);
21332133
let ident = ast_util::path_to_ident(path);
21342134
let llval = alloc_ty(bcx, var_ty, bcx.ident(ident));
2135-
bcx = populate(bcx, var_ty, llval);
2136-
let mut llmap = match binding_mode {
2137-
BindLocal => bcx.fcx.lllocals.borrow_mut(),
2138-
BindArgument => bcx.fcx.llargs.borrow_mut(),
2135+
let datum = Datum {
2136+
val: llval,
2137+
ty: var_ty,
2138+
mode: ByRef(ZeroMem)
21392139
};
2140-
llmap.get().insert(p_id, llval);
2141-
add_clean(bcx, llval, var_ty);
2142-
return bcx;
2140+
{
2141+
let mut llmap = match binding_mode {
2142+
BindLocal => bcx.fcx.lllocals.borrow_mut(),
2143+
BindArgument => bcx.fcx.llargs.borrow_mut()
2144+
};
2145+
llmap.get().insert(p_id, datum);
2146+
}
2147+
let bcx = populate(bcx, datum);
2148+
datum.add_clean(bcx);
2149+
bcx
21432150
}
21442151

21452152
fn bind_irrefutable_pat<'a>(
@@ -2179,7 +2186,7 @@ fn bind_irrefutable_pat<'a>(
21792186

21802187
let _indenter = indenter();
21812188

2182-
let _icx = push_ctxt("alt::bind_irrefutable_pat");
2189+
let _icx = push_ctxt("match::bind_irrefutable_pat");
21832190
let mut bcx = bcx;
21842191
let tcx = bcx.tcx();
21852192
let ccx = bcx.ccx();
@@ -2191,21 +2198,23 @@ fn bind_irrefutable_pat<'a>(
21912198
// map.
21922199
bcx = mk_binding_alloca(
21932200
bcx, pat.id, path, binding_mode,
2194-
|bcx, variable_ty, llvariable_val| {
2201+
|bcx, var_datum| {
21952202
match pat_binding_mode {
21962203
ast::BindByValue(_) => {
21972204
// By value binding: move the value that `val`
21982205
// points at into the binding's stack slot.
2199-
let datum = Datum {val: val,
2200-
ty: variable_ty,
2201-
mode: ByRef(ZeroMem)};
2202-
datum.store_to(bcx, INIT, llvariable_val)
2206+
let datum = Datum {
2207+
val: val,
2208+
ty: var_datum.ty,
2209+
mode: ByRef(ZeroMem)
2210+
};
2211+
datum.store_to(bcx, INIT, var_datum.val)
22032212
}
22042213

22052214
ast::BindByRef(_) => {
22062215
// By ref binding: the value of the variable
22072216
// is the pointer `val` itself.
2208-
Store(bcx, val, llvariable_val);
2217+
Store(bcx, val, var_datum.val);
22092218
bcx
22102219
}
22112220
}

src/librustc/middle/trans/asm.rs

-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ use middle::trans::callee;
2020
use middle::trans::common::*;
2121
use middle::trans::expr::*;
2222
use middle::trans::type_of::*;
23-
use middle::ty;
2423

2524
use middle::trans::type_::Type;
2625

@@ -56,7 +55,6 @@ pub fn trans_inline_asm<'a>(bcx: &'a Block<'a>, ia: &ast::InlineAsm)
5655
unpack_result!(bcx, {
5756
callee::trans_arg_expr(bcx,
5857
expr_ty(bcx, input),
59-
ty::ByCopy,
6058
input,
6159
&mut cleanups,
6260
callee::DontAutorefArg)

0 commit comments

Comments
 (0)