Skip to content

Make allocator_kind a query. #85909

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_ast/src/expand/allocator.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use rustc_span::symbol::{sym, Symbol};

#[derive(Clone, Copy)]
#[derive(Clone, Debug, Copy, HashStable_Generic)]
pub enum AllocatorKind {
Global,
Default,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_cranelift/src/allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_ssa/src/back/symbol_export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_ssa/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,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);
Expand Down
6 changes: 1 addition & 5 deletions compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use crate::native_libs;
use crate::rmeta::encoder;

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

fn allocator_kind(&self) -> Option<AllocatorKind> {
self.allocator_kind()
}
}
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/dep_graph/dep_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_middle/src/middle/cstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use crate::ty::TyCtxt;

use rustc_ast as ast;
use rustc_ast::expand::allocator::AllocatorKind;
use rustc_data_structures::svh::Svh;
use rustc_data_structures::sync::{self, MetadataRef};
use rustc_hir::def::DefKind;
Expand Down Expand Up @@ -215,7 +214,6 @@ pub trait CrateStore {

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

pub type CrateStoreDyn = dyn CrateStore + sync::Sync;
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_middle/src/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1416,6 +1416,10 @@ rustc_queries! {
eval_always
desc { "check whether crate {} is a private dependency", c }
}
query allocator_kind(_: ()) -> Option<AllocatorKind> {
eval_always
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) }
Expand Down
5 changes: 0 additions & 5 deletions compiler/rustc_middle/src/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ use crate::ty::{
TraitObjectVisitor, Ty, TyKind, TyS, TyVar, TyVid, TypeAndMut, UintTy, Visibility,
};
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;
Expand Down Expand Up @@ -1259,10 +1258,6 @@ impl<'tcx> TyCtxt<'tcx> {
self.all_crate_nums(())
}

pub fn allocator_kind(self) -> Option<AllocatorKind> {
self.cstore.allocator_kind()
}

pub fn features(self) -> &'tcx rustc_feature::Features {
self.features_query(())
}
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_middle/src/ty/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down