Skip to content

Commit 09253e2

Browse files
committed
rustc_resolve: use the visitor model more, remove redundant repeated lookups.
1 parent b3f9a27 commit 09253e2

26 files changed

+331
-719
lines changed

src/librustc/middle/astconv_util.rs

Lines changed: 22 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -35,55 +35,36 @@ pub fn check_path_args(tcx: &ty::ctxt,
3535
if (flags & NO_REGIONS) != 0 {
3636
if path.segments.iter().any(|s| s.parameters.has_lifetimes()) {
3737
span_err!(tcx.sess, path.span, E0110,
38-
"region parameters are not allowed on this type");
38+
"lifetime parameters are not allowed on this type");
3939
}
4040
}
4141
}
4242

4343
pub fn ast_ty_to_prim_ty<'tcx>(tcx: &ty::ctxt<'tcx>, ast_ty: &ast::Ty)
4444
-> Option<Ty<'tcx>> {
45-
match ast_ty.node {
46-
ast::TyPath(ref path) => {
47-
let a_def = match tcx.def_map.borrow().get(&ast_ty.id) {
48-
None => {
49-
tcx.sess.span_bug(ast_ty.span,
50-
&format!("unbound path {}",
51-
path.repr(tcx))[])
52-
}
53-
Some(&d) => d
54-
};
55-
match a_def {
56-
def::DefPrimTy(nty) => {
57-
match nty {
58-
ast::TyBool => {
59-
check_path_args(tcx, path, NO_TPS | NO_REGIONS);
60-
Some(tcx.types.bool)
61-
}
62-
ast::TyChar => {
63-
check_path_args(tcx, path, NO_TPS | NO_REGIONS);
64-
Some(tcx.types.char)
65-
}
66-
ast::TyInt(it) => {
67-
check_path_args(tcx, path, NO_TPS | NO_REGIONS);
68-
Some(ty::mk_mach_int(tcx, it))
69-
}
70-
ast::TyUint(uit) => {
71-
check_path_args(tcx, path, NO_TPS | NO_REGIONS);
72-
Some(ty::mk_mach_uint(tcx, uit))
73-
}
74-
ast::TyFloat(ft) => {
75-
check_path_args(tcx, path, NO_TPS | NO_REGIONS);
76-
Some(ty::mk_mach_float(tcx, ft))
77-
}
78-
ast::TyStr => {
79-
Some(ty::mk_str(tcx))
80-
}
81-
}
82-
}
83-
_ => None
45+
if let ast::TyPath(ref path) = ast_ty.node {
46+
let def = match tcx.def_map.borrow().get(&ast_ty.id) {
47+
None => {
48+
tcx.sess.span_bug(ast_ty.span,
49+
&format!("unbound path {}", path.repr(tcx))[])
8450
}
51+
Some(&d) => d
52+
};
53+
if let def::DefPrimTy(nty) = def {
54+
check_path_args(tcx, path, NO_TPS | NO_REGIONS);
55+
Some(match nty {
56+
ast::TyBool => tcx.types.bool,
57+
ast::TyChar => tcx.types.char,
58+
ast::TyInt(it) => ty::mk_mach_int(tcx, it),
59+
ast::TyUint(uit) => ty::mk_mach_uint(tcx, uit),
60+
ast::TyFloat(ft) => ty::mk_mach_float(tcx, ft),
61+
ast::TyStr => ty::mk_str(tcx)
62+
})
63+
} else {
64+
None
8565
}
86-
_ => None
66+
} else {
67+
None
8768
}
8869
}
8970

src/librustc/middle/astencode.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -454,9 +454,6 @@ impl tr for def::Def {
454454
}
455455
def::DefStruct(did) => def::DefStruct(did.tr(dcx)),
456456
def::DefRegion(nid) => def::DefRegion(dcx.tr_id(nid)),
457-
def::DefTyParamBinder(nid) => {
458-
def::DefTyParamBinder(dcx.tr_id(nid))
459-
}
460457
def::DefLabel(nid) => def::DefLabel(dcx.tr_id(nid))
461458
}
462459
}

