Skip to content

Commit 0a0525e

Browse files
committed
Pass around a pointer to the ty::method rather than the individual bits of info
1 parent 5695965 commit 0a0525e

File tree

5 files changed

+65
-67
lines changed

5 files changed

+65
-67
lines changed

src/librustc/middle/trans/callee.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,7 @@ pub fn trans_fn_ref_with_vtables(
238238

239239
// Modify the def_id if this is a default method; we want to be
240240
// monomorphizing the trait's code.
241-
let (def_id, opt_impl_did) =
242-
match tcx.provided_method_sources.find(&def_id) {
241+
let (def_id, opt_impl_did) = match tcx.provided_method_sources.find(&def_id) {
243242
None => (def_id, None),
244243
Some(source) => (source.method_id, Some(source.impl_id))
245244
};

src/librustc/middle/trans/meth.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,8 @@ pub fn method_with_name(ccx: @CrateContext, impl_id: ast::def_id,
376376
}
377377
}
378378
379-
pub fn method_with_name_or_default(ccx: @CrateContext, impl_id: ast::def_id,
379+
pub fn method_with_name_or_default(ccx: @CrateContext,
380+
impl_id: ast::def_id,
380381
name: ast::ident) -> ast::def_id {
381382
if impl_id.crate == ast::local_crate {
382383
match *ccx.tcx.items.get(&impl_id.node) {

src/librustc/middle/typeck/check/method.rs

Lines changed: 53 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -176,13 +176,7 @@ pub struct LookupContext<'self> {
176176
pub struct Candidate {
177177
rcvr_ty: ty::t,
178178
rcvr_substs: ty::substs,
179-
explicit_self: ast::self_ty_,
180-
181-
// FIXME #3446---these two fields should be easily derived from
182-
// origin, yet are not
183-
num_method_tps: uint,
184-
self_mode: ast::rmode,
185-
179+
method_ty: @ty::method,
186180
origin: method_origin,
187181
}
188182

@@ -474,7 +468,7 @@ pub impl<'self> LookupContext<'self> {
474468
}
475469
}
476470
};
477-
let method = &trait_methods[pos];
471+
let method = trait_methods[pos];
478472

479473
let (rcvr_ty, rcvr_substs) =
480474
self.create_rcvr_ty_and_substs_for_method(
@@ -486,9 +480,7 @@ pub impl<'self> LookupContext<'self> {
486480
let cand = Candidate {
487481
rcvr_ty: rcvr_ty,
488482
rcvr_substs: rcvr_substs,
489-
explicit_self: method.self_ty,
490-
num_method_tps: method.tps.len(),
491-
self_mode: get_mode_from_self_type(method.self_ty),
483+
method_ty: method,
492484
origin: method_param(
493485
method_param {
494486
trait_id: init_trait_id,
@@ -520,7 +512,7 @@ pub impl<'self> LookupContext<'self> {
520512
Some(i) => i,
521513
None => { return; } // no method with the right name
522514
};
523-
let method = &ms[index];
515+
let method = ms[index];
524516

525517
/* FIXME(#3157) we should transform the vstore in accordance
526518
with the self type
@@ -554,9 +546,7 @@ pub impl<'self> LookupContext<'self> {
554546
self.inherent_candidates.push(Candidate {
555547
rcvr_ty: rcvr_ty,
556548
rcvr_substs: rcvr_substs,
557-
explicit_self: method.self_ty,
558-
num_method_tps: method.tps.len(),
559-
self_mode: get_mode_from_self_type(method.self_ty),
549+
method_ty: method,
560550
origin: method_trait(did, index, store)
561551
});
562552
}
@@ -565,63 +555,65 @@ pub impl<'self> LookupContext<'self> {
565555
self_ty: ty::t,
566556
did: def_id,
567557
substs: &ty::substs) {
558+
struct MethodInfo {
559+
method_ty: @ty::method,
560+
trait_def_id: ast::def_id,
561+
index: uint
562+
}
563+
568564
let tcx = self.tcx();
569565
// First, try self methods
570-
let mut method = None;
566+
let mut method_info: Option<MethodInfo> = None;
571567
let methods = ty::trait_methods(tcx, did);
572-
let mut index = None;
573-
let mut trait_did = None;
574568
match vec::position(*methods, |m| m.ident == self.m_name) {
575569
Some(i) => {
576-
index = Some(i);
577-
trait_did = Some(did);
578-
method = Some((methods[i].self_ty, methods[i].tps.len()));
570+
method_info = Some(MethodInfo {
571+
method_ty: methods[i],
572+
index: i,
573+
trait_def_id: did
574+
});
579575
}
580576
None => ()
581577
}
582578
// No method found yet? Check each supertrait
583-
if method.is_none() {
579+
if method_info.is_none() {
584580
for ty::trait_supertraits(tcx, did).each() |trait_ref| {
585581
let supertrait_methods =
586582
ty::trait_methods(tcx, trait_ref.def_id);
587583
match vec::position(*supertrait_methods,
588584
|m| m.ident == self.m_name) {
589585
Some(i) => {
590-
index = Some(i);
591-
trait_did = Some(trait_ref.def_id);
592-
method = Some((supertrait_methods[i].self_ty,
593-
supertrait_methods[i].tps.len()));
586+
method_info = Some(MethodInfo {
587+
method_ty: supertrait_methods[i],
588+
index: i,
589+
trait_def_id: trait_ref.def_id
590+
});
594591
break;
595592
}
596593
None => ()
597594
}
598595
}
599596
}
600-
match (method, index, trait_did) {
601-
(Some((method_self_ty, method_num_tps)),
602-
Some(index), Some(trait_did)) => {
603-
597+
match method_info {
598+
Some(ref info) => {
604599
// We've found a method -- return it
605-
let rcvr_substs = substs { self_ty: Some(self_ty),
600+
let rcvr_substs = substs {self_ty: Some(self_ty),
606601
..copy *substs };
607602
let (rcvr_ty, rcvr_substs) =
608603
self.create_rcvr_ty_and_substs_for_method(
609-
method_self_ty,
604+
info.method_ty.self_ty,
610605
self_ty,
611606
rcvr_substs,
612607
TransformTypeNormally);
613-
let origin = if trait_did == did {
614-
method_self(trait_did, index)
615-
}
616-
else {
617-
method_super(trait_did, index)
608+
let origin = if did == info.trait_def_id {
609+
method_self(info.trait_def_id, info.index)
610+
} else {
611+
method_super(info.trait_def_id, info.index)
618612
};
619613
self.inherent_candidates.push(Candidate {
620614
rcvr_ty: rcvr_ty,
621615
rcvr_substs: rcvr_substs,
622-
explicit_self: method_self_ty,
623-
num_method_tps: method_num_tps,
624-
self_mode: get_mode_from_self_type(method_self_ty),
616+
method_ty: info.method_ty,
625617
origin: origin
626618
});
627619
}
@@ -653,7 +645,7 @@ pub impl<'self> LookupContext<'self> {
653645
}
654646
};
655647

656-
let method = &impl_info.methods[idx];
648+
let method = ty::method(self.tcx(), impl_info.methods[idx].did);
657649

658650
// determine the `self` of the impl with fresh
659651
// variables for each parameter:
@@ -669,18 +661,16 @@ pub impl<'self> LookupContext<'self> {
669661

670662
let (impl_ty, impl_substs) =
671663
self.create_rcvr_ty_and_substs_for_method(
672-
method.self_type,
664+
method.self_ty,
673665
impl_ty,
674666
impl_substs,
675667
TransformTypeNormally);
676668

677669
candidates.push(Candidate {
678670
rcvr_ty: impl_ty,
679671
rcvr_substs: impl_substs,
680-
explicit_self: method.self_type,
681-
num_method_tps: method.n_tps,
682-
self_mode: get_mode_from_self_type(method.self_type),
683-
origin: method_static(method.did)
672+
method_ty: method,
673+
origin: method_static(method.def_id)
684674
});
685675
}
686676

@@ -701,6 +691,9 @@ pub impl<'self> LookupContext<'self> {
701691
debug!("(pushing candidates from provided methods) adding \
702692
candidate");
703693

694+
let method = ty::method(self.tcx(),
695+
provided_method_info.method_info.did);
696+
704697
// XXX: Needs to support generics.
705698
let dummy_substs = substs {
706699
self_r: None,
@@ -709,18 +702,15 @@ pub impl<'self> LookupContext<'self> {
709702
};
710703
let (impl_ty, impl_substs) =
711704
self.create_rcvr_ty_and_substs_for_method(
712-
provided_method_info.method_info.self_type,
705+
method.self_ty,
713706
self_ty,
714707
dummy_substs,
715708
TransformTypeNormally);
716709

717710
candidates.push(Candidate {
718711
rcvr_ty: impl_ty,
719712
rcvr_substs: impl_substs,
720-
explicit_self: provided_method_info.method_info.self_type,
721-
num_method_tps: provided_method_info.method_info.n_tps,
722-
self_mode: get_mode_from_self_type(
723-
provided_method_info.method_info.self_type),
713+
method_ty: method,
724714
origin: method_static(provided_method_info.method_info.did)
725715
});
726716
}
@@ -1126,20 +1116,21 @@ pub impl<'self> LookupContext<'self> {
11261116
// If they were not explicitly supplied, just construct fresh
11271117
// type variables.
11281118
let num_supplied_tps = self.supplied_tps.len();
1119+
let num_method_tps = candidate.method_ty.tps.len();
11291120
let m_substs = {
11301121
if num_supplied_tps == 0u {
1131-
self.fcx.infcx().next_ty_vars(candidate.num_method_tps)
1132-
} else if candidate.num_method_tps == 0u {
1122+
self.fcx.infcx().next_ty_vars(num_method_tps)
1123+
} else if num_method_tps == 0u {
11331124
tcx.sess.span_err(
11341125
self.expr.span,
11351126
~"this method does not take type parameters");
1136-
self.fcx.infcx().next_ty_vars(candidate.num_method_tps)
1137-
} else if num_supplied_tps != candidate.num_method_tps {
1127+
self.fcx.infcx().next_ty_vars(num_method_tps)
1128+
} else if num_supplied_tps != num_method_tps {
11381129
tcx.sess.span_err(
11391130
self.expr.span,
11401131
~"incorrect number of type \
11411132
parameters given for this method");
1142-
self.fcx.infcx().next_ty_vars(candidate.num_method_tps)
1133+
self.fcx.infcx().next_ty_vars(num_method_tps)
11431134
} else {
11441135
self.supplied_tps.to_vec()
11451136
}
@@ -1178,14 +1169,16 @@ pub impl<'self> LookupContext<'self> {
11781169
let fty = ty::mk_bare_fn(tcx, ty::BareFnTy {sig: fn_sig, ..bare_fn_ty});
11791170
debug!("after replacing bound regions, fty=%s", self.ty_to_str(fty));
11801171

1172+
let self_mode = get_mode_from_self_type(candidate.method_ty.self_ty);
1173+
11811174
self.fcx.write_ty(self.callee_id, fty);
11821175
self.fcx.write_substs(self.callee_id, all_substs);
11831176
method_map_entry {
11841177
self_arg: arg {
1185-
mode: ast::expl(candidate.self_mode),
1178+
mode: ast::expl(self_mode),
11861179
ty: candidate.rcvr_ty,
11871180
},
1188-
explicit_self: candidate.explicit_self,
1181+
explicit_self: candidate.method_ty.self_ty,
11891182
origin: candidate.origin,
11901183
}
11911184
}
@@ -1217,7 +1210,7 @@ pub impl<'self> LookupContext<'self> {
12171210
self-type through a boxed trait");
12181211
}
12191212

1220-
if candidate.num_method_tps > 0 {
1213+
if candidate.method_ty.tps.len() > 0 {
12211214
self.tcx().sess.span_err(
12221215
self.expr.span,
12231216
~"cannot call a generic method through a boxed trait");
@@ -1334,10 +1327,9 @@ pub impl<'self> LookupContext<'self> {
13341327
}
13351328

13361329
fn cand_to_str(&self, cand: &Candidate) -> ~str {
1337-
fmt!("Candidate(rcvr_ty=%s, rcvr_substs=%s, self_mode=%?, origin=%?)",
1330+
fmt!("Candidate(rcvr_ty=%s, rcvr_substs=%s, origin=%?)",
13381331
self.ty_to_str(cand.rcvr_ty),
13391332
ty::substs_to_str(self.tcx(), &cand.rcvr_substs),
1340-
cand.self_mode,
13411333
cand.origin)
13421334
}
13431335

src/librustc/middle/typeck/check/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2125,7 +2125,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
21252125
match expr.node {
21262126
ast::expr_vstore(ev, vst) => {
21272127
let typ = match ev.node {
2128-
ast::expr_lit(@codemap::spanned { node: ast::lit_str(s), _ }) => {
2128+
ast::expr_lit(@codemap::spanned { node: ast::lit_str(_), _ }) => {
21292129
let tt = ast_expr_vstore_to_vstore(fcx, ev, vst);
21302130
ty::mk_estr(tcx, tt)
21312131
}
@@ -2162,7 +2162,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
21622162
}
21632163
}
21642164
ast::expr_repeat(element, count_expr, mutbl) => {
2165-
let count = ty::eval_repeat_count(tcx, count_expr);
2165+
let _ = ty::eval_repeat_count(tcx, count_expr);
21662166
check_expr_with_hint(fcx, count_expr, ty::mk_uint(tcx));
21672167
let tt = ast_expr_vstore_to_vstore(fcx, ev, vst);
21682168
let mutability = match vst {

src/librustc/middle/typeck/coherence.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,10 +333,16 @@ pub impl CoherenceChecker {
333333
let new_id = parse::next_node_id(tcx.sess.parse_sess);
334334
let new_did = local_def(new_id);
335335
336+
let new_method_ty = @ty::method {
337+
def_id: new_did,
338+
..copy *trait_method
339+
};
340+
336341
// XXX: Perform substitutions.
337342
let new_polytype = ty::lookup_item_type(tcx,
338343
trait_method.def_id);
339344
tcx.tcache.insert(new_did, new_polytype);
345+
tcx.methods.insert(new_did, new_method_ty);
340346
341347
// Pair the new synthesized ID up with the
342348
// ID of the method.
@@ -498,7 +504,7 @@ pub impl CoherenceChecker {
498504

499505
fn each_provided_trait_method(&self,
500506
trait_did: ast::def_id,
501-
f: &fn(x: &ty::method) -> bool) {
507+
f: &fn(x: @ty::method) -> bool) {
502508
// Make a list of all the names of the provided methods.
503509
// XXX: This is horrible.
504510
let mut provided_method_idents = HashSet::new();

0 commit comments

Comments
 (0)