Make allocator_kind a query.

This commit is contained in:
Camille GILLOT 2021-05-11 22:05:54 +02:00
parent e1e6949558
commit ee94fbb607
8 changed files with 10 additions and 10 deletions

View file

@ -1,6 +1,6 @@
use rustc_span::symbol::{sym, Symbol};
#[derive(Clone, Copy)]
#[derive(Clone, Debug, Copy, HashStable_Generic)]
pub enum AllocatorKind {
Global,
Default,

View file

@ -19,7 +19,7 @@ pub(crate) fn codegen(
});
if any_dynamic_crate {
false
} else if let Some(kind) = tcx.allocator_kind() {
} else if let Some(kind) = tcx.allocator_kind(()) {
codegen_inner(module, unwind_context, kind);
true
} else {

View file

@ -180,7 +180,7 @@ fn exported_symbols_provider_local(
symbols.push((exported_symbol, SymbolExportLevel::C));
}
if tcx.allocator_kind().is_some() {
if tcx.allocator_kind(()).is_some() {
for method in ALLOCATOR_METHODS {
let symbol_name = format!("__rust_{}", method.name);
let exported_symbol = ExportedSymbol::NoDefId(SymbolName::new(tcx, &symbol_name));

View file

@ -517,7 +517,7 @@ pub fn codegen_crate<B: ExtraBackendMethods>(
});
let allocator_module = if any_dynamic_crate {
None
} else if let Some(kind) = tcx.allocator_kind() {
} else if let Some(kind) = tcx.allocator_kind(()) {
let llmod_id =
cgu_name_builder.build_cgu_name(LOCAL_CRATE, &["crate"], Some("allocator")).to_string();
let mut modules = backend.new_metadata(tcx, &llmod_id);

View file

@ -285,7 +285,7 @@ pub type DepNode = rustc_query_system::dep_graph::DepNode<DepKind>;
// required that their size stay the same, but we don't want to change
// it inadvertently. This assert just ensures we're aware of any change.
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
static_assert_size!(DepNode, 17);
static_assert_size!(DepNode, 18);
#[cfg(not(any(target_arch = "x86", target_arch = "x86_64")))]
static_assert_size!(DepNode, 24);

View file

@ -1412,6 +1412,9 @@ rustc_queries! {
eval_always
desc { "generating a postorder list of CrateNums" }
}
query allocator_kind(_: ()) -> Option<AllocatorKind> {
desc { "allocator kind for the current crate" }
}
query upvars_mentioned(def_id: DefId) -> Option<&'tcx FxIndexMap<hir::HirId, hir::Upvar>> {
desc { |tcx| "collecting upvars mentioned in `{}`", tcx.def_path_str(def_id) }

View file

@ -25,7 +25,6 @@ use crate::ty::{
TraitObjectVisitor, Ty, TyKind, TyS, TyVar, TyVid, TypeAndMut, UintTy,
};
use rustc_ast as ast;
use rustc_ast::expand::allocator::AllocatorKind;
use rustc_attr as attr;
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::profiling::SelfProfilerRef;
@ -1207,10 +1206,6 @@ impl<'tcx> TyCtxt<'tcx> {
self.all_crate_nums(())
}
pub fn allocator_kind(self) -> Option<AllocatorKind> {
self.untracked_resolutions.cstore.allocator_kind()
}
pub fn features(self) -> &'tcx rustc_feature::Features {
self.features_query(())
}
@ -2817,4 +2812,5 @@ pub fn provide(providers: &mut ty::query::Providers) {
// We want to check if the panic handler was defined in this crate
tcx.lang_items().panic_impl().map_or(false, |did| did.is_local())
};
providers.allocator_kind = |tcx, ()| tcx.resolutions(()).cstore.allocator_kind();
}

View file

@ -33,6 +33,7 @@ use crate::traits::{self, ImplSource};
use crate::ty::subst::{GenericArg, SubstsRef};
use crate::ty::util::AlwaysRequiresDrop;
use crate::ty::{self, AdtSizedConstraint, CrateInherentImpls, ParamEnvAnd, Ty, TyCtxt};
use rustc_ast::expand::allocator::AllocatorKind;
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap};
use rustc_data_structures::steal::Steal;
use rustc_data_structures::svh::Svh;