From 6a371d2c8939c3a32ff0da69eb66b271ffa58288 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Tue, 11 May 2021 22:05:54 +0200 Subject: [PATCH 1/3] Make allocator_kind a query. --- compiler/rustc_ast/src/expand/allocator.rs | 2 +- compiler/rustc_codegen_cranelift/src/allocator.rs | 2 +- compiler/rustc_codegen_ssa/src/back/symbol_export.rs | 2 +- compiler/rustc_codegen_ssa/src/base.rs | 2 +- compiler/rustc_middle/src/query/mod.rs | 4 ++++ compiler/rustc_middle/src/ty/context.rs | 6 +----- compiler/rustc_middle/src/ty/query/mod.rs | 1 + 7 files changed, 10 insertions(+), 9 deletions(-) diff --git a/compiler/rustc_ast/src/expand/allocator.rs b/compiler/rustc_ast/src/expand/allocator.rs index cd27f958e46..1976e4ad3c9 100644 --- a/compiler/rustc_ast/src/expand/allocator.rs +++ b/compiler/rustc_ast/src/expand/allocator.rs @@ -1,6 +1,6 @@ use rustc_span::symbol::{sym, Symbol}; -#[derive(Clone, Copy)] +#[derive(Clone, Debug, Copy, HashStable_Generic)] pub enum AllocatorKind { Global, Default, diff --git a/compiler/rustc_codegen_cranelift/src/allocator.rs b/compiler/rustc_codegen_cranelift/src/allocator.rs index 357a9f2daf7..d39486c2f10 100644 --- a/compiler/rustc_codegen_cranelift/src/allocator.rs +++ b/compiler/rustc_codegen_cranelift/src/allocator.rs @@ -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 { diff --git a/compiler/rustc_codegen_ssa/src/back/symbol_export.rs b/compiler/rustc_codegen_ssa/src/back/symbol_export.rs index b2ecc3b0f32..8a035e62e2a 100644 --- a/compiler/rustc_codegen_ssa/src/back/symbol_export.rs +++ b/compiler/rustc_codegen_ssa/src/back/symbol_export.rs @@ -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)); diff --git a/compiler/rustc_codegen_ssa/src/base.rs b/compiler/rustc_codegen_ssa/src/base.rs index 38ab39febe0..31ae84f4ca1 100644 --- a/compiler/rustc_codegen_ssa/src/base.rs +++ b/compiler/rustc_codegen_ssa/src/base.rs @@ -518,7 +518,7 @@ pub fn codegen_crate( }); 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); diff --git a/compiler/rustc_middle/src/query/mod.rs b/compiler/rustc_middle/src/query/mod.rs index dda407940e3..f66ff008801 100644 --- a/compiler/rustc_middle/src/query/mod.rs +++ b/compiler/rustc_middle/src/query/mod.rs @@ -1416,6 +1416,10 @@ rustc_queries! { eval_always desc { "check whether crate {} is a private dependency", c } } + query allocator_kind(_: ()) -> Option { + eval_always + desc { "allocator kind for the current crate" } + } query upvars_mentioned(def_id: DefId) -> Option<&'tcx FxIndexMap> { desc { |tcx| "collecting upvars mentioned in `{}`", tcx.def_path_str(def_id) } diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index a74070100f4..558d3adffa9 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -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; @@ -1259,10 +1258,6 @@ impl<'tcx> TyCtxt<'tcx> { self.all_crate_nums(()) } - pub fn allocator_kind(self) -> Option { - self.cstore.allocator_kind() - } - pub fn features(self) -> &'tcx rustc_feature::Features { self.features_query(()) } @@ -2839,4 +2834,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.cstore.allocator_kind(); } diff --git a/compiler/rustc_middle/src/ty/query/mod.rs b/compiler/rustc_middle/src/ty/query/mod.rs index 297110ee3ec..2ac121fec7e 100644 --- a/compiler/rustc_middle/src/ty/query/mod.rs +++ b/compiler/rustc_middle/src/ty/query/mod.rs @@ -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; From ed9ee25108bdeaa60e47c71db2f8db3e974d16fa Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Thu, 3 Jun 2021 19:59:41 +0200 Subject: [PATCH 2/3] 256th query. --- compiler/rustc_middle/src/dep_graph/dep_node.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_middle/src/dep_graph/dep_node.rs b/compiler/rustc_middle/src/dep_graph/dep_node.rs index aa54d1ae7b9..8476929eaec 100644 --- a/compiler/rustc_middle/src/dep_graph/dep_node.rs +++ b/compiler/rustc_middle/src/dep_graph/dep_node.rs @@ -285,7 +285,7 @@ pub type DepNode = rustc_query_system::dep_graph::DepNode; // 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); From cbdfbdd40bb6c25cf33c922339f0b303d0576377 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sun, 6 Jun 2021 11:30:08 +0200 Subject: [PATCH 3/3] Implement the query in cstore_impl. --- compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs | 6 +----- compiler/rustc_middle/src/middle/cstore.rs | 2 -- compiler/rustc_middle/src/ty/context.rs | 1 - 3 files changed, 1 insertion(+), 8 deletions(-) diff --git a/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs b/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs index 9a97835d9c0..5e116122179 100644 --- a/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs +++ b/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs @@ -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; @@ -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, @@ -535,8 +535,4 @@ impl CrateStore for CStore { fn encode_metadata(&self, tcx: TyCtxt<'_>) -> EncodedMetadata { encoder::encode_metadata(tcx) } - - fn allocator_kind(&self) -> Option { - self.allocator_kind() - } } diff --git a/compiler/rustc_middle/src/middle/cstore.rs b/compiler/rustc_middle/src/middle/cstore.rs index a7ab43d106c..1f40b227d91 100644 --- a/compiler/rustc_middle/src/middle/cstore.rs +++ b/compiler/rustc_middle/src/middle/cstore.rs @@ -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; @@ -215,7 +214,6 @@ pub trait CrateStore { // utility functions fn encode_metadata(&self, tcx: TyCtxt<'_>) -> EncodedMetadata; - fn allocator_kind(&self) -> Option; } pub type CrateStoreDyn = dyn CrateStore + sync::Sync; diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index 558d3adffa9..0c3a01bcb73 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -2834,5 +2834,4 @@ 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.cstore.allocator_kind(); }