use rustc_data_structures::OnDrop;
use rustc_data_structures::sync::Lrc;
use rustc_data_structures::fx::{FxHashSet, FxHashMap};
+use rustc_errors::registry::Registry;
use rustc_parse::new_parser_from_source_str;
+use rustc::ty;
use std::path::PathBuf;
use std::result;
use std::sync::{Arc, Mutex};
use syntax::token;
use syntax::source_map::{FileName, FileLoader, SourceMap};
use syntax::sess::ParseSess;
-use syntax_expand::config::process_configure_mod;
use syntax_pos::edition;
pub type Result<T> = result::Result<T, ErrorReported>;
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 {
pub fn parse_cfgspecs(cfgspecs: Vec<String>) -> FxHashSet<(String, Option<String>)> {
syntax::with_default_globals(move || {
let cfg = cfgspecs.into_iter().map(|s| {
- let sess = ParseSess::with_silent_emitter(process_configure_mod);
+ let sess = ParseSess::with_silent_emitter();
let filename = FileName::cfg_spec_source_code(&s);
let mut parser = new_parser_from_source_str(&sess, filename, s.to_string());
/// 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<'_>)>,
+
+ /// Registry of diagnostics codes.
+ pub registry: Registry,
}
-pub fn run_compiler_in_existing_thread_pool<F, R>(config: Config, f: F) -> R
-where
- F: FnOnce(&Compiler) -> R,
-{
+pub fn run_compiler_in_existing_thread_pool<R>(
+ config: Config,
+ f: impl FnOnce(&Compiler) -> R,
+) -> R {
+ let registry = &config.registry;
let (sess, codegen_backend, source_map) = util::create_session(
config.opts,
config.crate_cfg,
config.file_loader,
config.input_path.clone(),
config.lint_caps,
+ registry.clone(),
);
let compiler = Compiler {
queries: Default::default(),
crate_name: config.crate_name,
register_lints: config.register_lints,
+ override_queries: config.override_queries,
};
let _sess_abort_error = OnDrop(|| {
- compiler.sess.diagnostic().print_error_count(&util::diagnostics_registry());
+ compiler.sess.diagnostic().print_error_count(registry);
});
f(&compiler)
}
-pub fn run_compiler<F, R>(mut config: Config, f: F) -> R
-where
- F: FnOnce(&Compiler) -> R + Send,
- R: Send,
-{
+pub fn run_compiler<R: Send>(mut config: Config, f: impl FnOnce(&Compiler) -> R + Send) -> R {
let stderr = config.stderr.take();
util::spawn_thread_pool(
config.opts.edition,
)
}
-pub fn default_thread_pool<F, R>(edition: edition::Edition, f: F) -> R
-where
- F: FnOnce() -> R + Send,
- R: Send,
-{
+pub fn default_thread_pool<R: Send>(edition: edition::Edition, f: impl FnOnce() -> R + Send) -> R {
// the 1 here is duplicating code in config.opts.debugging_opts.threads
// which also defaults to 1; it ultimately doesn't matter as the default
// isn't threaded, and just ignores this parameter