Auto merge of #36240 - leeopop:master, r=jseyfried

Allow CompilerControllers to access rustc_plugin::registry::Registry

fixes #36064

I chose to put ructc_plugin::registry::Registry structure
into CompilerState structure, instead of Session structure.
This will preserve dependencies among librustc, libructc_driver, and libructc_plugin.

@jseyfried @sanxiyn
This commit is contained in:
bors 2016-09-04 18:36:42 -07:00 committed by GitHub
commit 86995dc8c5
5 changed files with 14 additions and 9 deletions

View File

@ -99,7 +99,7 @@ pub fn compile_input(sess: &Session,
} }
}; };
let krate = { let (krate, registry) = {
let mut compile_state = CompileState::state_after_parse(input, let mut compile_state = CompileState::state_after_parse(input,
sess, sess,
outdir, outdir,
@ -111,14 +111,14 @@ pub fn compile_input(sess: &Session,
compile_state, compile_state,
Ok(())); Ok(()));
compile_state.krate.unwrap() (compile_state.krate.unwrap(), compile_state.registry)
}; };
let outputs = build_output_filenames(input, outdir, output, &krate.attrs, sess); let outputs = build_output_filenames(input, outdir, output, &krate.attrs, sess);
let crate_name = link::find_crate_name(Some(sess), &krate.attrs, input); let crate_name = link::find_crate_name(Some(sess), &krate.attrs, input);
let ExpansionResult { expanded_crate, defs, analysis, resolutions, mut hir_forest } = { let ExpansionResult { expanded_crate, defs, analysis, resolutions, mut hir_forest } = {
phase_2_configure_and_expand( phase_2_configure_and_expand(
sess, &cstore, krate, &crate_name, addl_plugins, control.make_glob_map, sess, &cstore, krate, registry, &crate_name, addl_plugins, control.make_glob_map,
|expanded_crate| { |expanded_crate| {
let mut state = CompileState::state_after_expand( let mut state = CompileState::state_after_expand(
input, sess, outdir, output, &cstore, expanded_crate, &crate_name, input, sess, outdir, output, &cstore, expanded_crate, &crate_name,
@ -332,6 +332,7 @@ pub struct CompileState<'a, 'b, 'ast: 'a, 'tcx: 'b> where 'ast: 'tcx {
pub input: &'a Input, pub input: &'a Input,
pub session: &'ast Session, pub session: &'ast Session,
pub krate: Option<ast::Crate>, pub krate: Option<ast::Crate>,
pub registry: Option<Registry<'a>>,
pub cstore: Option<&'a CStore>, pub cstore: Option<&'a CStore>,
pub crate_name: Option<&'a str>, pub crate_name: Option<&'a str>,
pub output_filenames: Option<&'a OutputFilenames>, pub output_filenames: Option<&'a OutputFilenames>,
@ -360,6 +361,7 @@ impl<'a, 'b, 'ast, 'tcx> CompileState<'a, 'b, 'ast, 'tcx> {
out_file: None, out_file: None,
arenas: None, arenas: None,
krate: None, krate: None,
registry: None,
cstore: None, cstore: None,
crate_name: None, crate_name: None,
output_filenames: None, output_filenames: None,
@ -382,6 +384,8 @@ impl<'a, 'b, 'ast, 'tcx> CompileState<'a, 'b, 'ast, 'tcx> {
cstore: &'a CStore) cstore: &'a CStore)
-> CompileState<'a, 'b, 'ast, 'tcx> { -> CompileState<'a, 'b, 'ast, 'tcx> {
CompileState { CompileState {
// Initialize the registry before moving `krate`
registry: Some(Registry::new(&session, krate.span)),
krate: Some(krate), krate: Some(krate),
cstore: Some(cstore), cstore: Some(cstore),
out_file: out_file.as_ref().map(|s| &**s), out_file: out_file.as_ref().map(|s| &**s),
@ -548,6 +552,7 @@ pub struct ExpansionResult<'a> {
pub fn phase_2_configure_and_expand<'a, F>(sess: &Session, pub fn phase_2_configure_and_expand<'a, F>(sess: &Session,
cstore: &CStore, cstore: &CStore,
mut krate: ast::Crate, mut krate: ast::Crate,
registry: Option<Registry>,
crate_name: &'a str, crate_name: &'a str,
addl_plugins: Option<Vec<String>>, addl_plugins: Option<Vec<String>>,
make_glob_map: MakeGlobMap, make_glob_map: MakeGlobMap,
@ -595,7 +600,7 @@ pub fn phase_2_configure_and_expand<'a, F>(sess: &Session,
addl_plugins.take().unwrap()) addl_plugins.take().unwrap())
}); });
let mut registry = Registry::new(sess, &krate); let mut registry = registry.unwrap_or(Registry::new(sess, krate.span));
time(time_passes, "plugin registration", || { time(time_passes, "plugin registration", || {
if sess.features.borrow().rustc_diagnostic_macros { if sess.features.borrow().rustc_diagnostic_macros {

View File

@ -115,7 +115,7 @@ fn test_env<F>(source_string: &str,
let krate = driver::phase_1_parse_input(&sess, krate_config, &input).unwrap(); let krate = driver::phase_1_parse_input(&sess, krate_config, &input).unwrap();
let driver::ExpansionResult { defs, resolutions, mut hir_forest, .. } = { let driver::ExpansionResult { defs, resolutions, mut hir_forest, .. } = {
driver::phase_2_configure_and_expand( driver::phase_2_configure_and_expand(
&sess, &cstore, krate, "test", None, MakeGlobMap::No, |_| Ok(()), &sess, &cstore, krate, None, "test", None, MakeGlobMap::No, |_| Ok(()),
).expect("phase 2 aborted") ).expect("phase 2 aborted")
}; };
let _ignore = dep_graph.in_ignore(); let _ignore = dep_graph.in_ignore();

View File

@ -69,11 +69,11 @@ pub struct Registry<'a> {
impl<'a> Registry<'a> { impl<'a> Registry<'a> {
#[doc(hidden)] #[doc(hidden)]
pub fn new(sess: &'a Session, krate: &ast::Crate) -> Registry<'a> { pub fn new(sess: &'a Session, krate_span: Span) -> Registry<'a> {
Registry { Registry {
sess: sess, sess: sess,
args_hidden: None, args_hidden: None,
krate_span: krate.span, krate_span: krate_span,
syntax_exts: vec!(), syntax_exts: vec!(),
early_lint_passes: vec!(), early_lint_passes: vec!(),
late_lint_passes: vec!(), late_lint_passes: vec!(),

View File

@ -146,7 +146,7 @@ pub fn run_core(search_paths: SearchPaths,
let driver::ExpansionResult { defs, analysis, resolutions, mut hir_forest, .. } = { let driver::ExpansionResult { defs, analysis, resolutions, mut hir_forest, .. } = {
driver::phase_2_configure_and_expand( driver::phase_2_configure_and_expand(
&sess, &cstore, krate, &name, None, resolve::MakeGlobMap::No, |_| Ok(()), &sess, &cstore, krate, None, &name, None, resolve::MakeGlobMap::No, |_| Ok(()),
).expect("phase_2_configure_and_expand aborted in rustdoc!") ).expect("phase_2_configure_and_expand aborted in rustdoc!")
}; };

View File

@ -94,7 +94,7 @@ pub fn run(input: &str,
let krate = panictry!(driver::phase_1_parse_input(&sess, cfg, &input)); let krate = panictry!(driver::phase_1_parse_input(&sess, cfg, &input));
let driver::ExpansionResult { defs, mut hir_forest, .. } = { let driver::ExpansionResult { defs, mut hir_forest, .. } = {
phase_2_configure_and_expand( phase_2_configure_and_expand(
&sess, &cstore, krate, "rustdoc-test", None, MakeGlobMap::No, |_| Ok(()) &sess, &cstore, krate, None, "rustdoc-test", None, MakeGlobMap::No, |_| Ok(())
).expect("phase_2_configure_and_expand aborted in rustdoc!") ).expect("phase_2_configure_and_expand aborted in rustdoc!")
}; };