diff options
| author | Camille GILLOT <gillot.camille@gmail.com> | 2021-06-22 19:20:25 +0200 |
|---|---|---|
| committer | Camille GILLOT <gillot.camille@gmail.com> | 2021-07-13 23:10:56 +0200 |
| commit | 616ce3c5c029446ef8b0d7a3525f96b2e451840c (patch) | |
| tree | 8f0248045ab43e37c49d01771f988cd3e8020dd4 /compiler/rustc_resolve/src | |
| parent | cff0ea5f88cf926a4cb326545ec63ccd27afb846 (diff) | |
| download | rust-616ce3c5c029446ef8b0d7a3525f96b2e451840c.tar.gz rust-616ce3c5c029446ef8b0d7a3525f96b2e451840c.zip | |
Cache expansion hash.
Diffstat (limited to 'compiler/rustc_resolve/src')
| -rw-r--r-- | compiler/rustc_resolve/src/lib.rs | 44 | ||||
| -rw-r--r-- | compiler/rustc_resolve/src/macros.rs | 40 |
2 files changed, 65 insertions, 19 deletions
diff --git a/compiler/rustc_resolve/src/lib.rs b/compiler/rustc_resolve/src/lib.rs index bcdae1cb43d..4d124152151 100644 --- a/compiler/rustc_resolve/src/lib.rs +++ b/compiler/rustc_resolve/src/lib.rs @@ -39,7 +39,7 @@ use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder}; use rustc_expand::base::{DeriveResolutions, SyntaxExtension, SyntaxExtensionKind}; use rustc_hir::def::Namespace::*; use rustc_hir::def::{self, CtorOf, DefKind, NonMacroAttrKind, PartialRes}; -use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, LocalDefId, CRATE_DEF_INDEX}; +use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, DefPathHash, LocalDefId, CRATE_DEF_INDEX}; use rustc_hir::definitions::{DefKey, DefPathData, Definitions}; use rustc_hir::TraitCandidate; use rustc_index::vec::IndexVec; @@ -54,7 +54,7 @@ use rustc_session::lint::{BuiltinLintDiagnostics, LintBuffer}; use rustc_session::Session; use rustc_span::edition::Edition; use rustc_span::hygiene::{ExpnId, ExpnKind, MacroKind, SyntaxContext, Transparency}; -use rustc_span::source_map::Spanned; +use rustc_span::source_map::{CachingSourceMapView, Spanned}; use rustc_span::symbol::{kw, sym, Ident, Symbol}; use rustc_span::{Span, DUMMY_SP}; @@ -1149,6 +1149,13 @@ impl ResolverAstLowering for Resolver<'_> { self.opt_local_def_id(node).unwrap_or_else(|| panic!("no entry for node id: `{:?}`", node)) } + fn def_path_hash(&self, def_id: DefId) -> DefPathHash { + match def_id.as_local() { + Some(def_id) => self.definitions.def_path_hash(def_id), + None => self.cstore().def_path_hash(def_id), + } + } + /// Adds a definition with a parent definition. fn create_def( &mut self, @@ -1192,6 +1199,32 @@ impl ResolverAstLowering for Resolver<'_> { } } +struct ExpandHasher<'a, 'b> { + source_map: CachingSourceMapView<'a>, + resolver: &'a Resolver<'b>, +} + +impl<'a, 'b> rustc_span::HashStableContext for ExpandHasher<'a, 'b> { + #[inline] + fn hash_spans(&self) -> bool { + true + } + + #[inline] + fn def_path_hash(&self, def_id: DefId) -> DefPathHash { + self.resolver.def_path_hash(def_id) + } + + #[inline] + fn span_data_to_lines_and_cols( + &mut self, + span: &rustc_span::SpanData, + ) -> Option<(Lrc<rustc_span::SourceFile>, usize, rustc_span::BytePos, usize, rustc_span::BytePos)> + { + self.source_map.span_data_to_lines_and_cols(span) + } +} + impl<'a> Resolver<'a> { pub fn new( session: &'a Session, @@ -1364,6 +1397,13 @@ impl<'a> Resolver<'a> { resolver } + fn create_stable_hashing_context(&self) -> ExpandHasher<'_, 'a> { + ExpandHasher { + source_map: CachingSourceMapView::new(self.session.source_map()), + resolver: self, + } + } + pub fn next_node_id(&mut self) -> NodeId { let next = self .next_node_id diff --git a/compiler/rustc_resolve/src/macros.rs b/compiler/rustc_resolve/src/macros.rs index e024ade7b3c..8686704388f 100644 --- a/compiler/rustc_resolve/src/macros.rs +++ b/compiler/rustc_resolve/src/macros.rs @@ -218,14 +218,17 @@ impl<'a> ResolverExpand for Resolver<'a> { parent_module_id: Option<NodeId>, ) -> ExpnId { let parent_module = parent_module_id.map(|module_id| self.local_def_id(module_id)); - let expn_id = ExpnId::fresh(Some(ExpnData::allow_unstable( - ExpnKind::AstPass(pass), - call_site, - self.session.edition(), - features.into(), - None, - parent_module.map(LocalDefId::to_def_id), - ))); + let expn_id = ExpnId::fresh( + ExpnData::allow_unstable( + ExpnKind::AstPass(pass), + call_site, + self.session.edition(), + features.into(), + None, + parent_module.map(LocalDefId::to_def_id), + ), + self.create_stable_hashing_context(), + ); let parent_scope = parent_module .map_or(self.empty_module, |parent_def_id| self.module_map[&parent_def_id]); @@ -287,15 +290,18 @@ impl<'a> ResolverExpand for Resolver<'a> { )?; let span = invoc.span(); - invoc_id.set_expn_data(ext.expn_data( - parent_scope.expansion, - span, - fast_print_path(path), - res.opt_def_id(), - res.opt_def_id().map(|macro_def_id| { - self.macro_def_scope_from_def_id(macro_def_id).nearest_parent_mod - }), - )); + invoc_id.set_expn_data( + ext.expn_data( + parent_scope.expansion, + span, + fast_print_path(path), + res.opt_def_id(), + res.opt_def_id().map(|macro_def_id| { + self.macro_def_scope_from_def_id(macro_def_id).nearest_parent_mod + }), + ), + self.create_stable_hashing_context(), + ); if let Res::Def(_, _) = res { // Gate macro attributes in `#[derive]` output. |
