Skip to content

Commit 43e0266

Browse files
committed
Store partial resolution and full resolution separately
1 parent 1c11ea3 commit 43e0266

File tree

16 files changed

+80
-46
lines changed

16 files changed

+80
-46
lines changed

src/librustc/hir/def.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ impl PathResolution {
101101
}
102102

103103
// Definition mapping
104-
pub type DefMap = NodeMap<PathResolution>;
104+
pub type DefMap = NodeMap<Def>;
105+
pub type AssocMap = NodeMap<PathResolution>;
105106
// This is the replacement export map. It maps a module to all of the exports
106107
// within.
107108
pub type ExportMap = NodeMap<Vec<Export>>;

src/librustc/hir/lowering.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ use hir;
4444
use hir::map::Definitions;
4545
use hir::map::definitions::DefPathData;
4646
use hir::def_id::{DefIndex, DefId};
47-
use hir::def::{Def, PathResolution};
47+
use hir::def::Def;
4848
use session::Session;
4949

5050
use std::collections::BTreeMap;
@@ -74,7 +74,7 @@ pub trait Resolver {
7474
fn resolve_generated_global_path(&mut self, path: &hir::Path, is_value: bool) -> Def;
7575

7676
// Obtain the resolution for a node id
77-
fn get_resolution(&mut self, id: NodeId) -> Option<PathResolution>;
77+
fn get_resolution(&mut self, id: NodeId) -> Option<Def>;
7878

7979
// Record the resolution of a path or binding generated by the lowerer when expanding.
8080
fn record_resolution(&mut self, id: NodeId, def: Def);
@@ -873,7 +873,7 @@ impl<'a> LoweringContext<'a> {
873873
PatKind::Wild => hir::PatKind::Wild,
874874
PatKind::Ident(ref binding_mode, pth1, ref sub) => {
875875
self.with_parent_def(p.id, |this| {
876-
match this.resolver.get_resolution(p.id).map(|d| d.base_def) {
876+
match this.resolver.get_resolution(p.id) {
877877
// `None` can occur in body-less function signatures
878878
None | Some(Def::Local(..)) => {
879879
hir::PatKind::Binding(this.lower_binding_mode(binding_mode),

src/librustc/hir/pat_util.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ pub fn pat_is_refutable(dm: &DefMap, pat: &hir::Pat) -> bool {
5757
PatKind::TupleStruct(..) |
5858
PatKind::Path(..) |
5959
PatKind::Struct(..) => {
60-
match dm.get(&pat.id).map(|d| d.full_def()) {
60+
match dm.get(&pat.id).cloned() {
6161
Some(Def::Variant(..)) | Some(Def::VariantCtor(..)) => true,
6262
_ => false
6363
}
@@ -70,7 +70,7 @@ pub fn pat_is_refutable(dm: &DefMap, pat: &hir::Pat) -> bool {
7070
pub fn pat_is_const(dm: &DefMap, pat: &hir::Pat) -> bool {
7171
match pat.node {
7272
PatKind::Path(..) => {
73-
match dm.get(&pat.id).map(|d| d.full_def()) {
73+
match dm.get(&pat.id).cloned() {
7474
Some(Def::Const(..)) | Some(Def::AssociatedConst(..)) => true,
7575
_ => false
7676
}
@@ -173,7 +173,7 @@ pub fn necessary_variants(dm: &DefMap, pat: &hir::Pat) -> Vec<DefId> {
173173
PatKind::TupleStruct(..) |
174174
PatKind::Path(..) |
175175
PatKind::Struct(..) => {
176-
match dm.get(&p.id).map(|d| d.full_def()) {
176+
match dm.get(&p.id).cloned() {
177177
Some(Def::Variant(id)) |
178178
Some(Def::VariantCtor(id, ..)) => variants.push(id),
179179
_ => ()

src/librustc/middle/resolve_lifetime.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,8 +247,8 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
247247
hir::TyPath(None, ref path) => {
248248
// if this path references a trait, then this will resolve to
249249
// a trait ref, which introduces a binding scope.
250-
match self.def_map.get(&ty.id).map(|d| (d.base_def, d.depth)) {
251-
Some((Def::Trait(..), 0)) => {
250+
match self.def_map.get(&ty.id).cloned() {
251+
Some(Def::Trait(..)) => {
252252
self.with(LateScope(&[], self.scope), |_, this| {
253253
this.visit_path(path, ty.id);
254254
});

src/librustc/ty/context.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use dep_graph::{DepGraph, DepTrackingMap};
1414
use session::Session;
1515
use middle;
1616
use hir::TraitMap;
17-
use hir::def::DefMap;
17+
use hir::def::{AssocMap, DefMap};
1818
use hir::def_id::{CrateNum, DefId, DefIndex, LOCAL_CRATE};
1919
use hir::map as ast_map;
2020
use hir::map::{DefKey, DefPathData, DisambiguatedDefPathData};
@@ -379,11 +379,14 @@ pub struct GlobalCtxt<'tcx> {
379379

380380
pub sess: &'tcx Session,
381381

382-
/// Map from path id to the results from resolve; generated
383-
/// initially by resolve and updated during typeck in some cases
384-
/// (e.g., UFCS paths)
382+
/// Map from path id to definition; generated
383+
/// initially by resolve and updated during typeck for
384+
/// associated items
385385
pub def_map: RefCell<DefMap>,
386386

387+
/// Map from path id to partial resolution for associated items
388+
pub assoc_map: AssocMap,
389+
387390
/// Map indicating what traits are in scope for places where this
388391
/// is relevant; generated by resolve.
389392
pub trait_map: TraitMap,
@@ -769,6 +772,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
769772
pub fn create_and_enter<F, R>(s: &'tcx Session,
770773
arenas: &'tcx CtxtArenas<'tcx>,
771774
def_map: DefMap,
775+
assoc_map: AssocMap,
772776
trait_map: TraitMap,
773777
named_region_map: resolve_lifetime::NamedRegionMap,
774778
map: ast_map::Map<'tcx>,
@@ -798,6 +802,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
798802
variance_computed: Cell::new(false),
799803
sess: s,
800804
def_map: RefCell::new(def_map),
805+
assoc_map: assoc_map,
801806
trait_map: trait_map,
802807
tables: RefCell::new(Tables::empty()),
803808
impl_trait_refs: RefCell::new(DepTrackingMap::new(dep_graph.clone())),

src/librustc/ty/mod.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2259,18 +2259,24 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
22592259

22602260
/// Returns a path resolution for node id if it exists, panics otherwise.
22612261
pub fn expect_resolution(self, id: NodeId) -> PathResolution {
2262-
*self.def_map.borrow().get(&id).expect("no def-map entry for node id")
2262+
if let Some(def) = self.def_map.borrow().get(&id) {
2263+
return PathResolution::new(*def);
2264+
}
2265+
if let Some(resolution) = self.assoc_map.get(&id) {
2266+
return *resolution;
2267+
}
2268+
panic!("no def-map entry for node id");
22632269
}
22642270

22652271
/// Returns a fully resolved definition for node id if it exists, panics otherwise.
22662272
pub fn expect_def(self, id: NodeId) -> Def {
2267-
self.expect_resolution(id).full_def()
2273+
*self.def_map.borrow().get(&id).expect("no def-map entry for node id")
22682274
}
22692275

22702276
/// Returns a fully resolved definition for node id if it exists, or none if no
2271-
/// definition exists, panics on partial resolutions to catch errors.
2277+
/// definition exists or only a partial resolution exists.
22722278
pub fn expect_def_or_none(self, id: NodeId) -> Option<Def> {
2273-
self.def_map.borrow().get(&id).map(|resolution| resolution.full_def())
2279+
self.def_map.borrow().get(&id).cloned()
22742280
}
22752281

22762282
// Returns `ty::VariantDef` if `def` refers to a struct,

src/librustc_const_eval/eval.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use rustc::hir::map as ast_map;
1919
use rustc::hir::map::blocks::FnLikeNode;
2020
use rustc::middle::cstore::InlinedItem;
2121
use rustc::traits;
22-
use rustc::hir::def::{Def, CtorKind, PathResolution};
22+
use rustc::hir::def::{Def, CtorKind};
2323
use rustc::hir::def_id::DefId;
2424
use rustc::hir::pat_util::def_to_path;
2525
use rustc::ty::{self, Ty, TyCtxt};
@@ -284,7 +284,7 @@ pub fn const_expr_to_pat<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
284284
hir::ExprCall(ref callee, ref args) => {
285285
let def = tcx.expect_def(callee.id);
286286
if let Vacant(entry) = tcx.def_map.borrow_mut().entry(expr.id) {
287-
entry.insert(PathResolution::new(def));
287+
entry.insert(def);
288288
}
289289
let path = match def {
290290
Def::StructCtor(def_id, CtorKind::Fn) |

src/librustc_driver/driver.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
use rustc::hir;
1212
use rustc::hir::{map as hir_map, FreevarMap, TraitMap};
13-
use rustc::hir::def::DefMap;
13+
use rustc::hir::def::{AssocMap, DefMap};
1414
use rustc::hir::lowering::lower_crate;
1515
use rustc_data_structures::blake2b::Blake2bHasher;
1616
use rustc_data_structures::fmt_wrap::FmtWrap;
@@ -64,6 +64,7 @@ use derive_registrar;
6464
#[derive(Clone)]
6565
pub struct Resolutions {
6666
pub def_map: DefMap,
67+
pub assoc_map: AssocMap,
6768
pub freevars: FreevarMap,
6869
pub trait_map: TraitMap,
6970
pub maybe_unused_trait_imports: NodeSet,
@@ -790,6 +791,7 @@ pub fn phase_2_configure_and_expand<'a, F>(sess: &Session,
790791
},
791792
resolutions: Resolutions {
792793
def_map: resolver.def_map,
794+
assoc_map: resolver.assoc_map,
793795
freevars: resolver.freevars,
794796
trait_map: resolver.trait_map,
795797
maybe_unused_trait_imports: resolver.maybe_unused_trait_imports,
@@ -866,6 +868,7 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session,
866868
TyCtxt::create_and_enter(sess,
867869
arenas,
868870
resolutions.def_map,
871+
resolutions.assoc_map,
869872
resolutions.trait_map,
870873
named_region_map,
871874
hir_map,

src/librustc_incremental/calculate_svh/svh_visitor.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -802,7 +802,12 @@ impl<'a, 'hash, 'tcx> StrictVersionHashVisitor<'a, 'hash, 'tcx> {
802802

803803
if let Some(def) = self.tcx.def_map.borrow().get(&id) {
804804
debug!("hash_resolve: id={:?} def={:?} st={:?}", id, def, self.st);
805-
self.hash_partial_def(def);
805+
self.hash_def(*def);
806+
}
807+
808+
if let Some(partial_def) = self.tcx.assoc_map.get(&id) {
809+
debug!("hash_resolve: id={:?} partial_def={:?} st={:?}", id, partial_def, self.st);
810+
self.hash_partial_def(partial_def);
806811
}
807812

808813
if let Some(traits) = self.tcx.trait_map.get(&id) {

src/librustc_metadata/astencode.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use schema::*;
1818

1919
use rustc::middle::cstore::{InlinedItem, InlinedItemRef};
2020
use rustc::middle::const_qualif::ConstQualif;
21-
use rustc::hir::def::{self, Def};
21+
use rustc::hir::def::Def;
2222
use rustc::hir::def_id::DefId;
2323
use rustc::ty::{self, TyCtxt, Ty};
2424

@@ -141,7 +141,7 @@ pub fn decode_inlined_item<'a, 'tcx>(cdata: &CrateMetadata,
141141
for (id, entry) in ast.side_tables.decode((cdata, tcx, id_ranges)) {
142142
match entry {
143143
TableEntry::Def(def) => {
144-
tcx.def_map.borrow_mut().insert(id, def::PathResolution::new(def));
144+
tcx.def_map.borrow_mut().insert(id, def);
145145
}
146146
TableEntry::NodeType(ty) => {
147147
tcx.tables.borrow_mut().node_types.insert(id, ty);

0 commit comments

Comments
 (0)