mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-28 09:44:08 +00:00
Add a callback that allows compiler consumers to override queries.
This commit is contained in:
parent
2a9be46cc4
commit
f9f5a88bc4
@ -181,6 +181,7 @@ pub fn run_compiler(
|
||||
crate_name: None,
|
||||
lint_caps: Default::default(),
|
||||
register_lints: None,
|
||||
override_queries: None,
|
||||
};
|
||||
callbacks.config(&mut config);
|
||||
config
|
||||
@ -259,6 +260,7 @@ pub fn run_compiler(
|
||||
crate_name: None,
|
||||
lint_caps: Default::default(),
|
||||
register_lints: None,
|
||||
override_queries: None,
|
||||
};
|
||||
|
||||
callbacks.config(&mut config);
|
||||
|
@ -12,6 +12,7 @@ use rustc_data_structures::OnDrop;
|
||||
use rustc_data_structures::sync::Lrc;
|
||||
use rustc_data_structures::fx::{FxHashSet, FxHashMap};
|
||||
use rustc_parse::new_parser_from_source_str;
|
||||
use rustc::ty;
|
||||
use std::path::PathBuf;
|
||||
use std::result;
|
||||
use std::sync::{Arc, Mutex};
|
||||
@ -38,6 +39,8 @@ pub struct Compiler {
|
||||
pub(crate) queries: Queries,
|
||||
pub(crate) crate_name: Option<String>,
|
||||
pub(crate) register_lints: Option<Box<dyn Fn(&Session, &mut lint::LintStore) + Send + Sync>>,
|
||||
pub(crate) override_queries:
|
||||
Option<fn(&Session, &mut ty::query::Providers<'_>, &mut ty::query::Providers<'_>)>,
|
||||
}
|
||||
|
||||
impl Compiler {
|
||||
@ -131,6 +134,13 @@ pub struct Config {
|
||||
/// Note that if you find a Some here you probably want to call that function in the new
|
||||
/// function being registered.
|
||||
pub register_lints: Option<Box<dyn Fn(&Session, &mut lint::LintStore) + Send + Sync>>,
|
||||
|
||||
/// This is a callback from the driver that is called just after we have populated
|
||||
/// the list of queries.
|
||||
///
|
||||
/// The second parameter is local providers and the third parameter is external providers.
|
||||
pub override_queries:
|
||||
Option<fn(&Session, &mut ty::query::Providers<'_>, &mut ty::query::Providers<'_>)>,
|
||||
}
|
||||
|
||||
pub fn run_compiler_in_existing_thread_pool<F, R>(config: Config, f: F) -> R
|
||||
@ -157,6 +167,7 @@ where
|
||||
queries: Default::default(),
|
||||
crate_name: config.crate_name,
|
||||
register_lints: config.register_lints,
|
||||
override_queries: config.override_queries,
|
||||
};
|
||||
|
||||
let _sess_abort_error = OnDrop(|| {
|
||||
|
@ -786,6 +786,7 @@ pub fn create_global_ctxt(
|
||||
let codegen_backend = compiler.codegen_backend().clone();
|
||||
let crate_name = crate_name.to_string();
|
||||
let defs = mem::take(&mut resolver_outputs.definitions);
|
||||
let override_queries = compiler.override_queries;
|
||||
|
||||
let ((), result) = BoxedGlobalCtxt::new(static move || {
|
||||
let sess = &*sess;
|
||||
@ -810,6 +811,10 @@ pub fn create_global_ctxt(
|
||||
default_provide_extern(&mut extern_providers);
|
||||
codegen_backend.provide_extern(&mut extern_providers);
|
||||
|
||||
if let Some(callback) = override_queries {
|
||||
callback(sess, &mut local_providers, &mut extern_providers);
|
||||
}
|
||||
|
||||
let gcx = TyCtxt::create_global_ctxt(
|
||||
sess,
|
||||
lint_store,
|
||||
|
@ -335,6 +335,7 @@ pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOpt
|
||||
crate_name,
|
||||
lint_caps,
|
||||
register_lints: None,
|
||||
override_queries: None,
|
||||
};
|
||||
|
||||
interface::run_compiler_in_existing_thread_pool(config, |compiler| {
|
||||
|
@ -79,6 +79,7 @@ pub fn run(options: Options) -> i32 {
|
||||
crate_name: options.crate_name.clone(),
|
||||
lint_caps: Default::default(),
|
||||
register_lints: None,
|
||||
override_queries: None,
|
||||
};
|
||||
|
||||
let mut test_args = options.test_args.clone();
|
||||
|
@ -60,6 +60,7 @@ fn compile(code: String, output: PathBuf, sysroot: PathBuf) {
|
||||
crate_name: None,
|
||||
lint_caps: Default::default(),
|
||||
register_lints: None,
|
||||
override_queries: None,
|
||||
};
|
||||
|
||||
interface::run_compiler(config, |compiler| {
|
||||
|
Loading…
Reference in New Issue
Block a user