Skip to content

Commit

Permalink
Auto merge of #72882 - marmeladema:save-analysis-hir-tree, r=Xanewok
Browse files Browse the repository at this point in the history
save_analysis: work on HIR tree instead of AST

In order to reduce the uses of `NodeId`s in the compiler, `save_analysis` crate has been reworked to operate on the HIR tree instead of the AST.

cc #50928
  • Loading branch information
bors committed Jun 4, 2020
2 parents 2a5cbb0 + 70228f9 commit 3d5d0f8
Show file tree
Hide file tree
Showing 6 changed files with 903 additions and 999 deletions.
16 changes: 4 additions & 12 deletions src/librustc_driver/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,20 +346,22 @@ pub fn run_compiler(

queries.global_ctxt()?;

// Drop AST after creating GlobalCtxt to free memory
let _timer = sess.prof.generic_activity("drop_ast");
mem::drop(queries.expansion()?.take());

if sess.opts.debugging_opts.no_analysis || sess.opts.debugging_opts.ast_json {
return early_exit();
}

if sess.opts.debugging_opts.save_analysis {
let expanded_crate = &queries.expansion()?.peek().0;
let crate_name = queries.crate_name()?.peek().clone();
queries.global_ctxt()?.peek_mut().enter(|tcx| {
let result = tcx.analysis(LOCAL_CRATE);

sess.time("save_analysis", || {
save::process_crate(
tcx,
&expanded_crate,
&crate_name,
&compiler.input(),
None,
Expand All @@ -371,13 +373,7 @@ pub fn run_compiler(
});

result
// AST will be dropped *after* the `after_analysis` callback
// (needed by the RLS)
})?;
} else {
// Drop AST after creating GlobalCtxt to free memory
let _timer = sess.prof.generic_activity("drop_ast");
mem::drop(queries.expansion()?.take());
}

queries.global_ctxt()?.peek_mut().enter(|tcx| tcx.analysis(LOCAL_CRATE))?;
Expand All @@ -386,10 +382,6 @@ pub fn run_compiler(
return early_exit();
}

if sess.opts.debugging_opts.save_analysis {
mem::drop(queries.expansion()?.take());
}

queries.ongoing_codegen()?;

if sess.opts.debugging_opts.print_type_sizes {
Expand Down
24 changes: 24 additions & 0 deletions src/librustc_hir_pretty/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,30 @@ pub fn visibility_qualified<S: Into<Cow<'static, str>>>(vis: &hir::Visibility<'_
})
}

pub fn generic_params_to_string(generic_params: &[GenericParam<'_>]) -> String {
to_string(NO_ANN, |s| s.print_generic_params(generic_params))
}

pub fn bounds_to_string<'b>(bounds: impl IntoIterator<Item = &'b hir::GenericBound<'b>>) -> String {
to_string(NO_ANN, |s| s.print_bounds("", bounds))
}

pub fn param_to_string(arg: &hir::Param<'_>) -> String {
to_string(NO_ANN, |s| s.print_param(arg))
}

pub fn ty_to_string(ty: &hir::Ty<'_>) -> String {
to_string(NO_ANN, |s| s.print_type(ty))
}

pub fn path_segment_to_string(segment: &hir::PathSegment<'_>) -> String {
to_string(NO_ANN, |s| s.print_path_segment(segment))
}

pub fn path_to_string(segment: &hir::Path<'_>) -> String {
to_string(NO_ANN, |s| s.print_path(segment, false))
}

impl<'a> State<'a> {
pub fn cbox(&mut self, u: usize) {
self.s.cbox(u);
Expand Down
Loading

0 comments on commit 3d5d0f8

Please sign in to comment.