Skip to content

Commit 6a371d2

Browse files
committed
Make allocator_kind a query.
1 parent 9543636 commit 6a371d2

File tree

7 files changed

+10
-9
lines changed

7 files changed

+10
-9
lines changed

compiler/rustc_ast/src/expand/allocator.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use rustc_span::symbol::{sym, Symbol};
22

3-
#[derive(Clone, Copy)]
3+
#[derive(Clone, Debug, Copy, HashStable_Generic)]
44
pub enum AllocatorKind {
55
Global,
66
Default,

compiler/rustc_codegen_cranelift/src/allocator.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub(crate) fn codegen(
1919
});
2020
if any_dynamic_crate {
2121
false
22-
} else if let Some(kind) = tcx.allocator_kind() {
22+
} else if let Some(kind) = tcx.allocator_kind(()) {
2323
codegen_inner(module, unwind_context, kind);
2424
true
2525
} else {

compiler/rustc_codegen_ssa/src/back/symbol_export.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ fn exported_symbols_provider_local(
180180
symbols.push((exported_symbol, SymbolExportLevel::C));
181181
}
182182

183-
if tcx.allocator_kind().is_some() {
183+
if tcx.allocator_kind(()).is_some() {
184184
for method in ALLOCATOR_METHODS {
185185
let symbol_name = format!("__rust_{}", method.name);
186186
let exported_symbol = ExportedSymbol::NoDefId(SymbolName::new(tcx, &symbol_name));

compiler/rustc_codegen_ssa/src/base.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ pub fn codegen_crate<B: ExtraBackendMethods>(
518518
});
519519
let allocator_module = if any_dynamic_crate {
520520
None
521-
} else if let Some(kind) = tcx.allocator_kind() {
521+
} else if let Some(kind) = tcx.allocator_kind(()) {
522522
let llmod_id =
523523
cgu_name_builder.build_cgu_name(LOCAL_CRATE, &["crate"], Some("allocator")).to_string();
524524
let mut modules = backend.new_metadata(tcx, &llmod_id);

compiler/rustc_middle/src/query/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1416,6 +1416,10 @@ rustc_queries! {
14161416
eval_always
14171417
desc { "check whether crate {} is a private dependency", c }
14181418
}
1419+
query allocator_kind(_: ()) -> Option<AllocatorKind> {
1420+
eval_always
1421+
desc { "allocator kind for the current crate" }
1422+
}
14191423

14201424
query upvars_mentioned(def_id: DefId) -> Option<&'tcx FxIndexMap<hir::HirId, hir::Upvar>> {
14211425
desc { |tcx| "collecting upvars mentioned in `{}`", tcx.def_path_str(def_id) }

compiler/rustc_middle/src/ty/context.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ use crate::ty::{
2626
TraitObjectVisitor, Ty, TyKind, TyS, TyVar, TyVid, TypeAndMut, UintTy, Visibility,
2727
};
2828
use rustc_ast as ast;
29-
use rustc_ast::expand::allocator::AllocatorKind;
3029
use rustc_attr as attr;
3130
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
3231
use rustc_data_structures::profiling::SelfProfilerRef;
@@ -1259,10 +1258,6 @@ impl<'tcx> TyCtxt<'tcx> {
12591258
self.all_crate_nums(())
12601259
}
12611260

1262-
pub fn allocator_kind(self) -> Option<AllocatorKind> {
1263-
self.cstore.allocator_kind()
1264-
}
1265-
12661261
pub fn features(self) -> &'tcx rustc_feature::Features {
12671262
self.features_query(())
12681263
}
@@ -2839,4 +2834,5 @@ pub fn provide(providers: &mut ty::query::Providers) {
28392834
// We want to check if the panic handler was defined in this crate
28402835
tcx.lang_items().panic_impl().map_or(false, |did| did.is_local())
28412836
};
2837+
providers.allocator_kind = |tcx, ()| tcx.cstore.allocator_kind();
28422838
}

compiler/rustc_middle/src/ty/query/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ use crate::traits::{self, ImplSource};
3333
use crate::ty::subst::{GenericArg, SubstsRef};
3434
use crate::ty::util::AlwaysRequiresDrop;
3535
use crate::ty::{self, AdtSizedConstraint, CrateInherentImpls, ParamEnvAnd, Ty, TyCtxt};
36+
use rustc_ast::expand::allocator::AllocatorKind;
3637
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap};
3738
use rustc_data_structures::steal::Steal;
3839
use rustc_data_structures::svh::Svh;

0 commit comments

Comments
 (0)