Cache expansion hash.
This commit is contained in:
parent
cff0ea5f88
commit
616ce3c5c0
12 changed files with 263 additions and 217 deletions
|
@ -48,7 +48,7 @@ use rustc_data_structures::sync::Lrc;
|
|||
use rustc_errors::{struct_span_err, Applicability};
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def::{DefKind, Namespace, PartialRes, PerNS, Res};
|
||||
use rustc_hir::def_id::{DefId, DefIdMap, LocalDefId, CRATE_DEF_ID};
|
||||
use rustc_hir::def_id::{DefId, DefIdMap, DefPathHash, LocalDefId, CRATE_DEF_ID};
|
||||
use rustc_hir::definitions::{DefKey, DefPathData, Definitions};
|
||||
use rustc_hir::intravisit;
|
||||
use rustc_hir::{ConstArg, GenericArg, ParamName};
|
||||
|
@ -59,7 +59,7 @@ use rustc_session::utils::{FlattenNonterminals, NtToTokenstream};
|
|||
use rustc_session::Session;
|
||||
use rustc_span::edition::Edition;
|
||||
use rustc_span::hygiene::ExpnId;
|
||||
use rustc_span::source_map::{respan, DesugaringKind};
|
||||
use rustc_span::source_map::{respan, CachingSourceMapView, DesugaringKind};
|
||||
use rustc_span::symbol::{kw, sym, Ident, Symbol};
|
||||
use rustc_span::{Span, DUMMY_SP};
|
||||
use rustc_target::spec::abi::Abi;
|
||||
|
@ -204,6 +204,8 @@ pub trait ResolverAstLowering {
|
|||
|
||||
fn local_def_id(&self, node: NodeId) -> LocalDefId;
|
||||
|
||||
fn def_path_hash(&self, def_id: DefId) -> DefPathHash;
|
||||
|
||||
fn create_def(
|
||||
&mut self,
|
||||
parent: LocalDefId,
|
||||
|
@ -214,6 +216,32 @@ pub trait ResolverAstLowering {
|
|||
) -> LocalDefId;
|
||||
}
|
||||
|
||||
struct LoweringHasher<'a> {
|
||||
source_map: CachingSourceMapView<'a>,
|
||||
resolver: &'a dyn ResolverAstLowering,
|
||||
}
|
||||
|
||||
impl<'a> rustc_span::HashStableContext for LoweringHasher<'a> {
|
||||
#[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)
|
||||
}
|
||||
}
|
||||
|
||||
/// Context of `impl Trait` in code, which determines whether it is allowed in an HIR subtree,
|
||||
/// and if so, what meaning it has.
|
||||
#[derive(Debug)]
|
||||
|
@ -565,6 +593,13 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
|||
lowered
|
||||
}
|
||||
|
||||
fn create_stable_hashing_context(&self) -> LoweringHasher<'_> {
|
||||
LoweringHasher {
|
||||
source_map: CachingSourceMapView::new(self.sess.source_map()),
|
||||
resolver: self.resolver,
|
||||
}
|
||||
}
|
||||
|
||||
fn lower_node_id_generic(
|
||||
&mut self,
|
||||
ast_node_id: NodeId,
|
||||
|
@ -684,7 +719,12 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
|||
span: Span,
|
||||
allow_internal_unstable: Option<Lrc<[Symbol]>>,
|
||||
) -> Span {
|
||||
span.mark_with_reason(allow_internal_unstable, reason, self.sess.edition())
|
||||
span.mark_with_reason(
|
||||
allow_internal_unstable,
|
||||
reason,
|
||||
self.sess.edition(),
|
||||
self.create_stable_hashing_context(),
|
||||
)
|
||||
}
|
||||
|
||||
fn with_anonymous_lifetime_mode<R>(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue