diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2017-08-29 11:10:22 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2017-08-29 14:53:03 -0700 |
| commit | 32d35e6e9fb9a5f1cbb51fdff6aed9398c4ec271 (patch) | |
| tree | ca79236fee833534495828bd366627fcab75be84 /src | |
| parent | faf477a8c232d0442d16a4025f49d3ae1519131e (diff) | |
| download | rust-32d35e6e9fb9a5f1cbb51fdff6aed9398c4ec271.tar.gz rust-32d35e6e9fb9a5f1cbb51fdff6aed9398c4ec271.zip | |
rustc: Make the `trait_map` of TyCtxt private
This 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.
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustc/dep_graph/dep_node.rs | 2 | ||||
| -rw-r--r-- | src/librustc/ich/hcx.rs | 6 | ||||
| -rw-r--r-- | src/librustc/ty/context.rs | 18 | ||||
| -rw-r--r-- | src/librustc/ty/maps.rs | 19 | ||||
| -rw-r--r-- | src/librustc/ty/mod.rs | 1 | ||||
| -rw-r--r-- | src/librustc_typeck/check/method/probe.rs | 5 |
6 files changed, 43 insertions, 8 deletions
diff --git a/src/librustc/dep_graph/dep_node.rs b/src/librustc/dep_graph/dep_node.rs index 9a80db472db..92078f97e41 100644 --- a/src/librustc/dep_graph/dep_node.rs +++ b/src/librustc/dep_graph/dep_node.rs @@ -62,6 +62,7 @@ use hir::def_id::{CrateNum, DefId}; use hir::map::DefPathHash; +use hir::HirId; use ich::Fingerprint; use ty::{TyCtxt, Instance, InstanceDef}; @@ -527,6 +528,7 @@ define_dep_nodes!( <'tcx> [] HasGlobalAllocator(DefId), [] ExternCrate(DefId), [] LintLevels, + [] InScopeTraits(HirId), ); trait DepNodeParams<'a, 'gcx: 'tcx + 'a, 'tcx: 'a> : fmt::Debug { diff --git a/src/librustc/ich/hcx.rs b/src/librustc/ich/hcx.rs index 218483232d6..234f3a883d7 100644 --- a/src/librustc/ich/hcx.rs +++ b/src/librustc/ich/hcx.rs @@ -205,13 +205,15 @@ impl<'a, 'gcx, 'tcx> HashStable<StableHashingContext<'a, 'gcx, 'tcx>> for ast::N // corresponding entry in the `trait_map` we need to hash that. // Make sure we don't ignore too much by checking that there is // no entry in a debug_assert!(). - debug_assert!(hcx.tcx.trait_map.get(self).is_none()); + let hir_id = hcx.tcx.hir.node_to_hir_id(*self); + debug_assert!(hcx.tcx.in_scope_traits(hir_id).is_none()); } NodeIdHashingMode::HashDefPath => { hcx.tcx.hir.definitions().node_to_hir_id(*self).hash_stable(hcx, hasher); } NodeIdHashingMode::HashTraitsInScope => { - if let Some(traits) = hcx.tcx.trait_map.get(self) { + let hir_id = hcx.tcx.hir.node_to_hir_id(*self); + if let Some(traits) = hcx.tcx.in_scope_traits(hir_id) { // The ordering of the candidates is not fixed. So we hash // the def-ids and then sort them and hash the collection. let mut candidates: AccumulateVec<[_; 8]> = diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs index 1fe53882c70..9ff5a33af50 100644 --- a/src/librustc/ty/context.rs +++ b/src/librustc/ty/context.rs @@ -14,7 +14,7 @@ use dep_graph::DepGraph; use errors::DiagnosticBuilder; use session::Session; use middle; -use hir::{TraitMap}; +use hir::{TraitCandidate, HirId}; use hir::def::{Def, ExportMap}; use hir::def_id::{CrateNum, DefId, LOCAL_CRATE}; use hir::map as hir_map; @@ -819,7 +819,7 @@ pub struct GlobalCtxt<'tcx> { /// Map indicating what traits are in scope for places where this /// is relevant; generated by resolve. - pub trait_map: TraitMap, + trait_map: FxHashMap<HirId, Rc<Vec<TraitCandidate>>>, /// Export map produced by name resolution. pub export_map: ExportMap, @@ -1078,7 +1078,9 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { dep_graph: dep_graph.clone(), types: common_types, named_region_map, - trait_map: resolutions.trait_map, + trait_map: resolutions.trait_map.into_iter().map(|(k, v)| { + (hir.node_to_hir_id(k), Rc::new(v)) + }).collect(), export_map: resolutions.export_map, hir, def_path_hash_to_def_id, @@ -1997,3 +1999,13 @@ impl<T, R, E> InternIteratorElement<T, R> for Result<T, E> { Ok(f(&iter.collect::<Result<AccumulateVec<[_; 8]>, _>>()?)) } } + +fn in_scope_traits<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, id: HirId) + -> Option<Rc<Vec<TraitCandidate>>> +{ + tcx.gcx.trait_map.get(&id).cloned() +} + +pub fn provide(providers: &mut ty::maps::Providers) { + providers.in_scope_traits = in_scope_traits; +} diff --git a/src/librustc/ty/maps.rs b/src/librustc/ty/maps.rs index 03e093c5a50..25c2c6b0d71 100644 --- a/src/librustc/ty/maps.rs +++ b/src/librustc/ty/maps.rs @@ -12,7 +12,7 @@ use dep_graph::{DepConstructor, DepNode, DepNodeIndex}; use errors::{Diagnostic, DiagnosticBuilder}; use hir::def_id::{CrateNum, DefId, LOCAL_CRATE}; use hir::def::Def; -use hir; +use hir::{self, TraitCandidate, HirId}; use lint; use middle::const_val; use middle::cstore::{ExternCrate, LinkagePreference}; @@ -80,6 +80,15 @@ impl Key for CrateNum { } } +impl Key for HirId { + fn map_crate(&self) -> CrateNum { + LOCAL_CRATE + } + fn default_span(&self, _tcx: TyCtxt) -> Span { + DUMMY_SP + } +} + impl Key for DefId { fn map_crate(&self) -> CrateNum { self.krate @@ -540,6 +549,12 @@ impl<'tcx> QueryDescription for queries::lint_levels<'tcx> { } } +impl<'tcx> QueryDescription for queries::in_scope_traits<'tcx> { + fn describe(_tcx: TyCtxt, _: HirId) -> String { + format!("fetching the traits in scope at a particular ast node") + } +} + // If enabled, send a message to the profile-queries thread macro_rules! profq_msg { ($tcx:expr, $msg:expr) => { @@ -1108,6 +1123,8 @@ define_maps! { <'tcx> [] extern_crate: ExternCrate(DefId) -> Rc<Option<ExternCrate>>, [] lint_levels: lint_levels(CrateNum) -> Rc<lint::LintLevelMap>, + + [] in_scope_traits: InScopeTraits(HirId) -> Option<Rc<Vec<TraitCandidate>>>, } fn type_param_predicates<'tcx>((item_id, param_id): (DefId, DefId)) -> DepConstructor<'tcx> { diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index 8cabb88ee98..ca735599a0d 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -2517,6 +2517,7 @@ fn param_env<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, pub fn provide(providers: &mut ty::maps::Providers) { util::provide(providers); + context::provide(providers); *providers = ty::maps::Providers { associated_item, associated_item_def_ids, diff --git a/src/librustc_typeck/check/method/probe.rs b/src/librustc_typeck/check/method/probe.rs index 5e5a27f2ba1..056a1c90654 100644 --- a/src/librustc_typeck/check/method/probe.rs +++ b/src/librustc_typeck/check/method/probe.rs @@ -663,9 +663,10 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> { expr_id: ast::NodeId) -> Result<(), MethodError<'tcx>> { let mut duplicates = FxHashSet(); - let opt_applicable_traits = self.tcx.trait_map.get(&expr_id); + let expr_hir_id = self.tcx.hir.node_to_hir_id(expr_id); + let opt_applicable_traits = self.tcx.in_scope_traits(expr_hir_id); if let Some(applicable_traits) = opt_applicable_traits { - for trait_candidate in applicable_traits { + for trait_candidate in applicable_traits.iter() { let trait_did = trait_candidate.def_id; if duplicates.insert(trait_did) { let import_id = trait_candidate.import_id; |
