Consume resolutions for lowering separately.
This commit is contained in:
parent
8ffbd814af
commit
ae5959f4ba
5 changed files with 59 additions and 36 deletions
|
@ -15,7 +15,7 @@ use rustc_hir::def_id::{LocalDefId, CRATE_DEF_ID};
|
||||||
use rustc_hir::definitions::Definitions;
|
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::ResolverOutputs;
|
use rustc_middle::ty::{ResolverAstLowering, ResolverOutputs};
|
||||||
use rustc_session::cstore::CrateStoreDyn;
|
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;
|
||||||
|
@ -30,7 +30,8 @@ pub(super) struct ItemLowerer<'a, 'hir> {
|
||||||
pub(super) sess: &'a Session,
|
pub(super) sess: &'a Session,
|
||||||
pub(super) definitions: &'a mut Definitions,
|
pub(super) definitions: &'a mut Definitions,
|
||||||
pub(super) cstore: &'a CrateStoreDyn,
|
pub(super) cstore: &'a CrateStoreDyn,
|
||||||
pub(super) resolver: &'a mut ResolverOutputs,
|
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>>>,
|
||||||
|
@ -62,12 +63,12 @@ impl<'a, 'hir> ItemLowerer<'a, 'hir> {
|
||||||
owner: NodeId,
|
owner: NodeId,
|
||||||
f: impl FnOnce(&mut LoweringContext<'_, 'hir>) -> hir::OwnerNode<'hir>,
|
f: impl FnOnce(&mut LoweringContext<'_, 'hir>) -> hir::OwnerNode<'hir>,
|
||||||
) {
|
) {
|
||||||
let next_node_id = self.resolver.next_node_id;
|
|
||||||
let mut lctx = LoweringContext {
|
let mut lctx = LoweringContext {
|
||||||
// Pseudo-globals.
|
// Pseudo-globals.
|
||||||
sess: &self.sess,
|
sess: &self.sess,
|
||||||
definitions: self.definitions,
|
definitions: self.definitions,
|
||||||
cstore: self.cstore,
|
cstore: self.cstore,
|
||||||
|
resolutions: self.resolutions,
|
||||||
resolver: self.resolver,
|
resolver: self.resolver,
|
||||||
arena: self.arena,
|
arena: self.arena,
|
||||||
|
|
||||||
|
@ -80,8 +81,6 @@ impl<'a, 'hir> ItemLowerer<'a, 'hir> {
|
||||||
node_id_to_local_id: Default::default(),
|
node_id_to_local_id: Default::default(),
|
||||||
local_id_to_def_id: SortedMap::new(),
|
local_id_to_def_id: SortedMap::new(),
|
||||||
trait_map: Default::default(),
|
trait_map: Default::default(),
|
||||||
local_node_id_to_def_id: FxHashMap::default(),
|
|
||||||
next_node_id,
|
|
||||||
|
|
||||||
// Lowering state.
|
// Lowering state.
|
||||||
catch_scope: None,
|
catch_scope: None,
|
||||||
|
|
|
@ -56,7 +56,7 @@ use rustc_hir::def_id::{LocalDefId, CRATE_DEF_ID};
|
||||||
use rustc_hir::definitions::{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::ResolverOutputs;
|
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::cstore::CrateStoreDyn;
|
||||||
use rustc_session::parse::feature_err;
|
use rustc_session::parse::feature_err;
|
||||||
|
@ -91,7 +91,8 @@ struct LoweringContext<'a, 'hir: 'a> {
|
||||||
|
|
||||||
definitions: &'a mut Definitions,
|
definitions: &'a mut Definitions,
|
||||||
cstore: &'a CrateStoreDyn,
|
cstore: &'a CrateStoreDyn,
|
||||||
resolver: &'a mut ResolverOutputs,
|
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>,
|
||||||
|
@ -133,10 +134,6 @@ struct LoweringContext<'a, 'hir: 'a> {
|
||||||
/// NodeIds that are lowered inside the current HIR owner.
|
/// NodeIds that are lowered inside the current HIR owner.
|
||||||
node_id_to_local_id: FxHashMap<NodeId, hir::ItemLocalId>,
|
node_id_to_local_id: FxHashMap<NodeId, hir::ItemLocalId>,
|
||||||
|
|
||||||
// The next_node_id is reset for each item.
|
|
||||||
next_node_id: ast::NodeId,
|
|
||||||
local_node_id_to_def_id: FxHashMap<ast::NodeId, LocalDefId>,
|
|
||||||
|
|
||||||
allow_try_trait: Option<Lrc<[Symbol]>>,
|
allow_try_trait: Option<Lrc<[Symbol]>>,
|
||||||
allow_gen_future: Option<Lrc<[Symbol]>>,
|
allow_gen_future: Option<Lrc<[Symbol]>>,
|
||||||
allow_into_future: Option<Lrc<[Symbol]>>,
|
allow_into_future: Option<Lrc<[Symbol]>>,
|
||||||
|
@ -174,7 +171,7 @@ trait ResolverAstLoweringExt {
|
||||||
fn decl_macro_kind(&self, def_id: LocalDefId) -> MacroKind;
|
fn decl_macro_kind(&self, def_id: LocalDefId) -> MacroKind;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ResolverAstLoweringExt for ResolverOutputs {
|
impl ResolverAstLoweringExt for ResolverAstLowering {
|
||||||
fn legacy_const_generic_args(&self, expr: &Expr) -> Option<Vec<usize>> {
|
fn legacy_const_generic_args(&self, expr: &Expr) -> Option<Vec<usize>> {
|
||||||
if let ExprKind::Path(None, path) = &expr.kind {
|
if let ExprKind::Path(None, path) = &expr.kind {
|
||||||
// Don't perform legacy const generics rewriting if the path already
|
// Don't perform legacy const generics rewriting if the path already
|
||||||
|
@ -415,7 +412,8 @@ pub fn lower_crate<'hir>(
|
||||||
krate: &Crate,
|
krate: &Crate,
|
||||||
definitions: &mut Definitions,
|
definitions: &mut Definitions,
|
||||||
cstore: &CrateStoreDyn,
|
cstore: &CrateStoreDyn,
|
||||||
resolver: &mut ResolverOutputs,
|
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");
|
||||||
|
@ -430,7 +428,8 @@ pub fn lower_crate<'hir>(
|
||||||
sess,
|
sess,
|
||||||
definitions,
|
definitions,
|
||||||
cstore,
|
cstore,
|
||||||
resolver,
|
resolutions,
|
||||||
|
resolver: &mut resolver,
|
||||||
arena,
|
arena,
|
||||||
ast_index: &ast_index,
|
ast_index: &ast_index,
|
||||||
owners: &mut owners,
|
owners: &mut owners,
|
||||||
|
@ -438,7 +437,7 @@ pub fn lower_crate<'hir>(
|
||||||
.lower_node(def_id);
|
.lower_node(def_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
let hir_hash = compute_hir_hash(sess, definitions, cstore, 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)
|
||||||
}
|
}
|
||||||
|
@ -464,7 +463,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
self.sess,
|
self.sess,
|
||||||
self.definitions,
|
self.definitions,
|
||||||
self.cstore,
|
self.cstore,
|
||||||
&self.resolver.source_span,
|
&self.resolutions.source_span,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -489,25 +488,21 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
// we don't need a mapping from `NodeId` to `LocalDefId`.
|
// we don't need a mapping from `NodeId` to `LocalDefId`.
|
||||||
if node_id != ast::DUMMY_NODE_ID {
|
if node_id != ast::DUMMY_NODE_ID {
|
||||||
debug!("create_def: def_id_to_node_id[{:?}] <-> {:?}", def_id, node_id);
|
debug!("create_def: def_id_to_node_id[{:?}] <-> {:?}", def_id, node_id);
|
||||||
self.local_node_id_to_def_id.insert(node_id, def_id);
|
self.resolver.node_id_to_def_id.insert(node_id, def_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
def_id
|
def_id
|
||||||
}
|
}
|
||||||
|
|
||||||
fn next_node_id(&mut self) -> NodeId {
|
fn next_node_id(&mut self) -> NodeId {
|
||||||
let start = self.next_node_id;
|
let start = self.resolver.next_node_id;
|
||||||
let next = start.as_u32().checked_add(1).expect("input too large; ran out of NodeIds");
|
let next = start.as_u32().checked_add(1).expect("input too large; ran out of NodeIds");
|
||||||
self.next_node_id = ast::NodeId::from_u32(next);
|
self.resolver.next_node_id = ast::NodeId::from_u32(next);
|
||||||
start
|
start
|
||||||
}
|
}
|
||||||
|
|
||||||
fn opt_local_def_id(&self, node: NodeId) -> Option<LocalDefId> {
|
fn opt_local_def_id(&self, node: NodeId) -> Option<LocalDefId> {
|
||||||
if node <= self.resolver.next_node_id {
|
|
||||||
self.resolver.node_id_to_def_id.get(&node).copied()
|
self.resolver.node_id_to_def_id.get(&node).copied()
|
||||||
} else {
|
|
||||||
self.local_node_id_to_def_id.get(&node).copied()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn local_def_id(&self, node: NodeId) -> LocalDefId {
|
fn local_def_id(&self, node: NodeId) -> LocalDefId {
|
||||||
|
|
|
@ -21,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};
|
||||||
|
@ -139,7 +139,8 @@ mod boxed_resolver {
|
||||||
|
|
||||||
pub fn to_resolver_outputs(
|
pub fn to_resolver_outputs(
|
||||||
resolver: Rc<RefCell<BoxedResolver>>,
|
resolver: Rc<RefCell<BoxedResolver>>,
|
||||||
) -> (Definitions, Box<CrateStoreDyn>, ResolverOutputs) {
|
) -> (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();
|
||||||
|
@ -485,13 +486,21 @@ fn lower_to_hir<'tcx>(
|
||||||
sess: &Session,
|
sess: &Session,
|
||||||
definitions: &mut Definitions,
|
definitions: &mut Definitions,
|
||||||
cstore: &CrateStoreDyn,
|
cstore: &CrateStoreDyn,
|
||||||
resolver: &mut ResolverOutputs,
|
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 =
|
let hir_crate = rustc_ast_lowering::lower_crate(
|
||||||
rustc_ast_lowering::lower_crate(sess, &krate, definitions, cstore, resolver, arena);
|
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));
|
||||||
|
@ -829,14 +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, mut resolver_outputs) =
|
let (mut definitions, cstore, resolver_outputs, resolver_for_lowering) =
|
||||||
BoxedResolver::to_resolver_outputs(resolver);
|
BoxedResolver::to_resolver_outputs(resolver);
|
||||||
|
|
||||||
let sess = &compiler.session();
|
let sess = &compiler.session();
|
||||||
|
|
||||||
// Lower AST to HIR.
|
// Lower AST to HIR.
|
||||||
let krate =
|
let krate = lower_to_hir(
|
||||||
lower_to_hir(sess, &mut definitions, &*cstore, &mut resolver_outputs, krate, hir_arena);
|
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);
|
||||||
|
|
||||||
|
|
|
@ -160,7 +160,12 @@ pub struct ResolverOutputs {
|
||||||
/// exist under `std`. For example, wrote `str::from_utf8` instead of `std::str::from_utf8`.
|
/// exist under `std`. For example, wrote `str::from_utf8` instead of `std::str::from_utf8`.
|
||||||
pub confused_type_with_std_module: FxHashMap<Span, Span>,
|
pub confused_type_with_std_module: FxHashMap<Span, Span>,
|
||||||
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>>>,
|
pub legacy_const_generic_args: FxHashMap<DefId, Option<Vec<usize>>>,
|
||||||
|
|
||||||
/// Resolutions for nodes that have a single resolution.
|
/// Resolutions for nodes that have a single resolution.
|
||||||
|
|
|
@ -1392,7 +1392,9 @@ impl<'a> Resolver<'a> {
|
||||||
Default::default()
|
Default::default()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn into_outputs(self) -> (Definitions, Box<CrateStoreDyn>, 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 cstore = Box::new(self.crate_loader.into_cstore());
|
||||||
|
@ -1429,6 +1431,8 @@ 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,
|
legacy_const_generic_args: self.legacy_const_generic_args,
|
||||||
partial_res_map: self.partial_res_map,
|
partial_res_map: self.partial_res_map,
|
||||||
import_res_map: self.import_res_map,
|
import_res_map: self.import_res_map,
|
||||||
|
@ -1441,10 +1445,12 @@ impl<'a> Resolver<'a> {
|
||||||
trait_map: self.trait_map,
|
trait_map: self.trait_map,
|
||||||
builtin_macro_kinds: self.builtin_macro_kinds,
|
builtin_macro_kinds: self.builtin_macro_kinds,
|
||||||
};
|
};
|
||||||
(definitions, cstore, resolutions)
|
(definitions, cstore, resolutions, resolutions_lowering)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn clone_outputs(&self) -> (Definitions, Box<CrateStoreDyn>, 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();
|
||||||
let definitions = self.definitions.clone();
|
let definitions = self.definitions.clone();
|
||||||
let cstore = Box::new(self.cstore().clone());
|
let cstore = Box::new(self.cstore().clone());
|
||||||
|
@ -1469,6 +1475,8 @@ impl<'a> Resolver<'a> {
|
||||||
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(),
|
access_levels: self.access_levels.clone(),
|
||||||
|
};
|
||||||
|
let resolutions_lowering = ty::ResolverAstLowering {
|
||||||
legacy_const_generic_args: self.legacy_const_generic_args.clone(),
|
legacy_const_generic_args: self.legacy_const_generic_args.clone(),
|
||||||
partial_res_map: self.partial_res_map.clone(),
|
partial_res_map: self.partial_res_map.clone(),
|
||||||
import_res_map: self.import_res_map.clone(),
|
import_res_map: self.import_res_map.clone(),
|
||||||
|
@ -1481,7 +1489,7 @@ impl<'a> Resolver<'a> {
|
||||||
trait_map: self.trait_map.clone(),
|
trait_map: self.trait_map.clone(),
|
||||||
builtin_macro_kinds: self.builtin_macro_kinds.clone(),
|
builtin_macro_kinds: self.builtin_macro_kinds.clone(),
|
||||||
};
|
};
|
||||||
(definitions, cstore, resolutions)
|
(definitions, cstore, resolutions, resolutions_lowering)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_stable_hashing_context(&self) -> StableHashingContext<'_> {
|
fn create_stable_hashing_context(&self) -> StableHashingContext<'_> {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue