Skip to content

Commit 05a2d32

Browse files
committed
auto merge of #12571 : eddyb/rust/kill-callee-id, r=nikomatsakis
Every method call and overloaded operator had a `callee_id` that was be used to store the method type and type substitutions, that information is now stored in the `method_map`, alongside the method's origin.
2 parents 6c41f99 + 05e4d94 commit 05a2d32

Some content is hidden

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

47 files changed

+593
-669
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: 70 additions & 37 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;
@@ -50,7 +50,7 @@ use writer = serialize::ebml::writer;
5050
// Auxiliary maps of things to be encoded
5151
pub struct Maps {
5252
root_map: middle::borrowck::root_map,
53-
method_map: middle::typeck::method_map,
53+
method_map: middle::typeck::MethodMap,
5454
vtable_map: middle::typeck::vtable_map,
5555
capture_map: middle::moves::CaptureMap,
5656
}
@@ -574,30 +574,68 @@ 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 {
582-
typeck::method_static(did) => {
583-
typeck::method_static(did.tr(xcx))
584-
}
585-
typeck::method_param(ref mp) => {
586-
typeck::method_param(
587-
typeck::method_param {
588-
trait_id: mp.trait_id.tr(xcx),
589-
.. *mp
590-
}
591-
)
592-
}
593-
typeck::method_object(ref mo) => {
594-
typeck::method_object(
595-
typeck::method_object {
596-
trait_id: mo.trait_id.tr(xcx),
597-
.. *mo
598-
}
599-
)
600-
}
622+
typeck::MethodStatic(did) => typeck::MethodStatic(did.tr(xcx)),
623+
typeck::MethodParam(ref mp) => {
624+
typeck::MethodParam(
625+
typeck::MethodParam {
626+
trait_id: mp.trait_id.tr(xcx),
627+
.. *mp
628+
}
629+
)
630+
}
631+
typeck::MethodObject(ref mo) => {
632+
typeck::MethodObject(
633+
typeck::MethodObject {
634+
trait_id: mo.trait_id.tr(xcx),
635+
.. *mo
636+
}
637+
)
638+
}
601639
}
602640
}
603641
}
@@ -993,17 +1031,13 @@ fn encode_side_tables_for_id(ecx: &e::EncodeContext,
9931031
}
9941032
}
9951033

996-
{
997-
let method_map = maps.method_map.borrow();
998-
let r = method_map.get().find(&id);
999-
for &origin in r.iter() {
1000-
ebml_w.tag(c::tag_table_method_map, |ebml_w| {
1001-
ebml_w.id(id);
1002-
ebml_w.tag(c::tag_table_val, |ebml_w| {
1003-
origin.encode(ebml_w);
1004-
})
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)
10051039
})
1006-
}
1040+
})
10071041
}
10081042

10091043
{
@@ -1337,9 +1371,8 @@ fn decode_side_tables(xcx: @ExtendedDecodeContext,
13371371
ty_param_defs.get().insert(id, bounds);
13381372
}
13391373
c::tag_table_method_map => {
1340-
let origin: method_origin = Decodable::decode(val_dsr);
1341-
let mut method_map = dcx.maps.method_map.borrow_mut();
1342-
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);
13431376
}
13441377
c::tag_table_vtable_map => {
13451378
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/borrowck/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ impl Visitor<()> for BorrowckCtxt {
7070
}
7171

7272
pub fn check_crate(tcx: ty::ctxt,
73-
method_map: typeck::method_map,
73+
method_map: typeck::MethodMap,
7474
moves_map: moves::MovesMap,
7575
moved_variables_set: moves::MovedVariablesSet,
7676
capture_map: moves::CaptureMap,
@@ -156,7 +156,7 @@ fn borrowck_fn(this: &mut BorrowckCtxt,
156156

157157
pub struct BorrowckCtxt {
158158
tcx: ty::ctxt,
159-
method_map: typeck::method_map,
159+
method_map: typeck::MethodMap,
160160
moves_map: moves::MovesMap,
161161
moved_variables_set: moves::MovedVariablesSet,
162162
capture_map: moves::CaptureMap,
@@ -909,7 +909,7 @@ impl Repr for LoanPath {
909909

910910
struct TcxTyper {
911911
tcx: ty::ctxt,
912-
method_map: typeck::method_map,
912+
method_map: typeck::MethodMap,
913913
}
914914

915915
impl mc::Typer for TcxTyper {

src/librustc/middle/borrowck/move_data.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ impl MoveData {
565565
impl FlowedMoveData {
566566
pub fn new(move_data: MoveData,
567567
tcx: ty::ctxt,
568-
method_map: typeck::method_map,
568+
method_map: typeck::MethodMap,
569569
id_range: ast_util::IdRange,
570570
body: &ast::Block)
571571
-> FlowedMoveData {

src/librustc/middle/cfg/construct.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use syntax::opt_vec;
1919

2020
struct CFGBuilder {
2121
tcx: ty::ctxt,
22-
method_map: typeck::method_map,
22+
method_map: typeck::MethodMap,
2323
exit_map: HashMap<ast::NodeId, CFGIndex>,
2424
graph: CFGGraph,
2525
loop_scopes: ~[LoopScope],
@@ -32,7 +32,7 @@ struct LoopScope {
3232
}
3333

3434
pub fn construct(tcx: ty::ctxt,
35-
method_map: typeck::method_map,
35+
method_map: typeck::MethodMap,
3636
blk: &ast::Block) -> CFG {
3737
let mut cfg_builder = CFGBuilder {
3838
exit_map: HashMap::new(),
@@ -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/cfg/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ pub struct CFGIndices {
5454

5555
impl CFG {
5656
pub fn new(tcx: ty::ctxt,
57-
method_map: typeck::method_map,
57+
method_map: typeck::MethodMap,
5858
blk: &ast::Block) -> CFG {
5959
construct::construct(tcx, method_map, blk)
6060
}

src/librustc/middle/check_const.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use syntax::visit;
2323
struct CheckCrateVisitor {
2424
sess: Session,
2525
def_map: resolve::DefMap,
26-
method_map: typeck::method_map,
26+
method_map: typeck::MethodMap,
2727
tcx: ty::ctxt,
2828
}
2929

@@ -43,7 +43,7 @@ impl Visitor<bool> for CheckCrateVisitor {
4343
pub fn check_crate(sess: Session,
4444
krate: &Crate,
4545
def_map: resolve::DefMap,
46-
method_map: typeck::method_map,
46+
method_map: typeck::MethodMap,
4747
tcx: ty::ctxt) {
4848
let mut v = CheckCrateVisitor {
4949
sess: sess,
@@ -102,14 +102,14 @@ pub fn check_pat(v: &mut CheckCrateVisitor, p: &Pat, _is_const: bool) {
102102
pub fn check_expr(v: &mut CheckCrateVisitor,
103103
sess: Session,
104104
def_map: resolve::DefMap,
105-
method_map: typeck::method_map,
105+
method_map: typeck::MethodMap,
106106
tcx: ty::ctxt,
107107
e: &Expr,
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;

0 commit comments

Comments
 (0)