@@ -283,120 +283,127 @@ 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+ let linker = compiler. enter ( |queries| {
287+ let early_exit = || sess. compile_status ( ) . map ( |_| None ) ;
288+ queries. parse ( ) ?;
289+
290+ if let Some ( ppm) = & sess. opts . pretty {
291+ if ppm. needs_ast_map ( ) {
292+ queries. global_ctxt ( ) ?. peek_mut ( ) . enter ( |tcx| {
293+ let expanded_crate = queries. expansion ( ) ?. take ( ) . 0 ;
294+ pretty:: print_after_hir_lowering (
295+ tcx,
296+ compiler. input ( ) ,
297+ & expanded_crate,
298+ * ppm,
299+ compiler. output_file ( ) . as_ref ( ) . map ( |p| & * * p) ,
300+ ) ;
301+ Ok ( ( ) )
302+ } ) ?;
303+ } else {
304+ let krate = queries. parse ( ) ?. take ( ) ;
305+ pretty:: print_after_parsing (
306+ sess,
307+ & compiler. input ( ) ,
308+ & krate,
296309 * ppm,
297310 compiler. output_file ( ) . as_ref ( ) . map ( |p| & * * p) ,
298311 ) ;
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- ) ;
312+ }
313+ return early_exit ( ) ;
310314 }
311- return sess. compile_status ( ) ;
312- }
313315
314- if callbacks. after_parsing ( compiler) == Compilation :: Stop {
315- return sess . compile_status ( ) ;
316- }
316+ if callbacks. after_parsing ( compiler) == Compilation :: Stop {
317+ return early_exit ( ) ;
318+ }
317319
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- }
320+ if sess. opts . debugging_opts . parse_only ||
321+ sess. opts . debugging_opts . show_span . is_some ( ) ||
322+ sess. opts . debugging_opts . ast_json_noexpand {
323+ return early_exit ( ) ;
324+ }
323325
324- {
325- let ( _, lint_store) = & * compiler . register_plugins ( ) ?. peek ( ) ;
326+ {
327+ let ( _, lint_store) = & * queries . register_plugins ( ) ?. peek ( ) ;
326328
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 ) ;
330- return sess. compile_status ( ) ;
329+ // Lint plugins are registered; now we can process command line flags.
330+ if sess. opts . describe_lints {
331+ describe_lints ( & sess, & lint_store, true ) ;
332+ return early_exit ( ) ;
333+ }
331334 }
332- }
333335
334- compiler . expansion ( ) ?;
335- if callbacks. after_expansion ( compiler) == Compilation :: Stop {
336- return sess . compile_status ( ) ;
337- }
336+ queries . expansion ( ) ?;
337+ if callbacks. after_expansion ( compiler) == Compilation :: Stop {
338+ return early_exit ( ) ;
339+ }
338340
339- compiler . prepare_outputs ( ) ?;
341+ queries . prepare_outputs ( ) ?;
340342
341- if sess. opts . output_types . contains_key ( & OutputType :: DepInfo )
342- && sess. opts . output_types . len ( ) == 1
343- {
344- return sess . compile_status ( ) ;
345- }
343+ if sess. opts . output_types . contains_key ( & OutputType :: DepInfo )
344+ && sess. opts . output_types . len ( ) == 1
345+ {
346+ return early_exit ( ) ;
347+ }
346348
347- compiler . global_ctxt ( ) ?;
349+ queries . global_ctxt ( ) ?;
348350
349- if sess. opts . debugging_opts . no_analysis ||
350- sess. opts . debugging_opts . ast_json {
351- return sess . compile_status ( ) ;
352- }
351+ if sess. opts . debugging_opts . no_analysis ||
352+ sess. opts . debugging_opts . ast_json {
353+ return early_exit ( ) ;
354+ }
353355
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- }
356+ if sess. opts . debugging_opts . save_analysis {
357+ let expanded_crate = & queries. expansion ( ) ?. peek ( ) . 0 ;
358+ let crate_name = queries. crate_name ( ) ?. peek ( ) . clone ( ) ;
359+ queries. global_ctxt ( ) ?. peek_mut ( ) . enter ( |tcx| {
360+ let result = tcx. analysis ( LOCAL_CRATE ) ;
361+
362+ time ( sess, "save analysis" , || {
363+ save:: process_crate (
364+ tcx,
365+ & expanded_crate,
366+ & crate_name,
367+ & compiler. input ( ) ,
368+ None ,
369+ DumpHandler :: new (
370+ compiler. output_dir ( ) . as_ref ( ) . map ( |p| & * * p) , & crate_name
371+ )
372+ )
373+ } ) ;
379374
380- compiler. global_ctxt ( ) ?. peek_mut ( ) . enter ( |tcx| tcx. analysis ( LOCAL_CRATE ) ) ?;
375+ result
376+ // AST will be dropped *after* the `after_analysis` callback
377+ // (needed by the RLS)
378+ } ) ?;
379+ } else {
380+ // Drop AST after creating GlobalCtxt to free memory
381+ mem:: drop ( queries. expansion ( ) ?. take ( ) ) ;
382+ }
381383
382- if callbacks. after_analysis ( compiler) == Compilation :: Stop {
383- return sess. compile_status ( ) ;
384- }
384+ queries. global_ctxt ( ) ?. peek_mut ( ) . enter ( |tcx| tcx. analysis ( LOCAL_CRATE ) ) ?;
385385
386- if sess . opts . debugging_opts . save_analysis {
387- mem :: drop ( compiler . expansion ( ) ? . take ( ) ) ;
388- }
386+ if callbacks . after_analysis ( compiler ) == Compilation :: Stop {
387+ return early_exit ( ) ;
388+ }
389389
390- compiler. ongoing_codegen ( ) ?;
390+ if sess. opts . debugging_opts . save_analysis {
391+ mem:: drop ( queries. expansion ( ) ?. take ( ) ) ;
392+ }
391393
392- // Drop GlobalCtxt after starting codegen to free memory
393- mem:: drop ( compiler. global_ctxt ( ) ?. take ( ) ) ;
394+ queries. ongoing_codegen ( ) ?;
394395
395- if sess. opts . debugging_opts . print_type_sizes {
396- sess. code_stats . print_type_sizes ( ) ;
397- }
396+ if sess. opts . debugging_opts . print_type_sizes {
397+ sess. code_stats . print_type_sizes ( ) ;
398+ }
398399
399- compiler. link ( ) ?;
400+ let linker = queries. linker ( ) ?;
401+ Ok ( Some ( linker) )
402+ } ) ?;
403+
404+ if let Some ( linker) = linker {
405+ linker. link ( ) ?
406+ }
400407
401408 if sess. opts . debugging_opts . perf_stats {
402409 sess. print_perf_stats ( ) ;
0 commit comments