LocalCrate key
This commit is contained in:
parent
dcaf956de0
commit
d213114cb5
11 changed files with 33 additions and 21 deletions
|
@ -10,6 +10,7 @@ use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
|
||||||
use rustc_middle::middle::exported_symbols::{
|
use rustc_middle::middle::exported_symbols::{
|
||||||
metadata_symbol_name, ExportedSymbol, SymbolExportInfo, SymbolExportKind, SymbolExportLevel,
|
metadata_symbol_name, ExportedSymbol, SymbolExportInfo, SymbolExportKind, SymbolExportLevel,
|
||||||
};
|
};
|
||||||
|
use rustc_middle::query::LocalCrate;
|
||||||
use rustc_middle::ty::query::{ExternProviders, Providers};
|
use rustc_middle::ty::query::{ExternProviders, Providers};
|
||||||
use rustc_middle::ty::subst::{GenericArgKind, SubstsRef};
|
use rustc_middle::ty::subst::{GenericArgKind, SubstsRef};
|
||||||
use rustc_middle::ty::Instance;
|
use rustc_middle::ty::Instance;
|
||||||
|
@ -41,7 +42,7 @@ pub fn crates_export_threshold(crate_types: &[CrateType]) -> SymbolExportLevel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn reachable_non_generics_provider(tcx: TyCtxt<'_>, (): ()) -> DefIdMap<SymbolExportInfo> {
|
fn reachable_non_generics_provider(tcx: TyCtxt<'_>, _: LocalCrate) -> DefIdMap<SymbolExportInfo> {
|
||||||
if !tcx.sess.opts.output_types.should_codegen() {
|
if !tcx.sess.opts.output_types.should_codegen() {
|
||||||
return Default::default();
|
return Default::default();
|
||||||
}
|
}
|
||||||
|
@ -168,7 +169,7 @@ fn is_reachable_non_generic_provider_extern(tcx: TyCtxt<'_>, def_id: DefId) -> b
|
||||||
|
|
||||||
fn exported_symbols_provider_local(
|
fn exported_symbols_provider_local(
|
||||||
tcx: TyCtxt<'_>,
|
tcx: TyCtxt<'_>,
|
||||||
(): (),
|
_: LocalCrate,
|
||||||
) -> &[(ExportedSymbol<'_>, SymbolExportInfo)] {
|
) -> &[(ExportedSymbol<'_>, SymbolExportInfo)] {
|
||||||
if !tcx.sess.opts.output_types.should_codegen() {
|
if !tcx.sess.opts.output_types.should_codegen() {
|
||||||
return &[];
|
return &[];
|
||||||
|
|
|
@ -13,6 +13,7 @@ use rustc_middle::arena::ArenaAllocatable;
|
||||||
use rustc_middle::metadata::ModChild;
|
use rustc_middle::metadata::ModChild;
|
||||||
use rustc_middle::middle::exported_symbols::ExportedSymbol;
|
use rustc_middle::middle::exported_symbols::ExportedSymbol;
|
||||||
use rustc_middle::middle::stability::DeprecationEntry;
|
use rustc_middle::middle::stability::DeprecationEntry;
|
||||||
|
use rustc_middle::query::LocalCrate;
|
||||||
use rustc_middle::ty::fast_reject::SimplifiedType;
|
use rustc_middle::ty::fast_reject::SimplifiedType;
|
||||||
use rustc_middle::ty::query::{ExternProviders, Providers};
|
use rustc_middle::ty::query::{ExternProviders, Providers};
|
||||||
use rustc_middle::ty::{self, TyCtxt};
|
use rustc_middle::ty::{self, TyCtxt};
|
||||||
|
@ -367,7 +368,7 @@ pub(in crate::rmeta) fn provide(providers: &mut Providers) {
|
||||||
*providers = Providers {
|
*providers = Providers {
|
||||||
allocator_kind: |tcx, ()| CStore::from_tcx(tcx).allocator_kind(),
|
allocator_kind: |tcx, ()| CStore::from_tcx(tcx).allocator_kind(),
|
||||||
alloc_error_handler_kind: |tcx, ()| CStore::from_tcx(tcx).alloc_error_handler_kind(),
|
alloc_error_handler_kind: |tcx, ()| CStore::from_tcx(tcx).alloc_error_handler_kind(),
|
||||||
is_private_dep: |_tcx, ()| false,
|
is_private_dep: |_tcx, LocalCrate| false,
|
||||||
native_library: |tcx, id| {
|
native_library: |tcx, id| {
|
||||||
tcx.native_libraries(id.krate)
|
tcx.native_libraries(id.krate)
|
||||||
.iter()
|
.iter()
|
||||||
|
@ -383,8 +384,8 @@ pub(in crate::rmeta) fn provide(providers: &mut Providers) {
|
||||||
.contains(&id)
|
.contains(&id)
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
native_libraries: |tcx, ()| native_libs::collect(tcx),
|
native_libraries: |tcx, LocalCrate| native_libs::collect(tcx),
|
||||||
foreign_modules: |tcx, ()| {
|
foreign_modules: |tcx, LocalCrate| {
|
||||||
foreign_modules::collect(tcx).into_iter().map(|m| (m.def_id, m)).collect()
|
foreign_modules::collect(tcx).into_iter().map(|m| (m.def_id, m)).collect()
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -482,8 +483,8 @@ pub(in crate::rmeta) fn provide(providers: &mut Providers) {
|
||||||
},
|
},
|
||||||
|
|
||||||
dependency_formats: |tcx, ()| Lrc::new(crate::dependency_format::calculate(tcx)),
|
dependency_formats: |tcx, ()| Lrc::new(crate::dependency_format::calculate(tcx)),
|
||||||
has_global_allocator: |tcx, ()| CStore::from_tcx(tcx).has_global_allocator(),
|
has_global_allocator: |tcx, LocalCrate| CStore::from_tcx(tcx).has_global_allocator(),
|
||||||
has_alloc_error_handler: |tcx, ()| CStore::from_tcx(tcx).has_alloc_error_handler(),
|
has_alloc_error_handler: |tcx, LocalCrate| CStore::from_tcx(tcx).has_alloc_error_handler(),
|
||||||
postorder_cnums: |tcx, ()| {
|
postorder_cnums: |tcx, ()| {
|
||||||
tcx.arena
|
tcx.arena
|
||||||
.alloc_slice(&CStore::from_tcx(tcx).crate_dependencies_in_postorder(LOCAL_CRATE))
|
.alloc_slice(&CStore::from_tcx(tcx).crate_dependencies_in_postorder(LOCAL_CRATE))
|
||||||
|
|
|
@ -24,6 +24,7 @@ use rustc_middle::middle::exported_symbols::{
|
||||||
metadata_symbol_name, ExportedSymbol, SymbolExportInfo,
|
metadata_symbol_name, ExportedSymbol, SymbolExportInfo,
|
||||||
};
|
};
|
||||||
use rustc_middle::mir::interpret;
|
use rustc_middle::mir::interpret;
|
||||||
|
use rustc_middle::query::LocalCrate;
|
||||||
use rustc_middle::traits::specialization_graph;
|
use rustc_middle::traits::specialization_graph;
|
||||||
use rustc_middle::ty::codec::TyEncoder;
|
use rustc_middle::ty::codec::TyEncoder;
|
||||||
use rustc_middle::ty::fast_reject::{self, SimplifiedType, TreatParams, TreatProjections};
|
use rustc_middle::ty::fast_reject::{self, SimplifiedType, TreatParams, TreatProjections};
|
||||||
|
@ -2240,7 +2241,7 @@ pub fn provide(providers: &mut Providers) {
|
||||||
.get(&def_id)
|
.get(&def_id)
|
||||||
.expect("no traits in scope for a doc link")
|
.expect("no traits in scope for a doc link")
|
||||||
},
|
},
|
||||||
traits_in_crate: |tcx, ()| {
|
traits_in_crate: |tcx, LocalCrate| {
|
||||||
let mut traits = Vec::new();
|
let mut traits = Vec::new();
|
||||||
for id in tcx.hir().items() {
|
for id in tcx.hir().items() {
|
||||||
if matches!(tcx.def_kind(id.owner_id), DefKind::Trait | DefKind::TraitAlias) {
|
if matches!(tcx.def_kind(id.owner_id), DefKind::Trait | DefKind::TraitAlias) {
|
||||||
|
@ -2252,7 +2253,7 @@ pub fn provide(providers: &mut Providers) {
|
||||||
traits.sort_by_cached_key(|&def_id| tcx.def_path_hash(def_id));
|
traits.sort_by_cached_key(|&def_id| tcx.def_path_hash(def_id));
|
||||||
tcx.arena.alloc_slice(&traits)
|
tcx.arena.alloc_slice(&traits)
|
||||||
},
|
},
|
||||||
trait_impls_in_crate: |tcx, ()| {
|
trait_impls_in_crate: |tcx, LocalCrate| {
|
||||||
let mut trait_impls = Vec::new();
|
let mut trait_impls = Vec::new();
|
||||||
for id in tcx.hir().items() {
|
for id in tcx.hir().items() {
|
||||||
if matches!(tcx.def_kind(id.owner_id), DefKind::Impl { .. })
|
if matches!(tcx.def_kind(id.owner_id), DefKind::Impl { .. })
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use crate::hir::{ModuleItems, Owner};
|
use crate::hir::{ModuleItems, Owner};
|
||||||
|
use crate::query::LocalCrate;
|
||||||
use crate::ty::TyCtxt;
|
use crate::ty::TyCtxt;
|
||||||
use rustc_ast as ast;
|
use rustc_ast as ast;
|
||||||
use rustc_data_structures::fingerprint::Fingerprint;
|
use rustc_data_structures::fingerprint::Fingerprint;
|
||||||
|
@ -1131,7 +1132,7 @@ impl<'hir> intravisit::Map<'hir> for Map<'hir> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn crate_hash(tcx: TyCtxt<'_>, (): ()) -> Svh {
|
pub(super) fn crate_hash(tcx: TyCtxt<'_>, _: LocalCrate) -> Svh {
|
||||||
let krate = tcx.hir_crate(());
|
let krate = tcx.hir_crate(());
|
||||||
let hir_body_hash = krate.opt_hir_hash.expect("HIR hash missing while computing crate hash");
|
let hir_body_hash = krate.opt_hir_hash.expect("HIR hash missing while computing crate hash");
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,10 @@ use rustc_query_system::query::{DefaultCacheSelector, SingleCacheSelector, VecCa
|
||||||
use rustc_span::symbol::{Ident, Symbol};
|
use rustc_span::symbol::{Ident, Symbol};
|
||||||
use rustc_span::{Span, DUMMY_SP};
|
use rustc_span::{Span, DUMMY_SP};
|
||||||
|
|
||||||
|
/// Placeholder for `CrateNum`'s "local" counterpart
|
||||||
|
#[derive(Copy, Clone, Debug)]
|
||||||
|
pub struct LocalCrate;
|
||||||
|
|
||||||
/// The `Key` trait controls what types can legally be used as the key
|
/// The `Key` trait controls what types can legally be used as the key
|
||||||
/// for a query.
|
/// for a query.
|
||||||
pub trait Key: Sized {
|
pub trait Key: Sized {
|
||||||
|
@ -115,11 +119,11 @@ impl Key for CrateNum {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AsLocalKey for CrateNum {
|
impl AsLocalKey for CrateNum {
|
||||||
type LocalKey = ();
|
type LocalKey = LocalCrate;
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn as_local_key(&self) -> Option<Self::LocalKey> {
|
fn as_local_key(&self) -> Option<Self::LocalKey> {
|
||||||
(*self == LOCAL_CRATE).then_some(())
|
(*self == LOCAL_CRATE).then_some(LocalCrate)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ use crate::ty::{self, print::describe_as_module, TyCtxt};
|
||||||
use rustc_span::def_id::LOCAL_CRATE;
|
use rustc_span::def_id::LOCAL_CRATE;
|
||||||
|
|
||||||
mod keys;
|
mod keys;
|
||||||
pub use keys::{AsLocalKey, Key};
|
pub use keys::{AsLocalKey, Key, LocalCrate};
|
||||||
|
|
||||||
// Each of these queries corresponds to a function pointer field in the
|
// Each of these queries corresponds to a function pointer field in the
|
||||||
// `Providers` struct for requesting a value of that type, and a method
|
// `Providers` struct for requesting a value of that type, and a method
|
||||||
|
|
|
@ -15,6 +15,7 @@ use crate::mir::interpret::{self, Allocation, ConstAllocation};
|
||||||
use crate::mir::{
|
use crate::mir::{
|
||||||
Body, BorrowCheckResult, Field, Local, Place, PlaceElem, ProjectionKind, Promoted,
|
Body, BorrowCheckResult, Field, Local, Place, PlaceElem, ProjectionKind, Promoted,
|
||||||
};
|
};
|
||||||
|
use crate::query::LocalCrate;
|
||||||
use crate::thir::Thir;
|
use crate::thir::Thir;
|
||||||
use crate::traits;
|
use crate::traits;
|
||||||
use crate::traits::solve;
|
use crate::traits::solve;
|
||||||
|
@ -2519,10 +2520,10 @@ pub fn provide(providers: &mut ty::query::Providers) {
|
||||||
providers.extern_mod_stmt_cnum =
|
providers.extern_mod_stmt_cnum =
|
||||||
|tcx, id| tcx.resolutions(()).extern_crate_map.get(&id).cloned();
|
|tcx, id| tcx.resolutions(()).extern_crate_map.get(&id).cloned();
|
||||||
providers.is_panic_runtime =
|
providers.is_panic_runtime =
|
||||||
|tcx, ()| tcx.sess.contains_name(tcx.hir().krate_attrs(), sym::panic_runtime);
|
|tcx, LocalCrate| tcx.sess.contains_name(tcx.hir().krate_attrs(), sym::panic_runtime);
|
||||||
providers.is_compiler_builtins =
|
providers.is_compiler_builtins =
|
||||||
|tcx, ()| tcx.sess.contains_name(tcx.hir().krate_attrs(), sym::compiler_builtins);
|
|tcx, LocalCrate| tcx.sess.contains_name(tcx.hir().krate_attrs(), sym::compiler_builtins);
|
||||||
providers.has_panic_handler = |tcx, ()| {
|
providers.has_panic_handler = |tcx, LocalCrate| {
|
||||||
// We want to check if the panic handler was defined in this crate
|
// 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())
|
tcx.lang_items().panic_impl().map_or(false, |did| did.is_local())
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
use rustc_hir::def_id::{LocalDefId, LOCAL_CRATE};
|
use rustc_hir::def_id::{LocalDefId, LOCAL_CRATE};
|
||||||
use rustc_middle::mir::*;
|
use rustc_middle::mir::*;
|
||||||
|
use rustc_middle::query::LocalCrate;
|
||||||
use rustc_middle::ty::layout;
|
use rustc_middle::ty::layout;
|
||||||
use rustc_middle::ty::query::Providers;
|
use rustc_middle::ty::query::Providers;
|
||||||
use rustc_middle::ty::{self, TyCtxt};
|
use rustc_middle::ty::{self, TyCtxt};
|
||||||
|
@ -121,7 +122,7 @@ fn has_ffi_unwind_calls(tcx: TyCtxt<'_>, local_def_id: LocalDefId) -> bool {
|
||||||
tainted
|
tainted
|
||||||
}
|
}
|
||||||
|
|
||||||
fn required_panic_strategy(tcx: TyCtxt<'_>, (): ()) -> Option<PanicStrategy> {
|
fn required_panic_strategy(tcx: TyCtxt<'_>, _: LocalCrate) -> Option<PanicStrategy> {
|
||||||
if tcx.is_panic_runtime(LOCAL_CRATE) {
|
if tcx.is_panic_runtime(LOCAL_CRATE) {
|
||||||
return Some(tcx.sess.panic_strategy());
|
return Some(tcx.sess.panic_strategy());
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,8 +5,8 @@ use rustc_data_structures::fx::FxHashSet;
|
||||||
use rustc_expand::base::resolve_path;
|
use rustc_expand::base::resolve_path;
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::HirId;
|
use rustc_hir::HirId;
|
||||||
use rustc_middle::ty::query::Providers;
|
|
||||||
use rustc_middle::ty::TyCtxt;
|
use rustc_middle::ty::TyCtxt;
|
||||||
|
use rustc_middle::{query::LocalCrate, ty::query::Providers};
|
||||||
use rustc_span::{sym, DebuggerVisualizerFile, DebuggerVisualizerType};
|
use rustc_span::{sym, DebuggerVisualizerFile, DebuggerVisualizerType};
|
||||||
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
@ -67,7 +67,7 @@ fn check_for_debugger_visualizer(
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Traverses and collects the debugger visualizers for a specific crate.
|
/// Traverses and collects the debugger visualizers for a specific crate.
|
||||||
fn debugger_visualizers(tcx: TyCtxt<'_>, (): ()) -> Vec<DebuggerVisualizerFile> {
|
fn debugger_visualizers(tcx: TyCtxt<'_>, _: LocalCrate) -> Vec<DebuggerVisualizerFile> {
|
||||||
// Initialize the collector.
|
// Initialize the collector.
|
||||||
let mut debugger_visualizers = FxHashSet::default();
|
let mut debugger_visualizers = FxHashSet::default();
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
use rustc_ast as ast;
|
use rustc_ast as ast;
|
||||||
use rustc_hir::diagnostic_items::DiagnosticItems;
|
use rustc_hir::diagnostic_items::DiagnosticItems;
|
||||||
use rustc_hir::OwnerId;
|
use rustc_hir::OwnerId;
|
||||||
|
use rustc_middle::query::LocalCrate;
|
||||||
use rustc_middle::ty::query::Providers;
|
use rustc_middle::ty::query::Providers;
|
||||||
use rustc_middle::ty::TyCtxt;
|
use rustc_middle::ty::TyCtxt;
|
||||||
use rustc_span::def_id::{DefId, LOCAL_CRATE};
|
use rustc_span::def_id::{DefId, LOCAL_CRATE};
|
||||||
|
@ -62,7 +63,7 @@ fn extract(attrs: &[ast::Attribute]) -> Option<Symbol> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Traverse and collect the diagnostic items in the current
|
/// Traverse and collect the diagnostic items in the current
|
||||||
fn diagnostic_items(tcx: TyCtxt<'_>, (): ()) -> DiagnosticItems {
|
fn diagnostic_items(tcx: TyCtxt<'_>, _: LocalCrate) -> DiagnosticItems {
|
||||||
// Initialize the collector.
|
// Initialize the collector.
|
||||||
let mut diagnostic_items = DiagnosticItems::default();
|
let mut diagnostic_items = DiagnosticItems::default();
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,7 @@ use rustc_middle::{
|
||||||
ExportedSymbol, SymbolExportInfo, SymbolExportKind, SymbolExportLevel,
|
ExportedSymbol, SymbolExportInfo, SymbolExportKind, SymbolExportLevel,
|
||||||
},
|
},
|
||||||
ty::{query::ExternProviders, TyCtxt},
|
ty::{query::ExternProviders, TyCtxt},
|
||||||
|
query::LocalCrate,
|
||||||
};
|
};
|
||||||
use rustc_session::{config::CrateType, search_paths::PathKind, CtfeBacktrace};
|
use rustc_session::{config::CrateType, search_paths::PathKind, CtfeBacktrace};
|
||||||
|
|
||||||
|
@ -107,7 +108,7 @@ impl rustc_driver::Callbacks for MiriBeRustCompilerCalls {
|
||||||
config.override_queries = Some(|_, local_providers, _| {
|
config.override_queries = Some(|_, local_providers, _| {
|
||||||
// `exported_symbols` and `reachable_non_generics` provided by rustc always returns
|
// `exported_symbols` and `reachable_non_generics` provided by rustc always returns
|
||||||
// an empty result if `tcx.sess.opts.output_types.should_codegen()` is false.
|
// an empty result if `tcx.sess.opts.output_types.should_codegen()` is false.
|
||||||
local_providers.exported_symbols = |tcx, ()| {
|
local_providers.exported_symbols = |tcx, LocalCrate| {
|
||||||
let reachable_set = tcx.with_stable_hashing_context(|hcx| {
|
let reachable_set = tcx.with_stable_hashing_context(|hcx| {
|
||||||
tcx.reachable_set(()).to_sorted(&hcx, true)
|
tcx.reachable_set(()).to_sorted(&hcx, true)
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue