@@ -283,120 +283,124 @@ pub fn run_compiler(
283283 return sess. compile_status ( ) ;
284284 }
285285
286- compiler. parse ( ) ?;
287-
288- if let Some ( ppm) = & sess. opts . pretty {
289- if ppm. needs_ast_map ( ) {
290- compiler. global_ctxt ( ) ?. peek_mut ( ) . enter ( |tcx| {
291- let expanded_crate = compiler. expansion ( ) ?. take ( ) . 0 ;
292- pretty:: print_after_hir_lowering (
293- tcx,
294- compiler. input ( ) ,
295- & expanded_crate,
286+ compiler. enter ( |queries| {
287+ queries. parse ( ) ?;
288+
289+ if let Some ( ppm) = & sess. opts . pretty {
290+ if ppm. needs_ast_map ( ) {
291+ queries. global_ctxt ( ) ?. peek_mut ( ) . enter ( |tcx| {
292+ let expanded_crate = queries. expansion ( ) ?. take ( ) . 0 ;
293+ pretty:: print_after_hir_lowering (
294+ tcx,
295+ compiler. input ( ) ,
296+ & expanded_crate,
297+ * ppm,
298+ compiler. output_file ( ) . as_ref ( ) . map ( |p| & * * p) ,
299+ ) ;
300+ Ok ( ( ) )
301+ } ) ?;
302+ } else {
303+ let krate = queries. parse ( ) ?. take ( ) ;
304+ pretty:: print_after_parsing (
305+ sess,
306+ & compiler. input ( ) ,
307+ & krate,
296308 * ppm,
297309 compiler. output_file ( ) . as_ref ( ) . map ( |p| & * * p) ,
298310 ) ;
299- Ok ( ( ) )
300- } ) ?;
301- } else {
302- let krate = compiler. parse ( ) ?. take ( ) ;
303- pretty:: print_after_parsing (
304- sess,
305- & compiler. input ( ) ,
306- & krate,
307- * ppm,
308- compiler. output_file ( ) . as_ref ( ) . map ( |p| & * * p) ,
309- ) ;
311+ }
312+ return sess. compile_status ( ) ;
310313 }
311- return sess. compile_status ( ) ;
312- }
313314
314- if callbacks. after_parsing ( compiler) == Compilation :: Stop {
315- return sess. compile_status ( ) ;
316- }
315+ if callbacks. after_parsing ( compiler) == Compilation :: Stop {
316+ return sess. compile_status ( ) ;
317+ }
317318
318- if sess. opts . debugging_opts . parse_only ||
319- sess. opts . debugging_opts . show_span . is_some ( ) ||
320- sess. opts . debugging_opts . ast_json_noexpand {
321- return sess. compile_status ( ) ;
322- }
319+ if sess. opts . debugging_opts . parse_only ||
320+ sess. opts . debugging_opts . show_span . is_some ( ) ||
321+ sess. opts . debugging_opts . ast_json_noexpand {
322+ return sess. compile_status ( ) ;
323+ }
324+
325+ {
326+ let ( _, lint_store) = & * queries. register_plugins ( ) ?. peek ( ) ;
323327
324- {
325- let ( _, lint_store) = & * compiler. register_plugins ( ) ?. peek ( ) ;
328+ // Lint plugins are registered; now we can process command line flags.
329+ if sess. opts . describe_lints {
330+ describe_lints ( & sess, & lint_store, true ) ;
331+ return sess. compile_status ( ) ;
332+ }
333+ }
326334
327- // Lint plugins are registered; now we can process command line flags.
328- if sess. opts . describe_lints {
329- describe_lints ( & sess, & lint_store, true ) ;
335+ queries. expansion ( ) ?;
336+ if callbacks. after_expansion ( compiler) == Compilation :: Stop {
330337 return sess. compile_status ( ) ;
331338 }
332- }
333339
334- compiler. expansion ( ) ?;
335- if callbacks. after_expansion ( compiler) == Compilation :: Stop {
336- return sess. compile_status ( ) ;
337- }
340+ queries. prepare_outputs ( ) ?;
341+
342+ if sess. opts . output_types . contains_key ( & OutputType :: DepInfo )
343+ && sess. opts . output_types . len ( ) == 1
344+ {
345+ return sess. compile_status ( ) ;
346+ }
338347
339- compiler . prepare_outputs ( ) ?;
348+ queries . global_ctxt ( ) ?;
340349
341- if sess. opts . output_types . contains_key ( & OutputType :: DepInfo )
342- && sess. opts . output_types . len ( ) == 1
343- {
344- return sess. compile_status ( ) ;
345- }
350+ if sess. opts . debugging_opts . no_analysis ||
351+ sess. opts . debugging_opts . ast_json {
352+ return sess. compile_status ( ) ;
353+ }
346354
347- compiler. global_ctxt ( ) ?;
355+ if sess. opts . debugging_opts . save_analysis {
356+ let expanded_crate = & queries. expansion ( ) ?. peek ( ) . 0 ;
357+ let crate_name = queries. crate_name ( ) ?. peek ( ) . clone ( ) ;
358+ queries. global_ctxt ( ) ?. peek_mut ( ) . enter ( |tcx| {
359+ let result = tcx. analysis ( LOCAL_CRATE ) ;
360+
361+ time ( sess, "save analysis" , || {
362+ save:: process_crate (
363+ tcx,
364+ & expanded_crate,
365+ & crate_name,
366+ & compiler. input ( ) ,
367+ None ,
368+ DumpHandler :: new ( compiler. output_dir ( ) . as_ref ( ) . map ( |p| & * * p) , & crate_name)
369+ )
370+ } ) ;
348371
349- if sess. opts . debugging_opts . no_analysis ||
350- sess. opts . debugging_opts . ast_json {
351- return sess. compile_status ( ) ;
352- }
372+ result
373+ // AST will be dropped *after* the `after_analysis` callback
374+ // (needed by the RLS)
375+ } ) ?;
376+ } else {
377+ // Drop AST after creating GlobalCtxt to free memory
378+ mem:: drop ( queries. expansion ( ) ?. take ( ) ) ;
379+ }
353380
354- if sess. opts . debugging_opts . save_analysis {
355- let expanded_crate = & compiler. expansion ( ) ?. peek ( ) . 0 ;
356- let crate_name = compiler. crate_name ( ) ?. peek ( ) . clone ( ) ;
357- compiler. global_ctxt ( ) ?. peek_mut ( ) . enter ( |tcx| {
358- let result = tcx. analysis ( LOCAL_CRATE ) ;
359-
360- time ( sess, "save analysis" , || {
361- save:: process_crate (
362- tcx,
363- & expanded_crate,
364- & crate_name,
365- & compiler. input ( ) ,
366- None ,
367- DumpHandler :: new ( compiler. output_dir ( ) . as_ref ( ) . map ( |p| & * * p) , & crate_name)
368- )
369- } ) ;
370-
371- result
372- // AST will be dropped *after* the `after_analysis` callback
373- // (needed by the RLS)
374- } ) ?;
375- } else {
376- // Drop AST after creating GlobalCtxt to free memory
377- mem:: drop ( compiler. expansion ( ) ?. take ( ) ) ;
378- }
381+ queries. global_ctxt ( ) ?. peek_mut ( ) . enter ( |tcx| tcx. analysis ( LOCAL_CRATE ) ) ?;
379382
380- compiler. global_ctxt ( ) ?. peek_mut ( ) . enter ( |tcx| tcx. analysis ( LOCAL_CRATE ) ) ?;
383+ if callbacks. after_analysis ( compiler) == Compilation :: Stop {
384+ return sess. compile_status ( ) ;
385+ }
381386
382- if callbacks . after_analysis ( compiler ) == Compilation :: Stop {
383- return sess . compile_status ( ) ;
384- }
387+ if sess . opts . debugging_opts . save_analysis {
388+ mem :: drop ( queries . expansion ( ) ? . take ( ) ) ;
389+ }
385390
386- if sess. opts . debugging_opts . save_analysis {
387- mem:: drop ( compiler. expansion ( ) ?. take ( ) ) ;
388- }
391+ queries. ongoing_codegen ( ) ?;
389392
390- compiler. ongoing_codegen ( ) ?;
393+ // Drop GlobalCtxt after starting codegen to free memory
394+ mem:: drop ( queries. global_ctxt ( ) ?. take ( ) ) ;
391395
392- // Drop GlobalCtxt after starting codegen to free memory
393- mem:: drop ( compiler. global_ctxt ( ) ?. take ( ) ) ;
396+ if sess. opts . debugging_opts . print_type_sizes {
397+ sess. code_stats . print_type_sizes ( ) ;
398+ }
394399
395- if sess. opts . debugging_opts . print_type_sizes {
396- sess. code_stats . print_type_sizes ( ) ;
397- }
400+ queries. link ( ) ?;
398401
399- compiler. link ( ) ?;
402+ Ok ( ( ) )
403+ } ) ?;
400404
401405 if sess. opts . debugging_opts . perf_stats {
402406 sess. print_perf_stats ( ) ;
0 commit comments