Skip to content

Simplify early compilation interface #86489

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jul 1, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Inline lower_to_hir.
  • Loading branch information
cjgillot committed Jun 30, 2021
commit b80f720a2af0ccad54a1236063888aa9418cdf0f
1 change: 1 addition & 0 deletions compiler/rustc_interface/src/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -793,6 +793,7 @@ pub fn create_global_ctxt<'tcx>(
arena: &'tcx WorkerLocal<Arena<'tcx>>,
) -> QueryContext<'tcx> {
let sess = &compiler.session();
let _timer = sess.timer("create_global_ctxt");

let query_result_on_disk_cache = rustc_incremental::load_query_result_cache(sess);

Expand Down
51 changes: 18 additions & 33 deletions compiler/rustc_interface/src/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@ use rustc_data_structures::svh::Svh;
use rustc_data_structures::sync::{Lrc, OnceCell, WorkerLocal};
use rustc_errors::ErrorReported;
use rustc_hir::def_id::LOCAL_CRATE;
use rustc_hir::Crate;
use rustc_incremental::DepGraphFuture;
use rustc_lint::LintStore;
use rustc_middle::arena::Arena;
use rustc_middle::dep_graph::DepGraph;
use rustc_middle::ty::{GlobalCtxt, ResolverOutputs, TyCtxt};
use rustc_middle::ty::{GlobalCtxt, TyCtxt};
use rustc_query_impl::Queries as TcxQueries;
use rustc_serialize::json;
use rustc_session::config::{self, OutputFilenames, OutputType};
Expand Down Expand Up @@ -83,7 +82,6 @@ pub struct Queries<'tcx> {
register_plugins: Query<(ast::Crate, Lrc<LintStore>)>,
expansion: Query<(ast::Crate, Steal<Rc<RefCell<BoxedResolver>>>, Lrc<LintStore>)>,
dep_graph: Query<DepGraph>,
lower_to_hir: Query<(&'tcx Crate<'tcx>, Steal<ResolverOutputs>)>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps Zoxc had something in mind when making lower_to_hir individually available, but if no tools use it right now, then it seems fine to remove.

prepare_outputs: Query<OutputFilenames>,
global_ctxt: Query<QueryContext<'tcx>>,
ongoing_codegen: Query<Box<dyn Any>>,
Expand All @@ -103,7 +101,6 @@ impl<'tcx> Queries<'tcx> {
register_plugins: Default::default(),
expansion: Default::default(),
dep_graph: Default::default(),
lower_to_hir: Default::default(),
prepare_outputs: Default::default(),
global_ctxt: Default::default(),
ongoing_codegen: Default::default(),
Expand All @@ -117,7 +114,7 @@ impl<'tcx> Queries<'tcx> {
&self.compiler.codegen_backend()
}

pub fn dep_graph_future(&self) -> Result<&Query<Option<DepGraphFuture>>> {
fn dep_graph_future(&self) -> Result<&Query<Option<DepGraphFuture>>> {
self.dep_graph_future.compute(|| {
let sess = self.session();
Ok(sess.opts.build_dep_graph().then(|| rustc_incremental::load_dep_graph(sess)))
Expand Down Expand Up @@ -191,7 +188,7 @@ impl<'tcx> Queries<'tcx> {
})
}

pub fn dep_graph(&self) -> Result<&Query<DepGraph>> {
fn dep_graph(&self) -> Result<&Query<DepGraph>> {
self.dep_graph.compute(|| {
let sess = self.session();
let future_opt = self.dep_graph_future()?.take();
Expand All @@ -207,28 +204,6 @@ impl<'tcx> Queries<'tcx> {
})
}

pub fn lower_to_hir(&'tcx self) -> Result<&Query<(&'tcx Crate<'tcx>, Steal<ResolverOutputs>)>> {
self.lower_to_hir.compute(|| {
let expansion_result = self.expansion()?;
let peeked = expansion_result.peek();
let krate = &peeked.0;
let resolver = peeked.1.steal();
let lint_store = &peeked.2;
let hir = resolver.borrow_mut().access(|resolver| {
Ok(passes::lower_to_hir(
self.session(),
lint_store,
resolver,
&*self.dep_graph()?.peek(),
&krate,
&self.hir_arena,
))
})?;
let hir = self.hir_arena.alloc(hir);
Ok((hir, Steal::new(BoxedResolver::to_resolver_outputs(resolver))))
})
}

pub fn prepare_outputs(&self) -> Result<&Query<OutputFilenames>> {
self.prepare_outputs.compute(|| {
let expansion_result = self.expansion()?;
Expand All @@ -248,14 +223,24 @@ impl<'tcx> Queries<'tcx> {
self.global_ctxt.compute(|| {
let crate_name = self.crate_name()?.peek().clone();
let outputs = self.prepare_outputs()?.peek().clone();
let lint_store = self.expansion()?.peek().2.clone();
let hir = self.lower_to_hir()?.peek();
let (ref krate, ref resolver, ref lint_store) = &*self.expansion()?.peek();
let resolver = resolver.steal();
let dep_graph = self.dep_graph()?.peek().clone();
let (ref krate, ref resolver_outputs) = &*hir;
let _timer = self.session().timer("create_global_ctxt");
let krate = resolver.borrow_mut().access(|resolver| {
Ok(passes::lower_to_hir(
self.session(),
lint_store,
resolver,
&dep_graph,
&krate,
&self.hir_arena,
))
})?;
let krate = self.hir_arena.alloc(krate);
let resolver_outputs = Steal::new(BoxedResolver::to_resolver_outputs(resolver));
Ok(passes::create_global_ctxt(
self.compiler,
lint_store,
lint_store.clone(),
krate,
dep_graph,
resolver_outputs.steal(),
Expand Down
1 change: 0 additions & 1 deletion src/librustdoc/doctest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ crate fn run(options: Options) -> Result<(), ErrorReported> {

let res = interface::run_compiler(config, |compiler| {
compiler.enter(|queries| {
let _lower_to_hir = queries.lower_to_hir()?;
let mut global_ctxt = queries.global_ctxt()?.take();

let collector = global_ctxt.enter(|tcx| {
Expand Down