Skip to content

Commit ad0b78d

Browse files
authored
Rollup merge of rust-lang#64016 - nnethercote:Compiler-fiddling, r=oli-obk
Streamline `Compiler` A few commits to clean up `Compiler`. r? @Zoxc
2 parents 94628af + 2521189 commit ad0b78d

File tree

3 files changed

+31
-21
lines changed

3 files changed

+31
-21
lines changed

src/librustc_interface/passes.rs

-4
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,6 @@ pub struct PluginInfo {
221221
}
222222

223223
pub fn register_plugins<'a>(
224-
compiler: &Compiler,
225224
sess: &'a Session,
226225
cstore: &'a CStore,
227226
mut krate: ast::Crate,
@@ -261,9 +260,6 @@ pub fn register_plugins<'a>(
261260
});
262261
}
263262

264-
// If necessary, compute the dependency graph (in the background).
265-
compiler.dep_graph_future().ok();
266-
267263
time(sess, "recursion limit", || {
268264
middle::recursion_limit::update_limits(sess, &krate);
269265
});

src/librustc_interface/queries.rs

+29-16
Original file line numberDiff line numberDiff line change
@@ -114,29 +114,38 @@ impl Compiler {
114114
let crate_name = self.crate_name()?.peek().clone();
115115
let krate = self.parse()?.take();
116116

117-
passes::register_plugins(
118-
self,
117+
let result = passes::register_plugins(
119118
self.session(),
120119
self.cstore(),
121120
krate,
122121
&crate_name,
123-
)
122+
);
123+
124+
// Compute the dependency graph (in the background). We want to do
125+
// this as early as possible, to give the DepGraph maximum time to
126+
// load before dep_graph() is called, but it also can't happen
127+
// until after rustc_incremental::prepare_session_directory() is
128+
// called, which happens within passes::register_plugins().
129+
self.dep_graph_future().ok();
130+
131+
result
124132
})
125133
}
126134

127135
pub fn crate_name(&self) -> Result<&Query<String>> {
128136
self.queries.crate_name.compute(|| {
129-
let parse_result = self.parse()?;
130-
let krate = parse_result.peek();
131-
let result = match self.crate_name {
137+
Ok(match self.crate_name {
132138
Some(ref crate_name) => crate_name.clone(),
133-
None => rustc_codegen_utils::link::find_crate_name(
134-
Some(self.session()),
135-
&krate.attrs,
136-
&self.input
137-
),
138-
};
139-
Ok(result)
139+
None => {
140+
let parse_result = self.parse()?;
141+
let krate = parse_result.peek();
142+
rustc_codegen_utils::link::find_crate_name(
143+
Some(self.session()),
144+
&krate.attrs,
145+
&self.input
146+
)
147+
}
148+
})
140149
})
141150
}
142151

@@ -194,7 +203,6 @@ impl Compiler {
194203

195204
pub fn prepare_outputs(&self) -> Result<&Query<OutputFilenames>> {
196205
self.queries.prepare_outputs.compute(|| {
197-
self.lower_to_hir()?;
198206
let krate = self.expansion()?;
199207
let krate = krate.peek();
200208
let crate_name = self.crate_name()?;
@@ -267,6 +275,11 @@ impl Compiler {
267275
})
268276
}
269277

278+
// This method is different to all the other methods in `Compiler` because
279+
// it lacks a `Queries` entry. It's also not currently used. It does serve
280+
// as an example of how `Compiler` can be used, with additional steps added
281+
// between some passes. And see `rustc_driver::run_compiler` for a more
282+
// complex example.
270283
pub fn compile(&self) -> Result<()> {
271284
self.prepare_outputs()?;
272285

@@ -278,12 +291,12 @@ impl Compiler {
278291

279292
self.global_ctxt()?;
280293

281-
// Drop AST after creating GlobalCtxt to free memory
294+
// Drop AST after creating GlobalCtxt to free memory.
282295
mem::drop(self.expansion()?.take());
283296

284297
self.ongoing_codegen()?;
285298

286-
// Drop GlobalCtxt after starting codegen to free memory
299+
// Drop GlobalCtxt after starting codegen to free memory.
287300
mem::drop(self.global_ctxt()?.take());
288301

289302
self.link().map(|_| ())

src/test/run-make-fulldeps/issue-19371/foo.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ fn compile(code: String, output: PathBuf, sysroot: PathBuf) {
6262
};
6363

6464
interface::run_compiler(config, |compiler| {
65-
compiler.compile().ok();
65+
// This runs all the passes prior to linking, too.
66+
compiler.link().ok();
6667
});
6768
}

0 commit comments

Comments
 (0)