Skip to content

Commit 3d5d0f8

Browse files
committed
Auto merge of rust-lang#72882 - marmeladema:save-analysis-hir-tree, r=Xanewok
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 rust-lang#50928
2 parents 2a5cbb0 + 70228f9 commit 3d5d0f8

File tree

6 files changed

+903
-999
lines changed

6 files changed

+903
-999
lines changed

src/librustc_driver/lib.rs

+4-12
Original file line numberDiff line numberDiff line change
@@ -346,20 +346,22 @@ pub fn run_compiler(
346346

347347
queries.global_ctxt()?;
348348

349+
// Drop AST after creating GlobalCtxt to free memory
350+
let _timer = sess.prof.generic_activity("drop_ast");
351+
mem::drop(queries.expansion()?.take());
352+
349353
if sess.opts.debugging_opts.no_analysis || sess.opts.debugging_opts.ast_json {
350354
return early_exit();
351355
}
352356

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

359362
sess.time("save_analysis", || {
360363
save::process_crate(
361364
tcx,
362-
&expanded_crate,
363365
&crate_name,
364366
&compiler.input(),
365367
None,
@@ -371,13 +373,7 @@ pub fn run_compiler(
371373
});
372374

373375
result
374-
// AST will be dropped *after* the `after_analysis` callback
375-
// (needed by the RLS)
376376
})?;
377-
} else {
378-
// Drop AST after creating GlobalCtxt to free memory
379-
let _timer = sess.prof.generic_activity("drop_ast");
380-
mem::drop(queries.expansion()?.take());
381377
}
382378

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

389-
if sess.opts.debugging_opts.save_analysis {
390-
mem::drop(queries.expansion()?.take());
391-
}
392-
393385
queries.ongoing_codegen()?;
394386

395387
if sess.opts.debugging_opts.print_type_sizes {

src/librustc_hir_pretty/lib.rs

+24
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,30 @@ pub fn visibility_qualified<S: Into<Cow<'static, str>>>(vis: &hir::Visibility<'_
203203
})
204204
}
205205

206+
pub fn generic_params_to_string(generic_params: &[GenericParam<'_>]) -> String {
207+
to_string(NO_ANN, |s| s.print_generic_params(generic_params))
208+
}
209+
210+
pub fn bounds_to_string<'b>(bounds: impl IntoIterator<Item = &'b hir::GenericBound<'b>>) -> String {
211+
to_string(NO_ANN, |s| s.print_bounds("", bounds))
212+
}
213+
214+
pub fn param_to_string(arg: &hir::Param<'_>) -> String {
215+
to_string(NO_ANN, |s| s.print_param(arg))
216+
}
217+
218+
pub fn ty_to_string(ty: &hir::Ty<'_>) -> String {
219+
to_string(NO_ANN, |s| s.print_type(ty))
220+
}
221+
222+
pub fn path_segment_to_string(segment: &hir::PathSegment<'_>) -> String {
223+
to_string(NO_ANN, |s| s.print_path_segment(segment))
224+
}
225+
226+
pub fn path_to_string(segment: &hir::Path<'_>) -> String {
227+
to_string(NO_ANN, |s| s.print_path(segment, false))
228+
}
229+
206230
impl<'a> State<'a> {
207231
pub fn cbox(&mut self, u: usize) {
208232
self.s.cbox(u);

0 commit comments

Comments
 (0)