Skip to content

Commit

Permalink
Add a comment to Compiler::compile().
Browse files Browse the repository at this point in the history
`Compiler::compile()` is different to all the other `Compiler` methods
because it lacks a `Queries` entry. It only has one call site, which is
in a test that doesn't need its specific characteristics.

This patch replaces that call with a call to `Compile::link()`, which is
similar enough for the test's purposes. It also notes that the method is
an illustrative example of how `Compiler` can be used.
  • Loading branch information
nnethercote committed Sep 18, 2019
1 parent d264a56 commit 2521189
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
9 changes: 7 additions & 2 deletions src/librustc_interface/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,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 @@ -286,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 2521189

Please sign in to comment.