]> git.lizzy.rs Git - rust.git/commitdiff
Make allocator_kind a query.
authorCamille GILLOT <gillot.camille@gmail.com>
Tue, 11 May 2021 20:05:54 +0000 (22:05 +0200)
committerCamille GILLOT <gillot.camille@gmail.com>
Sun, 20 Jun 2021 09:52:51 +0000 (11:52 +0200)
compiler/rustc_ast/src/expand/allocator.rs
compiler/rustc_codegen_cranelift/src/allocator.rs
compiler/rustc_codegen_ssa/src/back/symbol_export.rs
compiler/rustc_codegen_ssa/src/base.rs
compiler/rustc_middle/src/query/mod.rs
compiler/rustc_middle/src/ty/context.rs
compiler/rustc_middle/src/ty/query/mod.rs

index cd27f958e4641868450fbd841313b0b006bc3176..1976e4ad3c9fc73e4fe06f704990a7bcebacff7c 100644 (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,
index 357a9f2daf746e67e4f9bdea0e38a37637251e27..d39486c2f1002e485f849fb0c27fb3564c384e46 100644 (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 {
index b2ecc3b0f3242e33738c6255ca35e4365ff87f14..8a035e62e2a93263ad67700382f2e7b7a9080307 100644 (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));
index 38ab39febe066c4c0db3adfb8f4286d1ff0289e7..31ae84f4ca11d4d628fe7d115a30cc8f2d7198ca 100644 (file)
@@ -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);
index dda407940e3c3a950a1ed6a36c078f9dd88803f6..f66ff008801b689d9a76424fb38f639654ef054a 100644 (file)
         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) }
index a74070100f413131b1cb2e9b4e34b96654110200..558d3adffa9945b392f49f4cff93649466ceccc5 100644 (file)
@@ -26,7 +26,6 @@
     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 @@ pub fn crates(self) -> &'tcx [CrateNum] {
         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(())
     }
@@ -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();
 }
index 297110ee3ecff36950a33be1bd8babb3b86e57cc..2ac121fec7ee0db4df90c7de2766bf16695d300d 100644 (file)
@@ -33,6 +33,7 @@
 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;