Separate source_span
and expn_that_defined
from Definitions
.
This commit is contained in:
parent
b676edd641
commit
34e4d72929
13 changed files with 135 additions and 135 deletions
|
@ -11,7 +11,7 @@ use rustc_hir as hir;
|
||||||
use rustc_hir::def::{DefKind, Res};
|
use rustc_hir::def::{DefKind, Res};
|
||||||
use rustc_hir::definitions::DefPathData;
|
use rustc_hir::definitions::DefPathData;
|
||||||
use rustc_session::parse::feature_err;
|
use rustc_session::parse::feature_err;
|
||||||
use rustc_span::{sym, ExpnId, Span};
|
use rustc_span::{sym, Span};
|
||||||
use rustc_target::asm;
|
use rustc_target::asm;
|
||||||
use std::collections::hash_map::Entry;
|
use std::collections::hash_map::Entry;
|
||||||
use std::fmt::Write;
|
use std::fmt::Write;
|
||||||
|
@ -243,13 +243,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
// Wrap the expression in an AnonConst.
|
// Wrap the expression in an AnonConst.
|
||||||
let parent_def_id = self.current_hir_id_owner;
|
let parent_def_id = self.current_hir_id_owner;
|
||||||
let node_id = self.next_node_id();
|
let node_id = self.next_node_id();
|
||||||
self.create_def(
|
self.create_def(parent_def_id, node_id, DefPathData::AnonConst);
|
||||||
parent_def_id,
|
|
||||||
node_id,
|
|
||||||
DefPathData::AnonConst,
|
|
||||||
ExpnId::root(),
|
|
||||||
*op_sp,
|
|
||||||
);
|
|
||||||
let anon_const = AnonConst { id: node_id, value: P(expr) };
|
let anon_const = AnonConst { id: node_id, value: P(expr) };
|
||||||
hir::InlineAsmOperand::SymFn {
|
hir::InlineAsmOperand::SymFn {
|
||||||
anon_const: self.lower_anon_const(&anon_const),
|
anon_const: self.lower_anon_const(&anon_const),
|
||||||
|
|
|
@ -11,7 +11,6 @@ use rustc_errors::struct_span_err;
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::def::Res;
|
use rustc_hir::def::Res;
|
||||||
use rustc_hir::definitions::DefPathData;
|
use rustc_hir::definitions::DefPathData;
|
||||||
use rustc_span::hygiene::ExpnId;
|
|
||||||
use rustc_span::source_map::{respan, DesugaringKind, Span, Spanned};
|
use rustc_span::source_map::{respan, DesugaringKind, Span, Spanned};
|
||||||
use rustc_span::symbol::{sym, Ident};
|
use rustc_span::symbol::{sym, Ident};
|
||||||
use rustc_span::DUMMY_SP;
|
use rustc_span::DUMMY_SP;
|
||||||
|
@ -358,13 +357,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||||
let node_id = self.next_node_id();
|
let node_id = self.next_node_id();
|
||||||
|
|
||||||
// Add a definition for the in-band const def.
|
// Add a definition for the in-band const def.
|
||||||
self.create_def(
|
self.create_def(parent_def_id, node_id, DefPathData::AnonConst);
|
||||||
parent_def_id,
|
|
||||||
node_id,
|
|
||||||
DefPathData::AnonConst,
|
|
||||||
ExpnId::root(),
|
|
||||||
arg.span,
|
|
||||||
);
|
|
||||||
|
|
||||||
let anon_const = AnonConst { id: node_id, value: arg };
|
let anon_const = AnonConst { id: node_id, value: arg };
|
||||||
generic_args.push(AngleBracketedArg::Arg(GenericArg::Const(anon_const)));
|
generic_args.push(AngleBracketedArg::Arg(GenericArg::Const(anon_const)));
|
||||||
|
|
|
@ -61,7 +61,7 @@ use rustc_query_system::ich::StableHashingContext;
|
||||||
use rustc_session::cstore::CrateStoreDyn;
|
use rustc_session::cstore::CrateStoreDyn;
|
||||||
use rustc_session::parse::feature_err;
|
use rustc_session::parse::feature_err;
|
||||||
use rustc_session::Session;
|
use rustc_session::Session;
|
||||||
use rustc_span::hygiene::{ExpnId, MacroKind};
|
use rustc_span::hygiene::MacroKind;
|
||||||
use rustc_span::source_map::DesugaringKind;
|
use rustc_span::source_map::DesugaringKind;
|
||||||
use rustc_span::symbol::{kw, sym, Ident, Symbol};
|
use rustc_span::symbol::{kw, sym, Ident, Symbol};
|
||||||
use rustc_span::{Span, DUMMY_SP};
|
use rustc_span::{Span, DUMMY_SP};
|
||||||
|
@ -391,6 +391,7 @@ fn compute_hir_hash(
|
||||||
sess: &Session,
|
sess: &Session,
|
||||||
definitions: &Definitions,
|
definitions: &Definitions,
|
||||||
cstore: &CrateStoreDyn,
|
cstore: &CrateStoreDyn,
|
||||||
|
resolver: &ResolverOutputs,
|
||||||
owners: &IndexVec<LocalDefId, hir::MaybeOwner<&hir::OwnerInfo<'_>>>,
|
owners: &IndexVec<LocalDefId, hir::MaybeOwner<&hir::OwnerInfo<'_>>>,
|
||||||
) -> Fingerprint {
|
) -> Fingerprint {
|
||||||
let mut hir_body_nodes: Vec<_> = owners
|
let mut hir_body_nodes: Vec<_> = owners
|
||||||
|
@ -404,7 +405,7 @@ fn compute_hir_hash(
|
||||||
hir_body_nodes.sort_unstable_by_key(|bn| bn.0);
|
hir_body_nodes.sort_unstable_by_key(|bn| bn.0);
|
||||||
|
|
||||||
let mut stable_hasher = StableHasher::new();
|
let mut stable_hasher = StableHasher::new();
|
||||||
let mut hcx = StableHashingContext::new(sess, definitions, cstore);
|
let mut hcx = StableHashingContext::new(sess, definitions, cstore, &resolver.source_span);
|
||||||
hir_body_nodes.hash_stable(&mut hcx, &mut stable_hasher);
|
hir_body_nodes.hash_stable(&mut hcx, &mut stable_hasher);
|
||||||
stable_hasher.finish()
|
stable_hasher.finish()
|
||||||
}
|
}
|
||||||
|
@ -437,7 +438,7 @@ pub fn lower_crate<'hir>(
|
||||||
.lower_node(def_id);
|
.lower_node(def_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
let hir_hash = compute_hir_hash(sess, definitions, cstore, &owners);
|
let hir_hash = compute_hir_hash(sess, definitions, cstore, resolver, &owners);
|
||||||
let krate = hir::Crate { owners, hir_hash };
|
let krate = hir::Crate { owners, hir_hash };
|
||||||
arena.alloc(krate)
|
arena.alloc(krate)
|
||||||
}
|
}
|
||||||
|
@ -459,7 +460,12 @@ enum ParenthesizedGenericArgs {
|
||||||
|
|
||||||
impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
fn create_stable_hashing_context(&self) -> StableHashingContext<'_> {
|
fn create_stable_hashing_context(&self) -> StableHashingContext<'_> {
|
||||||
StableHashingContext::new(self.sess, self.definitions, self.cstore)
|
StableHashingContext::new(
|
||||||
|
self.sess,
|
||||||
|
self.definitions,
|
||||||
|
self.cstore,
|
||||||
|
&self.resolver.source_span,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_def(
|
fn create_def(
|
||||||
|
@ -467,8 +473,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
parent: LocalDefId,
|
parent: LocalDefId,
|
||||||
node_id: ast::NodeId,
|
node_id: ast::NodeId,
|
||||||
data: DefPathData,
|
data: DefPathData,
|
||||||
expn_id: ExpnId,
|
|
||||||
span: Span,
|
|
||||||
) -> LocalDefId {
|
) -> LocalDefId {
|
||||||
assert!(
|
assert!(
|
||||||
self.opt_local_def_id(node_id).is_none(),
|
self.opt_local_def_id(node_id).is_none(),
|
||||||
|
@ -478,7 +482,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
self.definitions.def_key(self.local_def_id(node_id)),
|
self.definitions.def_key(self.local_def_id(node_id)),
|
||||||
);
|
);
|
||||||
|
|
||||||
let def_id = self.definitions.create_def(parent, data, expn_id, span);
|
let def_id = self.definitions.create_def(parent, data);
|
||||||
|
|
||||||
// Some things for which we allocate `LocalDefId`s don't correspond to
|
// Some things for which we allocate `LocalDefId`s don't correspond to
|
||||||
// anything in the AST, so they don't have a `NodeId`. For these cases
|
// anything in the AST, so they don't have a `NodeId`. For these cases
|
||||||
|
@ -998,13 +1002,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
|
|
||||||
let parent_def_id = self.current_hir_id_owner;
|
let parent_def_id = self.current_hir_id_owner;
|
||||||
let impl_trait_node_id = self.next_node_id();
|
let impl_trait_node_id = self.next_node_id();
|
||||||
self.create_def(
|
self.create_def(parent_def_id, impl_trait_node_id, DefPathData::ImplTrait);
|
||||||
parent_def_id,
|
|
||||||
impl_trait_node_id,
|
|
||||||
DefPathData::ImplTrait,
|
|
||||||
ExpnId::root(),
|
|
||||||
constraint.span,
|
|
||||||
);
|
|
||||||
|
|
||||||
self.with_dyn_type_scope(false, |this| {
|
self.with_dyn_type_scope(false, |this| {
|
||||||
let node_id = this.next_node_id();
|
let node_id = this.next_node_id();
|
||||||
|
@ -1110,13 +1108,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
let node_id = self.next_node_id();
|
let node_id = self.next_node_id();
|
||||||
|
|
||||||
// Add a definition for the in-band const def.
|
// Add a definition for the in-band const def.
|
||||||
self.create_def(
|
self.create_def(parent_def_id, node_id, DefPathData::AnonConst);
|
||||||
parent_def_id,
|
|
||||||
node_id,
|
|
||||||
DefPathData::AnonConst,
|
|
||||||
ExpnId::root(),
|
|
||||||
ty.span,
|
|
||||||
);
|
|
||||||
|
|
||||||
let span = self.lower_span(ty.span);
|
let span = self.lower_span(ty.span);
|
||||||
let path_expr = Expr {
|
let path_expr = Expr {
|
||||||
|
@ -1624,13 +1616,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
let inner_node_id = self.next_node_id();
|
let inner_node_id = self.next_node_id();
|
||||||
|
|
||||||
// Add a definition for the in scope lifetime def.
|
// Add a definition for the in scope lifetime def.
|
||||||
self.create_def(
|
self.create_def(opaque_ty_def_id, inner_node_id, DefPathData::LifetimeNs(name));
|
||||||
opaque_ty_def_id,
|
|
||||||
inner_node_id,
|
|
||||||
DefPathData::LifetimeNs(name),
|
|
||||||
ExpnId::root(),
|
|
||||||
span.with_parent(None),
|
|
||||||
);
|
|
||||||
|
|
||||||
let (p_name, inner_res) = match outer_res {
|
let (p_name, inner_res) = match outer_res {
|
||||||
// Input lifetime like `'a`:
|
// Input lifetime like `'a`:
|
||||||
|
@ -1824,8 +1810,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
captured_lifetimes.parent_def_id,
|
captured_lifetimes.parent_def_id,
|
||||||
p_id,
|
p_id,
|
||||||
DefPathData::LifetimeNs(p_name.ident().name),
|
DefPathData::LifetimeNs(p_name.ident().name),
|
||||||
ExpnId::root(),
|
|
||||||
span.with_parent(None),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
v.insert((span, p_id, p_name, res));
|
v.insert((span, p_id, p_name, res));
|
||||||
|
@ -1850,8 +1834,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
captured_lifetimes.parent_def_id,
|
captured_lifetimes.parent_def_id,
|
||||||
p_id,
|
p_id,
|
||||||
DefPathData::LifetimeNs(kw::UnderscoreLifetime),
|
DefPathData::LifetimeNs(kw::UnderscoreLifetime),
|
||||||
ExpnId::root(),
|
|
||||||
span.with_parent(None),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
v.insert((span, p_id, ParamName::Fresh, res));
|
v.insert((span, p_id, ParamName::Fresh, res));
|
||||||
|
@ -1873,8 +1855,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
captured_lifetimes.parent_def_id,
|
captured_lifetimes.parent_def_id,
|
||||||
p_id,
|
p_id,
|
||||||
DefPathData::LifetimeNs(kw::UnderscoreLifetime),
|
DefPathData::LifetimeNs(kw::UnderscoreLifetime),
|
||||||
ExpnId::root(),
|
|
||||||
span.with_parent(None),
|
|
||||||
);
|
);
|
||||||
captured_lifetimes
|
captured_lifetimes
|
||||||
.captures
|
.captures
|
||||||
|
|
|
@ -11,9 +11,7 @@ use crate::def_path_hash_map::DefPathHashMap;
|
||||||
use rustc_data_structures::fx::FxHashMap;
|
use rustc_data_structures::fx::FxHashMap;
|
||||||
use rustc_data_structures::stable_hasher::StableHasher;
|
use rustc_data_structures::stable_hasher::StableHasher;
|
||||||
use rustc_index::vec::IndexVec;
|
use rustc_index::vec::IndexVec;
|
||||||
use rustc_span::hygiene::ExpnId;
|
|
||||||
use rustc_span::symbol::{kw, sym, Symbol};
|
use rustc_span::symbol::{kw, sym, Symbol};
|
||||||
use rustc_span::Span;
|
|
||||||
|
|
||||||
use std::fmt::{self, Write};
|
use std::fmt::{self, Write};
|
||||||
use std::hash::Hash;
|
use std::hash::Hash;
|
||||||
|
@ -101,11 +99,6 @@ pub struct Definitions {
|
||||||
table: DefPathTable,
|
table: DefPathTable,
|
||||||
next_disambiguator: FxHashMap<(LocalDefId, DefPathData), u32>,
|
next_disambiguator: FxHashMap<(LocalDefId, DefPathData), u32>,
|
||||||
|
|
||||||
/// Item with a given `LocalDefId` was defined during macro expansion with ID `ExpnId`.
|
|
||||||
expansions_that_defined: FxHashMap<LocalDefId, ExpnId>,
|
|
||||||
|
|
||||||
def_id_to_span: IndexVec<LocalDefId, Span>,
|
|
||||||
|
|
||||||
/// The [StableCrateId] of the local crate.
|
/// The [StableCrateId] of the local crate.
|
||||||
stable_crate_id: StableCrateId,
|
stable_crate_id: StableCrateId,
|
||||||
}
|
}
|
||||||
|
@ -323,7 +316,7 @@ impl Definitions {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Adds a root definition (no parent) and a few other reserved definitions.
|
/// Adds a root definition (no parent) and a few other reserved definitions.
|
||||||
pub fn new(stable_crate_id: StableCrateId, crate_span: Span) -> Definitions {
|
pub fn new(stable_crate_id: StableCrateId) -> Definitions {
|
||||||
let key = DefKey {
|
let key = DefKey {
|
||||||
parent: None,
|
parent: None,
|
||||||
disambiguated_data: DisambiguatedDefPathData {
|
disambiguated_data: DisambiguatedDefPathData {
|
||||||
|
@ -340,30 +333,12 @@ impl Definitions {
|
||||||
let root = LocalDefId { local_def_index: table.allocate(key, def_path_hash) };
|
let root = LocalDefId { local_def_index: table.allocate(key, def_path_hash) };
|
||||||
assert_eq!(root.local_def_index, CRATE_DEF_INDEX);
|
assert_eq!(root.local_def_index, CRATE_DEF_INDEX);
|
||||||
|
|
||||||
let mut def_id_to_span = IndexVec::new();
|
Definitions { table, next_disambiguator: Default::default(), stable_crate_id }
|
||||||
// A relative span's parent must be an absolute span.
|
|
||||||
debug_assert_eq!(crate_span.data_untracked().parent, None);
|
|
||||||
let _root = def_id_to_span.push(crate_span);
|
|
||||||
debug_assert_eq!(_root, root);
|
|
||||||
|
|
||||||
Definitions {
|
|
||||||
table,
|
|
||||||
next_disambiguator: Default::default(),
|
|
||||||
expansions_that_defined: Default::default(),
|
|
||||||
def_id_to_span,
|
|
||||||
stable_crate_id,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Adds a definition with a parent definition.
|
/// Adds a definition with a parent definition.
|
||||||
pub fn create_def(
|
pub fn create_def(&mut self, parent: LocalDefId, data: DefPathData) -> LocalDefId {
|
||||||
&mut self,
|
debug!("create_def(parent={:?}, data={:?})", parent, data);
|
||||||
parent: LocalDefId,
|
|
||||||
data: DefPathData,
|
|
||||||
expn_id: ExpnId,
|
|
||||||
span: Span,
|
|
||||||
) -> LocalDefId {
|
|
||||||
debug!("create_def(parent={:?}, data={:?}, expn_id={:?})", parent, data, expn_id);
|
|
||||||
|
|
||||||
// The root node must be created with `create_root_def()`.
|
// The root node must be created with `create_root_def()`.
|
||||||
assert!(data != DefPathData::CrateRoot);
|
assert!(data != DefPathData::CrateRoot);
|
||||||
|
@ -386,28 +361,7 @@ impl Definitions {
|
||||||
debug!("create_def: after disambiguation, key = {:?}", key);
|
debug!("create_def: after disambiguation, key = {:?}", key);
|
||||||
|
|
||||||
// Create the definition.
|
// Create the definition.
|
||||||
let def_id = LocalDefId { local_def_index: self.table.allocate(key, def_path_hash) };
|
LocalDefId { local_def_index: self.table.allocate(key, def_path_hash) }
|
||||||
|
|
||||||
if expn_id != ExpnId::root() {
|
|
||||||
self.expansions_that_defined.insert(def_id, expn_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
// A relative span's parent must be an absolute span.
|
|
||||||
debug_assert_eq!(span.data_untracked().parent, None);
|
|
||||||
let _id = self.def_id_to_span.push(span);
|
|
||||||
debug_assert_eq!(_id, def_id);
|
|
||||||
|
|
||||||
def_id
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn expansion_that_defined(&self, id: LocalDefId) -> ExpnId {
|
|
||||||
self.expansions_that_defined.get(&id).copied().unwrap_or_else(ExpnId::root)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Retrieves the span of the given `DefId` if `DefId` is in the local crate.
|
|
||||||
#[inline]
|
|
||||||
pub fn def_span(&self, def_id: LocalDefId) -> Span {
|
|
||||||
self.def_id_to_span[def_id]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn iter_local_def_id(&self) -> impl Iterator<Item = LocalDefId> + '_ {
|
pub fn iter_local_def_id(&self) -> impl Iterator<Item = LocalDefId> + '_ {
|
||||||
|
|
|
@ -1078,6 +1078,8 @@ pub(super) fn crate_hash(tcx: TyCtxt<'_>, crate_num: CrateNum) -> Svh {
|
||||||
|
|
||||||
let upstream_crates = upstream_crates(tcx);
|
let upstream_crates = upstream_crates(tcx);
|
||||||
|
|
||||||
|
let resolutions = tcx.resolutions(());
|
||||||
|
|
||||||
// We hash the final, remapped names of all local source files so we
|
// We hash the final, remapped names of all local source files so we
|
||||||
// don't have to include the path prefix remapping commandline args.
|
// don't have to include the path prefix remapping commandline args.
|
||||||
// If we included the full mapping in the SVH, we could only have
|
// If we included the full mapping in the SVH, we could only have
|
||||||
|
@ -1107,7 +1109,7 @@ pub(super) fn crate_hash(tcx: TyCtxt<'_>, crate_num: CrateNum) -> Svh {
|
||||||
.filter_map(|(def_id, info)| {
|
.filter_map(|(def_id, info)| {
|
||||||
let _ = info.as_owner()?;
|
let _ = info.as_owner()?;
|
||||||
let def_path_hash = definitions.def_path_hash(def_id);
|
let def_path_hash = definitions.def_path_hash(def_id);
|
||||||
let span = definitions.def_span(def_id);
|
let span = resolutions.source_span[def_id];
|
||||||
debug_assert_eq!(span.parent(), None);
|
debug_assert_eq!(span.parent(), None);
|
||||||
Some((def_path_hash, span))
|
Some((def_path_hash, span))
|
||||||
})
|
})
|
||||||
|
@ -1118,7 +1120,6 @@ pub(super) fn crate_hash(tcx: TyCtxt<'_>, crate_num: CrateNum) -> Svh {
|
||||||
tcx.sess.opts.dep_tracking_hash(true).hash_stable(&mut hcx, &mut stable_hasher);
|
tcx.sess.opts.dep_tracking_hash(true).hash_stable(&mut hcx, &mut stable_hasher);
|
||||||
tcx.sess.local_stable_crate_id().hash_stable(&mut hcx, &mut stable_hasher);
|
tcx.sess.local_stable_crate_id().hash_stable(&mut hcx, &mut stable_hasher);
|
||||||
// Hash visibility information since it does not appear in HIR.
|
// Hash visibility information since it does not appear in HIR.
|
||||||
let resolutions = tcx.resolutions(());
|
|
||||||
resolutions.visibilities.hash_stable(&mut hcx, &mut stable_hasher);
|
resolutions.visibilities.hash_stable(&mut hcx, &mut stable_hasher);
|
||||||
resolutions.has_pub_restricted.hash_stable(&mut hcx, &mut stable_hasher);
|
resolutions.has_pub_restricted.hash_stable(&mut hcx, &mut stable_hasher);
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
|
||||||
use rustc_hir::def_id::{DefId, LocalDefId};
|
use rustc_hir::def_id::{DefId, LocalDefId};
|
||||||
use rustc_hir::*;
|
use rustc_hir::*;
|
||||||
use rustc_query_system::ich::StableHashingContext;
|
use rustc_query_system::ich::StableHashingContext;
|
||||||
use rustc_span::DUMMY_SP;
|
use rustc_span::{ExpnId, DUMMY_SP};
|
||||||
|
|
||||||
/// Top-level HIR node for current owner. This only contains the node for which
|
/// Top-level HIR node for current owner. This only contains the node for which
|
||||||
/// `HirId::local_id == 0`, and excludes bodies.
|
/// `HirId::local_id == 0`, and excludes bodies.
|
||||||
|
@ -117,7 +117,8 @@ pub fn provide(providers: &mut Providers) {
|
||||||
};
|
};
|
||||||
providers.hir_attrs =
|
providers.hir_attrs =
|
||||||
|tcx, id| tcx.hir_crate(()).owners[id].as_owner().map_or(AttributeMap::EMPTY, |o| &o.attrs);
|
|tcx, id| tcx.hir_crate(()).owners[id].as_owner().map_or(AttributeMap::EMPTY, |o| &o.attrs);
|
||||||
providers.source_span = |tcx, def_id| tcx.definitions_untracked().def_span(def_id);
|
providers.source_span =
|
||||||
|
|tcx, def_id| tcx.resolutions(()).source_span.get(def_id).copied().unwrap_or(DUMMY_SP);
|
||||||
providers.def_span = |tcx, def_id| {
|
providers.def_span = |tcx, def_id| {
|
||||||
let def_id = def_id.expect_local();
|
let def_id = def_id.expect_local();
|
||||||
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id);
|
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id);
|
||||||
|
@ -147,7 +148,7 @@ pub fn provide(providers: &mut Providers) {
|
||||||
providers.all_local_trait_impls = |tcx, ()| &tcx.resolutions(()).trait_impls;
|
providers.all_local_trait_impls = |tcx, ()| &tcx.resolutions(()).trait_impls;
|
||||||
providers.expn_that_defined = |tcx, id| {
|
providers.expn_that_defined = |tcx, id| {
|
||||||
let id = id.expect_local();
|
let id = id.expect_local();
|
||||||
tcx.definitions_untracked().expansion_that_defined(id)
|
tcx.resolutions(()).expn_that_defined.get(&id).copied().unwrap_or(ExpnId::root())
|
||||||
};
|
};
|
||||||
providers.in_scope_traits_map =
|
providers.in_scope_traits_map =
|
||||||
|tcx, id| tcx.hir_crate(()).owners[id].as_owner().map(|owner_info| &owner_info.trait_map);
|
|tcx, id| tcx.hir_crate(()).owners[id].as_owner().map(|owner_info| &owner_info.trait_map);
|
||||||
|
|
|
@ -31,7 +31,6 @@ rustc_queries! {
|
||||||
/// This span is meant for dep-tracking rather than diagnostics. It should not be used outside
|
/// This span is meant for dep-tracking rather than diagnostics. It should not be used outside
|
||||||
/// of rustc_middle::hir::source_map.
|
/// of rustc_middle::hir::source_map.
|
||||||
query source_span(key: LocalDefId) -> Span {
|
query source_span(key: LocalDefId) -> Span {
|
||||||
eval_always
|
|
||||||
desc { "get the source span" }
|
desc { "get the source span" }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -272,8 +271,6 @@ rustc_queries! {
|
||||||
}
|
}
|
||||||
|
|
||||||
query expn_that_defined(key: DefId) -> rustc_span::ExpnId {
|
query expn_that_defined(key: DefId) -> rustc_span::ExpnId {
|
||||||
// This query reads from untracked data in definitions.
|
|
||||||
eval_always
|
|
||||||
desc { |tcx| "expansion that defined `{}`", tcx.def_path_str(key) }
|
desc { |tcx| "expansion that defined `{}`", tcx.def_path_str(key) }
|
||||||
separate_provide_extern
|
separate_provide_extern
|
||||||
}
|
}
|
||||||
|
|
|
@ -180,6 +180,7 @@ impl<'tcx> CtxtInterners<'tcx> {
|
||||||
sess: &Session,
|
sess: &Session,
|
||||||
definitions: &rustc_hir::definitions::Definitions,
|
definitions: &rustc_hir::definitions::Definitions,
|
||||||
cstore: &CrateStoreDyn,
|
cstore: &CrateStoreDyn,
|
||||||
|
source_span: &IndexVec<LocalDefId, Span>,
|
||||||
) -> Ty<'tcx> {
|
) -> Ty<'tcx> {
|
||||||
Ty(Interned::new_unchecked(
|
Ty(Interned::new_unchecked(
|
||||||
self.type_
|
self.type_
|
||||||
|
@ -194,7 +195,12 @@ impl<'tcx> CtxtInterners<'tcx> {
|
||||||
Fingerprint::ZERO
|
Fingerprint::ZERO
|
||||||
} else {
|
} else {
|
||||||
let mut hasher = StableHasher::new();
|
let mut hasher = StableHasher::new();
|
||||||
let mut hcx = StableHashingContext::ignore_spans(sess, definitions, cstore);
|
let mut hcx = StableHashingContext::ignore_spans(
|
||||||
|
sess,
|
||||||
|
definitions,
|
||||||
|
cstore,
|
||||||
|
source_span,
|
||||||
|
);
|
||||||
kind.hash_stable(&mut hcx, &mut hasher);
|
kind.hash_stable(&mut hcx, &mut hasher);
|
||||||
hasher.finish()
|
hasher.finish()
|
||||||
};
|
};
|
||||||
|
@ -934,8 +940,9 @@ impl<'tcx> CommonTypes<'tcx> {
|
||||||
sess: &Session,
|
sess: &Session,
|
||||||
definitions: &rustc_hir::definitions::Definitions,
|
definitions: &rustc_hir::definitions::Definitions,
|
||||||
cstore: &CrateStoreDyn,
|
cstore: &CrateStoreDyn,
|
||||||
|
source_span: &IndexVec<LocalDefId, Span>,
|
||||||
) -> CommonTypes<'tcx> {
|
) -> CommonTypes<'tcx> {
|
||||||
let mk = |ty| interners.intern_ty(ty, sess, definitions, cstore);
|
let mk = |ty| interners.intern_ty(ty, sess, definitions, cstore, source_span);
|
||||||
|
|
||||||
CommonTypes {
|
CommonTypes {
|
||||||
unit: mk(Tuple(List::empty())),
|
unit: mk(Tuple(List::empty())),
|
||||||
|
@ -1235,7 +1242,14 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
s.fatal(&err);
|
s.fatal(&err);
|
||||||
});
|
});
|
||||||
let interners = CtxtInterners::new(arena);
|
let interners = CtxtInterners::new(arena);
|
||||||
let common_types = CommonTypes::new(&interners, s, &definitions, &*cstore);
|
let common_types = CommonTypes::new(
|
||||||
|
&interners,
|
||||||
|
s,
|
||||||
|
&definitions,
|
||||||
|
&*cstore,
|
||||||
|
// This is only used to create a stable hashing context.
|
||||||
|
&untracked_resolutions.source_span,
|
||||||
|
);
|
||||||
let common_lifetimes = CommonLifetimes::new(&interners);
|
let common_lifetimes = CommonLifetimes::new(&interners);
|
||||||
let common_consts = CommonConsts::new(&interners, &common_types);
|
let common_consts = CommonConsts::new(&interners, &common_types);
|
||||||
|
|
||||||
|
@ -1452,14 +1466,31 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
&self.definitions
|
&self.definitions
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Note that this is *untracked* and should only be used within the query
|
||||||
|
/// system if the result is otherwise tracked through queries
|
||||||
|
#[inline]
|
||||||
|
pub fn source_span_untracked(self, def_id: LocalDefId) -> Span {
|
||||||
|
self.untracked_resolutions.source_span.get(def_id).copied().unwrap_or(DUMMY_SP)
|
||||||
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn create_stable_hashing_context(self) -> StableHashingContext<'tcx> {
|
pub fn create_stable_hashing_context(self) -> StableHashingContext<'tcx> {
|
||||||
StableHashingContext::new(self.sess, &self.definitions, &*self.cstore)
|
StableHashingContext::new(
|
||||||
|
self.sess,
|
||||||
|
&self.definitions,
|
||||||
|
&*self.cstore,
|
||||||
|
&self.untracked_resolutions.source_span,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn create_no_span_stable_hashing_context(self) -> StableHashingContext<'tcx> {
|
pub fn create_no_span_stable_hashing_context(self) -> StableHashingContext<'tcx> {
|
||||||
StableHashingContext::ignore_spans(self.sess, &self.definitions, &*self.cstore)
|
StableHashingContext::ignore_spans(
|
||||||
|
self.sess,
|
||||||
|
&self.definitions,
|
||||||
|
&*self.cstore,
|
||||||
|
&self.untracked_resolutions.source_span,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn serialize_query_result_cache(self, encoder: FileEncoder) -> FileEncodeResult {
|
pub fn serialize_query_result_cache(self, encoder: FileEncoder) -> FileEncodeResult {
|
||||||
|
@ -2250,7 +2281,14 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
#[allow(rustc::usage_of_ty_tykind)]
|
#[allow(rustc::usage_of_ty_tykind)]
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn mk_ty(self, st: TyKind<'tcx>) -> Ty<'tcx> {
|
pub fn mk_ty(self, st: TyKind<'tcx>) -> Ty<'tcx> {
|
||||||
self.interners.intern_ty(st, self.sess, &self.definitions, &*self.cstore)
|
self.interners.intern_ty(
|
||||||
|
st,
|
||||||
|
self.sess,
|
||||||
|
&self.definitions,
|
||||||
|
&*self.cstore,
|
||||||
|
// This is only used to create a stable hashing context.
|
||||||
|
&self.untracked_resolutions.source_span,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|
|
@ -43,7 +43,7 @@ use rustc_macros::HashStable;
|
||||||
use rustc_query_system::ich::StableHashingContext;
|
use rustc_query_system::ich::StableHashingContext;
|
||||||
use rustc_span::hygiene::MacroKind;
|
use rustc_span::hygiene::MacroKind;
|
||||||
use rustc_span::symbol::{kw, sym, Ident, Symbol};
|
use rustc_span::symbol::{kw, sym, Ident, Symbol};
|
||||||
use rustc_span::Span;
|
use rustc_span::{ExpnId, Span};
|
||||||
use rustc_target::abi::{Align, VariantIdx};
|
use rustc_target::abi::{Align, VariantIdx};
|
||||||
pub use subst::*;
|
pub use subst::*;
|
||||||
pub use vtable::*;
|
pub use vtable::*;
|
||||||
|
@ -138,6 +138,10 @@ pub struct ResolverOutputs {
|
||||||
pub visibilities: FxHashMap<LocalDefId, Visibility>,
|
pub visibilities: FxHashMap<LocalDefId, Visibility>,
|
||||||
/// This field is used to decide whether we should make `PRIVATE_IN_PUBLIC` a hard error.
|
/// This field is used to decide whether we should make `PRIVATE_IN_PUBLIC` a hard error.
|
||||||
pub has_pub_restricted: bool,
|
pub has_pub_restricted: bool,
|
||||||
|
/// Item with a given `LocalDefId` was defined during macro expansion with ID `ExpnId`.
|
||||||
|
pub expn_that_defined: FxHashMap<LocalDefId, ExpnId>,
|
||||||
|
/// Reference span for definitions.
|
||||||
|
pub source_span: IndexVec<LocalDefId, Span>,
|
||||||
pub access_levels: AccessLevels,
|
pub access_levels: AccessLevels,
|
||||||
pub extern_crate_map: FxHashMap<LocalDefId, CrateNum>,
|
pub extern_crate_map: FxHashMap<LocalDefId, CrateNum>,
|
||||||
pub maybe_unused_trait_imports: FxIndexSet<LocalDefId>,
|
pub maybe_unused_trait_imports: FxIndexSet<LocalDefId>,
|
||||||
|
|
|
@ -689,8 +689,7 @@ impl<'a, 'tcx> Decodable<CacheDecoder<'a, 'tcx>> for Span {
|
||||||
let dlo = u32::decode(decoder);
|
let dlo = u32::decode(decoder);
|
||||||
let dto = u32::decode(decoder);
|
let dto = u32::decode(decoder);
|
||||||
|
|
||||||
let enclosing =
|
let enclosing = decoder.tcx.source_span_untracked(parent.unwrap()).data_untracked();
|
||||||
decoder.tcx.definitions_untracked().def_span(parent.unwrap()).data_untracked();
|
|
||||||
let span = Span::new(
|
let span = Span::new(
|
||||||
enclosing.lo + BytePos::from_u32(dlo),
|
enclosing.lo + BytePos::from_u32(dlo),
|
||||||
enclosing.lo + BytePos::from_u32(dto),
|
enclosing.lo + BytePos::from_u32(dto),
|
||||||
|
@ -887,7 +886,7 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(parent) = span_data.parent {
|
if let Some(parent) = span_data.parent {
|
||||||
let enclosing = s.tcx.definitions_untracked().def_span(parent).data_untracked();
|
let enclosing = s.tcx.source_span(parent).data_untracked();
|
||||||
if enclosing.contains(span_data) {
|
if enclosing.contains(span_data) {
|
||||||
TAG_RELATIVE_SPAN.encode(s);
|
TAG_RELATIVE_SPAN.encode(s);
|
||||||
(span_data.lo - enclosing.lo).to_u32().encode(s);
|
(span_data.lo - enclosing.lo).to_u32().encode(s);
|
||||||
|
|
|
@ -7,6 +7,7 @@ use rustc_data_structures::sync::Lrc;
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::def_id::{DefId, LocalDefId};
|
use rustc_hir::def_id::{DefId, LocalDefId};
|
||||||
use rustc_hir::definitions::{DefPathHash, Definitions};
|
use rustc_hir::definitions::{DefPathHash, Definitions};
|
||||||
|
use rustc_index::vec::IndexVec;
|
||||||
use rustc_session::cstore::CrateStore;
|
use rustc_session::cstore::CrateStore;
|
||||||
use rustc_session::Session;
|
use rustc_session::Session;
|
||||||
use rustc_span::source_map::SourceMap;
|
use rustc_span::source_map::SourceMap;
|
||||||
|
@ -26,6 +27,7 @@ fn compute_ignored_attr_names() -> FxHashSet<Symbol> {
|
||||||
pub struct StableHashingContext<'a> {
|
pub struct StableHashingContext<'a> {
|
||||||
definitions: &'a Definitions,
|
definitions: &'a Definitions,
|
||||||
cstore: &'a dyn CrateStore,
|
cstore: &'a dyn CrateStore,
|
||||||
|
source_span: &'a IndexVec<LocalDefId, Span>,
|
||||||
// The value of `-Z incremental-ignore-spans`.
|
// The value of `-Z incremental-ignore-spans`.
|
||||||
// This field should only be used by `debug_opts_incremental_ignore_span`
|
// This field should only be used by `debug_opts_incremental_ignore_span`
|
||||||
incremental_ignore_spans: bool,
|
incremental_ignore_spans: bool,
|
||||||
|
@ -56,6 +58,7 @@ impl<'a> StableHashingContext<'a> {
|
||||||
sess: &'a Session,
|
sess: &'a Session,
|
||||||
definitions: &'a Definitions,
|
definitions: &'a Definitions,
|
||||||
cstore: &'a dyn CrateStore,
|
cstore: &'a dyn CrateStore,
|
||||||
|
source_span: &'a IndexVec<LocalDefId, Span>,
|
||||||
always_ignore_spans: bool,
|
always_ignore_spans: bool,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let hash_spans_initial =
|
let hash_spans_initial =
|
||||||
|
@ -65,6 +68,7 @@ impl<'a> StableHashingContext<'a> {
|
||||||
body_resolver: BodyResolver::Forbidden,
|
body_resolver: BodyResolver::Forbidden,
|
||||||
definitions,
|
definitions,
|
||||||
cstore,
|
cstore,
|
||||||
|
source_span,
|
||||||
incremental_ignore_spans: sess.opts.debugging_opts.incremental_ignore_spans,
|
incremental_ignore_spans: sess.opts.debugging_opts.incremental_ignore_spans,
|
||||||
caching_source_map: None,
|
caching_source_map: None,
|
||||||
raw_source_map: sess.source_map(),
|
raw_source_map: sess.source_map(),
|
||||||
|
@ -77,11 +81,13 @@ impl<'a> StableHashingContext<'a> {
|
||||||
sess: &'a Session,
|
sess: &'a Session,
|
||||||
definitions: &'a Definitions,
|
definitions: &'a Definitions,
|
||||||
cstore: &'a dyn CrateStore,
|
cstore: &'a dyn CrateStore,
|
||||||
|
source_span: &'a IndexVec<LocalDefId, Span>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self::new_with_or_without_spans(
|
Self::new_with_or_without_spans(
|
||||||
sess,
|
sess,
|
||||||
definitions,
|
definitions,
|
||||||
cstore,
|
cstore,
|
||||||
|
source_span,
|
||||||
/*always_ignore_spans=*/ false,
|
/*always_ignore_spans=*/ false,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -91,9 +97,10 @@ impl<'a> StableHashingContext<'a> {
|
||||||
sess: &'a Session,
|
sess: &'a Session,
|
||||||
definitions: &'a Definitions,
|
definitions: &'a Definitions,
|
||||||
cstore: &'a dyn CrateStore,
|
cstore: &'a dyn CrateStore,
|
||||||
|
source_span: &'a IndexVec<LocalDefId, Span>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let always_ignore_spans = true;
|
let always_ignore_spans = true;
|
||||||
Self::new_with_or_without_spans(sess, definitions, cstore, always_ignore_spans)
|
Self::new_with_or_without_spans(sess, definitions, cstore, source_span, always_ignore_spans)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Allow hashing
|
/// Allow hashing
|
||||||
|
@ -198,7 +205,7 @@ impl<'a> rustc_span::HashStableContext for StableHashingContext<'a> {
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn def_span(&self, def_id: LocalDefId) -> Span {
|
fn def_span(&self, def_id: LocalDefId) -> Span {
|
||||||
self.definitions.def_span(def_id)
|
self.source_span[def_id]
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|
|
@ -10,8 +10,9 @@ use rustc_errors::{Applicability, Diagnostic, DiagnosticBuilder, ErrorGuaranteed
|
||||||
use rustc_feature::BUILTIN_ATTRIBUTES;
|
use rustc_feature::BUILTIN_ATTRIBUTES;
|
||||||
use rustc_hir::def::Namespace::{self, *};
|
use rustc_hir::def::Namespace::{self, *};
|
||||||
use rustc_hir::def::{self, CtorKind, CtorOf, DefKind, NonMacroAttrKind, PerNS};
|
use rustc_hir::def::{self, CtorKind, CtorOf, DefKind, NonMacroAttrKind, PerNS};
|
||||||
use rustc_hir::def_id::{DefId, CRATE_DEF_ID, LOCAL_CRATE};
|
use rustc_hir::def_id::{DefId, LocalDefId, CRATE_DEF_ID, LOCAL_CRATE};
|
||||||
use rustc_hir::PrimTy;
|
use rustc_hir::PrimTy;
|
||||||
|
use rustc_index::vec::IndexVec;
|
||||||
use rustc_middle::bug;
|
use rustc_middle::bug;
|
||||||
use rustc_middle::ty::DefIdTree;
|
use rustc_middle::ty::DefIdTree;
|
||||||
use rustc_session::lint::builtin::ABSOLUTE_PATHS_NOT_STARTING_WITH_CRATE;
|
use rustc_session::lint::builtin::ABSOLUTE_PATHS_NOT_STARTING_WITH_CRATE;
|
||||||
|
@ -130,8 +131,8 @@ impl<'a> Resolver<'a> {
|
||||||
};
|
};
|
||||||
if !candidates.is_empty() {
|
if !candidates.is_empty() {
|
||||||
show_candidates(
|
show_candidates(
|
||||||
&self.definitions,
|
&self.session,
|
||||||
self.session,
|
&self.source_span,
|
||||||
&mut err,
|
&mut err,
|
||||||
span,
|
span,
|
||||||
&candidates,
|
&candidates,
|
||||||
|
@ -693,8 +694,8 @@ impl<'a> Resolver<'a> {
|
||||||
err.span_help(span, &help_msg);
|
err.span_help(span, &help_msg);
|
||||||
}
|
}
|
||||||
show_candidates(
|
show_candidates(
|
||||||
&self.definitions,
|
&self.session,
|
||||||
self.session,
|
&self.source_span,
|
||||||
&mut err,
|
&mut err,
|
||||||
Some(span),
|
Some(span),
|
||||||
&import_suggestions,
|
&import_suggestions,
|
||||||
|
@ -1474,8 +1475,8 @@ impl<'a> Resolver<'a> {
|
||||||
let import_suggestions =
|
let import_suggestions =
|
||||||
self.lookup_import_candidates(ident, Namespace::MacroNS, parent_scope, is_expected);
|
self.lookup_import_candidates(ident, Namespace::MacroNS, parent_scope, is_expected);
|
||||||
show_candidates(
|
show_candidates(
|
||||||
&self.definitions,
|
&self.session,
|
||||||
self.session,
|
&self.source_span,
|
||||||
err,
|
err,
|
||||||
None,
|
None,
|
||||||
&import_suggestions,
|
&import_suggestions,
|
||||||
|
@ -2444,8 +2445,8 @@ enum IsPattern {
|
||||||
/// entities with that name in all crates. This method allows outputting the
|
/// entities with that name in all crates. This method allows outputting the
|
||||||
/// results of this search in a programmer-friendly way
|
/// results of this search in a programmer-friendly way
|
||||||
fn show_candidates(
|
fn show_candidates(
|
||||||
definitions: &rustc_hir::definitions::Definitions,
|
|
||||||
session: &Session,
|
session: &Session,
|
||||||
|
source_span: &IndexVec<LocalDefId, Span>,
|
||||||
err: &mut Diagnostic,
|
err: &mut Diagnostic,
|
||||||
// This is `None` if all placement locations are inside expansions
|
// This is `None` if all placement locations are inside expansions
|
||||||
use_placement_span: Option<Span>,
|
use_placement_span: Option<Span>,
|
||||||
|
@ -2555,7 +2556,7 @@ fn show_candidates(
|
||||||
);
|
);
|
||||||
|
|
||||||
if let Some(local_def_id) = def_id.and_then(|did| did.as_local()) {
|
if let Some(local_def_id) = def_id.and_then(|did| did.as_local()) {
|
||||||
let span = definitions.def_span(local_def_id);
|
let span = source_span[local_def_id];
|
||||||
let span = session.source_map().guess_head_span(span);
|
let span = session.source_map().guess_head_span(span);
|
||||||
let mut multi_span = MultiSpan::from_span(span);
|
let mut multi_span = MultiSpan::from_span(span);
|
||||||
multi_span.push_span_label(span, "not accessible".to_string());
|
multi_span.push_span_label(span, "not accessible".to_string());
|
||||||
|
@ -2584,7 +2585,7 @@ fn show_candidates(
|
||||||
let mut spans = Vec::new();
|
let mut spans = Vec::new();
|
||||||
for (name, _, def_id, _) in &inaccessible_path_strings {
|
for (name, _, def_id, _) in &inaccessible_path_strings {
|
||||||
if let Some(local_def_id) = def_id.and_then(|did| did.as_local()) {
|
if let Some(local_def_id) = def_id.and_then(|did| did.as_local()) {
|
||||||
let span = definitions.def_span(local_def_id);
|
let span = source_span[local_def_id];
|
||||||
let span = session.source_map().guess_head_span(span);
|
let span = session.source_map().guess_head_span(span);
|
||||||
spans.push((name, span));
|
spans.push((name, span));
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -872,6 +872,10 @@ pub struct Resolver<'a> {
|
||||||
session: &'a Session,
|
session: &'a Session,
|
||||||
|
|
||||||
definitions: Definitions,
|
definitions: Definitions,
|
||||||
|
/// Item with a given `LocalDefId` was defined during macro expansion with ID `ExpnId`.
|
||||||
|
expn_that_defined: FxHashMap<LocalDefId, ExpnId>,
|
||||||
|
/// Reference span for definitions.
|
||||||
|
source_span: IndexVec<LocalDefId, Span>,
|
||||||
|
|
||||||
graph_root: Module<'a>,
|
graph_root: Module<'a>,
|
||||||
|
|
||||||
|
@ -1146,7 +1150,17 @@ impl Resolver<'_> {
|
||||||
self.definitions.def_key(self.node_id_to_def_id[&node_id]),
|
self.definitions.def_key(self.node_id_to_def_id[&node_id]),
|
||||||
);
|
);
|
||||||
|
|
||||||
let def_id = self.definitions.create_def(parent, data, expn_id, span);
|
let def_id = self.definitions.create_def(parent, data);
|
||||||
|
|
||||||
|
// Create the definition.
|
||||||
|
if expn_id != ExpnId::root() {
|
||||||
|
self.expn_that_defined.insert(def_id, expn_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
// A relative span's parent must be an absolute span.
|
||||||
|
debug_assert_eq!(span.data_untracked().parent, None);
|
||||||
|
let _id = self.source_span.push(span);
|
||||||
|
debug_assert_eq!(_id, def_id);
|
||||||
|
|
||||||
// Some things for which we allocate `LocalDefId`s don't correspond to
|
// Some things for which we allocate `LocalDefId`s don't correspond to
|
||||||
// anything in the AST, so they don't have a `NodeId`. For these cases
|
// anything in the AST, so they don't have a `NodeId`. For these cases
|
||||||
|
@ -1196,7 +1210,7 @@ impl<'a> Resolver<'a> {
|
||||||
&mut FxHashMap::default(),
|
&mut FxHashMap::default(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let definitions = Definitions::new(session.local_stable_crate_id(), krate.spans.inner_span);
|
let definitions = Definitions::new(session.local_stable_crate_id());
|
||||||
|
|
||||||
let mut visibilities = FxHashMap::default();
|
let mut visibilities = FxHashMap::default();
|
||||||
visibilities.insert(CRATE_DEF_ID, ty::Visibility::Public);
|
visibilities.insert(CRATE_DEF_ID, ty::Visibility::Public);
|
||||||
|
@ -1209,6 +1223,10 @@ impl<'a> Resolver<'a> {
|
||||||
let mut invocation_parents = FxHashMap::default();
|
let mut invocation_parents = FxHashMap::default();
|
||||||
invocation_parents.insert(LocalExpnId::ROOT, (CRATE_DEF_ID, ImplTraitContext::Existential));
|
invocation_parents.insert(LocalExpnId::ROOT, (CRATE_DEF_ID, ImplTraitContext::Existential));
|
||||||
|
|
||||||
|
let mut source_span = IndexVec::default();
|
||||||
|
let _id = source_span.push(krate.spans.inner_span);
|
||||||
|
debug_assert_eq!(_id, CRATE_DEF_ID);
|
||||||
|
|
||||||
let mut extern_prelude: FxHashMap<Ident, ExternPreludeEntry<'_>> = session
|
let mut extern_prelude: FxHashMap<Ident, ExternPreludeEntry<'_>> = session
|
||||||
.opts
|
.opts
|
||||||
.externs
|
.externs
|
||||||
|
@ -1233,6 +1251,8 @@ impl<'a> Resolver<'a> {
|
||||||
session,
|
session,
|
||||||
|
|
||||||
definitions,
|
definitions,
|
||||||
|
expn_that_defined: Default::default(),
|
||||||
|
source_span,
|
||||||
|
|
||||||
// The outermost module has def ID 0; this is not reflected in the
|
// The outermost module has def ID 0; this is not reflected in the
|
||||||
// AST.
|
// AST.
|
||||||
|
@ -1376,6 +1396,8 @@ impl<'a> Resolver<'a> {
|
||||||
let proc_macros = self.proc_macros.iter().map(|id| self.local_def_id(*id)).collect();
|
let proc_macros = self.proc_macros.iter().map(|id| self.local_def_id(*id)).collect();
|
||||||
let definitions = self.definitions;
|
let definitions = self.definitions;
|
||||||
let cstore = Box::new(self.crate_loader.into_cstore());
|
let cstore = Box::new(self.crate_loader.into_cstore());
|
||||||
|
let source_span = self.source_span;
|
||||||
|
let expn_that_defined = self.expn_that_defined;
|
||||||
let visibilities = self.visibilities;
|
let visibilities = self.visibilities;
|
||||||
let has_pub_restricted = self.has_pub_restricted;
|
let has_pub_restricted = self.has_pub_restricted;
|
||||||
let extern_crate_map = self.extern_crate_map;
|
let extern_crate_map = self.extern_crate_map;
|
||||||
|
@ -1387,6 +1409,8 @@ impl<'a> Resolver<'a> {
|
||||||
let confused_type_with_std_module = self.confused_type_with_std_module;
|
let confused_type_with_std_module = self.confused_type_with_std_module;
|
||||||
let access_levels = self.access_levels;
|
let access_levels = self.access_levels;
|
||||||
let resolutions = ResolverOutputs {
|
let resolutions = ResolverOutputs {
|
||||||
|
source_span,
|
||||||
|
expn_that_defined,
|
||||||
visibilities,
|
visibilities,
|
||||||
has_pub_restricted,
|
has_pub_restricted,
|
||||||
access_levels,
|
access_levels,
|
||||||
|
@ -1426,6 +1450,8 @@ impl<'a> Resolver<'a> {
|
||||||
let definitions = self.definitions.clone();
|
let definitions = self.definitions.clone();
|
||||||
let cstore = Box::new(self.cstore().clone());
|
let cstore = Box::new(self.cstore().clone());
|
||||||
let resolutions = ResolverOutputs {
|
let resolutions = ResolverOutputs {
|
||||||
|
source_span: self.source_span.clone(),
|
||||||
|
expn_that_defined: self.expn_that_defined.clone(),
|
||||||
visibilities: self.visibilities.clone(),
|
visibilities: self.visibilities.clone(),
|
||||||
has_pub_restricted: self.has_pub_restricted,
|
has_pub_restricted: self.has_pub_restricted,
|
||||||
extern_crate_map: self.extern_crate_map.clone(),
|
extern_crate_map: self.extern_crate_map.clone(),
|
||||||
|
@ -1461,7 +1487,12 @@ impl<'a> Resolver<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_stable_hashing_context(&self) -> StableHashingContext<'_> {
|
fn create_stable_hashing_context(&self) -> StableHashingContext<'_> {
|
||||||
StableHashingContext::new(self.session, &self.definitions, self.crate_loader.cstore())
|
StableHashingContext::new(
|
||||||
|
self.session,
|
||||||
|
&self.definitions,
|
||||||
|
self.crate_loader.cstore(),
|
||||||
|
&self.source_span,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn cstore(&self) -> &CStore {
|
pub fn cstore(&self) -> &CStore {
|
||||||
|
@ -1892,7 +1923,7 @@ impl<'a> Resolver<'a> {
|
||||||
/// Retrieves the span of the given `DefId` if `DefId` is in the local crate.
|
/// Retrieves the span of the given `DefId` if `DefId` is in the local crate.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn opt_span(&self, def_id: DefId) -> Option<Span> {
|
pub fn opt_span(&self, def_id: DefId) -> Option<Span> {
|
||||||
def_id.as_local().map(|def_id| self.definitions.def_span(def_id))
|
def_id.as_local().map(|def_id| self.source_span[def_id])
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Checks if an expression refers to a function marked with
|
/// Checks if an expression refers to a function marked with
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue