Skip to content
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

save_analysis: work on HIR tree instead of AST #72882

Merged
merged 2 commits into from
Jun 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
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());
Comment on lines +349 to +351
Copy link
Member

Choose a reason for hiding this comment

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

This needs a block around it, the _timer is supposed to be dropped after the next statement, in order for drop_ast to track only that, and not the rest of this large block. (it's not a big deal, but I was baffled as to why drop_ast had so much variance, or any children at all, in the profiling data)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry about that! Should be fixed by #75575


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)
marmeladema marked this conversation as resolved.
Show resolved Hide resolved
})?;
} 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