Skip to content

Commit 05e4d94

Browse files
committed
Replace callee_id with information stored in method_map.
1 parent 7a588ce commit 05e4d94

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+478
-550
lines changed

src/librustc/front/feature_gate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ impl Visitor<()> for Context {
255255

256256
fn visit_expr(&mut self, e: &ast::Expr, _: ()) {
257257
match e.node {
258-
ast::ExprUnary(_, ast::UnBox, _) => {
258+
ast::ExprUnary(ast::UnBox, _) => {
259259
self.gate_box(e.span);
260260
}
261261
_ => {}

src/librustc/middle/astencode.rs

Lines changed: 52 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use metadata::tydecode;
2121
use metadata::tydecode::{DefIdSource, NominalType, TypeWithId, TypeParameter,
2222
RegionParameter};
2323
use metadata::tyencode;
24-
use middle::typeck::method_origin;
24+
use middle::typeck::{MethodCallee, MethodOrigin};
2525
use middle::{ty, typeck, moves};
2626
use middle;
2727
use util::ppaux::ty_to_str;
@@ -574,10 +574,50 @@ impl tr for moves::CaptureVar {
574574
}
575575

576576
// ______________________________________________________________________
577-
// Encoding and decoding of method_origin
577+
// Encoding and decoding of MethodCallee
578578

579-
impl tr for method_origin {
580-
fn tr(&self, xcx: @ExtendedDecodeContext) -> method_origin {
579+
trait read_method_callee_helper {
580+
fn read_method_callee(&mut self, xcx: @ExtendedDecodeContext) -> MethodCallee;
581+
}
582+
583+
fn encode_method_callee(ecx: &e::EncodeContext,
584+
ebml_w: &mut writer::Encoder,
585+
method: &MethodCallee) {
586+
ebml_w.emit_struct("MethodCallee", 3, |ebml_w| {
587+
ebml_w.emit_struct_field("origin", 0u, |ebml_w| {
588+
method.origin.encode(ebml_w);
589+
});
590+
ebml_w.emit_struct_field("ty", 1u, |ebml_w| {
591+
ebml_w.emit_ty(ecx, method.ty);
592+
});
593+
ebml_w.emit_struct_field("substs", 2u, |ebml_w| {
594+
ebml_w.emit_substs(ecx, &method.substs);
595+
});
596+
})
597+
}
598+
599+
impl<'a> read_method_callee_helper for reader::Decoder<'a> {
600+
fn read_method_callee(&mut self, xcx: @ExtendedDecodeContext) -> MethodCallee {
601+
self.read_struct("MethodCallee", 3, |this| {
602+
MethodCallee {
603+
origin: this.read_struct_field("origin", 0, |this| {
604+
let method_origin: MethodOrigin =
605+
Decodable::decode(this);
606+
method_origin.tr(xcx)
607+
}),
608+
ty: this.read_struct_field("ty", 1, |this| {
609+
this.read_ty(xcx)
610+
}),
611+
substs: this.read_struct_field("substs", 2, |this| {
612+
this.read_substs(xcx)
613+
})
614+
}
615+
})
616+
}
617+
}
618+
619+
impl tr for MethodOrigin {
620+
fn tr(&self, xcx: @ExtendedDecodeContext) -> MethodOrigin {
581621
match *self {
582622
typeck::MethodStatic(did) => typeck::MethodStatic(did.tr(xcx)),
583623
typeck::MethodParam(ref mp) => {
@@ -991,17 +1031,13 @@ fn encode_side_tables_for_id(ecx: &e::EncodeContext,
9911031
}
9921032
}
9931033

994-
{
995-
let method_map = maps.method_map.borrow();
996-
let r = method_map.get().find(&id);
997-
for &origin in r.iter() {
998-
ebml_w.tag(c::tag_table_method_map, |ebml_w| {
999-
ebml_w.id(id);
1000-
ebml_w.tag(c::tag_table_val, |ebml_w| {
1001-
origin.encode(ebml_w);
1002-
})
1034+
for &method in maps.method_map.borrow().get().find(&id).iter() {
1035+
ebml_w.tag(c::tag_table_method_map, |ebml_w| {
1036+
ebml_w.id(id);
1037+
ebml_w.tag(c::tag_table_val, |ebml_w| {
1038+
encode_method_callee(ecx, ebml_w, method)
10031039
})
1004-
}
1040+
})
10051041
}
10061042

10071043
{
@@ -1335,9 +1371,8 @@ fn decode_side_tables(xcx: @ExtendedDecodeContext,
13351371
ty_param_defs.get().insert(id, bounds);
13361372
}
13371373
c::tag_table_method_map => {
1338-
let origin: method_origin = Decodable::decode(val_dsr);
1339-
let mut method_map = dcx.maps.method_map.borrow_mut();
1340-
method_map.get().insert(id, origin.tr(xcx));
1374+
let method = val_dsr.read_method_callee(xcx);
1375+
dcx.maps.method_map.borrow_mut().get().insert(id, method);
13411376
}
13421377
c::tag_table_vtable_map => {
13431378
let vtable_res =

src/librustc/middle/borrowck/check_loans.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -784,7 +784,6 @@ impl<'a> CheckLoanCtxt<'a> {
784784
pub fn check_call(&self,
785785
_expr: &ast::Expr,
786786
_callee: Option<@ast::Expr>,
787-
_callee_id: ast::NodeId,
788787
_callee_span: Span,
789788
_args: &[@ast::Expr]) {
790789
// NB: This call to check for conflicting loans is not truly
@@ -828,23 +827,22 @@ fn check_loans_in_expr<'a>(this: &mut CheckLoanCtxt<'a>,
828827
this.check_captured_variables(expr.id, expr.span)
829828
}
830829
ast::ExprAssign(dest, _) |
831-
ast::ExprAssignOp(_, _, dest, _) => {
830+
ast::ExprAssignOp(_, dest, _) => {
832831
this.check_assignment(dest);
833832
}
834833
ast::ExprCall(f, ref args) => {
835-
this.check_call(expr, Some(f), f.id, f.span, *args);
834+
this.check_call(expr, Some(f), f.span, *args);
836835
}
837-
ast::ExprMethodCall(callee_id, _, _, ref args) => {
838-
this.check_call(expr, None, callee_id, expr.span, *args);
836+
ast::ExprMethodCall(_, _, ref args) => {
837+
this.check_call(expr, None, expr.span, *args);
839838
}
840-
ast::ExprIndex(callee_id, _, rval) |
841-
ast::ExprBinary(callee_id, _, _, rval)
839+
ast::ExprIndex(_, rval) | ast::ExprBinary(_, _, rval)
842840
if method_map.get().contains_key(&expr.id) => {
843-
this.check_call(expr, None, callee_id, expr.span, [rval]);
841+
this.check_call(expr, None, expr.span, [rval]);
844842
}
845-
ast::ExprUnary(callee_id, _, _) | ast::ExprIndex(callee_id, _, _)
843+
ast::ExprUnary(_, _) | ast::ExprIndex(_, _)
846844
if method_map.get().contains_key(&expr.id) => {
847-
this.check_call(expr, None, callee_id, expr.span, []);
845+
this.check_call(expr, None, expr.span, []);
848846
}
849847
ast::ExprInlineAsm(ref ia) => {
850848
for &(_, out) in ia.outputs.iter() {

src/librustc/middle/borrowck/gather_loans/mod.rs

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -181,20 +181,9 @@ fn gather_loans_in_expr(this: &mut GatherLoanCtxt,
181181

182182
this.id_range.add(ex.id);
183183

184-
{
185-
let r = ex.get_callee_id();
186-
for callee_id in r.iter() {
187-
this.id_range.add(*callee_id);
188-
}
189-
}
190-
191184
// If this expression is borrowed, have to ensure it remains valid:
192-
{
193-
let adjustments = tcx.adjustments.borrow();
194-
let r = adjustments.get().find(&ex.id);
195-
for &adjustments in r.iter() {
196-
this.guarantee_adjustments(ex, *adjustments);
197-
}
185+
for &adjustments in tcx.adjustments.borrow().get().find(&ex.id).iter() {
186+
this.guarantee_adjustments(ex, *adjustments);
198187
}
199188

200189
// If this expression is a move, gather it:
@@ -225,7 +214,7 @@ fn gather_loans_in_expr(this: &mut GatherLoanCtxt,
225214
visit::walk_expr(this, ex, ());
226215
}
227216

228-
ast::ExprAssign(l, _) | ast::ExprAssignOp(_, _, l, _) => {
217+
ast::ExprAssign(l, _) | ast::ExprAssignOp(_, l, _) => {
229218
let l_cmt = this.bccx.cat_expr(l);
230219
match opt_loan_path(l_cmt) {
231220
Some(l_lp) => {
@@ -252,8 +241,8 @@ fn gather_loans_in_expr(this: &mut GatherLoanCtxt,
252241
visit::walk_expr(this, ex, ());
253242
}
254243

255-
ast::ExprIndex(_, _, arg) |
256-
ast::ExprBinary(_, _, _, arg)
244+
ast::ExprIndex(_, arg) |
245+
ast::ExprBinary(_, _, arg)
257246
if method_map.get().contains_key(&ex.id) => {
258247
// Arguments in method calls are always passed by ref.
259248
//

src/librustc/middle/cfg/construct.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ impl CFGBuilder {
305305
expr_exit
306306
}
307307

308-
ast::ExprBinary(_, op, l, r) if ast_util::lazy_binop(op) => {
308+
ast::ExprBinary(op, l, r) if ast_util::lazy_binop(op) => {
309309
//
310310
// [pred]
311311
// |
@@ -355,16 +355,16 @@ impl CFGBuilder {
355355
self.call(expr, pred, func, *args)
356356
}
357357

358-
ast::ExprMethodCall(_, _, _, ref args) => {
358+
ast::ExprMethodCall(_, _, ref args) => {
359359
self.call(expr, pred, args[0], args.slice_from(1))
360360
}
361361

362-
ast::ExprIndex(_, l, r) |
363-
ast::ExprBinary(_, _, l, r) if self.is_method_call(expr) => {
362+
ast::ExprIndex(l, r) |
363+
ast::ExprBinary(_, l, r) if self.is_method_call(expr) => {
364364
self.call(expr, pred, l, [r])
365365
}
366366

367-
ast::ExprUnary(_, _, e) if self.is_method_call(expr) => {
367+
ast::ExprUnary(_, e) if self.is_method_call(expr) => {
368368
self.call(expr, pred, e, [])
369369
}
370370

@@ -384,12 +384,12 @@ impl CFGBuilder {
384384
}
385385

386386
ast::ExprAssign(l, r) |
387-
ast::ExprAssignOp(_, _, l, r) => {
387+
ast::ExprAssignOp(_, l, r) => {
388388
self.straightline(expr, pred, [r, l])
389389
}
390390

391-
ast::ExprIndex(_, l, r) |
392-
ast::ExprBinary(_, _, l, r) => { // NB: && and || handled earlier
391+
ast::ExprIndex(l, r) |
392+
ast::ExprBinary(_, l, r) => { // NB: && and || handled earlier
393393
self.straightline(expr, pred, [l, r])
394394
}
395395

@@ -399,7 +399,7 @@ impl CFGBuilder {
399399

400400
ast::ExprAddrOf(_, e) |
401401
ast::ExprCast(e, _) |
402-
ast::ExprUnary(_, _, e) |
402+
ast::ExprUnary(_, e) |
403403
ast::ExprParen(e) |
404404
ast::ExprVstore(e, _) |
405405
ast::ExprField(e, _, _) => {

src/librustc/middle/check_const.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ pub fn check_expr(v: &mut CheckCrateVisitor,
108108
is_const: bool) {
109109
if is_const {
110110
match e.node {
111-
ExprUnary(_, UnDeref, _) => { }
112-
ExprUnary(_, UnBox, _) | ExprUnary(_, UnUniq, _) => {
111+
ExprUnary(UnDeref, _) => { }
112+
ExprUnary(UnBox, _) | ExprUnary(UnUniq, _) => {
113113
sess.span_err(e.span,
114114
"cannot do allocations in constant expressions");
115115
return;

src/librustc/middle/const_eval.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -225,10 +225,10 @@ impl ConstEvalVisitor {
225225
}
226226
}
227227

228-
ast::ExprUnary(_, _, inner) | ast::ExprParen(inner) =>
228+
ast::ExprUnary(_, inner) | ast::ExprParen(inner) =>
229229
self.classify(inner),
230230

231-
ast::ExprBinary(_, _, a, b) =>
231+
ast::ExprBinary(_, a, b) =>
232232
join(self.classify(a), self.classify(b)),
233233

234234
ast::ExprTup(ref es) |
@@ -262,7 +262,7 @@ impl ConstEvalVisitor {
262262

263263
ast::ExprField(base, _, _) => self.classify(base),
264264

265-
ast::ExprIndex(_, base, idx) =>
265+
ast::ExprIndex(base, idx) =>
266266
join(self.classify(base), self.classify(idx)),
267267

268268
ast::ExprAddrOf(ast::MutImmutable, base) => self.classify(base),
@@ -336,7 +336,7 @@ pub fn eval_const_expr_partial<T: ty::ExprTyProvider>(tcx: &T, e: &Expr)
336336
use middle::ty;
337337
fn fromb(b: bool) -> Result<const_val, ~str> { Ok(const_int(b as i64)) }
338338
match e.node {
339-
ExprUnary(_, UnNeg, inner) => {
339+
ExprUnary(UnNeg, inner) => {
340340
match eval_const_expr_partial(tcx, inner) {
341341
Ok(const_float(f)) => Ok(const_float(-f)),
342342
Ok(const_int(i)) => Ok(const_int(-i)),
@@ -346,15 +346,15 @@ pub fn eval_const_expr_partial<T: ty::ExprTyProvider>(tcx: &T, e: &Expr)
346346
ref err => ((*err).clone())
347347
}
348348
}
349-
ExprUnary(_, UnNot, inner) => {
349+
ExprUnary(UnNot, inner) => {
350350
match eval_const_expr_partial(tcx, inner) {
351351
Ok(const_int(i)) => Ok(const_int(!i)),
352352
Ok(const_uint(i)) => Ok(const_uint(!i)),
353353
Ok(const_bool(b)) => Ok(const_bool(!b)),
354354
_ => Err(~"not on float or string")
355355
}
356356
}
357-
ExprBinary(_, op, a, b) => {
357+
ExprBinary(op, a, b) => {
358358
match (eval_const_expr_partial(tcx, a),
359359
eval_const_expr_partial(tcx, b)) {
360360
(Ok(const_float(a)), Ok(const_float(b))) => {

src/librustc/middle/dataflow.rs

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ impl<'a, O:DataFlowOperator> PropagationContext<'a, O> {
556556
}
557557

558558
ast::ExprAssign(l, r) |
559-
ast::ExprAssignOp(_, _, l, r) => {
559+
ast::ExprAssignOp(_, l, r) => {
560560
self.walk_expr(r, in_out, loop_scopes);
561561
self.walk_expr(l, in_out, loop_scopes);
562562
}
@@ -579,35 +579,35 @@ impl<'a, O:DataFlowOperator> PropagationContext<'a, O> {
579579

580580
ast::ExprCall(f, ref args) => {
581581
self.walk_expr(f, in_out, loop_scopes);
582-
self.walk_call(f.id, expr.id, *args, in_out, loop_scopes);
582+
self.walk_call(expr.id, *args, in_out, loop_scopes);
583583
}
584584

585-
ast::ExprMethodCall(callee_id, _, _, ref args) => {
586-
self.walk_call(callee_id, expr.id, *args, in_out, loop_scopes);
585+
ast::ExprMethodCall(_, _, ref args) => {
586+
self.walk_call(expr.id, *args, in_out, loop_scopes);
587587
}
588588

589-
ast::ExprIndex(callee_id, l, r) |
590-
ast::ExprBinary(callee_id, _, l, r) if self.is_method_call(expr) => {
591-
self.walk_call(callee_id, expr.id, [l, r], in_out, loop_scopes);
589+
ast::ExprIndex(l, r) |
590+
ast::ExprBinary(_, l, r) if self.is_method_call(expr) => {
591+
self.walk_call(expr.id, [l, r], in_out, loop_scopes);
592592
}
593593

594-
ast::ExprUnary(callee_id, _, e) if self.is_method_call(expr) => {
595-
self.walk_call(callee_id, expr.id, [e], in_out, loop_scopes);
594+
ast::ExprUnary(_, e) if self.is_method_call(expr) => {
595+
self.walk_call(expr.id, [e], in_out, loop_scopes);
596596
}
597597

598598
ast::ExprTup(ref exprs) => {
599599
self.walk_exprs(*exprs, in_out, loop_scopes);
600600
}
601601

602-
ast::ExprBinary(_, op, l, r) if ast_util::lazy_binop(op) => {
602+
ast::ExprBinary(op, l, r) if ast_util::lazy_binop(op) => {
603603
self.walk_expr(l, in_out, loop_scopes);
604604
let temp = in_out.to_owned();
605605
self.walk_expr(r, in_out, loop_scopes);
606606
join_bits(&self.dfcx.oper, temp, in_out);
607607
}
608608

609-
ast::ExprIndex(_, l, r) |
610-
ast::ExprBinary(_, _, l, r) => {
609+
ast::ExprIndex(l, r) |
610+
ast::ExprBinary(_, l, r) => {
611611
self.walk_exprs([l, r], in_out, loop_scopes);
612612
}
613613

@@ -617,7 +617,7 @@ impl<'a, O:DataFlowOperator> PropagationContext<'a, O> {
617617

618618
ast::ExprAddrOf(_, e) |
619619
ast::ExprCast(e, _) |
620-
ast::ExprUnary(_, _, e) |
620+
ast::ExprUnary(_, e) |
621621
ast::ExprParen(e) |
622622
ast::ExprVstore(e, _) |
623623
ast::ExprField(e, _, _) => {
@@ -715,16 +715,15 @@ impl<'a, O:DataFlowOperator> PropagationContext<'a, O> {
715715
}
716716

717717
fn walk_call(&mut self,
718-
_callee_id: ast::NodeId,
719718
call_id: ast::NodeId,
720719
args: &[@ast::Expr],
721720
in_out: &mut [uint],
722721
loop_scopes: &mut ~[LoopScope]) {
723722
self.walk_exprs(args, in_out, loop_scopes);
724723

725724
// FIXME(#6268) nested method calls
726-
// self.merge_with_entry_set(callee_id, in_out);
727-
// self.dfcx.apply_gen_kill(callee_id, in_out);
725+
// self.merge_with_entry_set(in_out);
726+
// self.dfcx.apply_gen_kill(in_out);
728727

729728
let return_ty = ty::node_id_to_type(self.tcx(), call_id);
730729
let fails = ty::type_is_bot(return_ty);

0 commit comments

Comments
 (0)