Skip to content

Commit

Permalink
Have a single struct for queries and hook
Browse files Browse the repository at this point in the history
  • Loading branch information
oli-obk committed Sep 22, 2023
1 parent 9defc97 commit 2ba911c
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 26 deletions.
5 changes: 2 additions & 3 deletions compiler/rustc_codegen_gcc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,8 @@ use rustc_errors::{DiagnosticMessage, ErrorGuaranteed, Handler, SubdiagnosticMes
use rustc_fluent_macro::fluent_messages;
use rustc_metadata::EncodedMetadata;
use rustc_middle::dep_graph::{WorkProduct, WorkProductId};
use rustc_middle::query::Providers;
use rustc_middle::util::Providers;
use rustc_middle::ty::TyCtxt;
use rustc_middle::hooks;
use rustc_session::config::{Lto, OptLevel, OutputFilenames};
use rustc_session::Session;
use rustc_span::Symbol;
Expand Down Expand Up @@ -128,7 +127,7 @@ impl CodegenBackend for GccCodegenBackend {
*self.supports_128bit_integers.lock().expect("lock") = check_context.get_last_error() == Ok(None);
}

fn provide(&self, providers: &mut Providers, _: &mut hooks::Providers) {
fn provide(&self, providers: &mut Providers) {
// FIXME(antoyo) compute list of enabled features from cli flags
providers.global_backend_features = |_tcx, ()| vec![];
}
Expand Down
5 changes: 2 additions & 3 deletions compiler/rustc_codegen_llvm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,8 @@ use rustc_errors::{DiagnosticMessage, ErrorGuaranteed, FatalError, Handler, Subd
use rustc_fluent_macro::fluent_messages;
use rustc_metadata::EncodedMetadata;
use rustc_middle::dep_graph::{WorkProduct, WorkProductId};
use rustc_middle::hooks;
use rustc_middle::query::Providers;
use rustc_middle::ty::TyCtxt;
use rustc_middle::util::Providers;
use rustc_session::config::{OptLevel, OutputFilenames, PrintKind, PrintRequest};
use rustc_session::Session;
use rustc_span::symbol::Symbol;
Expand Down Expand Up @@ -269,7 +268,7 @@ impl CodegenBackend for LlvmCodegenBackend {
llvm_util::init(sess); // Make sure llvm is inited
}

fn provide(&self, providers: &mut Providers, _hooks: &mut hooks::Providers) {
fn provide(&self, providers: &mut Providers) {
providers.global_backend_features =
|tcx, ()| llvm_util::global_llvm_features(tcx.sess, true)
}
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_codegen_ssa/src/traits/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ use rustc_data_structures::sync::{DynSend, DynSync};
use rustc_errors::ErrorGuaranteed;
use rustc_metadata::EncodedMetadata;
use rustc_middle::dep_graph::{WorkProduct, WorkProductId};
use rustc_middle::hooks;
use rustc_middle::query::{ExternProviders, Providers};
use rustc_middle::query::ExternProviders;
use rustc_middle::ty::layout::{FnAbiOf, HasTyCtxt, LayoutOf, TyAndLayout};
use rustc_middle::ty::{Ty, TyCtxt};
use rustc_middle::util::Providers;
use rustc_session::{
config::{self, OutputFilenames, PrintRequest},
cstore::MetadataLoaderDyn,
Expand Down Expand Up @@ -85,7 +85,7 @@ pub trait CodegenBackend {
Box::new(crate::back::metadata::DefaultMetadataLoader)
}

fn provide(&self, _providers: &mut Providers, _hooks: &mut hooks::Providers) {}
fn provide(&self, _providers: &mut Providers) {}
fn provide_extern(&self, _providers: &mut ExternProviders) {}
fn codegen_crate<'tcx>(
&self,
Expand Down
7 changes: 3 additions & 4 deletions compiler/rustc_const_eval/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,11 @@ pub use errors::ReportErrorExt;

use rustc_errors::{DiagnosticMessage, SubdiagnosticMessage};
use rustc_fluent_macro::fluent_messages;
use rustc_middle::query::Providers;
use rustc_middle::{hooks, ty};
use rustc_middle::{ty, util::Providers};

fluent_messages! { "../messages.ftl" }

pub fn provide(providers: &mut Providers, hooks: &mut hooks::Providers) {
pub fn provide(providers: &mut Providers) {
const_eval::provide(providers);
providers.eval_to_const_value_raw = const_eval::eval_to_const_value_raw_provider;
providers.eval_to_allocation_raw = const_eval::eval_to_allocation_raw_provider;
Expand All @@ -52,7 +51,7 @@ pub fn provide(providers: &mut Providers, hooks: &mut hooks::Providers) {
let (param_env, raw) = param_env_and_value.into_parts();
const_eval::eval_to_valtree(tcx, param_env, raw)
};
hooks.try_destructure_mir_constant_for_diagnostics =
providers.hooks.try_destructure_mir_constant_for_diagnostics =
const_eval::try_destructure_mir_constant_for_diagnostics;
providers.valtree_to_const_val = |tcx, (ty, valtree)| {
const_eval::valtree_to_const_value(tcx, ty::ParamEnv::empty().and(ty), valtree)
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_interface/src/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ use rustc_data_structures::sync::Lrc;
use rustc_errors::registry::Registry;
use rustc_errors::{ErrorGuaranteed, Handler};
use rustc_lint::LintStore;
use rustc_middle::query::{ExternProviders, Providers};
use rustc_middle::query::ExternProviders;
use rustc_middle::util::Providers;
use rustc_middle::{bug, ty};
use rustc_parse::maybe_new_parser_from_source_str;
use rustc_query_impl::QueryCtxt;
Expand Down
21 changes: 10 additions & 11 deletions compiler/rustc_interface/src/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ use rustc_lint::{unerased_lint_store, BufferedEarlyLint, EarlyCheckNode, LintSto
use rustc_metadata::creader::CStore;
use rustc_middle::arena::Arena;
use rustc_middle::dep_graph::DepGraph;
use rustc_middle::hooks;
use rustc_middle::query::{ExternProviders, Providers};
use rustc_middle::query::ExternProviders;
use rustc_middle::ty::{self, GlobalCtxt, RegisteredTools, TyCtxt};
use rustc_middle::util::Providers;
use rustc_mir_build as mir_build;
use rustc_parse::{parse_crate_from_file, parse_crate_from_source_str, validate_attr};
use rustc_passes::{self, abi_test, hir_stats, layout_test};
Expand Down Expand Up @@ -646,16 +646,15 @@ fn output_filenames(tcx: TyCtxt<'_>, (): ()) -> Arc<OutputFilenames> {
outputs.into()
}

pub static DEFAULT_QUERY_PROVIDERS: LazyLock<(Providers, hooks::Providers)> = LazyLock::new(|| {
pub static DEFAULT_QUERY_PROVIDERS: LazyLock<Providers> = LazyLock::new(|| {
let providers = &mut Providers::default();
let hooks = &mut hooks::Providers::default();
providers.analysis = analysis;
providers.hir_crate = rustc_ast_lowering::lower_to_hir;
providers.output_filenames = output_filenames;
providers.resolver_for_lowering = resolver_for_lowering;
providers.early_lint_checks = early_lint_checks;
proc_macro_decls::provide(providers);
rustc_const_eval::provide(providers, hooks);
rustc_const_eval::provide(providers);
rustc_middle::hir::provide(providers);
mir_borrowck::provide(providers);
mir_build::provide(providers);
Expand All @@ -674,7 +673,7 @@ pub static DEFAULT_QUERY_PROVIDERS: LazyLock<(Providers, hooks::Providers)> = La
rustc_lint::provide(providers);
rustc_symbol_mangling::provide(providers);
rustc_codegen_ssa::provide(providers);
(*providers, *hooks)
*providers
});

pub static DEFAULT_EXTERN_QUERY_PROVIDERS: LazyLock<ExternProviders> = LazyLock::new(|| {
Expand Down Expand Up @@ -704,14 +703,14 @@ pub fn create_global_ctxt<'tcx>(
let query_result_on_disk_cache = rustc_incremental::load_query_result_cache(sess);

let codegen_backend = compiler.codegen_backend();
let (mut local_providers, mut hooks) = *DEFAULT_QUERY_PROVIDERS;
codegen_backend.provide(&mut local_providers, &mut hooks);
let mut providers = *DEFAULT_QUERY_PROVIDERS;
codegen_backend.provide(&mut providers);

let mut extern_providers = *DEFAULT_EXTERN_QUERY_PROVIDERS;
codegen_backend.provide_extern(&mut extern_providers);

if let Some(callback) = compiler.override_queries {
callback(sess, &mut local_providers, &mut extern_providers);
callback(sess, &mut providers, &mut extern_providers);
}

let incremental = dep_graph.is_fully_enabled();
Expand All @@ -729,12 +728,12 @@ pub fn create_global_ctxt<'tcx>(
dep_graph,
rustc_query_impl::query_callbacks(arena),
rustc_query_impl::query_system(
local_providers,
providers.queries,
extern_providers,
query_result_on_disk_cache,
incremental,
),
hooks,
providers.hooks,
)
})
})
Expand Down
23 changes: 23 additions & 0 deletions compiler/rustc_middle/src/util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,26 @@ pub mod find_self_call;

pub use call_kind::{call_kind, CallDesugaringKind, CallKind};
pub use find_self_call::find_self_call;

#[derive(Default, Copy, Clone)]
pub struct Providers {
pub queries: rustc_middle::query::Providers,
pub hooks: rustc_middle::hooks::Providers,
}

/// Backwards compatibility hack to keep the diff small. This
/// gives direct access to the `queries` field's fields, which
/// are what almost everything wants access to.
impl std::ops::DerefMut for Providers {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.queries
}
}

impl std::ops::Deref for Providers {
type Target = rustc_middle::query::Providers;

fn deref(&self) -> &Self::Target {
&self.queries
}
}
2 changes: 1 addition & 1 deletion src/librustdoc/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ pub(crate) fn create_config(
let body = hir.body(hir.body_owned_by(def_id));
debug!("visiting body for {def_id:?}");
EmitIgnoredResolutionErrors::new(tcx).visit_body(body);
(rustc_interface::DEFAULT_QUERY_PROVIDERS.0.typeck)(tcx, def_id)
(rustc_interface::DEFAULT_QUERY_PROVIDERS.typeck)(tcx, def_id)
};
}),
make_codegen_backend: None,
Expand Down

0 comments on commit 2ba911c

Please sign in to comment.