Skip to content

Commit

Permalink
Rollup merge of rust-lang#64016 - nnethercote:Compiler-fiddling, r=ol…
Browse files Browse the repository at this point in the history
…i-obk

Streamline `Compiler`

A few commits to clean up `Compiler`.

r? @Zoxc
  • Loading branch information
Centril authored Sep 24, 2019
2 parents 94628af + 2521189 commit ad0b78d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 21 deletions.
4 changes: 0 additions & 4 deletions src/librustc_interface/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,6 @@ pub struct PluginInfo {
}

pub fn register_plugins<'a>(
compiler: &Compiler,
sess: &'a Session,
cstore: &'a CStore,
mut krate: ast::Crate,
Expand Down Expand Up @@ -261,9 +260,6 @@ pub fn register_plugins<'a>(
});
}

// If necessary, compute the dependency graph (in the background).
compiler.dep_graph_future().ok();

time(sess, "recursion limit", || {
middle::recursion_limit::update_limits(sess, &krate);
});
Expand Down
45 changes: 29 additions & 16 deletions src/librustc_interface/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,29 +114,38 @@ impl Compiler {
let crate_name = self.crate_name()?.peek().clone();
let krate = self.parse()?.take();

passes::register_plugins(
self,
let result = passes::register_plugins(
self.session(),
self.cstore(),
krate,
&crate_name,
)
);

// Compute the dependency graph (in the background). We want to do
// this as early as possible, to give the DepGraph maximum time to
// load before dep_graph() is called, but it also can't happen
// until after rustc_incremental::prepare_session_directory() is
// called, which happens within passes::register_plugins().
self.dep_graph_future().ok();

result
})
}

pub fn crate_name(&self) -> Result<&Query<String>> {
self.queries.crate_name.compute(|| {
let parse_result = self.parse()?;
let krate = parse_result.peek();
let result = match self.crate_name {
Ok(match self.crate_name {
Some(ref crate_name) => crate_name.clone(),
None => rustc_codegen_utils::link::find_crate_name(
Some(self.session()),
&krate.attrs,
&self.input
),
};
Ok(result)
None => {
let parse_result = self.parse()?;
let krate = parse_result.peek();
rustc_codegen_utils::link::find_crate_name(
Some(self.session()),
&krate.attrs,
&self.input
)
}
})
})
}

Expand Down Expand Up @@ -194,7 +203,6 @@ impl Compiler {

pub fn prepare_outputs(&self) -> Result<&Query<OutputFilenames>> {
self.queries.prepare_outputs.compute(|| {
self.lower_to_hir()?;
let krate = self.expansion()?;
let krate = krate.peek();
let crate_name = self.crate_name()?;
Expand Down Expand Up @@ -267,6 +275,11 @@ impl Compiler {
})
}

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

Expand All @@ -278,12 +291,12 @@ impl Compiler {

self.global_ctxt()?;

// Drop AST after creating GlobalCtxt to free memory
// Drop AST after creating GlobalCtxt to free memory.
mem::drop(self.expansion()?.take());

self.ongoing_codegen()?;

// Drop GlobalCtxt after starting codegen to free memory
// Drop GlobalCtxt after starting codegen to free memory.
mem::drop(self.global_ctxt()?.take());

self.link().map(|_| ())
Expand Down
3 changes: 2 additions & 1 deletion src/test/run-make-fulldeps/issue-19371/foo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ fn compile(code: String, output: PathBuf, sysroot: PathBuf) {
};

interface::run_compiler(config, |compiler| {
compiler.compile().ok();
// This runs all the passes prior to linking, too.
compiler.link().ok();
});
}

0 comments on commit ad0b78d

Please sign in to comment.