Skip to content

Commit 5c279a4

Browse files
committed
Merge branch 'hide-trait-map' into rollup
2 parents 16bbff0 + 942c8dc commit 5c279a4

File tree

9 files changed

+75
-18
lines changed

9 files changed

+75
-18
lines changed

Diff for: src/librustc/dep_graph/dep_node.rs

+3
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
6363
use hir::def_id::{CrateNum, DefId};
6464
use hir::map::DefPathHash;
65+
use hir::HirId;
6566

6667
use ich::Fingerprint;
6768
use ty::{TyCtxt, Instance, InstanceDef};
@@ -528,6 +529,8 @@ define_dep_nodes!( <'tcx>
528529
[] ExternCrate(DefId),
529530
[] LintLevels,
530531
[] Specializes { impl1: DefId, impl2: DefId },
532+
[] InScopeTraits(HirId),
533+
[] ModuleExports(HirId),
531534
);
532535

533536
trait DepNodeParams<'a, 'gcx: 'tcx + 'a, 'tcx: 'a> : fmt::Debug {

Diff for: src/librustc/ich/hcx.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -205,13 +205,15 @@ impl<'a, 'gcx, 'tcx> HashStable<StableHashingContext<'a, 'gcx, 'tcx>> for ast::N
205205
// corresponding entry in the `trait_map` we need to hash that.
206206
// Make sure we don't ignore too much by checking that there is
207207
// no entry in a debug_assert!().
208-
debug_assert!(hcx.tcx.trait_map.get(self).is_none());
208+
let hir_id = hcx.tcx.hir.node_to_hir_id(*self);
209+
debug_assert!(hcx.tcx.in_scope_traits(hir_id).is_none());
209210
}
210211
NodeIdHashingMode::HashDefPath => {
211212
hcx.tcx.hir.definitions().node_to_hir_id(*self).hash_stable(hcx, hasher);
212213
}
213214
NodeIdHashingMode::HashTraitsInScope => {
214-
if let Some(traits) = hcx.tcx.trait_map.get(self) {
215+
let hir_id = hcx.tcx.hir.node_to_hir_id(*self);
216+
if let Some(traits) = hcx.tcx.in_scope_traits(hir_id) {
215217
// The ordering of the candidates is not fixed. So we hash
216218
// the def-ids and then sort them and hash the collection.
217219
let mut candidates: AccumulateVec<[_; 8]> =

Diff for: src/librustc/ty/context.rs

+27-6
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ use dep_graph::DepGraph;
1414
use errors::DiagnosticBuilder;
1515
use session::Session;
1616
use middle;
17-
use hir::{TraitMap};
18-
use hir::def::{Def, ExportMap};
17+
use hir::{TraitCandidate, HirId};
18+
use hir::def::{Def, Export};
1919
use hir::def_id::{CrateNum, DefId, LOCAL_CRATE};
2020
use hir::map as hir_map;
2121
use hir::map::DefPathHash;
@@ -817,10 +817,10 @@ pub struct GlobalCtxt<'tcx> {
817817

818818
/// Map indicating what traits are in scope for places where this
819819
/// is relevant; generated by resolve.
820-
pub trait_map: TraitMap,
820+
trait_map: FxHashMap<HirId, Rc<Vec<TraitCandidate>>>,
821821

822822
/// Export map produced by name resolution.
823-
pub export_map: ExportMap,
823+
export_map: FxHashMap<HirId, Rc<Vec<Export>>>,
824824

825825
pub named_region_map: resolve_lifetime::NamedRegionMap,
826826

@@ -1075,8 +1075,12 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
10751075
dep_graph: dep_graph.clone(),
10761076
types: common_types,
10771077
named_region_map,
1078-
trait_map: resolutions.trait_map,
1079-
export_map: resolutions.export_map,
1078+
trait_map: resolutions.trait_map.into_iter().map(|(k, v)| {
1079+
(hir.node_to_hir_id(k), Rc::new(v))
1080+
}).collect(),
1081+
export_map: resolutions.export_map.into_iter().map(|(k, v)| {
1082+
(hir.node_to_hir_id(k), Rc::new(v))
1083+
}).collect(),
10801084
hir,
10811085
def_path_hash_to_def_id,
10821086
maps: maps::Maps::new(providers),
@@ -1994,3 +1998,20 @@ impl<T, R, E> InternIteratorElement<T, R> for Result<T, E> {
19941998
Ok(f(&iter.collect::<Result<AccumulateVec<[_; 8]>, _>>()?))
19951999
}
19962000
}
2001+
2002+
fn in_scope_traits<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, id: HirId)
2003+
-> Option<Rc<Vec<TraitCandidate>>>
2004+
{
2005+
tcx.gcx.trait_map.get(&id).cloned()
2006+
}
2007+
2008+
fn module_exports<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, id: HirId)
2009+
-> Option<Rc<Vec<Export>>>
2010+
{
2011+
tcx.gcx.export_map.get(&id).cloned()
2012+
}
2013+
2014+
pub fn provide(providers: &mut ty::maps::Providers) {
2015+
providers.in_scope_traits = in_scope_traits;
2016+
providers.module_exports = module_exports;
2017+
}

Diff for: src/librustc/ty/maps.rs

+25-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
use dep_graph::{DepConstructor, DepNode, DepNodeIndex};
1212
use errors::{Diagnostic, DiagnosticBuilder};
1313
use hir::def_id::{CrateNum, DefId, LOCAL_CRATE};
14-
use hir::def::Def;
15-
use hir;
14+
use hir::def::{Def, Export};
15+
use hir::{self, TraitCandidate, HirId};
1616
use lint;
1717
use middle::const_val;
1818
use middle::cstore::{ExternCrate, LinkagePreference};
@@ -80,6 +80,15 @@ impl Key for CrateNum {
8080
}
8181
}
8282

83+
impl Key for HirId {
84+
fn map_crate(&self) -> CrateNum {
85+
LOCAL_CRATE
86+
}
87+
fn default_span(&self, _tcx: TyCtxt) -> Span {
88+
DUMMY_SP
89+
}
90+
}
91+
8392
impl Key for DefId {
8493
fn map_crate(&self) -> CrateNum {
8594
self.krate
@@ -546,6 +555,18 @@ impl<'tcx> QueryDescription for queries::specializes<'tcx> {
546555
}
547556
}
548557

558+
impl<'tcx> QueryDescription for queries::in_scope_traits<'tcx> {
559+
fn describe(_tcx: TyCtxt, _: HirId) -> String {
560+
format!("fetching the traits in scope at a particular ast node")
561+
}
562+
}
563+
564+
impl<'tcx> QueryDescription for queries::module_exports<'tcx> {
565+
fn describe(_tcx: TyCtxt, _: HirId) -> String {
566+
format!("fetching the exported items for a module")
567+
}
568+
}
569+
549570
// If enabled, send a message to the profile-queries thread
550571
macro_rules! profq_msg {
551572
($tcx:expr, $msg:expr) => {
@@ -1116,6 +1137,8 @@ define_maps! { <'tcx>
11161137
[] lint_levels: lint_levels(CrateNum) -> Rc<lint::LintLevelMap>,
11171138

11181139
[] specializes: specializes_node((DefId, DefId)) -> bool,
1140+
[] in_scope_traits: InScopeTraits(HirId) -> Option<Rc<Vec<TraitCandidate>>>,
1141+
[] module_exports: ModuleExports(HirId) -> Option<Rc<Vec<Export>>>,
11191142
}
11201143

11211144
fn type_param_predicates<'tcx>((item_id, param_id): (DefId, DefId)) -> DepConstructor<'tcx> {

Diff for: src/librustc/ty/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2517,6 +2517,7 @@ fn param_env<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
25172517

25182518
pub fn provide(providers: &mut ty::maps::Providers) {
25192519
util::provide(providers);
2520+
context::provide(providers);
25202521
*providers = ty::maps::Providers {
25212522
associated_item,
25222523
associated_item_def_ids,

Diff for: src/librustc_metadata/encoder.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -548,12 +548,13 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> {
548548
&hir::Visibility)>)
549549
-> Entry<'tcx> {
550550
let tcx = self.tcx;
551+
let hir_id = tcx.hir.node_to_hir_id(id);
551552
let def_id = tcx.hir.local_def_id(id);
552553
debug!("IsolatedEncoder::encode_info_for_mod({:?})", def_id);
553554

554555
let data = ModData {
555-
reexports: match tcx.export_map.get(&id) {
556-
Some(exports) if *vis == hir::Public => {
556+
reexports: match tcx.module_exports(hir_id) {
557+
Some(ref exports) if *vis == hir::Public => {
557558
self.lazy_seq_from_slice(exports.as_slice())
558559
}
559560
_ => LazySeq::empty(),

Diff for: src/librustc_privacy/lib.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -325,8 +325,9 @@ impl<'a, 'tcx> Visitor<'tcx> for EmbargoVisitor<'a, 'tcx> {
325325
// This code is here instead of in visit_item so that the
326326
// crate module gets processed as well.
327327
if self.prev_level.is_some() {
328-
if let Some(exports) = self.tcx.export_map.get(&id) {
329-
for export in exports {
328+
let hir_id = self.tcx.hir.node_to_hir_id(id);
329+
if let Some(exports) = self.tcx.module_exports(hir_id) {
330+
for export in exports.iter() {
330331
if let Some(node_id) = self.tcx.hir.as_local_node_id(export.def.def_id()) {
331332
self.update(node_id, Some(AccessLevel::Exported));
332333
}

Diff for: src/librustc_typeck/check/method/probe.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -639,10 +639,14 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
639639
fn assemble_extension_candidates_for_traits_in_scope(&mut self,
640640
expr_id: ast::NodeId)
641641
-> Result<(), MethodError<'tcx>> {
642+
if expr_id == ast::DUMMY_NODE_ID {
643+
return Ok(())
644+
}
642645
let mut duplicates = FxHashSet();
643-
let opt_applicable_traits = self.tcx.trait_map.get(&expr_id);
646+
let expr_hir_id = self.tcx.hir.node_to_hir_id(expr_id);
647+
let opt_applicable_traits = self.tcx.in_scope_traits(expr_hir_id);
644648
if let Some(applicable_traits) = opt_applicable_traits {
645-
for trait_candidate in applicable_traits {
649+
for trait_candidate in applicable_traits.iter() {
646650
let trait_did = trait_candidate.def_id;
647651
if duplicates.insert(trait_did) {
648652
let import_id = trait_candidate.import_id;

Diff for: src/librustdoc/visit_ast.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,9 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
199199
self.visit_item(item, None, &mut om);
200200
}
201201
self.inside_public_path = orig_inside_public_path;
202-
if let Some(exports) = self.cx.tcx.export_map.get(&id) {
203-
for export in exports {
202+
let hir_id = self.cx.tcx.hir.node_to_hir_id(id);
203+
if let Some(exports) = self.cx.tcx.module_exports(hir_id) {
204+
for export in exports.iter() {
204205
if let Def::Macro(def_id, ..) = export.def {
205206
if def_id.krate == LOCAL_CRATE || self.reexported_macros.contains(&def_id) {
206207
continue // These are `krate.exported_macros`, handled in `self.visit()`.

0 commit comments

Comments
 (0)