Move codegen_and_build_linker from Queries to Linker
This commit is contained in:
parent
8127461b0e
commit
bd2ff518ce
@ -30,7 +30,7 @@
|
||||
};
|
||||
use rustc_feature::find_gated_cfg;
|
||||
use rustc_interface::util::{self, get_codegen_backend};
|
||||
use rustc_interface::{interface, passes, Queries};
|
||||
use rustc_interface::{interface, passes, Linker, Queries};
|
||||
use rustc_lint::unerased_lint_store;
|
||||
use rustc_metadata::creader::MetadataLoader;
|
||||
use rustc_metadata::locator;
|
||||
@ -447,7 +447,9 @@ fn run_compiler(
|
||||
return early_exit();
|
||||
}
|
||||
|
||||
Ok(Some(queries.codegen_and_build_linker()?))
|
||||
queries.global_ctxt()?.enter(|tcx| {
|
||||
Ok(Some(Linker::codegen_and_build_linker(tcx, &*compiler.codegen_backend)?))
|
||||
})
|
||||
})?;
|
||||
|
||||
// Linking is done outside the `compiler.enter()` so that the
|
||||
|
@ -16,7 +16,7 @@
|
||||
pub use callbacks::setup_callbacks;
|
||||
pub use interface::{run_compiler, Config};
|
||||
pub use passes::DEFAULT_QUERY_PROVIDERS;
|
||||
pub use queries::Queries;
|
||||
pub use queries::{Linker, Queries};
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
@ -116,10 +116,22 @@ pub fn global_ctxt(&'tcx self) -> Result<QueryResult<'_, &'tcx GlobalCtxt<'tcx>>
|
||||
)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
pub fn codegen_and_build_linker(&'tcx self) -> Result<Linker> {
|
||||
self.global_ctxt()?.enter(|tcx| {
|
||||
let ongoing_codegen = passes::start_codegen(&*self.compiler.codegen_backend, tcx)?;
|
||||
pub struct Linker {
|
||||
dep_graph: DepGraph,
|
||||
output_filenames: Arc<OutputFilenames>,
|
||||
// Only present when incr. comp. is enabled.
|
||||
crate_hash: Option<Svh>,
|
||||
ongoing_codegen: Box<dyn Any>,
|
||||
}
|
||||
|
||||
impl Linker {
|
||||
pub fn codegen_and_build_linker(
|
||||
tcx: TyCtxt<'_>,
|
||||
codegen_backend: &dyn CodegenBackend,
|
||||
) -> Result<Linker> {
|
||||
let ongoing_codegen = passes::start_codegen(codegen_backend, tcx)?;
|
||||
|
||||
// This must run after monomorphization so that all generic types
|
||||
// have been instantiated.
|
||||
@ -143,19 +155,8 @@ pub fn codegen_and_build_linker(&'tcx self) -> Result<Linker> {
|
||||
},
|
||||
ongoing_codegen,
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Linker {
|
||||
dep_graph: DepGraph,
|
||||
output_filenames: Arc<OutputFilenames>,
|
||||
// Only present when incr. comp. is enabled.
|
||||
crate_hash: Option<Svh>,
|
||||
ongoing_codegen: Box<dyn Any>,
|
||||
}
|
||||
|
||||
impl Linker {
|
||||
pub fn link(self, sess: &Session, codegen_backend: &dyn CodegenBackend) -> Result<()> {
|
||||
let (codegen_results, work_products) =
|
||||
codegen_backend.join_codegen(self.ongoing_codegen, sess, &self.output_filenames);
|
||||
|
@ -17,6 +17,7 @@
|
||||
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use rustc_interface::Linker;
|
||||
use rustc_interface::interface;
|
||||
use rustc_session::config::{Input, Options, OutFileName, OutputType, OutputTypes};
|
||||
use rustc_span::FileName;
|
||||
@ -78,8 +79,10 @@ fn compile(code: String, output: PathBuf, sysroot: PathBuf, linker: Option<&Path
|
||||
|
||||
interface::run_compiler(config, |compiler| {
|
||||
let linker = compiler.enter(|queries| {
|
||||
queries.global_ctxt()?.enter(|tcx| tcx.analysis(()))?;
|
||||
queries.codegen_and_build_linker()
|
||||
queries.global_ctxt()?.enter(|tcx| {
|
||||
tcx.analysis(())?;
|
||||
Linker::codegen_and_build_linker(tcx, &*compiler.codegen_backend)
|
||||
})
|
||||
});
|
||||
linker.unwrap().link(&compiler.sess, &*compiler.codegen_backend).unwrap();
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user