Skip to content

Commit 3455304

Browse files
committed
Auto merge of rust-lang#85909 - cjgillot:alloc-kind-query, r=Aaron1011
Make allocator_kind a query. Part of rust-lang#85153 r? `@Aaron1011`
2 parents 3e9d7ec + cbdfbdd commit 3455304

File tree

10 files changed

+11
-17
lines changed

10 files changed

+11
-17
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_metadata/src/rmeta/decoder/cstore_impl.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use crate::native_libs;
44
use crate::rmeta::encoder;
55

66
use rustc_ast as ast;
7-
use rustc_ast::expand::allocator::AllocatorKind;
87
use rustc_data_structures::stable_map::FxHashMap;
98
use rustc_data_structures::svh::Svh;
109
use rustc_hir as hir;
@@ -242,6 +241,7 @@ pub fn provide(providers: &mut Providers) {
242241
// therefore no actual inputs, they're just reading tables calculated in
243242
// resolve! Does this work? Unsure! That's what the issue is about
244243
*providers = Providers {
244+
allocator_kind: |tcx, ()| CStore::from_tcx(tcx).allocator_kind(),
245245
is_dllimport_foreign_item: |tcx, id| match tcx.native_library_kind(id) {
246246
Some(
247247
NativeLibKind::Dylib { .. } | NativeLibKind::RawDylib | NativeLibKind::Unspecified,
@@ -535,8 +535,4 @@ impl CrateStore for CStore {
535535
fn encode_metadata(&self, tcx: TyCtxt<'_>) -> EncodedMetadata {
536536
encoder::encode_metadata(tcx)
537537
}
538-
539-
fn allocator_kind(&self) -> Option<AllocatorKind> {
540-
self.allocator_kind()
541-
}
542538
}

compiler/rustc_middle/src/dep_graph/dep_node.rs

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

290290
#[cfg(not(any(target_arch = "x86", target_arch = "x86_64")))]
291291
static_assert_size!(DepNode, 24);

compiler/rustc_middle/src/middle/cstore.rs

-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use crate::ty::TyCtxt;
66

77
use rustc_ast as ast;
8-
use rustc_ast::expand::allocator::AllocatorKind;
98
use rustc_data_structures::svh::Svh;
109
use rustc_data_structures::sync::{self, MetadataRef};
1110
use rustc_hir::def::DefKind;
@@ -215,7 +214,6 @@ pub trait CrateStore {
215214

216215
// utility functions
217216
fn encode_metadata(&self, tcx: TyCtxt<'_>) -> EncodedMetadata;
218-
fn allocator_kind(&self) -> Option<AllocatorKind>;
219217
}
220218

221219
pub type CrateStoreDyn = dyn CrateStore + sync::Sync;

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

-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;
@@ -1260,10 +1259,6 @@ impl<'tcx> TyCtxt<'tcx> {
12601259
self.all_crate_nums(())
12611260
}
12621261

1263-
pub fn allocator_kind(self) -> Option<AllocatorKind> {
1264-
self.cstore.allocator_kind()
1265-
}
1266-
12671262
pub fn features(self) -> &'tcx rustc_feature::Features {
12681263
self.features_query(())
12691264
}

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)