src/librustc/middle/def.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ pub enum Def {
5454
/// - If it's an ExprPath referring to some tuple struct, then DefMap maps
5555
/// it to a def whose id is the StructDef.ctor_id.
5656
DefStruct(ast::DefId),
57-
DefTyParamBinder(ast::NodeId), /* struct, impl or trait with ty params */
5857
DefRegion(ast::NodeId),
5958
DefLabel(ast::NodeId),
6059
DefMethod(ast::DefId /* method */, Option<ast::DefId> /* trait */, MethodProvenance),
@@ -145,7 +144,6 @@ impl Def {
145144
DefSelfTy(id) |
146145
DefUpvar(id, _) |
147146
DefRegion(id) |
148-
DefTyParamBinder(id) |
149147
DefLabel(id) => {
150148
local_def(id)
151149
}

src/librustc/middle/mem_categorization.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,7 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
580580
}
581581
def::DefMod(_) | def::DefForeignMod(_) | def::DefUse(_) |
582582
def::DefTrait(_) | def::DefTy(..) | def::DefPrimTy(_) |
583-
def::DefTyParam(..) | def::DefTyParamBinder(..) | def::DefRegion(_) |
583+
def::DefTyParam(..) | def::DefRegion(_) |
584584
def::DefLabel(_) | def::DefSelfTy(..) |
585585
def::DefAssociatedTy(..) | def::DefAssociatedPath(..)=> {
586586
Ok(Rc::new(cmt_ {

src/librustc_resolve/build_reduced_graph.rs

Lines changed: 11 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,15 @@ use Namespace::{TypeNS, ValueNS};
2323
use NameBindings;
2424
use ParentLink::{self, ModuleParentLink, BlockParentLink};
2525
use Resolver;
26-
use RibKind::*;
2726
use Shadowable;
2827
use TypeNsDef;
29-
use TypeParameters::HasTypeParameters;
3028

3129
use self::DuplicateCheckingMode::*;
3230
use self::NamespaceError::*;
3331

3432
use rustc::metadata::csearch;
3533
use rustc::metadata::decoder::{DefLike, DlDef, DlField, DlImpl};
3634
use rustc::middle::def::*;
37-
use rustc::middle::subst::FnSpace;
3835

3936
use syntax::ast::{Block, Crate};
4037
use syntax::ast::{DeclItem, DefId};
@@ -772,38 +769,25 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
772769
}
773770

774771
/// Constructs the reduced graph for one foreign item.
775-
fn build_reduced_graph_for_foreign_item<F>(&mut self,
776-
foreign_item: &ForeignItem,
777-
parent: &Rc<Module>,
778-
f: F) where
779-
F: FnOnce(&mut Resolver),
780-
{
772+
fn build_reduced_graph_for_foreign_item(&mut self,
773+
foreign_item: &ForeignItem,
774+
parent: &Rc<Module>) {
781775
let name = foreign_item.ident.name;
782776
let is_public = foreign_item.vis == ast::Public;
783777
let modifiers = if is_public { PUBLIC } else { DefModifiers::empty() } | IMPORTABLE;
784778
let name_bindings =
785779
self.add_child(name, parent, ForbidDuplicateValues,
786780
foreign_item.span);
787781

788-
match foreign_item.node {
789-
ForeignItemFn(_, ref generics) => {
790-
let def = DefFn(local_def(foreign_item.id), false);
791-
name_bindings.define_value(def, foreign_item.span, modifiers);
792-
793-
self.with_type_parameter_rib(
794-
HasTypeParameters(generics,
795-
FnSpace,
796-
foreign_item.id,
797-
NormalRibKind),
798-
f);
782+
let def = match foreign_item.node {
783+
ForeignItemFn(..) => {
784+
DefFn(local_def(foreign_item.id), false)
799785
}
800786
ForeignItemStatic(_, m) => {
801-
let def = DefStatic(local_def(foreign_item.id), m);
802-
name_bindings.define_value(def, foreign_item.span, modifiers);
803-
804-
f(self.resolver)
787+
DefStatic(local_def(foreign_item.id), m)
805788
}
806-
}
789+
};
790+
name_bindings.define_value(def, foreign_item.span, modifiers);
807791
}
808792

809793
fn build_reduced_graph_for_block(&mut self, block: &Block, parent: &Rc<Module>) -> Rc<Module> {
@@ -979,7 +963,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
979963
}
980964
DefLocal(..) | DefPrimTy(..) | DefTyParam(..) |
981965
DefUse(..) | DefUpvar(..) | DefRegion(..) |
982-
DefTyParamBinder(..) | DefLabel(..) | DefSelfTy(..) => {
966+
DefLabel(..) | DefSelfTy(..) => {
983967
panic!("didn't expect `{:?}`", def);
984968
}
985969
}
@@ -1240,16 +1224,7 @@ impl<'a, 'b, 'v, 'tcx> Visitor<'v> for BuildReducedGraphVisitor<'a, 'b, 'tcx> {
12401224
}
12411225

12421226
fn visit_foreign_item(&mut self, foreign_item: &ForeignItem) {
1243-
let parent = &self.parent;
1244-
self.builder.build_reduced_graph_for_foreign_item(foreign_item,
1245-
parent,
1246-
|r| {
1247-
let mut v = BuildReducedGraphVisitor {
1248-
builder: GraphBuilder { resolver: r },
1249-
parent: parent.clone()
1250-
};
1251-
visit::walk_foreign_item(&mut v, foreign_item);
1252-
})
1227+
self.builder.build_reduced_graph_for_foreign_item(foreign_item, &self.parent);
12531228
}
12541229

12551230
fn visit_block(&mut self, block: &Block) {

0 commit comments

Comments
 (0)