Skip to content

Commit b90d7d4

Browse files
committed
rustc: Refactor vtable lookup to use a vtable context, so that it can be called outside a function. rs=refactor
1 parent 9e0c596 commit b90d7d4

File tree

3 files changed

+101
-62
lines changed

3 files changed

+101
-62
lines changed

src/rustc/middle/typeck/check.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ use typeck::infer::{resolve_type, force_tvar};
7878
use result::{Result, Ok, Err};
7979
use syntax::print::pprust;
8080
use syntax::parse::token::special_idents;
81-
use vtable::LocationInfo;
81+
use vtable::{LocationInfo, VtableContext};
8282

8383
use std::map::HashMap;
8484

@@ -865,20 +865,20 @@ fn check_expr(fcx: @fn_ctxt, expr: @ast::expr,
865865
// declared on the impl declaration e.g., `impl<A,B> for ~[(A,B)]`
866866
// would return ($0, $1) where $0 and $1 are freshly instantiated type
867867
// variables.
868-
fn impl_self_ty(fcx: @fn_ctxt,
868+
fn impl_self_ty(vcx: &VtableContext,
869869
location_info: &LocationInfo, // (potential) receiver for
870870
// this impl
871871
did: ast::def_id) -> ty_param_substs_and_ty {
872-
let tcx = fcx.ccx.tcx;
872+
let tcx = vcx.tcx();
873873

874874
let {n_tps, region_param, raw_ty} = if did.crate == ast::local_crate {
875-
let region_param = fcx.tcx().region_paramd_items.find(did.node);
875+
let region_param = tcx.region_paramd_items.find(did.node);
876876
match tcx.items.find(did.node) {
877877
Some(ast_map::node_item(@{node: ast::item_impl(ts, _, st, _),
878878
_}, _)) => {
879879
{n_tps: ts.len(),
880880
region_param: region_param,
881-
raw_ty: fcx.ccx.to_ty(rscope::type_rscope(region_param), st)}
881+
raw_ty: vcx.ccx.to_ty(rscope::type_rscope(region_param), st)}
882882
}
883883
Some(ast_map::node_item(@{node: ast::item_class(_, ts),
884884
id: class_id, _},_)) => {
@@ -904,12 +904,12 @@ fn impl_self_ty(fcx: @fn_ctxt,
904904
};
905905

906906
let self_r = if region_param.is_some() {
907-
Some(fcx.infcx().next_region_var(location_info.span,
907+
Some(vcx.infcx.next_region_var(location_info.span,
908908
location_info.id))
909909
} else {
910910
None
911911
};
912-
let tps = fcx.infcx().next_ty_vars(n_tps);
912+
let tps = vcx.infcx.next_ty_vars(n_tps);
913913

914914
let substs = {self_r: self_r, self_ty: None, tps: tps};
915915
let substd_ty = ty::subst(tcx, &substs, raw_ty);

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,8 +492,12 @@ impl LookupContext {
492492
// determine the `self` of the impl with fresh
493493
// variables for each parameter:
494494
let location_info = &vtable::location_info_for_expr(self.self_expr);
495+
let vcx = VtableContext {
496+
ccx: self.fcx.ccx,
497+
infcx: self.fcx.infcx()
498+
};
495499
let {substs: impl_substs, ty: impl_ty} =
496-
impl_self_ty(self.fcx, location_info, impl_info.did);
500+
impl_self_ty(&vcx, location_info, impl_info.did);
497501

498502
let (impl_ty, impl_substs) =
499503
self.create_rcvr_ty_and_substs_for_method(

0 commit comments

Comments
 (0)