mirror of https://github.com/rust-lang/rust.git
Auto merge of #98106 - cjgillot:split-definitions, r=michaelwoerister
Split up `Definitions` and `ResolverAstLowering`. Split off https://github.com/rust-lang/rust/pull/95573 r? `@michaelwoerister`
This commit is contained in:
commit
3a8b0144c8
|
@ -3571,6 +3571,7 @@ dependencies = [
|
||||||
"rustc_errors",
|
"rustc_errors",
|
||||||
"rustc_hir",
|
"rustc_hir",
|
||||||
"rustc_index",
|
"rustc_index",
|
||||||
|
"rustc_middle",
|
||||||
"rustc_query_system",
|
"rustc_query_system",
|
||||||
"rustc_session",
|
"rustc_session",
|
||||||
"rustc_span",
|
"rustc_span",
|
||||||
|
@ -4376,7 +4377,6 @@ dependencies = [
|
||||||
"bitflags",
|
"bitflags",
|
||||||
"rustc_arena",
|
"rustc_arena",
|
||||||
"rustc_ast",
|
"rustc_ast",
|
||||||
"rustc_ast_lowering",
|
|
||||||
"rustc_ast_pretty",
|
"rustc_ast_pretty",
|
||||||
"rustc_attr",
|
"rustc_attr",
|
||||||
"rustc_data_structures",
|
"rustc_data_structures",
|
||||||
|
|
|
@ -14,6 +14,7 @@ rustc_hir = { path = "../rustc_hir" }
|
||||||
rustc_target = { path = "../rustc_target" }
|
rustc_target = { path = "../rustc_target" }
|
||||||
rustc_data_structures = { path = "../rustc_data_structures" }
|
rustc_data_structures = { path = "../rustc_data_structures" }
|
||||||
rustc_index = { path = "../rustc_index" }
|
rustc_index = { path = "../rustc_index" }
|
||||||
|
rustc_middle = { path = "../rustc_middle" }
|
||||||
rustc_query_system = { path = "../rustc_query_system" }
|
rustc_query_system = { path = "../rustc_query_system" }
|
||||||
rustc_span = { path = "../rustc_span" }
|
rustc_span = { path = "../rustc_span" }
|
||||||
rustc_errors = { path = "../rustc_errors" }
|
rustc_errors = { path = "../rustc_errors" }
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::{ImplTraitContext, ImplTraitPosition, ParamMode};
|
use crate::{ImplTraitContext, ImplTraitPosition, ParamMode, ResolverAstLoweringExt};
|
||||||
|
|
||||||
use super::LoweringContext;
|
use super::LoweringContext;
|
||||||
|
|
||||||
|
@ -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;
|
||||||
|
@ -242,14 +242,8 @@ 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.resolver.next_node_id();
|
let node_id = self.next_node_id();
|
||||||
self.resolver.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),
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::{FnDeclKind, ImplTraitPosition};
|
use super::ResolverAstLoweringExt;
|
||||||
|
|
||||||
use super::{ImplTraitContext, LoweringContext, ParamMode, ParenthesizedGenericArgs};
|
use super::{ImplTraitContext, LoweringContext, ParamMode, ParenthesizedGenericArgs};
|
||||||
|
use crate::{FnDeclKind, ImplTraitPosition};
|
||||||
|
|
||||||
use rustc_ast::attr;
|
use rustc_ast::attr;
|
||||||
use rustc_ast::ptr::P as AstP;
|
use rustc_ast::ptr::P as AstP;
|
||||||
|
@ -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;
|
||||||
|
@ -355,16 +354,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||||
for (idx, arg) in args.into_iter().enumerate() {
|
for (idx, arg) in args.into_iter().enumerate() {
|
||||||
if legacy_args_idx.contains(&idx) {
|
if legacy_args_idx.contains(&idx) {
|
||||||
let parent_def_id = self.current_hir_id_owner;
|
let parent_def_id = self.current_hir_id_owner;
|
||||||
let node_id = self.resolver.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.resolver.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)));
|
||||||
|
@ -724,7 +717,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||||
};
|
};
|
||||||
|
|
||||||
// `::std::task::Poll::Ready(result) => break result`
|
// `::std::task::Poll::Ready(result) => break result`
|
||||||
let loop_node_id = self.resolver.next_node_id();
|
let loop_node_id = self.next_node_id();
|
||||||
let loop_hir_id = self.lower_node_id(loop_node_id);
|
let loop_hir_id = self.lower_node_id(loop_node_id);
|
||||||
let ready_arm = {
|
let ready_arm = {
|
||||||
let x_ident = Ident::with_dummy_span(sym::result);
|
let x_ident = Ident::with_dummy_span(sym::result);
|
||||||
|
|
|
@ -6,6 +6,7 @@ use rustc_hir::definitions;
|
||||||
use rustc_hir::intravisit::{self, Visitor};
|
use rustc_hir::intravisit::{self, Visitor};
|
||||||
use rustc_hir::*;
|
use rustc_hir::*;
|
||||||
use rustc_index::vec::{Idx, IndexVec};
|
use rustc_index::vec::{Idx, IndexVec};
|
||||||
|
use rustc_middle::span_bug;
|
||||||
use rustc_session::Session;
|
use rustc_session::Session;
|
||||||
use rustc_span::source_map::SourceMap;
|
use rustc_span::source_map::SourceMap;
|
||||||
use rustc_span::{Span, DUMMY_SP};
|
use rustc_span::{Span, DUMMY_SP};
|
||||||
|
@ -75,7 +76,8 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
|
||||||
// owner of that node.
|
// owner of that node.
|
||||||
if cfg!(debug_assertions) {
|
if cfg!(debug_assertions) {
|
||||||
if hir_id.owner != self.owner {
|
if hir_id.owner != self.owner {
|
||||||
panic!(
|
span_bug!(
|
||||||
|
span,
|
||||||
"inconsistent DepNode at `{:?}` for `{:?}`: \
|
"inconsistent DepNode at `{:?}` for `{:?}`: \
|
||||||
current_dep_node_owner={} ({:?}), hir_id.owner={} ({:?})",
|
current_dep_node_owner={} ({:?}), hir_id.owner={} ({:?})",
|
||||||
self.source_map.span_to_diagnostic_string(span),
|
self.source_map.span_to_diagnostic_string(span),
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use super::{AstOwner, ImplTraitContext, ImplTraitPosition, ResolverAstLowering};
|
use super::ResolverAstLoweringExt;
|
||||||
|
use super::{AstOwner, ImplTraitContext, ImplTraitPosition};
|
||||||
use super::{LoweringContext, ParamMode};
|
use super::{LoweringContext, ParamMode};
|
||||||
use crate::{Arena, FnDeclKind};
|
use crate::{Arena, FnDeclKind};
|
||||||
|
|
||||||
|
@ -11,8 +12,11 @@ use rustc_errors::struct_span_err;
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::def::{DefKind, Res};
|
use rustc_hir::def::{DefKind, Res};
|
||||||
use rustc_hir::def_id::{LocalDefId, CRATE_DEF_ID};
|
use rustc_hir::def_id::{LocalDefId, CRATE_DEF_ID};
|
||||||
|
use rustc_hir::definitions::Definitions;
|
||||||
use rustc_hir::PredicateOrigin;
|
use rustc_hir::PredicateOrigin;
|
||||||
use rustc_index::vec::{Idx, IndexVec};
|
use rustc_index::vec::{Idx, IndexVec};
|
||||||
|
use rustc_middle::ty::{ResolverAstLowering, ResolverOutputs};
|
||||||
|
use rustc_session::cstore::CrateStoreDyn;
|
||||||
use rustc_session::Session;
|
use rustc_session::Session;
|
||||||
use rustc_span::source_map::DesugaringKind;
|
use rustc_span::source_map::DesugaringKind;
|
||||||
use rustc_span::symbol::{kw, sym, Ident};
|
use rustc_span::symbol::{kw, sym, Ident};
|
||||||
|
@ -24,7 +28,10 @@ use std::iter;
|
||||||
|
|
||||||
pub(super) struct ItemLowerer<'a, 'hir> {
|
pub(super) struct ItemLowerer<'a, 'hir> {
|
||||||
pub(super) sess: &'a Session,
|
pub(super) sess: &'a Session,
|
||||||
pub(super) resolver: &'a mut dyn ResolverAstLowering,
|
pub(super) definitions: &'a mut Definitions,
|
||||||
|
pub(super) cstore: &'a CrateStoreDyn,
|
||||||
|
pub(super) resolutions: &'a ResolverOutputs,
|
||||||
|
pub(super) resolver: &'a mut ResolverAstLowering,
|
||||||
pub(super) arena: &'hir Arena<'hir>,
|
pub(super) arena: &'hir Arena<'hir>,
|
||||||
pub(super) ast_index: &'a IndexVec<LocalDefId, AstOwner<'a>>,
|
pub(super) ast_index: &'a IndexVec<LocalDefId, AstOwner<'a>>,
|
||||||
pub(super) owners: &'a mut IndexVec<LocalDefId, hir::MaybeOwner<&'hir hir::OwnerInfo<'hir>>>,
|
pub(super) owners: &'a mut IndexVec<LocalDefId, hir::MaybeOwner<&'hir hir::OwnerInfo<'hir>>>,
|
||||||
|
@ -59,6 +66,9 @@ impl<'a, 'hir> ItemLowerer<'a, 'hir> {
|
||||||
let mut lctx = LoweringContext {
|
let mut lctx = LoweringContext {
|
||||||
// Pseudo-globals.
|
// Pseudo-globals.
|
||||||
sess: &self.sess,
|
sess: &self.sess,
|
||||||
|
definitions: self.definitions,
|
||||||
|
cstore: self.cstore,
|
||||||
|
resolutions: self.resolutions,
|
||||||
resolver: self.resolver,
|
resolver: self.resolver,
|
||||||
arena: self.arena,
|
arena: self.arena,
|
||||||
|
|
||||||
|
@ -118,8 +128,7 @@ impl<'a, 'hir> ItemLowerer<'a, 'hir> {
|
||||||
|
|
||||||
#[instrument(level = "debug", skip(self, c))]
|
#[instrument(level = "debug", skip(self, c))]
|
||||||
fn lower_crate(&mut self, c: &Crate) {
|
fn lower_crate(&mut self, c: &Crate) {
|
||||||
debug_assert_eq!(self.resolver.local_def_id(CRATE_NODE_ID), CRATE_DEF_ID);
|
debug_assert_eq!(self.resolver.node_id_to_def_id[&CRATE_NODE_ID], CRATE_DEF_ID);
|
||||||
|
|
||||||
self.with_lctx(CRATE_NODE_ID, |lctx| {
|
self.with_lctx(CRATE_NODE_ID, |lctx| {
|
||||||
let module = lctx.lower_mod(&c.items, &c.spans);
|
let module = lctx.lower_mod(&c.items, &c.spans);
|
||||||
lctx.lower_attrs(hir::CRATE_HIR_ID, &c.attrs);
|
lctx.lower_attrs(hir::CRATE_HIR_ID, &c.attrs);
|
||||||
|
@ -133,10 +142,10 @@ impl<'a, 'hir> ItemLowerer<'a, 'hir> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn lower_assoc_item(&mut self, item: &AssocItem, ctxt: AssocCtxt) {
|
fn lower_assoc_item(&mut self, item: &AssocItem, ctxt: AssocCtxt) {
|
||||||
let def_id = self.resolver.local_def_id(item.id);
|
let def_id = self.resolver.node_id_to_def_id[&item.id];
|
||||||
|
|
||||||
let parent_id = {
|
let parent_id = {
|
||||||
let parent = self.resolver.definitions().def_key(def_id).parent;
|
let parent = self.definitions.def_key(def_id).parent;
|
||||||
let local_def_index = parent.unwrap();
|
let local_def_index = parent.unwrap();
|
||||||
LocalDefId { local_def_index }
|
LocalDefId { local_def_index }
|
||||||
};
|
};
|
||||||
|
@ -177,7 +186,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn lower_item_ref(&mut self, i: &Item) -> SmallVec<[hir::ItemId; 1]> {
|
pub(super) fn lower_item_ref(&mut self, i: &Item) -> SmallVec<[hir::ItemId; 1]> {
|
||||||
let mut node_ids = smallvec![hir::ItemId { def_id: self.resolver.local_def_id(i.id) }];
|
let mut node_ids = smallvec![hir::ItemId { def_id: self.local_def_id(i.id) }];
|
||||||
if let ItemKind::Use(ref use_tree) = &i.kind {
|
if let ItemKind::Use(ref use_tree) = &i.kind {
|
||||||
self.lower_item_id_use_tree(use_tree, i.id, &mut node_ids);
|
self.lower_item_id_use_tree(use_tree, i.id, &mut node_ids);
|
||||||
}
|
}
|
||||||
|
@ -193,7 +202,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||||
match tree.kind {
|
match tree.kind {
|
||||||
UseTreeKind::Nested(ref nested_vec) => {
|
UseTreeKind::Nested(ref nested_vec) => {
|
||||||
for &(ref nested, id) in nested_vec {
|
for &(ref nested, id) in nested_vec {
|
||||||
vec.push(hir::ItemId { def_id: self.resolver.local_def_id(id) });
|
vec.push(hir::ItemId { def_id: self.local_def_id(id) });
|
||||||
self.lower_item_id_use_tree(nested, id, vec);
|
self.lower_item_id_use_tree(nested, id, vec);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -202,7 +211,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||||
for (_, &id) in
|
for (_, &id) in
|
||||||
iter::zip(self.expect_full_res_from_use(base_id).skip(1), &[id1, id2])
|
iter::zip(self.expect_full_res_from_use(base_id).skip(1), &[id1, id2])
|
||||||
{
|
{
|
||||||
vec.push(hir::ItemId { def_id: self.resolver.local_def_id(id) });
|
vec.push(hir::ItemId { def_id: self.local_def_id(id) });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -467,7 +476,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||||
}
|
}
|
||||||
ItemKind::MacroDef(MacroDef { ref body, macro_rules }) => {
|
ItemKind::MacroDef(MacroDef { ref body, macro_rules }) => {
|
||||||
let body = P(self.lower_mac_args(body));
|
let body = P(self.lower_mac_args(body));
|
||||||
let macro_kind = self.resolver.decl_macro_kind(self.resolver.local_def_id(id));
|
let macro_kind = self.resolver.decl_macro_kind(self.local_def_id(id));
|
||||||
hir::ItemKind::Macro(ast::MacroDef { body, macro_rules }, macro_kind)
|
hir::ItemKind::Macro(ast::MacroDef { body, macro_rules }, macro_kind)
|
||||||
}
|
}
|
||||||
ItemKind::MacCall(..) => {
|
ItemKind::MacCall(..) => {
|
||||||
|
@ -527,7 +536,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||||
// Essentially a single `use` which imports two names is desugared into
|
// Essentially a single `use` which imports two names is desugared into
|
||||||
// two imports.
|
// two imports.
|
||||||
for new_node_id in [id1, id2] {
|
for new_node_id in [id1, id2] {
|
||||||
let new_id = self.resolver.local_def_id(new_node_id);
|
let new_id = self.local_def_id(new_node_id);
|
||||||
let Some(res) = resolutions.next() else {
|
let Some(res) = resolutions.next() else {
|
||||||
// Associate an HirId to both ids even if there is no resolution.
|
// Associate an HirId to both ids even if there is no resolution.
|
||||||
let _old = self.children.insert(
|
let _old = self.children.insert(
|
||||||
|
@ -540,7 +549,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||||
let ident = *ident;
|
let ident = *ident;
|
||||||
let mut path = path.clone();
|
let mut path = path.clone();
|
||||||
for seg in &mut path.segments {
|
for seg in &mut path.segments {
|
||||||
seg.id = self.resolver.next_node_id();
|
seg.id = self.next_node_id();
|
||||||
}
|
}
|
||||||
let span = path.span;
|
let span = path.span;
|
||||||
|
|
||||||
|
@ -603,13 +612,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||||
|
|
||||||
// Add all the nested `PathListItem`s to the HIR.
|
// Add all the nested `PathListItem`s to the HIR.
|
||||||
for &(ref use_tree, id) in trees {
|
for &(ref use_tree, id) in trees {
|
||||||
let new_hir_id = self.resolver.local_def_id(id);
|
let new_hir_id = self.local_def_id(id);
|
||||||
|
|
||||||
let mut prefix = prefix.clone();
|
let mut prefix = prefix.clone();
|
||||||
|
|
||||||
// Give the segments new node-ids since they are being cloned.
|
// Give the segments new node-ids since they are being cloned.
|
||||||
for seg in &mut prefix.segments {
|
for seg in &mut prefix.segments {
|
||||||
seg.id = self.resolver.next_node_id();
|
seg.id = self.next_node_id();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Each `use` import is an item and thus are owners of the
|
// Each `use` import is an item and thus are owners of the
|
||||||
|
@ -683,7 +692,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||||
|
|
||||||
fn lower_foreign_item_ref(&mut self, i: &ForeignItem) -> hir::ForeignItemRef {
|
fn lower_foreign_item_ref(&mut self, i: &ForeignItem) -> hir::ForeignItemRef {
|
||||||
hir::ForeignItemRef {
|
hir::ForeignItemRef {
|
||||||
id: hir::ForeignItemId { def_id: self.resolver.local_def_id(i.id) },
|
id: hir::ForeignItemId { def_id: self.local_def_id(i.id) },
|
||||||
ident: self.lower_ident(i.ident),
|
ident: self.lower_ident(i.ident),
|
||||||
span: self.lower_span(i.span),
|
span: self.lower_span(i.span),
|
||||||
}
|
}
|
||||||
|
@ -839,7 +848,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||||
}
|
}
|
||||||
AssocItemKind::MacCall(..) => unimplemented!(),
|
AssocItemKind::MacCall(..) => unimplemented!(),
|
||||||
};
|
};
|
||||||
let id = hir::TraitItemId { def_id: self.resolver.local_def_id(i.id) };
|
let id = hir::TraitItemId { def_id: self.local_def_id(i.id) };
|
||||||
let defaultness = hir::Defaultness::Default { has_value: has_default };
|
let defaultness = hir::Defaultness::Default { has_value: has_default };
|
||||||
hir::TraitItemRef {
|
hir::TraitItemRef {
|
||||||
id,
|
id,
|
||||||
|
@ -919,7 +928,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||||
let has_value = true;
|
let has_value = true;
|
||||||
let (defaultness, _) = self.lower_defaultness(i.kind.defaultness(), has_value);
|
let (defaultness, _) = self.lower_defaultness(i.kind.defaultness(), has_value);
|
||||||
hir::ImplItemRef {
|
hir::ImplItemRef {
|
||||||
id: hir::ImplItemId { def_id: self.resolver.local_def_id(i.id) },
|
id: hir::ImplItemId { def_id: self.local_def_id(i.id) },
|
||||||
ident: self.lower_ident(i.ident),
|
ident: self.lower_ident(i.ident),
|
||||||
span: self.lower_span(i.span),
|
span: self.lower_span(i.span),
|
||||||
defaultness,
|
defaultness,
|
||||||
|
@ -1331,7 +1340,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||||
generics
|
generics
|
||||||
.params
|
.params
|
||||||
.iter()
|
.iter()
|
||||||
.any(|p| def_id == self.resolver.local_def_id(p.id).to_def_id())
|
.any(|p| def_id == self.local_def_id(p.id).to_def_id())
|
||||||
}
|
}
|
||||||
// Either the `bounded_ty` is not a plain type parameter, or
|
// Either the `bounded_ty` is not a plain type parameter, or
|
||||||
// it's not found in the generic type parameters list.
|
// it's not found in the generic type parameters list.
|
||||||
|
@ -1435,7 +1444,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||||
match kind {
|
match kind {
|
||||||
GenericParamKind::Const { .. } => None,
|
GenericParamKind::Const { .. } => None,
|
||||||
GenericParamKind::Type { .. } => {
|
GenericParamKind::Type { .. } => {
|
||||||
let def_id = self.resolver.local_def_id(id).to_def_id();
|
let def_id = self.local_def_id(id).to_def_id();
|
||||||
let ty_path = self.arena.alloc(hir::Path {
|
let ty_path = self.arena.alloc(hir::Path {
|
||||||
span: param_span,
|
span: param_span,
|
||||||
res: Res::Def(DefKind::TyParam, def_id),
|
res: Res::Def(DefKind::TyParam, def_id),
|
||||||
|
@ -1458,7 +1467,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||||
let res = self.resolver.get_lifetime_res(id).unwrap_or_else(|| {
|
let res = self.resolver.get_lifetime_res(id).unwrap_or_else(|| {
|
||||||
panic!("Missing resolution for lifetime {:?} at {:?}", id, ident.span)
|
panic!("Missing resolution for lifetime {:?} at {:?}", id, ident.span)
|
||||||
});
|
});
|
||||||
let lt_id = self.resolver.next_node_id();
|
let lt_id = self.next_node_id();
|
||||||
let lifetime = self.new_named_lifetime_with_res(lt_id, ident_span, ident, res);
|
let lifetime = self.new_named_lifetime_with_res(lt_id, ident_span, ident, res);
|
||||||
Some(hir::WherePredicate::RegionPredicate(hir::WhereRegionPredicate {
|
Some(hir::WherePredicate::RegionPredicate(hir::WhereRegionPredicate {
|
||||||
lifetime,
|
lifetime,
|
||||||
|
|
|
@ -51,15 +51,17 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
|
||||||
use rustc_data_structures::sync::Lrc;
|
use rustc_data_structures::sync::Lrc;
|
||||||
use rustc_errors::{struct_span_err, Applicability};
|
use rustc_errors::{struct_span_err, Applicability};
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::def::{DefKind, Namespace, PartialRes, PerNS, Res};
|
use rustc_hir::def::{DefKind, LifetimeRes, Namespace, PartialRes, PerNS, Res};
|
||||||
use rustc_hir::def_id::{DefId, DefPathHash, LocalDefId, CRATE_DEF_ID};
|
use rustc_hir::def_id::{LocalDefId, CRATE_DEF_ID};
|
||||||
use rustc_hir::definitions::{DefKey, DefPathData, Definitions};
|
use rustc_hir::definitions::{DefPathData, Definitions};
|
||||||
use rustc_hir::{ConstArg, GenericArg, ItemLocalId, ParamName, TraitCandidate};
|
use rustc_hir::{ConstArg, GenericArg, ItemLocalId, ParamName, TraitCandidate};
|
||||||
use rustc_index::vec::{Idx, IndexVec};
|
use rustc_index::vec::{Idx, IndexVec};
|
||||||
|
use rustc_middle::ty::{ResolverAstLowering, ResolverOutputs};
|
||||||
use rustc_query_system::ich::StableHashingContext;
|
use rustc_query_system::ich::StableHashingContext;
|
||||||
|
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};
|
||||||
|
@ -87,7 +89,10 @@ struct LoweringContext<'a, 'hir: 'a> {
|
||||||
/// Used to assign IDs to HIR nodes that do not directly correspond to AST nodes.
|
/// Used to assign IDs to HIR nodes that do not directly correspond to AST nodes.
|
||||||
sess: &'a Session,
|
sess: &'a Session,
|
||||||
|
|
||||||
resolver: &'a mut dyn ResolverAstLowering,
|
definitions: &'a mut Definitions,
|
||||||
|
cstore: &'a CrateStoreDyn,
|
||||||
|
resolutions: &'a ResolverOutputs,
|
||||||
|
resolver: &'a mut ResolverAstLowering,
|
||||||
|
|
||||||
/// Used to allocate HIR nodes.
|
/// Used to allocate HIR nodes.
|
||||||
arena: &'hir Arena<'hir>,
|
arena: &'hir Arena<'hir>,
|
||||||
|
@ -134,46 +139,6 @@ struct LoweringContext<'a, 'hir: 'a> {
|
||||||
allow_into_future: Option<Lrc<[Symbol]>>,
|
allow_into_future: Option<Lrc<[Symbol]>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Resolution for a lifetime appearing in a type.
|
|
||||||
#[derive(Copy, Clone, Debug)]
|
|
||||||
pub enum LifetimeRes {
|
|
||||||
/// Successfully linked the lifetime to a generic parameter.
|
|
||||||
Param {
|
|
||||||
/// Id of the generic parameter that introduced it.
|
|
||||||
param: LocalDefId,
|
|
||||||
/// Id of the introducing place. That can be:
|
|
||||||
/// - an item's id, for the item's generic parameters;
|
|
||||||
/// - a TraitRef's ref_id, identifying the `for<...>` binder;
|
|
||||||
/// - a BareFn type's id;
|
|
||||||
/// - a Path's id when this path has parenthesized generic args.
|
|
||||||
///
|
|
||||||
/// This information is used for impl-trait lifetime captures, to know when to or not to
|
|
||||||
/// capture any given lifetime.
|
|
||||||
binder: NodeId,
|
|
||||||
},
|
|
||||||
/// Created a generic parameter for an anonymous lifetime.
|
|
||||||
Fresh {
|
|
||||||
/// Id of the generic parameter that introduced it.
|
|
||||||
param: LocalDefId,
|
|
||||||
/// Id of the introducing place. See `Param`.
|
|
||||||
binder: NodeId,
|
|
||||||
},
|
|
||||||
/// This variant is used for anonymous lifetimes that we did not resolve during
|
|
||||||
/// late resolution. Shifting the work to the HIR lifetime resolver.
|
|
||||||
Anonymous {
|
|
||||||
/// Id of the introducing place. See `Param`.
|
|
||||||
binder: NodeId,
|
|
||||||
/// Whether this lifetime was spelled or elided.
|
|
||||||
elided: bool,
|
|
||||||
},
|
|
||||||
/// Explicit `'static` lifetime.
|
|
||||||
Static,
|
|
||||||
/// Resolution failure.
|
|
||||||
Error,
|
|
||||||
/// HACK: This is used to recover the NodeId of an elided lifetime.
|
|
||||||
ElidedAnchor { start: NodeId, end: NodeId },
|
|
||||||
}
|
|
||||||
|
|
||||||
/// When we lower a lifetime, it is inserted in `captures`, and the resolution is modified so
|
/// When we lower a lifetime, it is inserted in `captures`, and the resolution is modified so
|
||||||
/// to point to the lifetime parameter impl-trait will generate.
|
/// to point to the lifetime parameter impl-trait will generate.
|
||||||
/// When traversing `for<...>` binders, they are inserted in `binders_to_ignore` so we know *not*
|
/// When traversing `for<...>` binders, they are inserted in `binders_to_ignore` so we know *not*
|
||||||
|
@ -196,54 +161,75 @@ struct LifetimeCaptureContext {
|
||||||
binders_to_ignore: FxHashSet<NodeId>,
|
binders_to_ignore: FxHashSet<NodeId>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait ResolverAstLowering {
|
trait ResolverAstLoweringExt {
|
||||||
fn def_key(&self, id: DefId) -> DefKey;
|
fn legacy_const_generic_args(&self, expr: &Expr) -> Option<Vec<usize>>;
|
||||||
|
fn get_partial_res(&self, id: NodeId) -> Option<PartialRes>;
|
||||||
|
fn get_import_res(&self, id: NodeId) -> PerNS<Option<Res<NodeId>>>;
|
||||||
|
fn get_label_res(&self, id: NodeId) -> Option<NodeId>;
|
||||||
|
fn get_lifetime_res(&self, id: NodeId) -> Option<LifetimeRes>;
|
||||||
|
fn take_extra_lifetime_params(&mut self, id: NodeId) -> Vec<(Ident, NodeId, LifetimeRes)>;
|
||||||
|
fn decl_macro_kind(&self, def_id: LocalDefId) -> MacroKind;
|
||||||
|
}
|
||||||
|
|
||||||
fn def_span(&self, id: LocalDefId) -> Span;
|
impl ResolverAstLoweringExt for ResolverAstLowering {
|
||||||
|
fn legacy_const_generic_args(&self, expr: &Expr) -> Option<Vec<usize>> {
|
||||||
|
if let ExprKind::Path(None, path) = &expr.kind {
|
||||||
|
// Don't perform legacy const generics rewriting if the path already
|
||||||
|
// has generic arguments.
|
||||||
|
if path.segments.last().unwrap().args.is_some() {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
|
||||||
fn item_generics_num_lifetimes(&self, def: DefId) -> usize;
|
let partial_res = self.partial_res_map.get(&expr.id)?;
|
||||||
|
if partial_res.unresolved_segments() != 0 {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
|
||||||
fn legacy_const_generic_args(&mut self, expr: &Expr) -> Option<Vec<usize>>;
|
if let Res::Def(DefKind::Fn, def_id) = partial_res.base_res() {
|
||||||
|
// We only support cross-crate argument rewriting. Uses
|
||||||
|
// within the same crate should be updated to use the new
|
||||||
|
// const generics style.
|
||||||
|
if def_id.is_local() {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(v) = self.legacy_const_generic_args.get(&def_id) {
|
||||||
|
return v.clone();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
/// Obtains resolution for a `NodeId` with a single resolution.
|
/// Obtains resolution for a `NodeId` with a single resolution.
|
||||||
fn get_partial_res(&self, id: NodeId) -> Option<PartialRes>;
|
fn get_partial_res(&self, id: NodeId) -> Option<PartialRes> {
|
||||||
|
self.partial_res_map.get(&id).copied()
|
||||||
|
}
|
||||||
|
|
||||||
/// Obtains per-namespace resolutions for `use` statement with the given `NodeId`.
|
/// Obtains per-namespace resolutions for `use` statement with the given `NodeId`.
|
||||||
fn get_import_res(&self, id: NodeId) -> PerNS<Option<Res<NodeId>>>;
|
fn get_import_res(&self, id: NodeId) -> PerNS<Option<Res<NodeId>>> {
|
||||||
|
self.import_res_map.get(&id).copied().unwrap_or_default()
|
||||||
|
}
|
||||||
|
|
||||||
/// Obtains resolution for a label with the given `NodeId`.
|
/// Obtains resolution for a label with the given `NodeId`.
|
||||||
fn get_label_res(&self, id: NodeId) -> Option<NodeId>;
|
fn get_label_res(&self, id: NodeId) -> Option<NodeId> {
|
||||||
|
self.label_res_map.get(&id).copied()
|
||||||
|
}
|
||||||
|
|
||||||
/// Obtains resolution for a lifetime with the given `NodeId`.
|
/// Obtains resolution for a lifetime with the given `NodeId`.
|
||||||
fn get_lifetime_res(&self, id: NodeId) -> Option<LifetimeRes>;
|
fn get_lifetime_res(&self, id: NodeId) -> Option<LifetimeRes> {
|
||||||
|
self.lifetimes_res_map.get(&id).copied()
|
||||||
|
}
|
||||||
|
|
||||||
/// Obtain the list of lifetimes parameters to add to an item.
|
/// Obtain the list of lifetimes parameters to add to an item.
|
||||||
fn take_extra_lifetime_params(&mut self, id: NodeId) -> Vec<(Ident, NodeId, LifetimeRes)>;
|
fn take_extra_lifetime_params(&mut self, id: NodeId) -> Vec<(Ident, NodeId, LifetimeRes)> {
|
||||||
|
self.extra_lifetime_params_map.remove(&id).unwrap_or_default()
|
||||||
|
}
|
||||||
|
|
||||||
fn create_stable_hashing_context(&self) -> StableHashingContext<'_>;
|
fn decl_macro_kind(&self, def_id: LocalDefId) -> MacroKind {
|
||||||
|
self.builtin_macro_kinds.get(&def_id).copied().unwrap_or(MacroKind::Bang)
|
||||||
fn definitions(&self) -> &Definitions;
|
}
|
||||||
|
|
||||||
fn next_node_id(&mut self) -> NodeId;
|
|
||||||
|
|
||||||
fn take_trait_map(&mut self, node: NodeId) -> Option<Vec<hir::TraitCandidate>>;
|
|
||||||
|
|
||||||
fn opt_local_def_id(&self, node: NodeId) -> Option<LocalDefId>;
|
|
||||||
|
|
||||||
fn local_def_id(&self, node: NodeId) -> LocalDefId;
|
|
||||||
|
|
||||||
fn def_path_hash(&self, def_id: DefId) -> DefPathHash;
|
|
||||||
|
|
||||||
fn create_def(
|
|
||||||
&mut self,
|
|
||||||
parent: LocalDefId,
|
|
||||||
node_id: ast::NodeId,
|
|
||||||
data: DefPathData,
|
|
||||||
expn_id: ExpnId,
|
|
||||||
span: Span,
|
|
||||||
) -> LocalDefId;
|
|
||||||
|
|
||||||
fn decl_macro_kind(&self, def_id: LocalDefId) -> MacroKind;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Context of `impl Trait` in code, which determines whether it is allowed in an HIR subtree,
|
/// Context of `impl Trait` in code, which determines whether it is allowed in an HIR subtree,
|
||||||
|
@ -353,17 +339,17 @@ enum AstOwner<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn index_crate<'a>(
|
fn index_crate<'a>(
|
||||||
resolver: &dyn ResolverAstLowering,
|
node_id_to_def_id: &FxHashMap<NodeId, LocalDefId>,
|
||||||
krate: &'a Crate,
|
krate: &'a Crate,
|
||||||
) -> IndexVec<LocalDefId, AstOwner<'a>> {
|
) -> IndexVec<LocalDefId, AstOwner<'a>> {
|
||||||
let mut indexer = Indexer { resolver, index: IndexVec::new() };
|
let mut indexer = Indexer { node_id_to_def_id, index: IndexVec::new() };
|
||||||
indexer.index.ensure_contains_elem(CRATE_DEF_ID, || AstOwner::NonOwner);
|
indexer.index.ensure_contains_elem(CRATE_DEF_ID, || AstOwner::NonOwner);
|
||||||
indexer.index[CRATE_DEF_ID] = AstOwner::Crate(krate);
|
indexer.index[CRATE_DEF_ID] = AstOwner::Crate(krate);
|
||||||
visit::walk_crate(&mut indexer, krate);
|
visit::walk_crate(&mut indexer, krate);
|
||||||
return indexer.index;
|
return indexer.index;
|
||||||
|
|
||||||
struct Indexer<'s, 'a> {
|
struct Indexer<'s, 'a> {
|
||||||
resolver: &'s dyn ResolverAstLowering,
|
node_id_to_def_id: &'s FxHashMap<NodeId, LocalDefId>,
|
||||||
index: IndexVec<LocalDefId, AstOwner<'a>>,
|
index: IndexVec<LocalDefId, AstOwner<'a>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -374,21 +360,21 @@ fn index_crate<'a>(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_item(&mut self, item: &'a ast::Item) {
|
fn visit_item(&mut self, item: &'a ast::Item) {
|
||||||
let def_id = self.resolver.local_def_id(item.id);
|
let def_id = self.node_id_to_def_id[&item.id];
|
||||||
self.index.ensure_contains_elem(def_id, || AstOwner::NonOwner);
|
self.index.ensure_contains_elem(def_id, || AstOwner::NonOwner);
|
||||||
self.index[def_id] = AstOwner::Item(item);
|
self.index[def_id] = AstOwner::Item(item);
|
||||||
visit::walk_item(self, item)
|
visit::walk_item(self, item)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_assoc_item(&mut self, item: &'a ast::AssocItem, ctxt: visit::AssocCtxt) {
|
fn visit_assoc_item(&mut self, item: &'a ast::AssocItem, ctxt: visit::AssocCtxt) {
|
||||||
let def_id = self.resolver.local_def_id(item.id);
|
let def_id = self.node_id_to_def_id[&item.id];
|
||||||
self.index.ensure_contains_elem(def_id, || AstOwner::NonOwner);
|
self.index.ensure_contains_elem(def_id, || AstOwner::NonOwner);
|
||||||
self.index[def_id] = AstOwner::AssocItem(item, ctxt);
|
self.index[def_id] = AstOwner::AssocItem(item, ctxt);
|
||||||
visit::walk_assoc_item(self, item, ctxt);
|
visit::walk_assoc_item(self, item, ctxt);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_foreign_item(&mut self, item: &'a ast::ForeignItem) {
|
fn visit_foreign_item(&mut self, item: &'a ast::ForeignItem) {
|
||||||
let def_id = self.resolver.local_def_id(item.id);
|
let def_id = self.node_id_to_def_id[&item.id];
|
||||||
self.index.ensure_contains_elem(def_id, || AstOwner::NonOwner);
|
self.index.ensure_contains_elem(def_id, || AstOwner::NonOwner);
|
||||||
self.index[def_id] = AstOwner::ForeignItem(item);
|
self.index[def_id] = AstOwner::ForeignItem(item);
|
||||||
visit::walk_foreign_item(self, item);
|
visit::walk_foreign_item(self, item);
|
||||||
|
@ -399,44 +385,59 @@ fn index_crate<'a>(
|
||||||
/// Compute the hash for the HIR of the full crate.
|
/// Compute the hash for the HIR of the full crate.
|
||||||
/// This hash will then be part of the crate_hash which is stored in the metadata.
|
/// This hash will then be part of the crate_hash which is stored in the metadata.
|
||||||
fn compute_hir_hash(
|
fn compute_hir_hash(
|
||||||
resolver: &mut dyn ResolverAstLowering,
|
sess: &Session,
|
||||||
|
definitions: &Definitions,
|
||||||
|
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
|
||||||
.iter_enumerated()
|
.iter_enumerated()
|
||||||
.filter_map(|(def_id, info)| {
|
.filter_map(|(def_id, info)| {
|
||||||
let info = info.as_owner()?;
|
let info = info.as_owner()?;
|
||||||
let def_path_hash = resolver.definitions().def_path_hash(def_id);
|
let def_path_hash = definitions.def_path_hash(def_id);
|
||||||
Some((def_path_hash, info))
|
Some((def_path_hash, info))
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
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 = resolver.create_stable_hashing_context();
|
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()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn lower_crate<'a, 'hir>(
|
pub fn lower_crate<'hir>(
|
||||||
sess: &'a Session,
|
sess: &Session,
|
||||||
krate: &'a Crate,
|
krate: &Crate,
|
||||||
resolver: &'a mut dyn ResolverAstLowering,
|
definitions: &mut Definitions,
|
||||||
|
cstore: &CrateStoreDyn,
|
||||||
|
resolutions: &ResolverOutputs,
|
||||||
|
mut resolver: ResolverAstLowering,
|
||||||
arena: &'hir Arena<'hir>,
|
arena: &'hir Arena<'hir>,
|
||||||
) -> &'hir hir::Crate<'hir> {
|
) -> &'hir hir::Crate<'hir> {
|
||||||
let _prof_timer = sess.prof.verbose_generic_activity("hir_lowering");
|
let _prof_timer = sess.prof.verbose_generic_activity("hir_lowering");
|
||||||
|
|
||||||
let ast_index = index_crate(resolver, krate);
|
let ast_index = index_crate(&resolver.node_id_to_def_id, krate);
|
||||||
|
|
||||||
let mut owners =
|
let mut owners =
|
||||||
IndexVec::from_fn_n(|_| hir::MaybeOwner::Phantom, resolver.definitions().def_index_count());
|
IndexVec::from_fn_n(|_| hir::MaybeOwner::Phantom, definitions.def_index_count());
|
||||||
|
|
||||||
for def_id in ast_index.indices() {
|
for def_id in ast_index.indices() {
|
||||||
item::ItemLowerer { sess, resolver, arena, ast_index: &ast_index, owners: &mut owners }
|
item::ItemLowerer {
|
||||||
.lower_node(def_id);
|
sess,
|
||||||
|
definitions,
|
||||||
|
cstore,
|
||||||
|
resolutions,
|
||||||
|
resolver: &mut resolver,
|
||||||
|
arena,
|
||||||
|
ast_index: &ast_index,
|
||||||
|
owners: &mut owners,
|
||||||
|
}
|
||||||
|
.lower_node(def_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
let hir_hash = compute_hir_hash(resolver, &owners);
|
let hir_hash = compute_hir_hash(sess, definitions, cstore, resolutions, &owners);
|
||||||
let krate = hir::Crate { owners, hir_hash };
|
let krate = hir::Crate { owners, hir_hash };
|
||||||
arena.alloc(krate)
|
arena.alloc(krate)
|
||||||
}
|
}
|
||||||
|
@ -457,13 +458,64 @@ enum ParenthesizedGenericArgs {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
|
fn create_stable_hashing_context(&self) -> StableHashingContext<'_> {
|
||||||
|
StableHashingContext::new(
|
||||||
|
self.sess,
|
||||||
|
self.definitions,
|
||||||
|
self.cstore,
|
||||||
|
&self.resolutions.source_span,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn create_def(
|
||||||
|
&mut self,
|
||||||
|
parent: LocalDefId,
|
||||||
|
node_id: ast::NodeId,
|
||||||
|
data: DefPathData,
|
||||||
|
) -> LocalDefId {
|
||||||
|
assert!(
|
||||||
|
self.opt_local_def_id(node_id).is_none(),
|
||||||
|
"adding a def'n for node-id {:?} and data {:?} but a previous def'n exists: {:?}",
|
||||||
|
node_id,
|
||||||
|
data,
|
||||||
|
self.definitions.def_key(self.local_def_id(node_id)),
|
||||||
|
);
|
||||||
|
|
||||||
|
let def_id = self.definitions.create_def(parent, data);
|
||||||
|
|
||||||
|
// 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
|
||||||
|
// we don't need a mapping from `NodeId` to `LocalDefId`.
|
||||||
|
if node_id != ast::DUMMY_NODE_ID {
|
||||||
|
debug!("create_def: def_id_to_node_id[{:?}] <-> {:?}", def_id, node_id);
|
||||||
|
self.resolver.node_id_to_def_id.insert(node_id, def_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
def_id
|
||||||
|
}
|
||||||
|
|
||||||
|
fn next_node_id(&mut self) -> NodeId {
|
||||||
|
let start = self.resolver.next_node_id;
|
||||||
|
let next = start.as_u32().checked_add(1).expect("input too large; ran out of NodeIds");
|
||||||
|
self.resolver.next_node_id = ast::NodeId::from_u32(next);
|
||||||
|
start
|
||||||
|
}
|
||||||
|
|
||||||
|
fn opt_local_def_id(&self, node: NodeId) -> Option<LocalDefId> {
|
||||||
|
self.resolver.node_id_to_def_id.get(&node).copied()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn local_def_id(&self, node: NodeId) -> LocalDefId {
|
||||||
|
self.opt_local_def_id(node).unwrap_or_else(|| panic!("no entry for node id: `{:?}`", node))
|
||||||
|
}
|
||||||
|
|
||||||
#[instrument(level = "debug", skip(self, f))]
|
#[instrument(level = "debug", skip(self, f))]
|
||||||
fn with_hir_id_owner(
|
fn with_hir_id_owner(
|
||||||
&mut self,
|
&mut self,
|
||||||
owner: NodeId,
|
owner: NodeId,
|
||||||
f: impl FnOnce(&mut Self) -> hir::OwnerNode<'hir>,
|
f: impl FnOnce(&mut Self) -> hir::OwnerNode<'hir>,
|
||||||
) {
|
) {
|
||||||
let def_id = self.resolver.local_def_id(owner);
|
let def_id = self.local_def_id(owner);
|
||||||
|
|
||||||
let current_attrs = std::mem::take(&mut self.attrs);
|
let current_attrs = std::mem::take(&mut self.attrs);
|
||||||
let current_bodies = std::mem::take(&mut self.bodies);
|
let current_bodies = std::mem::take(&mut self.bodies);
|
||||||
|
@ -475,6 +527,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
std::mem::replace(&mut self.item_local_id_counter, hir::ItemLocalId::new(1));
|
std::mem::replace(&mut self.item_local_id_counter, hir::ItemLocalId::new(1));
|
||||||
let current_impl_trait_defs = std::mem::take(&mut self.impl_trait_defs);
|
let current_impl_trait_defs = std::mem::take(&mut self.impl_trait_defs);
|
||||||
let current_impl_trait_bounds = std::mem::take(&mut self.impl_trait_bounds);
|
let current_impl_trait_bounds = std::mem::take(&mut self.impl_trait_bounds);
|
||||||
|
// Do not reset `next_node_id` and `node_id_to_def_id` as we want to refer to the
|
||||||
|
// subdefinitions' nodes.
|
||||||
|
|
||||||
// Always allocate the first `HirId` for the owner itself.
|
// Always allocate the first `HirId` for the owner itself.
|
||||||
let _old = self.node_id_to_local_id.insert(owner, hir::ItemLocalId::new(0));
|
let _old = self.node_id_to_local_id.insert(owner, hir::ItemLocalId::new(0));
|
||||||
|
@ -518,8 +572,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
bodies.sort_by_key(|(k, _)| *k);
|
bodies.sort_by_key(|(k, _)| *k);
|
||||||
let bodies = SortedMap::from_presorted_elements(bodies);
|
let bodies = SortedMap::from_presorted_elements(bodies);
|
||||||
let (hash_including_bodies, hash_without_bodies) = self.hash_owner(node, &bodies);
|
let (hash_including_bodies, hash_without_bodies) = self.hash_owner(node, &bodies);
|
||||||
let (nodes, parenting) =
|
let (nodes, parenting) = index::index_hir(self.sess, self.definitions, node, &bodies);
|
||||||
index::index_hir(self.sess, self.resolver.definitions(), node, &bodies);
|
|
||||||
let nodes = hir::OwnerNodes {
|
let nodes = hir::OwnerNodes {
|
||||||
hash_including_bodies,
|
hash_including_bodies,
|
||||||
hash_without_bodies,
|
hash_without_bodies,
|
||||||
|
@ -528,7 +581,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
local_id_to_def_id,
|
local_id_to_def_id,
|
||||||
};
|
};
|
||||||
let attrs = {
|
let attrs = {
|
||||||
let mut hcx = self.resolver.create_stable_hashing_context();
|
let mut hcx = self.create_stable_hashing_context();
|
||||||
let mut stable_hasher = StableHasher::new();
|
let mut stable_hasher = StableHasher::new();
|
||||||
attrs.hash_stable(&mut hcx, &mut stable_hasher);
|
attrs.hash_stable(&mut hcx, &mut stable_hasher);
|
||||||
let hash = stable_hasher.finish();
|
let hash = stable_hasher.finish();
|
||||||
|
@ -545,7 +598,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
node: hir::OwnerNode<'hir>,
|
node: hir::OwnerNode<'hir>,
|
||||||
bodies: &SortedMap<hir::ItemLocalId, &'hir hir::Body<'hir>>,
|
bodies: &SortedMap<hir::ItemLocalId, &'hir hir::Body<'hir>>,
|
||||||
) -> (Fingerprint, Fingerprint) {
|
) -> (Fingerprint, Fingerprint) {
|
||||||
let mut hcx = self.resolver.create_stable_hashing_context();
|
let mut hcx = self.create_stable_hashing_context();
|
||||||
let mut stable_hasher = StableHasher::new();
|
let mut stable_hasher = StableHasher::new();
|
||||||
hcx.with_hir_bodies(true, node.def_id(), bodies, |hcx| {
|
hcx.with_hir_bodies(true, node.def_id(), bodies, |hcx| {
|
||||||
node.hash_stable(hcx, &mut stable_hasher)
|
node.hash_stable(hcx, &mut stable_hasher)
|
||||||
|
@ -582,13 +635,13 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
self.item_local_id_counter.increment_by(1);
|
self.item_local_id_counter.increment_by(1);
|
||||||
|
|
||||||
assert_ne!(local_id, hir::ItemLocalId::new(0));
|
assert_ne!(local_id, hir::ItemLocalId::new(0));
|
||||||
if let Some(def_id) = self.resolver.opt_local_def_id(ast_node_id) {
|
if let Some(def_id) = self.opt_local_def_id(ast_node_id) {
|
||||||
// Do not override a `MaybeOwner::Owner` that may already here.
|
// Do not override a `MaybeOwner::Owner` that may already here.
|
||||||
self.children.entry(def_id).or_insert(hir::MaybeOwner::NonOwner(hir_id));
|
self.children.entry(def_id).or_insert(hir::MaybeOwner::NonOwner(hir_id));
|
||||||
self.local_id_to_def_id.insert(local_id, def_id);
|
self.local_id_to_def_id.insert(local_id, def_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(traits) = self.resolver.take_trait_map(ast_node_id) {
|
if let Some(traits) = self.resolver.trait_map.remove(&ast_node_id) {
|
||||||
self.trait_map.insert(hir_id.local_id, traits.into_boxed_slice());
|
self.trait_map.insert(hir_id.local_id, traits.into_boxed_slice());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -598,7 +651,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn next_id(&mut self) -> hir::HirId {
|
fn next_id(&mut self) -> hir::HirId {
|
||||||
let node_id = self.resolver.next_node_id();
|
let node_id = self.next_node_id();
|
||||||
self.lower_node_id(node_id)
|
self.lower_node_id(node_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -648,7 +701,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
allow_internal_unstable,
|
allow_internal_unstable,
|
||||||
reason,
|
reason,
|
||||||
self.sess.edition(),
|
self.sess.edition(),
|
||||||
self.resolver.create_stable_hashing_context(),
|
self.create_stable_hashing_context(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -940,17 +993,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
// constructing the HIR for `impl bounds...` and then lowering that.
|
// constructing the HIR for `impl bounds...` and then lowering that.
|
||||||
|
|
||||||
let parent_def_id = self.current_hir_id_owner;
|
let parent_def_id = self.current_hir_id_owner;
|
||||||
let impl_trait_node_id = self.resolver.next_node_id();
|
let impl_trait_node_id = self.next_node_id();
|
||||||
self.resolver.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.resolver.next_node_id();
|
let node_id = this.next_node_id();
|
||||||
let ty = this.lower_ty(
|
let ty = this.lower_ty(
|
||||||
&Ty {
|
&Ty {
|
||||||
id: node_id,
|
id: node_id,
|
||||||
|
@ -1050,16 +1097,10 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
// Construct an AnonConst where the expr is the "ty"'s path.
|
// Construct an AnonConst where the expr is the "ty"'s path.
|
||||||
|
|
||||||
let parent_def_id = self.current_hir_id_owner;
|
let parent_def_id = self.current_hir_id_owner;
|
||||||
let node_id = self.resolver.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.resolver.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 {
|
||||||
|
@ -1129,7 +1170,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
debug_assert_eq!(start.plus(1), end);
|
debug_assert_eq!(start.plus(1), end);
|
||||||
start
|
start
|
||||||
} else {
|
} else {
|
||||||
self.resolver.next_node_id()
|
self.next_node_id()
|
||||||
};
|
};
|
||||||
let span = self.sess.source_map().next_point(t.span.shrink_to_lo());
|
let span = self.sess.source_map().next_point(t.span.shrink_to_lo());
|
||||||
Lifetime { ident: Ident::new(kw::UnderscoreLifetime, span), id }
|
Lifetime { ident: Ident::new(kw::UnderscoreLifetime, span), id }
|
||||||
|
@ -1272,7 +1313,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
// frequently opened issues show.
|
// frequently opened issues show.
|
||||||
let opaque_ty_span = self.mark_span_with_reason(DesugaringKind::OpaqueTy, span, None);
|
let opaque_ty_span = self.mark_span_with_reason(DesugaringKind::OpaqueTy, span, None);
|
||||||
|
|
||||||
let opaque_ty_def_id = self.resolver.local_def_id(opaque_ty_node_id);
|
let opaque_ty_def_id = self.local_def_id(opaque_ty_node_id);
|
||||||
|
|
||||||
let mut collected_lifetimes = FxHashMap::default();
|
let mut collected_lifetimes = FxHashMap::default();
|
||||||
self.with_hir_id_owner(opaque_ty_node_id, |lctx| {
|
self.with_hir_id_owner(opaque_ty_node_id, |lctx| {
|
||||||
|
@ -1290,7 +1331,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
let lifetime_defs = lctx.arena.alloc_from_iter(collected_lifetimes.iter().map(
|
let lifetime_defs = lctx.arena.alloc_from_iter(collected_lifetimes.iter().map(
|
||||||
|(_, &(span, p_id, p_name, _))| {
|
|(_, &(span, p_id, p_name, _))| {
|
||||||
let hir_id = lctx.lower_node_id(p_id);
|
let hir_id = lctx.lower_node_id(p_id);
|
||||||
debug_assert_ne!(lctx.resolver.opt_local_def_id(p_id), None);
|
debug_assert_ne!(lctx.opt_local_def_id(p_id), None);
|
||||||
|
|
||||||
let kind = if p_name.ident().name == kw::UnderscoreLifetime {
|
let kind = if p_name.ident().name == kw::UnderscoreLifetime {
|
||||||
hir::LifetimeParamKind::Elided
|
hir::LifetimeParamKind::Elided
|
||||||
|
@ -1329,7 +1370,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
|
|
||||||
let lifetimes = self.arena.alloc_from_iter(collected_lifetimes.into_iter().map(
|
let lifetimes = self.arena.alloc_from_iter(collected_lifetimes.into_iter().map(
|
||||||
|(_, (span, _, p_name, res))| {
|
|(_, (span, _, p_name, res))| {
|
||||||
let id = self.resolver.next_node_id();
|
let id = self.next_node_id();
|
||||||
let ident = Ident::new(p_name.ident().name, span);
|
let ident = Ident::new(p_name.ident().name, span);
|
||||||
let l = self.new_named_lifetime_with_res(id, span, ident, res);
|
let l = self.new_named_lifetime_with_res(id, span, ident, res);
|
||||||
hir::GenericArg::Lifetime(l)
|
hir::GenericArg::Lifetime(l)
|
||||||
|
@ -1438,7 +1479,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
FnRetTy::Ty(ref ty) => {
|
FnRetTy::Ty(ref ty) => {
|
||||||
let context = match fn_node_id {
|
let context = match fn_node_id {
|
||||||
Some(fn_node_id) if kind.impl_trait_return_allowed() => {
|
Some(fn_node_id) if kind.impl_trait_return_allowed() => {
|
||||||
let fn_def_id = self.resolver.local_def_id(fn_node_id);
|
let fn_def_id = self.local_def_id(fn_node_id);
|
||||||
ImplTraitContext::ReturnPositionOpaqueTy {
|
ImplTraitContext::ReturnPositionOpaqueTy {
|
||||||
origin: hir::OpaqueTyOrigin::FnReturn(fn_def_id),
|
origin: hir::OpaqueTyOrigin::FnReturn(fn_def_id),
|
||||||
}
|
}
|
||||||
|
@ -1512,8 +1553,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
|
|
||||||
let opaque_ty_span = self.mark_span_with_reason(DesugaringKind::Async, span, None);
|
let opaque_ty_span = self.mark_span_with_reason(DesugaringKind::Async, span, None);
|
||||||
|
|
||||||
let opaque_ty_def_id = self.resolver.local_def_id(opaque_ty_node_id);
|
let opaque_ty_def_id = self.local_def_id(opaque_ty_node_id);
|
||||||
let fn_def_id = self.resolver.local_def_id(fn_node_id);
|
let fn_def_id = self.local_def_id(fn_node_id);
|
||||||
|
|
||||||
// When we create the opaque type for this async fn, it is going to have
|
// When we create the opaque type for this async fn, it is going to have
|
||||||
// to capture all the lifetimes involved in the signature (including in the
|
// to capture all the lifetimes involved in the signature (including in the
|
||||||
|
@ -1563,17 +1604,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
debug!(?extra_lifetime_params);
|
debug!(?extra_lifetime_params);
|
||||||
for (ident, outer_node_id, outer_res) in extra_lifetime_params {
|
for (ident, outer_node_id, outer_res) in extra_lifetime_params {
|
||||||
let Ident { name, span } = ident;
|
let Ident { name, span } = ident;
|
||||||
let outer_def_id = self.resolver.local_def_id(outer_node_id);
|
let outer_def_id = self.local_def_id(outer_node_id);
|
||||||
let inner_node_id = self.resolver.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.resolver.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`:
|
||||||
|
@ -1614,7 +1649,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
let generic_params =
|
let generic_params =
|
||||||
this.arena.alloc_from_iter(captures.iter().map(|(_, &(span, p_id, p_name, _))| {
|
this.arena.alloc_from_iter(captures.iter().map(|(_, &(span, p_id, p_name, _))| {
|
||||||
let hir_id = this.lower_node_id(p_id);
|
let hir_id = this.lower_node_id(p_id);
|
||||||
debug_assert_ne!(this.resolver.opt_local_def_id(p_id), None);
|
debug_assert_ne!(this.opt_local_def_id(p_id), None);
|
||||||
|
|
||||||
let kind = if p_name.ident().name == kw::UnderscoreLifetime {
|
let kind = if p_name.ident().name == kw::UnderscoreLifetime {
|
||||||
hir::LifetimeParamKind::Elided
|
hir::LifetimeParamKind::Elided
|
||||||
|
@ -1666,7 +1701,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
// generate `'_`.
|
// generate `'_`.
|
||||||
let generic_args =
|
let generic_args =
|
||||||
self.arena.alloc_from_iter(captures.into_iter().map(|(_, (span, _, p_name, res))| {
|
self.arena.alloc_from_iter(captures.into_iter().map(|(_, (span, _, p_name, res))| {
|
||||||
let id = self.resolver.next_node_id();
|
let id = self.next_node_id();
|
||||||
let ident = Ident::new(p_name.ident().name, span);
|
let ident = Ident::new(p_name.ident().name, span);
|
||||||
let l = self.new_named_lifetime_with_res(id, span, ident, res);
|
let l = self.new_named_lifetime_with_res(id, span, ident, res);
|
||||||
hir::GenericArg::Lifetime(l)
|
hir::GenericArg::Lifetime(l)
|
||||||
|
@ -1757,74 +1792,74 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
LifetimeRes::Param { mut param, binder } => {
|
LifetimeRes::Param { mut param, binder } => {
|
||||||
debug_assert_ne!(ident.name, kw::UnderscoreLifetime);
|
debug_assert_ne!(ident.name, kw::UnderscoreLifetime);
|
||||||
let p_name = ParamName::Plain(ident);
|
let p_name = ParamName::Plain(ident);
|
||||||
if let Some(LifetimeCaptureContext { parent_def_id, captures, binders_to_ignore }) =
|
if let Some(mut captured_lifetimes) = self.captured_lifetimes.take() {
|
||||||
&mut self.captured_lifetimes
|
if !captured_lifetimes.binders_to_ignore.contains(&binder) {
|
||||||
&& !binders_to_ignore.contains(&binder)
|
match captured_lifetimes.captures.entry(param) {
|
||||||
{
|
Entry::Occupied(o) => param = self.local_def_id(o.get().1),
|
||||||
match captures.entry(param) {
|
Entry::Vacant(v) => {
|
||||||
Entry::Occupied(o) => param = self.resolver.local_def_id(o.get().1),
|
let p_id = self.next_node_id();
|
||||||
Entry::Vacant(v) => {
|
let p_def_id = self.create_def(
|
||||||
let p_id = self.resolver.next_node_id();
|
captured_lifetimes.parent_def_id,
|
||||||
let p_def_id = self.resolver.create_def(
|
p_id,
|
||||||
*parent_def_id,
|
DefPathData::LifetimeNs(p_name.ident().name),
|
||||||
p_id,
|
);
|
||||||
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));
|
||||||
param = p_def_id;
|
param = p_def_id;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.captured_lifetimes = Some(captured_lifetimes);
|
||||||
}
|
}
|
||||||
hir::LifetimeName::Param(param, p_name)
|
hir::LifetimeName::Param(param, p_name)
|
||||||
}
|
}
|
||||||
LifetimeRes::Fresh { mut param, binder } => {
|
LifetimeRes::Fresh { mut param, binder } => {
|
||||||
debug_assert_eq!(ident.name, kw::UnderscoreLifetime);
|
debug_assert_eq!(ident.name, kw::UnderscoreLifetime);
|
||||||
if let Some(LifetimeCaptureContext { parent_def_id, captures, binders_to_ignore }) =
|
if let Some(mut captured_lifetimes) = self.captured_lifetimes.take() {
|
||||||
&mut self.captured_lifetimes
|
if !captured_lifetimes.binders_to_ignore.contains(&binder) {
|
||||||
&& !binders_to_ignore.contains(&binder)
|
match captured_lifetimes.captures.entry(param) {
|
||||||
{
|
Entry::Occupied(o) => param = self.local_def_id(o.get().1),
|
||||||
match captures.entry(param) {
|
Entry::Vacant(v) => {
|
||||||
Entry::Occupied(o) => param = self.resolver.local_def_id(o.get().1),
|
let p_id = self.next_node_id();
|
||||||
Entry::Vacant(v) => {
|
let p_def_id = self.create_def(
|
||||||
let p_id = self.resolver.next_node_id();
|
captured_lifetimes.parent_def_id,
|
||||||
let p_def_id = self.resolver.create_def(
|
p_id,
|
||||||
*parent_def_id,
|
DefPathData::LifetimeNs(kw::UnderscoreLifetime),
|
||||||
p_id,
|
);
|
||||||
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));
|
||||||
param = p_def_id;
|
param = p_def_id;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.captured_lifetimes = Some(captured_lifetimes);
|
||||||
}
|
}
|
||||||
hir::LifetimeName::Param(param, ParamName::Fresh)
|
hir::LifetimeName::Param(param, ParamName::Fresh)
|
||||||
}
|
}
|
||||||
LifetimeRes::Anonymous { binder, elided } => {
|
LifetimeRes::Anonymous { binder, elided } => {
|
||||||
if let Some(LifetimeCaptureContext { parent_def_id, captures, binders_to_ignore }) =
|
let mut l_name = None;
|
||||||
&mut self.captured_lifetimes
|
if let Some(mut captured_lifetimes) = self.captured_lifetimes.take() {
|
||||||
&& !binders_to_ignore.contains(&binder)
|
if !captured_lifetimes.binders_to_ignore.contains(&binder) {
|
||||||
{
|
let p_id = self.next_node_id();
|
||||||
let p_id = self.resolver.next_node_id();
|
let p_def_id = self.create_def(
|
||||||
let p_def_id = self.resolver.create_def(
|
captured_lifetimes.parent_def_id,
|
||||||
*parent_def_id,
|
p_id,
|
||||||
p_id,
|
DefPathData::LifetimeNs(kw::UnderscoreLifetime),
|
||||||
DefPathData::LifetimeNs(kw::UnderscoreLifetime),
|
);
|
||||||
ExpnId::root(),
|
captured_lifetimes
|
||||||
span.with_parent(None),
|
.captures
|
||||||
);
|
.insert(p_def_id, (span, p_id, ParamName::Fresh, res));
|
||||||
captures.insert(p_def_id, (span, p_id, ParamName::Fresh, res));
|
l_name = Some(hir::LifetimeName::Param(p_def_id, ParamName::Fresh));
|
||||||
hir::LifetimeName::Param(p_def_id, ParamName::Fresh)
|
}
|
||||||
} else if elided {
|
self.captured_lifetimes = Some(captured_lifetimes);
|
||||||
|
};
|
||||||
|
l_name.unwrap_or(if elided {
|
||||||
hir::LifetimeName::Implicit
|
hir::LifetimeName::Implicit
|
||||||
} else {
|
} else {
|
||||||
hir::LifetimeName::Underscore
|
hir::LifetimeName::Underscore
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
LifetimeRes::Static => hir::LifetimeName::Static,
|
LifetimeRes::Static => hir::LifetimeName::Static,
|
||||||
LifetimeRes::Error => hir::LifetimeName::Error,
|
LifetimeRes::Error => hir::LifetimeName::Error,
|
||||||
|
@ -1954,7 +1989,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
bounds: &[GenericBound],
|
bounds: &[GenericBound],
|
||||||
) -> (hir::GenericParam<'hir>, Option<hir::WherePredicate<'hir>>, hir::TyKind<'hir>) {
|
) -> (hir::GenericParam<'hir>, Option<hir::WherePredicate<'hir>>, hir::TyKind<'hir>) {
|
||||||
// Add a definition for the in-band `Param`.
|
// Add a definition for the in-band `Param`.
|
||||||
let def_id = self.resolver.local_def_id(node_id);
|
let def_id = self.local_def_id(node_id);
|
||||||
|
|
||||||
let hir_bounds = self.lower_param_bounds(bounds, ImplTraitContext::Universal);
|
let hir_bounds = self.lower_param_bounds(bounds, ImplTraitContext::Universal);
|
||||||
// Set the name to `impl Bound1 + Bound2`.
|
// Set the name to `impl Bound1 + Bound2`.
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::ImplTraitPosition;
|
use super::ResolverAstLoweringExt;
|
||||||
|
|
||||||
use super::{ImplTraitContext, LoweringContext, ParamMode};
|
use super::{ImplTraitContext, LoweringContext, ParamMode};
|
||||||
|
use crate::ImplTraitPosition;
|
||||||
|
|
||||||
use rustc_ast::ptr::P;
|
use rustc_ast::ptr::P;
|
||||||
use rustc_ast::*;
|
use rustc_ast::*;
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
use crate::ImplTraitPosition;
|
use crate::ImplTraitPosition;
|
||||||
|
|
||||||
|
use super::ResolverAstLoweringExt;
|
||||||
use super::{GenericArgsCtor, LifetimeRes, ParenthesizedGenericArgs};
|
use super::{GenericArgsCtor, LifetimeRes, ParenthesizedGenericArgs};
|
||||||
use super::{ImplTraitContext, LoweringContext, ParamMode};
|
use super::{ImplTraitContext, LoweringContext, ParamMode};
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
use crate::def_id::DefId;
|
|
||||||
use crate::hir;
|
use crate::hir;
|
||||||
|
|
||||||
use rustc_ast as ast;
|
use rustc_ast as ast;
|
||||||
use rustc_ast::NodeId;
|
use rustc_ast::NodeId;
|
||||||
use rustc_macros::HashStable_Generic;
|
use rustc_macros::HashStable_Generic;
|
||||||
|
use rustc_span::def_id::{DefId, LocalDefId};
|
||||||
use rustc_span::hygiene::MacroKind;
|
use rustc_span::hygiene::MacroKind;
|
||||||
use rustc_span::Symbol;
|
use rustc_span::Symbol;
|
||||||
|
|
||||||
|
@ -711,3 +711,43 @@ impl<Id> Res<Id> {
|
||||||
matches!(self, Res::Def(DefKind::Ctor(_, CtorKind::Const), _) | Res::SelfCtor(..))
|
matches!(self, Res::Def(DefKind::Ctor(_, CtorKind::Const), _) | Res::SelfCtor(..))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Resolution for a lifetime appearing in a type.
|
||||||
|
#[derive(Copy, Clone, Debug)]
|
||||||
|
pub enum LifetimeRes {
|
||||||
|
/// Successfully linked the lifetime to a generic parameter.
|
||||||
|
Param {
|
||||||
|
/// Id of the generic parameter that introduced it.
|
||||||
|
param: LocalDefId,
|
||||||
|
/// Id of the introducing place. That can be:
|
||||||
|
/// - an item's id, for the item's generic parameters;
|
||||||
|
/// - a TraitRef's ref_id, identifying the `for<...>` binder;
|
||||||
|
/// - a BareFn type's id;
|
||||||
|
/// - a Path's id when this path has parenthesized generic args.
|
||||||
|
///
|
||||||
|
/// This information is used for impl-trait lifetime captures, to know when to or not to
|
||||||
|
/// capture any given lifetime.
|
||||||
|
binder: NodeId,
|
||||||
|
},
|
||||||
|
/// Created a generic parameter for an anonymous lifetime.
|
||||||
|
Fresh {
|
||||||
|
/// Id of the generic parameter that introduced it.
|
||||||
|
param: LocalDefId,
|
||||||
|
/// Id of the introducing place. See `Param`.
|
||||||
|
binder: NodeId,
|
||||||
|
},
|
||||||
|
/// This variant is used for anonymous lifetimes that we did not resolve during
|
||||||
|
/// late resolution. Shifting the work to the HIR lifetime resolver.
|
||||||
|
Anonymous {
|
||||||
|
/// Id of the introducing place. See `Param`.
|
||||||
|
binder: NodeId,
|
||||||
|
/// Whether this lifetime was spelled or elided.
|
||||||
|
elided: bool,
|
||||||
|
},
|
||||||
|
/// Explicit `'static` lifetime.
|
||||||
|
Static,
|
||||||
|
/// Resolution failure.
|
||||||
|
Error,
|
||||||
|
/// HACK: This is used to recover the NodeId of an elided lifetime.
|
||||||
|
ElidedAnchor { start: NodeId, end: NodeId },
|
||||||
|
}
|
||||||
|
|
|
@ -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> + '_ {
|
||||||
|
|
|
@ -13,6 +13,7 @@ use rustc_data_structures::temp_dir::MaybeTempDir;
|
||||||
use rustc_errors::{Applicability, ErrorGuaranteed, MultiSpan, PResult};
|
use rustc_errors::{Applicability, ErrorGuaranteed, MultiSpan, PResult};
|
||||||
use rustc_expand::base::{ExtCtxt, LintStoreExpand, ResolverExpand};
|
use rustc_expand::base::{ExtCtxt, LintStoreExpand, ResolverExpand};
|
||||||
use rustc_hir::def_id::{StableCrateId, LOCAL_CRATE};
|
use rustc_hir::def_id::{StableCrateId, LOCAL_CRATE};
|
||||||
|
use rustc_hir::definitions::Definitions;
|
||||||
use rustc_hir::Crate;
|
use rustc_hir::Crate;
|
||||||
use rustc_lint::{EarlyCheckNode, LintStore};
|
use rustc_lint::{EarlyCheckNode, LintStore};
|
||||||
use rustc_metadata::creader::CStore;
|
use rustc_metadata::creader::CStore;
|
||||||
|
@ -20,7 +21,7 @@ use rustc_metadata::{encode_metadata, EncodedMetadata};
|
||||||
use rustc_middle::arena::Arena;
|
use rustc_middle::arena::Arena;
|
||||||
use rustc_middle::dep_graph::DepGraph;
|
use rustc_middle::dep_graph::DepGraph;
|
||||||
use rustc_middle::ty::query::{ExternProviders, Providers};
|
use rustc_middle::ty::query::{ExternProviders, Providers};
|
||||||
use rustc_middle::ty::{self, GlobalCtxt, RegisteredTools, ResolverOutputs, TyCtxt};
|
use rustc_middle::ty::{self, GlobalCtxt, RegisteredTools, TyCtxt};
|
||||||
use rustc_mir_build as mir_build;
|
use rustc_mir_build as mir_build;
|
||||||
use rustc_parse::{parse_crate_from_file, parse_crate_from_source_str, validate_attr};
|
use rustc_parse::{parse_crate_from_file, parse_crate_from_source_str, validate_attr};
|
||||||
use rustc_passes::{self, hir_stats, layout_test};
|
use rustc_passes::{self, hir_stats, layout_test};
|
||||||
|
@ -28,7 +29,7 @@ use rustc_plugin_impl as plugin;
|
||||||
use rustc_query_impl::{OnDiskCache, Queries as TcxQueries};
|
use rustc_query_impl::{OnDiskCache, Queries as TcxQueries};
|
||||||
use rustc_resolve::{Resolver, ResolverArenas};
|
use rustc_resolve::{Resolver, ResolverArenas};
|
||||||
use rustc_session::config::{CrateType, Input, OutputFilenames, OutputType};
|
use rustc_session::config::{CrateType, Input, OutputFilenames, OutputType};
|
||||||
use rustc_session::cstore::{MetadataLoader, MetadataLoaderDyn};
|
use rustc_session::cstore::{CrateStoreDyn, MetadataLoader, MetadataLoaderDyn};
|
||||||
use rustc_session::output::{filename_for_input, filename_for_metadata};
|
use rustc_session::output::{filename_for_input, filename_for_metadata};
|
||||||
use rustc_session::search_paths::PathKind;
|
use rustc_session::search_paths::PathKind;
|
||||||
use rustc_session::{Limit, Session};
|
use rustc_session::{Limit, Session};
|
||||||
|
@ -136,7 +137,10 @@ mod boxed_resolver {
|
||||||
f((&mut *resolver).as_mut().unwrap())
|
f((&mut *resolver).as_mut().unwrap())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn to_resolver_outputs(resolver: Rc<RefCell<BoxedResolver>>) -> ResolverOutputs {
|
pub fn to_resolver_outputs(
|
||||||
|
resolver: Rc<RefCell<BoxedResolver>>,
|
||||||
|
) -> (Definitions, Box<CrateStoreDyn>, ty::ResolverOutputs, ty::ResolverAstLowering)
|
||||||
|
{
|
||||||
match Rc::try_unwrap(resolver) {
|
match Rc::try_unwrap(resolver) {
|
||||||
Ok(resolver) => {
|
Ok(resolver) => {
|
||||||
let mut resolver = resolver.into_inner();
|
let mut resolver = resolver.into_inner();
|
||||||
|
@ -478,14 +482,25 @@ pub fn configure_and_expand(
|
||||||
Ok(krate)
|
Ok(krate)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn lower_to_hir<'res, 'tcx>(
|
fn lower_to_hir<'tcx>(
|
||||||
sess: &'tcx Session,
|
sess: &Session,
|
||||||
resolver: &'res mut Resolver<'_>,
|
definitions: &mut Definitions,
|
||||||
|
cstore: &CrateStoreDyn,
|
||||||
|
resolutions: &ty::ResolverOutputs,
|
||||||
|
resolver: ty::ResolverAstLowering,
|
||||||
krate: Rc<ast::Crate>,
|
krate: Rc<ast::Crate>,
|
||||||
arena: &'tcx rustc_ast_lowering::Arena<'tcx>,
|
arena: &'tcx rustc_ast_lowering::Arena<'tcx>,
|
||||||
) -> &'tcx Crate<'tcx> {
|
) -> &'tcx Crate<'tcx> {
|
||||||
// Lower AST to HIR.
|
// Lower AST to HIR.
|
||||||
let hir_crate = rustc_ast_lowering::lower_crate(sess, &*krate, resolver, arena);
|
let hir_crate = rustc_ast_lowering::lower_crate(
|
||||||
|
sess,
|
||||||
|
&krate,
|
||||||
|
definitions,
|
||||||
|
cstore,
|
||||||
|
resolutions,
|
||||||
|
resolver,
|
||||||
|
arena,
|
||||||
|
);
|
||||||
|
|
||||||
// Drop AST to free memory
|
// Drop AST to free memory
|
||||||
sess.time("drop_ast", || std::mem::drop(krate));
|
sess.time("drop_ast", || std::mem::drop(krate));
|
||||||
|
@ -823,10 +838,21 @@ pub fn create_global_ctxt<'tcx>(
|
||||||
// incr. comp. yet.
|
// incr. comp. yet.
|
||||||
dep_graph.assert_ignored();
|
dep_graph.assert_ignored();
|
||||||
|
|
||||||
|
let (mut definitions, cstore, resolver_outputs, resolver_for_lowering) =
|
||||||
|
BoxedResolver::to_resolver_outputs(resolver);
|
||||||
|
|
||||||
let sess = &compiler.session();
|
let sess = &compiler.session();
|
||||||
let krate =
|
|
||||||
resolver.borrow_mut().access(|resolver| lower_to_hir(sess, resolver, krate, hir_arena));
|
// Lower AST to HIR.
|
||||||
let resolver_outputs = BoxedResolver::to_resolver_outputs(resolver);
|
let krate = lower_to_hir(
|
||||||
|
sess,
|
||||||
|
&mut definitions,
|
||||||
|
&*cstore,
|
||||||
|
&resolver_outputs,
|
||||||
|
resolver_for_lowering,
|
||||||
|
krate,
|
||||||
|
hir_arena,
|
||||||
|
);
|
||||||
|
|
||||||
let query_result_on_disk_cache = rustc_incremental::load_query_result_cache(sess);
|
let query_result_on_disk_cache = rustc_incremental::load_query_result_cache(sess);
|
||||||
|
|
||||||
|
@ -851,6 +877,8 @@ pub fn create_global_ctxt<'tcx>(
|
||||||
sess,
|
sess,
|
||||||
lint_store,
|
lint_store,
|
||||||
arena,
|
arena,
|
||||||
|
definitions,
|
||||||
|
cstore,
|
||||||
resolver_outputs,
|
resolver_outputs,
|
||||||
krate,
|
krate,
|
||||||
dep_graph,
|
dep_graph,
|
||||||
|
|
|
@ -423,7 +423,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn encode_def_path_table(&mut self) {
|
fn encode_def_path_table(&mut self) {
|
||||||
let table = self.tcx.resolutions(()).definitions.def_path_table();
|
let table = self.tcx.definitions_untracked().def_path_table();
|
||||||
if self.is_proc_macro {
|
if self.is_proc_macro {
|
||||||
for def_index in std::iter::once(CRATE_DEF_INDEX)
|
for def_index in std::iter::once(CRATE_DEF_INDEX)
|
||||||
.chain(self.tcx.resolutions(()).proc_macros.iter().map(|p| p.local_def_index))
|
.chain(self.tcx.resolutions(()).proc_macros.iter().map(|p| p.local_def_index))
|
||||||
|
@ -444,7 +444,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
|
||||||
|
|
||||||
fn encode_def_path_hash_map(&mut self) -> LazyValue<DefPathHashMapRef<'static>> {
|
fn encode_def_path_hash_map(&mut self) -> LazyValue<DefPathHashMapRef<'static>> {
|
||||||
self.lazy(DefPathHashMapRef::BorrowedFromTcx(
|
self.lazy(DefPathHashMapRef::BorrowedFromTcx(
|
||||||
self.tcx.resolutions(()).definitions.def_path_hash_to_def_index_map(),
|
self.tcx.definitions_untracked().def_path_hash_to_def_index_map(),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -170,7 +170,7 @@ impl<'hir> Map<'hir> {
|
||||||
|
|
||||||
pub fn def_key(self, def_id: LocalDefId) -> DefKey {
|
pub fn def_key(self, def_id: LocalDefId) -> DefKey {
|
||||||
// Accessing the DefKey is ok, since it is part of DefPathHash.
|
// Accessing the DefKey is ok, since it is part of DefPathHash.
|
||||||
self.tcx.untracked_resolutions.definitions.def_key(def_id)
|
self.tcx.definitions_untracked().def_key(def_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn def_path_from_hir_id(self, id: HirId) -> Option<DefPath> {
|
pub fn def_path_from_hir_id(self, id: HirId) -> Option<DefPath> {
|
||||||
|
@ -179,13 +179,13 @@ impl<'hir> Map<'hir> {
|
||||||
|
|
||||||
pub fn def_path(self, def_id: LocalDefId) -> DefPath {
|
pub fn def_path(self, def_id: LocalDefId) -> DefPath {
|
||||||
// Accessing the DefPath is ok, since it is part of DefPathHash.
|
// Accessing the DefPath is ok, since it is part of DefPathHash.
|
||||||
self.tcx.untracked_resolutions.definitions.def_path(def_id)
|
self.tcx.definitions_untracked().def_path(def_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn def_path_hash(self, def_id: LocalDefId) -> DefPathHash {
|
pub fn def_path_hash(self, def_id: LocalDefId) -> DefPathHash {
|
||||||
// Accessing the DefPathHash is ok, it is incr. comp. stable.
|
// Accessing the DefPathHash is ok, it is incr. comp. stable.
|
||||||
self.tcx.untracked_resolutions.definitions.def_path_hash(def_id)
|
self.tcx.definitions_untracked().def_path_hash(def_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -222,7 +222,7 @@ impl<'hir> Map<'hir> {
|
||||||
// Create a dependency to the crate to be sure we re-execute this when the amount of
|
// Create a dependency to the crate to be sure we re-execute this when the amount of
|
||||||
// definitions change.
|
// definitions change.
|
||||||
self.tcx.ensure().hir_crate(());
|
self.tcx.ensure().hir_crate(());
|
||||||
self.tcx.untracked_resolutions.definitions.iter_local_def_id()
|
self.tcx.definitions_untracked().iter_local_def_id()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn opt_def_kind(self, local_def_id: LocalDefId) -> Option<DefKind> {
|
pub fn opt_def_kind(self, local_def_id: LocalDefId) -> Option<DefKind> {
|
||||||
|
@ -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
|
||||||
|
@ -1100,14 +1102,14 @@ pub(super) fn crate_hash(tcx: TyCtxt<'_>, crate_num: CrateNum) -> Svh {
|
||||||
upstream_crates.hash_stable(&mut hcx, &mut stable_hasher);
|
upstream_crates.hash_stable(&mut hcx, &mut stable_hasher);
|
||||||
source_file_names.hash_stable(&mut hcx, &mut stable_hasher);
|
source_file_names.hash_stable(&mut hcx, &mut stable_hasher);
|
||||||
if tcx.sess.opts.debugging_opts.incremental_relative_spans {
|
if tcx.sess.opts.debugging_opts.incremental_relative_spans {
|
||||||
let definitions = &tcx.untracked_resolutions.definitions;
|
let definitions = &tcx.definitions_untracked();
|
||||||
let mut owner_spans: Vec<_> = krate
|
let mut owner_spans: Vec<_> = krate
|
||||||
.owners
|
.owners
|
||||||
.iter_enumerated()
|
.iter_enumerated()
|
||||||
.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);
|
||||||
|
|
||||||
|
@ -1131,7 +1132,7 @@ fn upstream_crates(tcx: TyCtxt<'_>) -> Vec<(StableCrateId, Svh)> {
|
||||||
.crates(())
|
.crates(())
|
||||||
.iter()
|
.iter()
|
||||||
.map(|&cnum| {
|
.map(|&cnum| {
|
||||||
let stable_crate_id = tcx.resolutions(()).cstore.stable_crate_id(cnum);
|
let stable_crate_id = tcx.stable_crate_id(cnum);
|
||||||
let hash = tcx.crate_hash(cnum);
|
let hash = tcx.crate_hash(cnum);
|
||||||
(stable_crate_id, hash)
|
(stable_crate_id, hash)
|
||||||
})
|
})
|
||||||
|
|
|
@ -7,13 +7,13 @@ pub mod nested_filter;
|
||||||
pub mod place;
|
pub mod place;
|
||||||
|
|
||||||
use crate::ty::query::Providers;
|
use crate::ty::query::Providers;
|
||||||
use crate::ty::{ImplSubject, TyCtxt};
|
use crate::ty::{DefIdTree, ImplSubject, TyCtxt};
|
||||||
use rustc_data_structures::fingerprint::Fingerprint;
|
use rustc_data_structures::fingerprint::Fingerprint;
|
||||||
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
|
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.
|
||||||
|
@ -104,23 +104,21 @@ pub fn provide(providers: &mut Providers) {
|
||||||
};
|
};
|
||||||
providers.hir_owner_nodes = |tcx, id| tcx.hir_crate(()).owners[id].map(|i| &i.nodes);
|
providers.hir_owner_nodes = |tcx, id| tcx.hir_crate(()).owners[id].map(|i| &i.nodes);
|
||||||
providers.hir_owner_parent = |tcx, id| {
|
providers.hir_owner_parent = |tcx, id| {
|
||||||
// Accessing the def_key is ok since its value is hashed as part of `id`'s DefPathHash.
|
// Accessing the local_parent is ok since its value is hashed as part of `id`'s DefPathHash.
|
||||||
let parent = tcx.untracked_resolutions.definitions.def_key(id).parent;
|
tcx.opt_local_parent(id).map_or(CRATE_HIR_ID, |parent| {
|
||||||
let parent = parent.map_or(CRATE_HIR_ID, |local_def_index| {
|
let mut parent_hir_id = tcx.hir().local_def_id_to_hir_id(parent);
|
||||||
let def_id = LocalDefId { local_def_index };
|
|
||||||
let mut parent_hir_id = tcx.hir().local_def_id_to_hir_id(def_id);
|
|
||||||
if let Some(local_id) =
|
if let Some(local_id) =
|
||||||
tcx.hir_crate(()).owners[parent_hir_id.owner].unwrap().parenting.get(&id)
|
tcx.hir_crate(()).owners[parent_hir_id.owner].unwrap().parenting.get(&id)
|
||||||
{
|
{
|
||||||
parent_hir_id.local_id = *local_id;
|
parent_hir_id.local_id = *local_id;
|
||||||
}
|
}
|
||||||
parent_hir_id
|
parent_hir_id
|
||||||
});
|
})
|
||||||
parent
|
|
||||||
};
|
};
|
||||||
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.resolutions(()).definitions.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);
|
||||||
|
@ -150,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.resolutions(()).definitions.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);
|
||||||
|
|
|
@ -271,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
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,6 +50,7 @@ use rustc_middle::mir::FakeReadCause;
|
||||||
use rustc_query_system::ich::StableHashingContext;
|
use rustc_query_system::ich::StableHashingContext;
|
||||||
use rustc_serialize::opaque::{FileEncodeResult, FileEncoder};
|
use rustc_serialize::opaque::{FileEncodeResult, FileEncoder};
|
||||||
use rustc_session::config::{CrateType, OutputFilenames};
|
use rustc_session::config::{CrateType, OutputFilenames};
|
||||||
|
use rustc_session::cstore::CrateStoreDyn;
|
||||||
use rustc_session::lint::{Level, Lint};
|
use rustc_session::lint::{Level, Lint};
|
||||||
use rustc_session::Limit;
|
use rustc_session::Limit;
|
||||||
use rustc_session::Session;
|
use rustc_session::Session;
|
||||||
|
@ -177,7 +178,9 @@ impl<'tcx> CtxtInterners<'tcx> {
|
||||||
&self,
|
&self,
|
||||||
kind: TyKind<'tcx>,
|
kind: TyKind<'tcx>,
|
||||||
sess: &Session,
|
sess: &Session,
|
||||||
resolutions: &ty::ResolverOutputs,
|
definitions: &rustc_hir::definitions::Definitions,
|
||||||
|
cstore: &CrateStoreDyn,
|
||||||
|
source_span: &IndexVec<LocalDefId, Span>,
|
||||||
) -> Ty<'tcx> {
|
) -> Ty<'tcx> {
|
||||||
Ty(Interned::new_unchecked(
|
Ty(Interned::new_unchecked(
|
||||||
self.type_
|
self.type_
|
||||||
|
@ -194,8 +197,9 @@ impl<'tcx> CtxtInterners<'tcx> {
|
||||||
let mut hasher = StableHasher::new();
|
let mut hasher = StableHasher::new();
|
||||||
let mut hcx = StableHashingContext::ignore_spans(
|
let mut hcx = StableHashingContext::ignore_spans(
|
||||||
sess,
|
sess,
|
||||||
&resolutions.definitions,
|
definitions,
|
||||||
&*resolutions.cstore,
|
cstore,
|
||||||
|
source_span,
|
||||||
);
|
);
|
||||||
kind.hash_stable(&mut hcx, &mut hasher);
|
kind.hash_stable(&mut hcx, &mut hasher);
|
||||||
hasher.finish()
|
hasher.finish()
|
||||||
|
@ -934,9 +938,11 @@ impl<'tcx> CommonTypes<'tcx> {
|
||||||
fn new(
|
fn new(
|
||||||
interners: &CtxtInterners<'tcx>,
|
interners: &CtxtInterners<'tcx>,
|
||||||
sess: &Session,
|
sess: &Session,
|
||||||
resolutions: &ty::ResolverOutputs,
|
definitions: &rustc_hir::definitions::Definitions,
|
||||||
|
cstore: &CrateStoreDyn,
|
||||||
|
source_span: &IndexVec<LocalDefId, Span>,
|
||||||
) -> CommonTypes<'tcx> {
|
) -> CommonTypes<'tcx> {
|
||||||
let mk = |ty| interners.intern_ty(ty, sess, resolutions);
|
let mk = |ty| interners.intern_ty(ty, sess, definitions, cstore, source_span);
|
||||||
|
|
||||||
CommonTypes {
|
CommonTypes {
|
||||||
unit: mk(Tuple(List::empty())),
|
unit: mk(Tuple(List::empty())),
|
||||||
|
@ -1057,6 +1063,9 @@ pub struct GlobalCtxt<'tcx> {
|
||||||
/// Common consts, pre-interned for your convenience.
|
/// Common consts, pre-interned for your convenience.
|
||||||
pub consts: CommonConsts<'tcx>,
|
pub consts: CommonConsts<'tcx>,
|
||||||
|
|
||||||
|
definitions: rustc_hir::definitions::Definitions,
|
||||||
|
cstore: Box<CrateStoreDyn>,
|
||||||
|
|
||||||
/// Output of the resolver.
|
/// Output of the resolver.
|
||||||
pub(crate) untracked_resolutions: ty::ResolverOutputs,
|
pub(crate) untracked_resolutions: ty::ResolverOutputs,
|
||||||
|
|
||||||
|
@ -1218,7 +1227,9 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
s: &'tcx Session,
|
s: &'tcx Session,
|
||||||
lint_store: Lrc<dyn Any + sync::Send + sync::Sync>,
|
lint_store: Lrc<dyn Any + sync::Send + sync::Sync>,
|
||||||
arena: &'tcx WorkerLocal<Arena<'tcx>>,
|
arena: &'tcx WorkerLocal<Arena<'tcx>>,
|
||||||
resolutions: ty::ResolverOutputs,
|
definitions: rustc_hir::definitions::Definitions,
|
||||||
|
cstore: Box<CrateStoreDyn>,
|
||||||
|
untracked_resolutions: ty::ResolverOutputs,
|
||||||
krate: &'tcx hir::Crate<'tcx>,
|
krate: &'tcx hir::Crate<'tcx>,
|
||||||
dep_graph: DepGraph,
|
dep_graph: DepGraph,
|
||||||
on_disk_cache: Option<&'tcx dyn OnDiskCache<'tcx>>,
|
on_disk_cache: Option<&'tcx dyn OnDiskCache<'tcx>>,
|
||||||
|
@ -1231,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, &resolutions);
|
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);
|
||||||
|
|
||||||
|
@ -1241,7 +1259,9 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
arena,
|
arena,
|
||||||
interners,
|
interners,
|
||||||
dep_graph,
|
dep_graph,
|
||||||
untracked_resolutions: resolutions,
|
definitions,
|
||||||
|
cstore,
|
||||||
|
untracked_resolutions,
|
||||||
prof: s.prof.clone(),
|
prof: s.prof.clone(),
|
||||||
types: common_types,
|
types: common_types,
|
||||||
lifetimes: common_lifetimes,
|
lifetimes: common_lifetimes,
|
||||||
|
@ -1342,9 +1362,9 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
pub fn def_key(self, id: DefId) -> rustc_hir::definitions::DefKey {
|
pub fn def_key(self, id: DefId) -> rustc_hir::definitions::DefKey {
|
||||||
// Accessing the DefKey is ok, since it is part of DefPathHash.
|
// Accessing the DefKey is ok, since it is part of DefPathHash.
|
||||||
if let Some(id) = id.as_local() {
|
if let Some(id) = id.as_local() {
|
||||||
self.untracked_resolutions.definitions.def_key(id)
|
self.definitions.def_key(id)
|
||||||
} else {
|
} else {
|
||||||
self.untracked_resolutions.cstore.def_key(id)
|
self.cstore.def_key(id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1356,9 +1376,9 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
pub fn def_path(self, id: DefId) -> rustc_hir::definitions::DefPath {
|
pub fn def_path(self, id: DefId) -> rustc_hir::definitions::DefPath {
|
||||||
// Accessing the DefPath is ok, since it is part of DefPathHash.
|
// Accessing the DefPath is ok, since it is part of DefPathHash.
|
||||||
if let Some(id) = id.as_local() {
|
if let Some(id) = id.as_local() {
|
||||||
self.untracked_resolutions.definitions.def_path(id)
|
self.definitions.def_path(id)
|
||||||
} else {
|
} else {
|
||||||
self.untracked_resolutions.cstore.def_path(id)
|
self.cstore.def_path(id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1366,9 +1386,9 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
pub fn def_path_hash(self, def_id: DefId) -> rustc_hir::definitions::DefPathHash {
|
pub fn def_path_hash(self, def_id: DefId) -> rustc_hir::definitions::DefPathHash {
|
||||||
// Accessing the DefPathHash is ok, it is incr. comp. stable.
|
// Accessing the DefPathHash is ok, it is incr. comp. stable.
|
||||||
if let Some(def_id) = def_id.as_local() {
|
if let Some(def_id) = def_id.as_local() {
|
||||||
self.untracked_resolutions.definitions.def_path_hash(def_id)
|
self.definitions.def_path_hash(def_id)
|
||||||
} else {
|
} else {
|
||||||
self.untracked_resolutions.cstore.def_path_hash(def_id)
|
self.cstore.def_path_hash(def_id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1377,7 +1397,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
if crate_num == LOCAL_CRATE {
|
if crate_num == LOCAL_CRATE {
|
||||||
self.sess.local_stable_crate_id()
|
self.sess.local_stable_crate_id()
|
||||||
} else {
|
} else {
|
||||||
self.untracked_resolutions.cstore.stable_crate_id(crate_num)
|
self.cstore.stable_crate_id(crate_num)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1388,7 +1408,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
if stable_crate_id == self.sess.local_stable_crate_id() {
|
if stable_crate_id == self.sess.local_stable_crate_id() {
|
||||||
LOCAL_CRATE
|
LOCAL_CRATE
|
||||||
} else {
|
} else {
|
||||||
self.untracked_resolutions.cstore.stable_crate_id_to_crate_num(stable_crate_id)
|
self.cstore.stable_crate_id_to_crate_num(stable_crate_id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1403,16 +1423,12 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
// If this is a DefPathHash from the local crate, we can look up the
|
// If this is a DefPathHash from the local crate, we can look up the
|
||||||
// DefId in the tcx's `Definitions`.
|
// DefId in the tcx's `Definitions`.
|
||||||
if stable_crate_id == self.sess.local_stable_crate_id() {
|
if stable_crate_id == self.sess.local_stable_crate_id() {
|
||||||
self.untracked_resolutions
|
self.definitions.local_def_path_hash_to_def_id(hash, err).to_def_id()
|
||||||
.definitions
|
|
||||||
.local_def_path_hash_to_def_id(hash, err)
|
|
||||||
.to_def_id()
|
|
||||||
} else {
|
} else {
|
||||||
// If this is a DefPathHash from an upstream crate, let the CrateStore map
|
// If this is a DefPathHash from an upstream crate, let the CrateStore map
|
||||||
// it to a DefId.
|
// it to a DefId.
|
||||||
let cstore = &self.untracked_resolutions.cstore;
|
let cnum = self.cstore.stable_crate_id_to_crate_num(stable_crate_id);
|
||||||
let cnum = cstore.stable_crate_id_to_crate_num(stable_crate_id);
|
self.cstore.def_path_hash_to_def_id(cnum, hash)
|
||||||
cstore.def_path_hash_to_def_id(cnum, hash)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1424,7 +1440,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
let (crate_name, stable_crate_id) = if def_id.is_local() {
|
let (crate_name, stable_crate_id) = if def_id.is_local() {
|
||||||
(self.crate_name, self.sess.local_stable_crate_id())
|
(self.crate_name, self.sess.local_stable_crate_id())
|
||||||
} else {
|
} else {
|
||||||
let cstore = &self.untracked_resolutions.cstore;
|
let cstore = &self.cstore;
|
||||||
(cstore.crate_name(def_id.krate), cstore.stable_crate_id(def_id.krate))
|
(cstore.crate_name(def_id.krate), cstore.stable_crate_id(def_id.krate))
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1440,29 +1456,40 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
|
|
||||||
/// Note that this is *untracked* and should only be used within the query
|
/// Note that this is *untracked* and should only be used within the query
|
||||||
/// system if the result is otherwise tracked through queries
|
/// system if the result is otherwise tracked through queries
|
||||||
pub fn cstore_untracked(self) -> &'tcx ty::CrateStoreDyn {
|
pub fn cstore_untracked(self) -> &'tcx CrateStoreDyn {
|
||||||
&*self.untracked_resolutions.cstore
|
&*self.cstore
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Note that this is *untracked* and should only be used within the query
|
/// Note that this is *untracked* and should only be used within the query
|
||||||
/// system if the result is otherwise tracked through queries
|
/// system if the result is otherwise tracked through queries
|
||||||
pub fn definitions_untracked(self) -> &'tcx hir::definitions::Definitions {
|
pub fn definitions_untracked(self) -> &'tcx hir::definitions::Definitions {
|
||||||
&self.untracked_resolutions.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> {
|
||||||
let resolutions = &self.gcx.untracked_resolutions;
|
StableHashingContext::new(
|
||||||
StableHashingContext::new(self.sess, &resolutions.definitions, &*resolutions.cstore)
|
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> {
|
||||||
let resolutions = &self.gcx.untracked_resolutions;
|
|
||||||
StableHashingContext::ignore_spans(
|
StableHashingContext::ignore_spans(
|
||||||
self.sess,
|
self.sess,
|
||||||
&resolutions.definitions,
|
&self.definitions,
|
||||||
&*resolutions.cstore,
|
&*self.cstore,
|
||||||
|
&self.untracked_resolutions.source_span,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2254,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.gcx.untracked_resolutions)
|
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]
|
||||||
|
|
|
@ -27,6 +27,7 @@ pub use adt::*;
|
||||||
pub use assoc::*;
|
pub use assoc::*;
|
||||||
pub use generics::*;
|
pub use generics::*;
|
||||||
use rustc_ast as ast;
|
use rustc_ast as ast;
|
||||||
|
use rustc_ast::node_id::NodeMap;
|
||||||
use rustc_attr as attr;
|
use rustc_attr as attr;
|
||||||
use rustc_data_structures::fingerprint::Fingerprint;
|
use rustc_data_structures::fingerprint::Fingerprint;
|
||||||
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap, FxIndexSet};
|
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap, FxIndexSet};
|
||||||
|
@ -34,14 +35,15 @@ use rustc_data_structures::intern::{Interned, WithStableHash};
|
||||||
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
|
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
|
||||||
use rustc_data_structures::tagged_ptr::CopyTaggedPtr;
|
use rustc_data_structures::tagged_ptr::CopyTaggedPtr;
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::def::{CtorKind, CtorOf, DefKind, Res};
|
use rustc_hir::def::{CtorKind, CtorOf, DefKind, LifetimeRes, Res};
|
||||||
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, LocalDefIdMap};
|
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, LocalDefIdMap};
|
||||||
use rustc_hir::Node;
|
use rustc_hir::Node;
|
||||||
|
use rustc_index::vec::IndexVec;
|
||||||
use rustc_macros::HashStable;
|
use rustc_macros::HashStable;
|
||||||
use rustc_query_system::ich::StableHashingContext;
|
use rustc_query_system::ich::StableHashingContext;
|
||||||
use rustc_session::cstore::CrateStoreDyn;
|
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::*;
|
||||||
|
@ -133,11 +135,13 @@ pub type RegisteredTools = FxHashSet<Ident>;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct ResolverOutputs {
|
pub struct ResolverOutputs {
|
||||||
pub definitions: rustc_hir::definitions::Definitions,
|
|
||||||
pub cstore: Box<CrateStoreDyn>,
|
|
||||||
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>,
|
||||||
|
@ -158,6 +162,34 @@ pub struct ResolverOutputs {
|
||||||
pub registered_tools: RegisteredTools,
|
pub registered_tools: RegisteredTools,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Resolutions that should only be used for lowering.
|
||||||
|
/// This struct is meant to be consumed by lowering.
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct ResolverAstLowering {
|
||||||
|
pub legacy_const_generic_args: FxHashMap<DefId, Option<Vec<usize>>>,
|
||||||
|
|
||||||
|
/// Resolutions for nodes that have a single resolution.
|
||||||
|
pub partial_res_map: NodeMap<hir::def::PartialRes>,
|
||||||
|
/// Resolutions for import nodes, which have multiple resolutions in different namespaces.
|
||||||
|
pub import_res_map: NodeMap<hir::def::PerNS<Option<Res<ast::NodeId>>>>,
|
||||||
|
/// Resolutions for labels (node IDs of their corresponding blocks or loops).
|
||||||
|
pub label_res_map: NodeMap<ast::NodeId>,
|
||||||
|
/// Resolutions for lifetimes.
|
||||||
|
pub lifetimes_res_map: NodeMap<LifetimeRes>,
|
||||||
|
/// Lifetime parameters that lowering will have to introduce.
|
||||||
|
pub extra_lifetime_params_map: NodeMap<Vec<(Ident, ast::NodeId, LifetimeRes)>>,
|
||||||
|
|
||||||
|
pub next_node_id: ast::NodeId,
|
||||||
|
|
||||||
|
pub node_id_to_def_id: FxHashMap<ast::NodeId, LocalDefId>,
|
||||||
|
pub def_id_to_node_id: IndexVec<LocalDefId, ast::NodeId>,
|
||||||
|
|
||||||
|
pub trait_map: NodeMap<Vec<hir::TraitCandidate>>,
|
||||||
|
/// A small map keeping true kinds of built-in macros that appear to be fn-like on
|
||||||
|
/// the surface (`macro` items in libcore), but are actually attributes or derives.
|
||||||
|
pub builtin_macro_kinds: FxHashMap<LocalDefId, MacroKind>,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug)]
|
#[derive(Clone, Copy, Debug)]
|
||||||
pub struct MainDefinition {
|
pub struct MainDefinition {
|
||||||
pub res: Res<ast::NodeId>,
|
pub res: Res<ast::NodeId>,
|
||||||
|
|
|
@ -690,8 +690,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),
|
||||||
|
@ -869,7 +868,7 @@ impl<'a, 'tcx> Encodable<CacheEncoder<'a, 'tcx>> for Span {
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
||||||
|
|
|
@ -6,6 +6,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;
|
||||||
|
@ -20,6 +21,7 @@ use rustc_span::{BytePos, CachingSourceMapView, SourceFile, Span, SpanData};
|
||||||
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,
|
||||||
|
@ -50,6 +52,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 =
|
||||||
|
@ -59,6 +62,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(),
|
||||||
|
@ -71,11 +75,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,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -85,9 +91,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
|
||||||
|
@ -189,7 +196,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]
|
||||||
|
|
|
@ -12,7 +12,6 @@ tracing = "0.1"
|
||||||
rustc_ast = { path = "../rustc_ast" }
|
rustc_ast = { path = "../rustc_ast" }
|
||||||
rustc_arena = { path = "../rustc_arena" }
|
rustc_arena = { path = "../rustc_arena" }
|
||||||
rustc_middle = { path = "../rustc_middle" }
|
rustc_middle = { path = "../rustc_middle" }
|
||||||
rustc_ast_lowering = { path = "../rustc_ast_lowering" }
|
|
||||||
rustc_ast_pretty = { path = "../rustc_ast_pretty" }
|
rustc_ast_pretty = { path = "../rustc_ast_pretty" }
|
||||||
rustc_attr = { path = "../rustc_attr" }
|
rustc_attr = { path = "../rustc_attr" }
|
||||||
rustc_data_structures = { path = "../rustc_data_structures" }
|
rustc_data_structures = { path = "../rustc_data_structures" }
|
||||||
|
|
|
@ -5,7 +5,6 @@ use rustc_ast::Crate;
|
||||||
use rustc_ast::EnumDef;
|
use rustc_ast::EnumDef;
|
||||||
use rustc_ast::ForeignMod;
|
use rustc_ast::ForeignMod;
|
||||||
use rustc_ast::NodeId;
|
use rustc_ast::NodeId;
|
||||||
use rustc_ast_lowering::ResolverAstLowering;
|
|
||||||
use rustc_hir::def_id::LocalDefId;
|
use rustc_hir::def_id::LocalDefId;
|
||||||
use rustc_hir::def_id::CRATE_DEF_ID;
|
use rustc_hir::def_id::CRATE_DEF_ID;
|
||||||
use rustc_middle::middle::privacy::AccessLevel;
|
use rustc_middle::middle::privacy::AccessLevel;
|
||||||
|
|
|
@ -18,7 +18,6 @@ use crate::{Resolver, ResolverArenas, Segment, ToNameBinding, VisResolutionError
|
||||||
use rustc_ast::visit::{self, AssocCtxt, Visitor};
|
use rustc_ast::visit::{self, AssocCtxt, Visitor};
|
||||||
use rustc_ast::{self as ast, AssocItem, AssocItemKind, MetaItemKind, StmtKind};
|
use rustc_ast::{self as ast, AssocItem, AssocItemKind, MetaItemKind, StmtKind};
|
||||||
use rustc_ast::{Block, Fn, ForeignItem, ForeignItemKind, Impl, Item, ItemKind, NodeId};
|
use rustc_ast::{Block, Fn, ForeignItem, ForeignItemKind, Impl, Item, ItemKind, NodeId};
|
||||||
use rustc_ast_lowering::ResolverAstLowering;
|
|
||||||
use rustc_attr as attr;
|
use rustc_attr as attr;
|
||||||
use rustc_data_structures::sync::Lrc;
|
use rustc_data_structures::sync::Lrc;
|
||||||
use rustc_errors::{struct_span_err, Applicability};
|
use rustc_errors::{struct_span_err, Applicability};
|
||||||
|
@ -28,7 +27,7 @@ use rustc_hir::def_id::{DefId, LocalDefId, CRATE_DEF_ID};
|
||||||
use rustc_metadata::creader::LoadedMacro;
|
use rustc_metadata::creader::LoadedMacro;
|
||||||
use rustc_middle::bug;
|
use rustc_middle::bug;
|
||||||
use rustc_middle::metadata::ModChild;
|
use rustc_middle::metadata::ModChild;
|
||||||
use rustc_middle::ty;
|
use rustc_middle::ty::{self, DefIdTree};
|
||||||
use rustc_session::cstore::CrateStore;
|
use rustc_session::cstore::CrateStore;
|
||||||
use rustc_span::hygiene::{ExpnId, LocalExpnId, MacroKind};
|
use rustc_span::hygiene::{ExpnId, LocalExpnId, MacroKind};
|
||||||
use rustc_span::source_map::{respan, Spanned};
|
use rustc_span::source_map::{respan, Spanned};
|
||||||
|
@ -113,10 +112,7 @@ impl<'a> Resolver<'a> {
|
||||||
loop {
|
loop {
|
||||||
match self.get_module(def_id) {
|
match self.get_module(def_id) {
|
||||||
Some(module) => return module,
|
Some(module) => return module,
|
||||||
None => {
|
None => def_id = self.parent(def_id),
|
||||||
def_id.index =
|
|
||||||
self.def_key(def_id).parent.expect("non-root `DefId` without parent")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,6 @@ use crate::Resolver;
|
||||||
use rustc_ast as ast;
|
use rustc_ast as ast;
|
||||||
use rustc_ast::node_id::NodeMap;
|
use rustc_ast::node_id::NodeMap;
|
||||||
use rustc_ast::visit::{self, Visitor};
|
use rustc_ast::visit::{self, Visitor};
|
||||||
use rustc_ast_lowering::ResolverAstLowering;
|
|
||||||
use rustc_data_structures::fx::FxHashSet;
|
use rustc_data_structures::fx::FxHashSet;
|
||||||
use rustc_errors::{pluralize, MultiSpan};
|
use rustc_errors::{pluralize, MultiSpan};
|
||||||
use rustc_session::lint::builtin::{MACRO_USE_EXTERN_CRATE, UNUSED_IMPORTS};
|
use rustc_session::lint::builtin::{MACRO_USE_EXTERN_CRATE, UNUSED_IMPORTS};
|
||||||
|
|
|
@ -2,7 +2,6 @@ use crate::{ImplTraitContext, Resolver};
|
||||||
use rustc_ast::visit::{self, FnKind};
|
use rustc_ast::visit::{self, FnKind};
|
||||||
use rustc_ast::walk_list;
|
use rustc_ast::walk_list;
|
||||||
use rustc_ast::*;
|
use rustc_ast::*;
|
||||||
use rustc_ast_lowering::ResolverAstLowering;
|
|
||||||
use rustc_expand::expand::AstFragment;
|
use rustc_expand::expand::AstFragment;
|
||||||
use rustc_hir::def_id::LocalDefId;
|
use rustc_hir::def_id::LocalDefId;
|
||||||
use rustc_hir::definitions::*;
|
use rustc_hir::definitions::*;
|
||||||
|
|
|
@ -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 {
|
||||||
|
|
|
@ -15,11 +15,10 @@ use crate::{ResolutionError, Resolver, Segment, UseError};
|
||||||
use rustc_ast::ptr::P;
|
use rustc_ast::ptr::P;
|
||||||
use rustc_ast::visit::{self, AssocCtxt, BoundKind, FnCtxt, FnKind, Visitor};
|
use rustc_ast::visit::{self, AssocCtxt, BoundKind, FnCtxt, FnKind, Visitor};
|
||||||
use rustc_ast::*;
|
use rustc_ast::*;
|
||||||
use rustc_ast_lowering::{LifetimeRes, ResolverAstLowering};
|
|
||||||
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap};
|
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap};
|
||||||
use rustc_errors::DiagnosticId;
|
use rustc_errors::DiagnosticId;
|
||||||
use rustc_hir::def::Namespace::{self, *};
|
use rustc_hir::def::Namespace::{self, *};
|
||||||
use rustc_hir::def::{self, CtorKind, DefKind, PartialRes, PerNS};
|
use rustc_hir::def::{self, CtorKind, DefKind, LifetimeRes, PartialRes, PerNS};
|
||||||
use rustc_hir::def_id::{DefId, LocalDefId, CRATE_DEF_ID};
|
use rustc_hir::def_id::{DefId, LocalDefId, CRATE_DEF_ID};
|
||||||
use rustc_hir::definitions::DefPathData;
|
use rustc_hir::definitions::DefPathData;
|
||||||
use rustc_hir::{PrimTy, TraitCandidate};
|
use rustc_hir::{PrimTy, TraitCandidate};
|
||||||
|
|
|
@ -11,7 +11,6 @@ use rustc_ast::{
|
||||||
self as ast, AssocItemKind, Expr, ExprKind, GenericParam, GenericParamKind, Item, ItemKind,
|
self as ast, AssocItemKind, Expr, ExprKind, GenericParam, GenericParamKind, Item, ItemKind,
|
||||||
NodeId, Path, Ty, TyKind,
|
NodeId, Path, Ty, TyKind,
|
||||||
};
|
};
|
||||||
use rustc_ast_lowering::ResolverAstLowering;
|
|
||||||
use rustc_ast_pretty::pprust::path_segment_to_string;
|
use rustc_ast_pretty::pprust::path_segment_to_string;
|
||||||
use rustc_data_structures::fx::{FxHashSet, FxIndexSet};
|
use rustc_data_structures::fx::{FxHashSet, FxIndexSet};
|
||||||
use rustc_errors::{
|
use rustc_errors::{
|
||||||
|
|
|
@ -27,17 +27,16 @@ use rustc_arena::{DroplessArena, TypedArena};
|
||||||
use rustc_ast::node_id::NodeMap;
|
use rustc_ast::node_id::NodeMap;
|
||||||
use rustc_ast::{self as ast, NodeId, CRATE_NODE_ID};
|
use rustc_ast::{self as ast, NodeId, CRATE_NODE_ID};
|
||||||
use rustc_ast::{AngleBracketedArg, Crate, Expr, ExprKind, GenericArg, GenericArgs, LitKind, Path};
|
use rustc_ast::{AngleBracketedArg, Crate, Expr, ExprKind, GenericArg, GenericArgs, LitKind, Path};
|
||||||
use rustc_ast_lowering::{LifetimeRes, ResolverAstLowering};
|
|
||||||
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap, FxIndexSet};
|
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap, FxIndexSet};
|
||||||
use rustc_data_structures::intern::Interned;
|
use rustc_data_structures::intern::Interned;
|
||||||
use rustc_data_structures::sync::Lrc;
|
use rustc_data_structures::sync::Lrc;
|
||||||
use rustc_errors::{Applicability, DiagnosticBuilder, ErrorGuaranteed};
|
use rustc_errors::{Applicability, DiagnosticBuilder, ErrorGuaranteed};
|
||||||
use rustc_expand::base::{DeriveResolutions, SyntaxExtension, SyntaxExtensionKind};
|
use rustc_expand::base::{DeriveResolutions, SyntaxExtension, SyntaxExtensionKind};
|
||||||
use rustc_hir::def::Namespace::*;
|
use rustc_hir::def::Namespace::*;
|
||||||
use rustc_hir::def::{self, CtorOf, DefKind, PartialRes};
|
use rustc_hir::def::{self, CtorOf, DefKind, LifetimeRes, PartialRes};
|
||||||
use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, DefPathHash, LocalDefId};
|
use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, LocalDefId};
|
||||||
use rustc_hir::def_id::{CRATE_DEF_ID, LOCAL_CRATE};
|
use rustc_hir::def_id::{CRATE_DEF_ID, LOCAL_CRATE};
|
||||||
use rustc_hir::definitions::{DefKey, DefPathData, Definitions};
|
use rustc_hir::definitions::{DefPathData, Definitions};
|
||||||
use rustc_hir::TraitCandidate;
|
use rustc_hir::TraitCandidate;
|
||||||
use rustc_index::vec::IndexVec;
|
use rustc_index::vec::IndexVec;
|
||||||
use rustc_metadata::creader::{CStore, CrateLoader};
|
use rustc_metadata::creader::{CStore, CrateLoader};
|
||||||
|
@ -47,7 +46,7 @@ use rustc_middle::span_bug;
|
||||||
use rustc_middle::ty::query::Providers;
|
use rustc_middle::ty::query::Providers;
|
||||||
use rustc_middle::ty::{self, DefIdTree, MainDefinition, RegisteredTools, ResolverOutputs};
|
use rustc_middle::ty::{self, DefIdTree, MainDefinition, RegisteredTools, ResolverOutputs};
|
||||||
use rustc_query_system::ich::StableHashingContext;
|
use rustc_query_system::ich::StableHashingContext;
|
||||||
use rustc_session::cstore::{CrateStore, MetadataLoaderDyn};
|
use rustc_session::cstore::{CrateStore, CrateStoreDyn, MetadataLoaderDyn};
|
||||||
use rustc_session::lint::LintBuffer;
|
use rustc_session::lint::LintBuffer;
|
||||||
use rustc_session::Session;
|
use rustc_session::Session;
|
||||||
use rustc_span::hygiene::{ExpnId, LocalExpnId, MacroKind, SyntaxContext, Transparency};
|
use rustc_span::hygiene::{ExpnId, LocalExpnId, MacroKind, SyntaxContext, Transparency};
|
||||||
|
@ -879,6 +878,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>,
|
||||||
|
|
||||||
|
@ -1127,85 +1130,15 @@ impl<'a, 'b> DefIdTree for &'a Resolver<'b> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This interface is used through the AST→HIR step, to embed full paths into the HIR. After that
|
impl Resolver<'_> {
|
||||||
/// the resolver is no longer needed as all the relevant information is inline.
|
|
||||||
impl ResolverAstLowering for Resolver<'_> {
|
|
||||||
fn def_key(&self, id: DefId) -> DefKey {
|
|
||||||
if let Some(id) = id.as_local() {
|
|
||||||
self.definitions.def_key(id)
|
|
||||||
} else {
|
|
||||||
self.cstore().def_key(id)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn def_span(&self, id: LocalDefId) -> Span {
|
|
||||||
self.definitions.def_span(id)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn item_generics_num_lifetimes(&self, def_id: DefId) -> usize {
|
|
||||||
if let Some(def_id) = def_id.as_local() {
|
|
||||||
self.item_generics_num_lifetimes[&def_id]
|
|
||||||
} else {
|
|
||||||
self.cstore().item_generics_num_lifetimes(def_id, self.session)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn legacy_const_generic_args(&mut self, expr: &Expr) -> Option<Vec<usize>> {
|
|
||||||
self.legacy_const_generic_args(expr)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_partial_res(&self, id: NodeId) -> Option<PartialRes> {
|
|
||||||
self.partial_res_map.get(&id).cloned()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_import_res(&self, id: NodeId) -> PerNS<Option<Res>> {
|
|
||||||
self.import_res_map.get(&id).cloned().unwrap_or_default()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_label_res(&self, id: NodeId) -> Option<NodeId> {
|
|
||||||
self.label_res_map.get(&id).cloned()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_lifetime_res(&self, id: NodeId) -> Option<LifetimeRes> {
|
|
||||||
self.lifetimes_res_map.get(&id).copied()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn take_extra_lifetime_params(&mut self, id: NodeId) -> Vec<(Ident, NodeId, LifetimeRes)> {
|
|
||||||
self.extra_lifetime_params_map.remove(&id).unwrap_or_default()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn create_stable_hashing_context(&self) -> StableHashingContext<'_> {
|
|
||||||
StableHashingContext::new(self.session, &self.definitions, self.crate_loader.cstore())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn definitions(&self) -> &Definitions {
|
|
||||||
&self.definitions
|
|
||||||
}
|
|
||||||
|
|
||||||
fn next_node_id(&mut self) -> NodeId {
|
|
||||||
self.next_node_id()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn take_trait_map(&mut self, node: NodeId) -> Option<Vec<TraitCandidate>> {
|
|
||||||
self.trait_map.remove(&node)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn opt_local_def_id(&self, node: NodeId) -> Option<LocalDefId> {
|
fn opt_local_def_id(&self, node: NodeId) -> Option<LocalDefId> {
|
||||||
self.node_id_to_def_id.get(&node).copied()
|
self.node_id_to_def_id.get(&node).copied()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn local_def_id(&self, node: NodeId) -> LocalDefId {
|
pub fn local_def_id(&self, node: NodeId) -> LocalDefId {
|
||||||
self.opt_local_def_id(node).unwrap_or_else(|| panic!("no entry for node id: `{:?}`", node))
|
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.
|
/// Adds a definition with a parent definition.
|
||||||
fn create_def(
|
fn create_def(
|
||||||
&mut self,
|
&mut self,
|
||||||
|
@ -1223,7 +1156,17 @@ impl ResolverAstLowering for 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
|
||||||
|
@ -1237,8 +1180,12 @@ impl ResolverAstLowering for Resolver<'_> {
|
||||||
def_id
|
def_id
|
||||||
}
|
}
|
||||||
|
|
||||||
fn decl_macro_kind(&self, def_id: LocalDefId) -> MacroKind {
|
fn item_generics_num_lifetimes(&self, def_id: DefId) -> usize {
|
||||||
self.builtin_macro_kinds.get(&def_id).copied().unwrap_or(MacroKind::Bang)
|
if let Some(def_id) = def_id.as_local() {
|
||||||
|
self.item_generics_num_lifetimes[&def_id]
|
||||||
|
} else {
|
||||||
|
self.cstore().item_generics_num_lifetimes(def_id, self.session)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1269,7 +1216,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);
|
||||||
|
@ -1282,6 +1229,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
|
||||||
|
@ -1306,6 +1257,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.
|
||||||
|
@ -1445,9 +1398,14 @@ impl<'a> Resolver<'a> {
|
||||||
Default::default()
|
Default::default()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn into_outputs(self) -> ResolverOutputs {
|
pub fn into_outputs(
|
||||||
|
self,
|
||||||
|
) -> (Definitions, Box<CrateStoreDyn>, ResolverOutputs, ty::ResolverAstLowering) {
|
||||||
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 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;
|
||||||
|
@ -1458,9 +1416,9 @@ impl<'a> Resolver<'a> {
|
||||||
let main_def = self.main_def;
|
let main_def = self.main_def;
|
||||||
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;
|
||||||
ResolverOutputs {
|
let resolutions = ResolverOutputs {
|
||||||
definitions,
|
source_span,
|
||||||
cstore: Box::new(self.crate_loader.into_cstore()),
|
expn_that_defined,
|
||||||
visibilities,
|
visibilities,
|
||||||
has_pub_restricted,
|
has_pub_restricted,
|
||||||
access_levels,
|
access_levels,
|
||||||
|
@ -1479,15 +1437,32 @@ impl<'a> Resolver<'a> {
|
||||||
proc_macros,
|
proc_macros,
|
||||||
confused_type_with_std_module,
|
confused_type_with_std_module,
|
||||||
registered_tools: self.registered_tools,
|
registered_tools: self.registered_tools,
|
||||||
}
|
};
|
||||||
|
let resolutions_lowering = ty::ResolverAstLowering {
|
||||||
|
legacy_const_generic_args: self.legacy_const_generic_args,
|
||||||
|
partial_res_map: self.partial_res_map,
|
||||||
|
import_res_map: self.import_res_map,
|
||||||
|
label_res_map: self.label_res_map,
|
||||||
|
lifetimes_res_map: self.lifetimes_res_map,
|
||||||
|
extra_lifetime_params_map: self.extra_lifetime_params_map,
|
||||||
|
next_node_id: self.next_node_id,
|
||||||
|
node_id_to_def_id: self.node_id_to_def_id,
|
||||||
|
def_id_to_node_id: self.def_id_to_node_id,
|
||||||
|
trait_map: self.trait_map,
|
||||||
|
builtin_macro_kinds: self.builtin_macro_kinds,
|
||||||
|
};
|
||||||
|
(definitions, cstore, resolutions, resolutions_lowering)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn clone_outputs(&self) -> ResolverOutputs {
|
pub fn clone_outputs(
|
||||||
|
&self,
|
||||||
|
) -> (Definitions, Box<CrateStoreDyn>, ResolverOutputs, ty::ResolverAstLowering) {
|
||||||
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();
|
||||||
ResolverOutputs {
|
let definitions = self.definitions.clone();
|
||||||
definitions: self.definitions.clone(),
|
let cstore = Box::new(self.cstore().clone());
|
||||||
access_levels: self.access_levels.clone(),
|
let resolutions = ResolverOutputs {
|
||||||
cstore: Box::new(self.cstore().clone()),
|
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(),
|
||||||
|
@ -1505,7 +1480,31 @@ impl<'a> Resolver<'a> {
|
||||||
proc_macros,
|
proc_macros,
|
||||||
confused_type_with_std_module: self.confused_type_with_std_module.clone(),
|
confused_type_with_std_module: self.confused_type_with_std_module.clone(),
|
||||||
registered_tools: self.registered_tools.clone(),
|
registered_tools: self.registered_tools.clone(),
|
||||||
}
|
access_levels: self.access_levels.clone(),
|
||||||
|
};
|
||||||
|
let resolutions_lowering = ty::ResolverAstLowering {
|
||||||
|
legacy_const_generic_args: self.legacy_const_generic_args.clone(),
|
||||||
|
partial_res_map: self.partial_res_map.clone(),
|
||||||
|
import_res_map: self.import_res_map.clone(),
|
||||||
|
label_res_map: self.label_res_map.clone(),
|
||||||
|
lifetimes_res_map: self.lifetimes_res_map.clone(),
|
||||||
|
extra_lifetime_params_map: self.extra_lifetime_params_map.clone(),
|
||||||
|
next_node_id: self.next_node_id.clone(),
|
||||||
|
node_id_to_def_id: self.node_id_to_def_id.clone(),
|
||||||
|
def_id_to_node_id: self.def_id_to_node_id.clone(),
|
||||||
|
trait_map: self.trait_map.clone(),
|
||||||
|
builtin_macro_kinds: self.builtin_macro_kinds.clone(),
|
||||||
|
};
|
||||||
|
(definitions, cstore, resolutions, resolutions_lowering)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn create_stable_hashing_context(&self) -> StableHashingContext<'_> {
|
||||||
|
StableHashingContext::new(
|
||||||
|
self.session,
|
||||||
|
&self.definitions,
|
||||||
|
self.crate_loader.cstore(),
|
||||||
|
&self.source_span,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn cstore(&self) -> &CStore {
|
pub fn cstore(&self) -> &CStore {
|
||||||
|
@ -1936,7 +1935,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
|
||||||
|
|
|
@ -7,7 +7,6 @@ use crate::{BuiltinMacroState, Determinacy};
|
||||||
use crate::{DeriveData, Finalize, ParentScope, ResolutionError, Resolver, ScopeSet};
|
use crate::{DeriveData, Finalize, ParentScope, ResolutionError, Resolver, ScopeSet};
|
||||||
use crate::{ModuleKind, ModuleOrUniformRoot, NameBinding, PathResult, Segment};
|
use crate::{ModuleKind, ModuleOrUniformRoot, NameBinding, PathResult, Segment};
|
||||||
use rustc_ast::{self as ast, Inline, ItemKind, ModKind, NodeId};
|
use rustc_ast::{self as ast, Inline, ItemKind, ModKind, NodeId};
|
||||||
use rustc_ast_lowering::ResolverAstLowering;
|
|
||||||
use rustc_ast_pretty::pprust;
|
use rustc_ast_pretty::pprust;
|
||||||
use rustc_attr::StabilityLevel;
|
use rustc_attr::StabilityLevel;
|
||||||
use rustc_data_structures::fx::FxHashSet;
|
use rustc_data_structures::fx::FxHashSet;
|
||||||
|
|
|
@ -36,7 +36,6 @@ extern crate tracing;
|
||||||
// Dependencies listed in Cargo.toml do not need `extern crate`.
|
// Dependencies listed in Cargo.toml do not need `extern crate`.
|
||||||
|
|
||||||
extern crate rustc_ast;
|
extern crate rustc_ast;
|
||||||
extern crate rustc_ast_lowering;
|
|
||||||
extern crate rustc_ast_pretty;
|
extern crate rustc_ast_pretty;
|
||||||
extern crate rustc_attr;
|
extern crate rustc_attr;
|
||||||
extern crate rustc_const_eval;
|
extern crate rustc_const_eval;
|
||||||
|
|
|
@ -5,7 +5,6 @@ use crate::passes::collect_intra_doc_links::{Disambiguator, PreprocessedMarkdown
|
||||||
|
|
||||||
use rustc_ast::visit::{self, AssocCtxt, Visitor};
|
use rustc_ast::visit::{self, AssocCtxt, Visitor};
|
||||||
use rustc_ast::{self as ast, ItemKind};
|
use rustc_ast::{self as ast, ItemKind};
|
||||||
use rustc_ast_lowering::ResolverAstLowering;
|
|
||||||
use rustc_data_structures::fx::FxHashMap;
|
use rustc_data_structures::fx::FxHashMap;
|
||||||
use rustc_hir::def::Namespace::*;
|
use rustc_hir::def::Namespace::*;
|
||||||
use rustc_hir::def::{DefKind, Namespace, Res};
|
use rustc_hir::def::{DefKind, Namespace, Res};
|
||||||
|
|
Loading…
Reference in New Issue