Skip to content

Commit 86995dc

Browse files
authored
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
2 parents 91f057d + ca5dfd0 commit 86995dc

File tree

5 files changed

+14
-9
lines changed

5 files changed

+14
-9
lines changed

src/librustc_driver/driver.rs

+9-4
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ pub fn compile_input(sess: &Session,
9999
}
100100
};
101101

102-
let krate = {
102+
let (krate, registry) = {
103103
let mut compile_state = CompileState::state_after_parse(input,
104104
sess,
105105
outdir,
@@ -111,14 +111,14 @@ pub fn compile_input(sess: &Session,
111111
compile_state,
112112
Ok(()));
113113

114-
compile_state.krate.unwrap()
114+
(compile_state.krate.unwrap(), compile_state.registry)
115115
};
116116

117117
let outputs = build_output_filenames(input, outdir, output, &krate.attrs, sess);
118118
let crate_name = link::find_crate_name(Some(sess), &krate.attrs, input);
119119
let ExpansionResult { expanded_crate, defs, analysis, resolutions, mut hir_forest } = {
120120
phase_2_configure_and_expand(
121-
sess, &cstore, krate, &crate_name, addl_plugins, control.make_glob_map,
121+
sess, &cstore, krate, registry, &crate_name, addl_plugins, control.make_glob_map,
122122
|expanded_crate| {
123123
let mut state = CompileState::state_after_expand(
124124
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 {
332332
pub input: &'a Input,
333333
pub session: &'ast Session,
334334
pub krate: Option<ast::Crate>,
335+
pub registry: Option<Registry<'a>>,
335336
pub cstore: Option<&'a CStore>,
336337
pub crate_name: Option<&'a str>,
337338
pub output_filenames: Option<&'a OutputFilenames>,
@@ -360,6 +361,7 @@ impl<'a, 'b, 'ast, 'tcx> CompileState<'a, 'b, 'ast, 'tcx> {
360361
out_file: None,
361362
arenas: None,
362363
krate: None,
364+
registry: None,
363365
cstore: None,
364366
crate_name: None,
365367
output_filenames: None,
@@ -382,6 +384,8 @@ impl<'a, 'b, 'ast, 'tcx> CompileState<'a, 'b, 'ast, 'tcx> {
382384
cstore: &'a CStore)
383385
-> CompileState<'a, 'b, 'ast, 'tcx> {
384386
CompileState {
387+
// Initialize the registry before moving `krate`
388+
registry: Some(Registry::new(&session, krate.span)),
385389
krate: Some(krate),
386390
cstore: Some(cstore),
387391
out_file: out_file.as_ref().map(|s| &**s),
@@ -548,6 +552,7 @@ pub struct ExpansionResult<'a> {
548552
pub fn phase_2_configure_and_expand<'a, F>(sess: &Session,
549553
cstore: &CStore,
550554
mut krate: ast::Crate,
555+
registry: Option<Registry>,
551556
crate_name: &'a str,
552557
addl_plugins: Option<Vec<String>>,
553558
make_glob_map: MakeGlobMap,
@@ -595,7 +600,7 @@ pub fn phase_2_configure_and_expand<'a, F>(sess: &Session,
595600
addl_plugins.take().unwrap())
596601
});
597602

598-
let mut registry = Registry::new(sess, &krate);
603+
let mut registry = registry.unwrap_or(Registry::new(sess, krate.span));
599604

600605
time(time_passes, "plugin registration", || {
601606
if sess.features.borrow().rustc_diagnostic_macros {

src/librustc_driver/test.rs

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

src/librustc_plugin/registry.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,11 @@ pub struct Registry<'a> {
6969

7070
impl<'a> Registry<'a> {
7171
#[doc(hidden)]
72-
pub fn new(sess: &'a Session, krate: &ast::Crate) -> Registry<'a> {
72+
pub fn new(sess: &'a Session, krate_span: Span) -> Registry<'a> {
7373
Registry {
7474
sess: sess,
7575
args_hidden: None,
76-
krate_span: krate.span,
76+
krate_span: krate_span,
7777
syntax_exts: vec!(),
7878
early_lint_passes: vec!(),
7979
late_lint_passes: vec!(),

src/librustdoc/core.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ pub fn run_core(search_paths: SearchPaths,
146146

147147
let driver::ExpansionResult { defs, analysis, resolutions, mut hir_forest, .. } = {
148148
driver::phase_2_configure_and_expand(
149-
&sess, &cstore, krate, &name, None, resolve::MakeGlobMap::No, |_| Ok(()),
149+
&sess, &cstore, krate, None, &name, None, resolve::MakeGlobMap::No, |_| Ok(()),
150150
).expect("phase_2_configure_and_expand aborted in rustdoc!")
151151
};
152152

src/librustdoc/test.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ pub fn run(input: &str,
9494
let krate = panictry!(driver::phase_1_parse_input(&sess, cfg, &input));
9595
let driver::ExpansionResult { defs, mut hir_forest, .. } = {
9696
phase_2_configure_and_expand(
97-
&sess, &cstore, krate, "rustdoc-test", None, MakeGlobMap::No, |_| Ok(())
97+
&sess, &cstore, krate, None, "rustdoc-test", None, MakeGlobMap::No, |_| Ok(())
9898
).expect("phase_2_configure_and_expand aborted in rustdoc!")
9999
};
100100

0 commit comments

Comments
 (0)