rustc_middle: Rearrange resolver outputs structures slightly
This commit is contained in:
parent
31d754a1df
commit
919673ea03
@ -16,7 +16,6 @@
|
||||
use rustc_errors::{ErrorGuaranteed, PResult};
|
||||
use rustc_expand::base::{ExtCtxt, LintStoreExpand, ResolverExpand};
|
||||
use rustc_hir::def_id::StableCrateId;
|
||||
use rustc_hir::definitions::Definitions;
|
||||
use rustc_lint::{BufferedEarlyLint, EarlyCheckNode, LintStore};
|
||||
use rustc_metadata::creader::CStore;
|
||||
use rustc_middle::arena::Arena;
|
||||
@ -30,7 +29,7 @@
|
||||
use rustc_query_impl::{OnDiskCache, Queries as TcxQueries};
|
||||
use rustc_resolve::{Resolver, ResolverArenas};
|
||||
use rustc_session::config::{CrateType, Input, OutputFilenames, OutputType};
|
||||
use rustc_session::cstore::{CrateStoreDyn, MetadataLoader, MetadataLoaderDyn};
|
||||
use rustc_session::cstore::{MetadataLoader, MetadataLoaderDyn};
|
||||
use rustc_session::output::filename_for_input;
|
||||
use rustc_session::search_paths::PathKind;
|
||||
use rustc_session::{Limit, Session};
|
||||
@ -135,10 +134,7 @@ pub fn access<F: for<'a> FnOnce(&mut Resolver<'a>) -> R, R>(&mut self, f: F) ->
|
||||
f((&mut *resolver).as_mut().unwrap())
|
||||
}
|
||||
|
||||
pub fn to_resolver_outputs(
|
||||
resolver: Rc<RefCell<BoxedResolver>>,
|
||||
) -> (Definitions, Box<CrateStoreDyn>, ty::ResolverOutputs, ty::ResolverAstLowering)
|
||||
{
|
||||
pub fn to_resolver_outputs(resolver: Rc<RefCell<BoxedResolver>>) -> ty::ResolverOutputs {
|
||||
match Rc::try_unwrap(resolver) {
|
||||
Ok(resolver) => {
|
||||
let mut resolver = resolver.into_inner();
|
||||
@ -788,8 +784,7 @@ pub fn create_global_ctxt<'tcx>(
|
||||
// incr. comp. yet.
|
||||
dep_graph.assert_ignored();
|
||||
|
||||
let (definitions, cstore, resolver_outputs, resolver_for_lowering) =
|
||||
BoxedResolver::to_resolver_outputs(resolver);
|
||||
let resolver_outputs = BoxedResolver::to_resolver_outputs(resolver);
|
||||
|
||||
let sess = &compiler.session();
|
||||
let query_result_on_disk_cache = rustc_incremental::load_query_result_cache(sess);
|
||||
@ -816,10 +811,7 @@ pub fn create_global_ctxt<'tcx>(
|
||||
lint_store,
|
||||
arena,
|
||||
hir_arena,
|
||||
definitions,
|
||||
cstore,
|
||||
resolver_outputs,
|
||||
resolver_for_lowering,
|
||||
krate,
|
||||
dep_graph,
|
||||
queries.on_disk_cache.as_ref().map(OnDiskCache::as_dyn),
|
||||
|
@ -23,7 +23,7 @@
|
||||
desc { "triggering a delay span bug" }
|
||||
}
|
||||
|
||||
query resolutions(_: ()) -> &'tcx ty::ResolverOutputs {
|
||||
query resolutions(_: ()) -> &'tcx ty::ResolverGlobalCtxt {
|
||||
eval_always
|
||||
no_hash
|
||||
desc { "getting the resolver outputs" }
|
||||
|
@ -79,7 +79,7 @@
|
||||
use std::ops::{Bound, Deref};
|
||||
use std::sync::Arc;
|
||||
|
||||
use super::{ImplPolarity, RvalueScopes};
|
||||
use super::{ImplPolarity, ResolverOutputs, RvalueScopes};
|
||||
|
||||
pub trait OnDiskCache<'tcx>: rustc_data_structures::sync::Sync {
|
||||
/// Creates a new `OnDiskCache` instance from the serialized data in `data`.
|
||||
@ -1067,10 +1067,9 @@ pub struct GlobalCtxt<'tcx> {
|
||||
pub consts: CommonConsts<'tcx>,
|
||||
|
||||
definitions: RwLock<Definitions>,
|
||||
cstore: Box<CrateStoreDyn>,
|
||||
|
||||
/// Output of the resolver.
|
||||
pub(crate) untracked_resolutions: ty::ResolverOutputs,
|
||||
pub(crate) untracked_resolutions: ty::ResolverGlobalCtxt,
|
||||
untracked_resolver_for_lowering: Steal<ty::ResolverAstLowering>,
|
||||
/// The entire crate as AST. This field serves as the input for the hir_crate query,
|
||||
/// which lowers it from AST to HIR. It must not be read or used by anything else.
|
||||
@ -1233,10 +1232,7 @@ pub fn create_global_ctxt(
|
||||
lint_store: Lrc<dyn Any + sync::Send + sync::Sync>,
|
||||
arena: &'tcx WorkerLocal<Arena<'tcx>>,
|
||||
hir_arena: &'tcx WorkerLocal<hir::Arena<'tcx>>,
|
||||
definitions: Definitions,
|
||||
cstore: Box<CrateStoreDyn>,
|
||||
untracked_resolutions: ty::ResolverOutputs,
|
||||
untracked_resolver_for_lowering: ty::ResolverAstLowering,
|
||||
resolver_outputs: ResolverOutputs,
|
||||
krate: Lrc<ast::Crate>,
|
||||
dep_graph: DepGraph,
|
||||
on_disk_cache: Option<&'tcx dyn OnDiskCache<'tcx>>,
|
||||
@ -1245,6 +1241,11 @@ pub fn create_global_ctxt(
|
||||
crate_name: &str,
|
||||
output_filenames: OutputFilenames,
|
||||
) -> GlobalCtxt<'tcx> {
|
||||
let ResolverOutputs {
|
||||
definitions,
|
||||
global_ctxt: untracked_resolutions,
|
||||
ast_lowering: untracked_resolver_for_lowering,
|
||||
} = resolver_outputs;
|
||||
let data_layout = TargetDataLayout::parse(&s.target).unwrap_or_else(|err| {
|
||||
s.emit_fatal(err);
|
||||
});
|
||||
@ -1253,7 +1254,7 @@ pub fn create_global_ctxt(
|
||||
&interners,
|
||||
s,
|
||||
&definitions,
|
||||
&*cstore,
|
||||
&*untracked_resolutions.cstore,
|
||||
// This is only used to create a stable hashing context.
|
||||
&untracked_resolutions.source_span,
|
||||
);
|
||||
@ -1268,7 +1269,6 @@ pub fn create_global_ctxt(
|
||||
interners,
|
||||
dep_graph,
|
||||
definitions: RwLock::new(definitions),
|
||||
cstore,
|
||||
prof: s.prof.clone(),
|
||||
types: common_types,
|
||||
lifetimes: common_lifetimes,
|
||||
@ -1369,7 +1369,7 @@ pub fn def_key(self, id: DefId) -> rustc_hir::definitions::DefKey {
|
||||
if let Some(id) = id.as_local() {
|
||||
self.definitions_untracked().def_key(id)
|
||||
} else {
|
||||
self.cstore.def_key(id)
|
||||
self.untracked_resolutions.cstore.def_key(id)
|
||||
}
|
||||
}
|
||||
|
||||
@ -1383,7 +1383,7 @@ pub fn def_path(self, id: DefId) -> rustc_hir::definitions::DefPath {
|
||||
if let Some(id) = id.as_local() {
|
||||
self.definitions_untracked().def_path(id)
|
||||
} else {
|
||||
self.cstore.def_path(id)
|
||||
self.untracked_resolutions.cstore.def_path(id)
|
||||
}
|
||||
}
|
||||
|
||||
@ -1393,7 +1393,7 @@ pub fn def_path_hash(self, def_id: DefId) -> rustc_hir::definitions::DefPathHash
|
||||
if let Some(def_id) = def_id.as_local() {
|
||||
self.definitions_untracked().def_path_hash(def_id)
|
||||
} else {
|
||||
self.cstore.def_path_hash(def_id)
|
||||
self.untracked_resolutions.cstore.def_path_hash(def_id)
|
||||
}
|
||||
}
|
||||
|
||||
@ -1402,7 +1402,7 @@ pub fn stable_crate_id(self, crate_num: CrateNum) -> StableCrateId {
|
||||
if crate_num == LOCAL_CRATE {
|
||||
self.sess.local_stable_crate_id()
|
||||
} else {
|
||||
self.cstore.stable_crate_id(crate_num)
|
||||
self.untracked_resolutions.cstore.stable_crate_id(crate_num)
|
||||
}
|
||||
}
|
||||
|
||||
@ -1413,7 +1413,7 @@ pub fn stable_crate_id_to_crate_num(self, stable_crate_id: StableCrateId) -> Cra
|
||||
if stable_crate_id == self.sess.local_stable_crate_id() {
|
||||
LOCAL_CRATE
|
||||
} else {
|
||||
self.cstore.stable_crate_id_to_crate_num(stable_crate_id)
|
||||
self.untracked_resolutions.cstore.stable_crate_id_to_crate_num(stable_crate_id)
|
||||
}
|
||||
}
|
||||
|
||||
@ -1432,8 +1432,9 @@ pub fn def_path_hash_to_def_id(self, hash: DefPathHash, err: &mut dyn FnMut() ->
|
||||
} else {
|
||||
// If this is a DefPathHash from an upstream crate, let the CrateStore map
|
||||
// it to a DefId.
|
||||
let cnum = self.cstore.stable_crate_id_to_crate_num(stable_crate_id);
|
||||
self.cstore.def_path_hash_to_def_id(cnum, hash)
|
||||
let cstore = &*self.untracked_resolutions.cstore;
|
||||
let cnum = cstore.stable_crate_id_to_crate_num(stable_crate_id);
|
||||
cstore.def_path_hash_to_def_id(cnum, hash)
|
||||
}
|
||||
}
|
||||
|
||||
@ -1445,7 +1446,7 @@ pub fn def_path_debug_str(self, def_id: DefId) -> String {
|
||||
let (crate_name, stable_crate_id) = if def_id.is_local() {
|
||||
(self.crate_name, self.sess.local_stable_crate_id())
|
||||
} else {
|
||||
let cstore = &self.cstore;
|
||||
let cstore = &*self.untracked_resolutions.cstore;
|
||||
(cstore.crate_name(def_id.krate), cstore.stable_crate_id(def_id.krate))
|
||||
};
|
||||
|
||||
@ -1520,7 +1521,7 @@ pub fn def_path_hash_to_def_index_map(
|
||||
/// Note that this is *untracked* and should only be used within the query
|
||||
/// system if the result is otherwise tracked through queries
|
||||
pub fn cstore_untracked(self) -> &'tcx CrateStoreDyn {
|
||||
&*self.cstore
|
||||
&*self.untracked_resolutions.cstore
|
||||
}
|
||||
|
||||
/// Note that this is *untracked* and should only be used within the query
|
||||
@ -1546,7 +1547,7 @@ pub fn with_stable_hashing_context<R>(
|
||||
let hcx = StableHashingContext::new(
|
||||
self.sess,
|
||||
&*definitions,
|
||||
&*self.cstore,
|
||||
&*self.untracked_resolutions.cstore,
|
||||
&self.untracked_resolutions.source_span,
|
||||
);
|
||||
f(hcx)
|
||||
@ -2364,7 +2365,7 @@ pub fn mk_ty(self, st: TyKind<'tcx>) -> Ty<'tcx> {
|
||||
st,
|
||||
self.sess,
|
||||
&self.definitions.read(),
|
||||
&*self.cstore,
|
||||
&*self.untracked_resolutions.cstore,
|
||||
// This is only used to create a stable hashing context.
|
||||
&self.untracked_resolutions.source_span,
|
||||
)
|
||||
|
@ -38,11 +38,13 @@
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def::{CtorKind, CtorOf, DefKind, LifetimeRes, Res};
|
||||
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, LocalDefIdMap};
|
||||
use rustc_hir::definitions::Definitions;
|
||||
use rustc_hir::Node;
|
||||
use rustc_index::vec::IndexVec;
|
||||
use rustc_macros::HashStable;
|
||||
use rustc_query_system::ich::StableHashingContext;
|
||||
use rustc_serialize::{Decodable, Encodable};
|
||||
use rustc_session::cstore::CrateStoreDyn;
|
||||
use rustc_span::hygiene::MacroKind;
|
||||
use rustc_span::symbol::{kw, sym, Ident, Symbol};
|
||||
use rustc_span::{ExpnId, Span};
|
||||
@ -142,8 +144,15 @@
|
||||
|
||||
pub type RegisteredTools = FxHashSet<Ident>;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct ResolverOutputs {
|
||||
pub definitions: Definitions,
|
||||
pub global_ctxt: ResolverGlobalCtxt,
|
||||
pub ast_lowering: ResolverAstLowering,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct ResolverGlobalCtxt {
|
||||
pub cstore: Box<CrateStoreDyn>,
|
||||
pub visibilities: FxHashMap<LocalDefId, Visibility>,
|
||||
/// This field is used to decide whether we should make `PRIVATE_IN_PUBLIC` a hard error.
|
||||
pub has_pub_restricted: bool,
|
||||
|
@ -42,9 +42,10 @@
|
||||
use rustc_middle::metadata::ModChild;
|
||||
use rustc_middle::middle::privacy::AccessLevels;
|
||||
use rustc_middle::span_bug;
|
||||
use rustc_middle::ty::{self, DefIdTree, MainDefinition, RegisteredTools, ResolverOutputs};
|
||||
use rustc_middle::ty::{self, DefIdTree, MainDefinition, RegisteredTools};
|
||||
use rustc_middle::ty::{ResolverGlobalCtxt, ResolverOutputs};
|
||||
use rustc_query_system::ich::StableHashingContext;
|
||||
use rustc_session::cstore::{CrateStore, CrateStoreDyn, MetadataLoaderDyn};
|
||||
use rustc_session::cstore::{CrateStore, MetadataLoaderDyn};
|
||||
use rustc_session::lint::LintBuffer;
|
||||
use rustc_session::Session;
|
||||
use rustc_span::hygiene::{ExpnId, LocalExpnId, MacroKind, SyntaxContext, Transparency};
|
||||
@ -1376,9 +1377,7 @@ pub fn arenas() -> ResolverArenas<'a> {
|
||||
Default::default()
|
||||
}
|
||||
|
||||
pub fn into_outputs(
|
||||
self,
|
||||
) -> (Definitions, Box<CrateStoreDyn>, ResolverOutputs, ty::ResolverAstLowering) {
|
||||
pub fn into_outputs(self) -> ResolverOutputs {
|
||||
let proc_macros = self.proc_macros.iter().map(|id| self.local_def_id(*id)).collect();
|
||||
let definitions = self.definitions;
|
||||
let cstore = Box::new(self.crate_loader.into_cstore());
|
||||
@ -1394,7 +1393,8 @@ pub fn into_outputs(
|
||||
let main_def = self.main_def;
|
||||
let confused_type_with_std_module = self.confused_type_with_std_module;
|
||||
let access_levels = self.access_levels;
|
||||
let resolutions = ResolverOutputs {
|
||||
let global_ctxt = ResolverGlobalCtxt {
|
||||
cstore,
|
||||
source_span,
|
||||
expn_that_defined,
|
||||
visibilities,
|
||||
@ -1416,7 +1416,7 @@ pub fn into_outputs(
|
||||
confused_type_with_std_module,
|
||||
registered_tools: self.registered_tools,
|
||||
};
|
||||
let resolutions_lowering = ty::ResolverAstLowering {
|
||||
let ast_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,
|
||||
@ -1429,16 +1429,15 @@ pub fn into_outputs(
|
||||
trait_map: self.trait_map,
|
||||
builtin_macro_kinds: self.builtin_macro_kinds,
|
||||
};
|
||||
(definitions, cstore, resolutions, resolutions_lowering)
|
||||
ResolverOutputs { definitions, global_ctxt, ast_lowering }
|
||||
}
|
||||
|
||||
pub fn clone_outputs(
|
||||
&self,
|
||||
) -> (Definitions, Box<CrateStoreDyn>, ResolverOutputs, ty::ResolverAstLowering) {
|
||||
pub fn clone_outputs(&self) -> ResolverOutputs {
|
||||
let proc_macros = self.proc_macros.iter().map(|id| self.local_def_id(*id)).collect();
|
||||
let definitions = self.definitions.clone();
|
||||
let cstore = Box::new(self.cstore().clone());
|
||||
let resolutions = ResolverOutputs {
|
||||
let global_ctxt = ResolverGlobalCtxt {
|
||||
cstore,
|
||||
source_span: self.source_span.clone(),
|
||||
expn_that_defined: self.expn_that_defined.clone(),
|
||||
visibilities: self.visibilities.clone(),
|
||||
@ -1460,7 +1459,7 @@ pub fn clone_outputs(
|
||||
registered_tools: self.registered_tools.clone(),
|
||||
access_levels: self.access_levels.clone(),
|
||||
};
|
||||
let resolutions_lowering = ty::ResolverAstLowering {
|
||||
let ast_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(),
|
||||
@ -1473,7 +1472,7 @@ pub fn clone_outputs(
|
||||
trait_map: self.trait_map.clone(),
|
||||
builtin_macro_kinds: self.builtin_macro_kinds.clone(),
|
||||
};
|
||||
(definitions, cstore, resolutions, resolutions_lowering)
|
||||
ResolverOutputs { definitions, global_ctxt, ast_lowering }
|
||||
}
|
||||
|
||||
fn create_stable_hashing_context(&self) -> StableHashingContext<'_> {
|
||||
|
Loading…
Reference in New Issue
Block a user