Skip to content

Commit 942c8dc

Browse files
committed
rustc: Make the export_map of TyCtxt private
This map, like `trait_map`, is calculated in resolve, but we want to be sure to track it for incremental compliation. Hide it behind a query to get more refactorings later.
1 parent 32d35e6 commit 942c8dc

File tree

7 files changed

+33
-10
lines changed

7 files changed

+33
-10
lines changed

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

+1
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,7 @@ define_dep_nodes!( <'tcx>
529529
[] ExternCrate(DefId),
530530
[] LintLevels,
531531
[] InScopeTraits(HirId),
532+
[] ModuleExports(HirId),
532533
);
533534

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

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

+12-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use errors::DiagnosticBuilder;
1515
use session::Session;
1616
use middle;
1717
use hir::{TraitCandidate, HirId};
18-
use hir::def::{Def, ExportMap};
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;
@@ -822,7 +822,7 @@ pub struct GlobalCtxt<'tcx> {
822822
trait_map: FxHashMap<HirId, Rc<Vec<TraitCandidate>>>,
823823

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

827827
pub named_region_map: resolve_lifetime::NamedRegionMap,
828828

@@ -1081,7 +1081,9 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
10811081
trait_map: resolutions.trait_map.into_iter().map(|(k, v)| {
10821082
(hir.node_to_hir_id(k), Rc::new(v))
10831083
}).collect(),
1084-
export_map: resolutions.export_map,
1084+
export_map: resolutions.export_map.into_iter().map(|(k, v)| {
1085+
(hir.node_to_hir_id(k), Rc::new(v))
1086+
}).collect(),
10851087
hir,
10861088
def_path_hash_to_def_id,
10871089
maps: maps::Maps::new(providers),
@@ -2006,6 +2008,13 @@ fn in_scope_traits<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, id: HirId)
20062008
tcx.gcx.trait_map.get(&id).cloned()
20072009
}
20082010

2011+
fn module_exports<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, id: HirId)
2012+
-> Option<Rc<Vec<Export>>>
2013+
{
2014+
tcx.gcx.export_map.get(&id).cloned()
2015+
}
2016+
20092017
pub fn provide(providers: &mut ty::maps::Providers) {
20102018
providers.in_scope_traits = in_scope_traits;
2019+
providers.module_exports = module_exports;
20112020
}

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

+8-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
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;
14+
use hir::def::{Def, Export};
1515
use hir::{self, TraitCandidate, HirId};
1616
use lint;
1717
use middle::const_val;
@@ -555,6 +555,12 @@ impl<'tcx> QueryDescription for queries::in_scope_traits<'tcx> {
555555
}
556556
}
557557

558+
impl<'tcx> QueryDescription for queries::module_exports<'tcx> {
559+
fn describe(_tcx: TyCtxt, _: HirId) -> String {
560+
format!("fetching the exported items for a module")
561+
}
562+
}
563+
558564
// If enabled, send a message to the profile-queries thread
559565
macro_rules! profq_msg {
560566
($tcx:expr, $msg:expr) => {
@@ -1125,6 +1131,7 @@ define_maps! { <'tcx>
11251131
[] lint_levels: lint_levels(CrateNum) -> Rc<lint::LintLevelMap>,
11261132

11271133
[] in_scope_traits: InScopeTraits(HirId) -> Option<Rc<Vec<TraitCandidate>>>,
1134+
[] module_exports: ModuleExports(HirId) -> Option<Rc<Vec<Export>>>,
11281135
}
11291136

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

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

+3
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,9 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
662662
fn assemble_extension_candidates_for_traits_in_scope(&mut self,
663663
expr_id: ast::NodeId)
664664
-> Result<(), MethodError<'tcx>> {
665+
if expr_id == ast::DUMMY_NODE_ID {
666+
return Ok(())
667+
}
665668
let mut duplicates = FxHashSet();
666669
let expr_hir_id = self.tcx.hir.node_to_hir_id(expr_id);
667670
let opt_applicable_traits = self.tcx.in_scope_traits(expr_hir_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)