@@ -8,11 +8,12 @@ use rustc_ast::{self as ast, visit};
88use rustc_borrowck as mir_borrowck;
99use rustc_codegen_ssa:: traits:: CodegenBackend ;
1010use rustc_data_structures:: parallel;
11+ use rustc_data_structures:: steal:: Steal ;
1112use rustc_data_structures:: sync:: { Lrc , OnceCell , WorkerLocal } ;
12- use rustc_errors:: { ErrorGuaranteed , PResult } ;
13+ use rustc_errors:: PResult ;
1314use rustc_expand:: base:: { ExtCtxt , LintStoreExpand , ResolverExpand } ;
1415use rustc_hir:: def_id:: { StableCrateId , LOCAL_CRATE } ;
15- use rustc_lint:: { BufferedEarlyLint , EarlyCheckNode , LintStore } ;
16+ use rustc_lint:: { unerased_lint_store , BufferedEarlyLint , EarlyCheckNode , LintStore } ;
1617use rustc_metadata:: creader:: CStore ;
1718use rustc_middle:: arena:: Arena ;
1819use rustc_middle:: dep_graph:: DepGraph ;
@@ -171,14 +172,12 @@ impl LintStoreExpand for LintStoreExpandImpl<'_> {
171172/// syntax expansion, secondary `cfg` expansion, synthesis of a test
172173/// harness if one is to be provided, injection of a dependency on the
173174/// standard library and prelude, and name resolution.
174- pub fn configure_and_expand (
175- sess : & Session ,
176- lint_store : & LintStore ,
177- mut krate : ast:: Crate ,
178- crate_name : Symbol ,
179- resolver : & mut Resolver < ' _ , ' _ > ,
180- ) -> Result < ast:: Crate > {
181- trace ! ( "configure_and_expand" ) ;
175+ #[ instrument( level = "trace" , skip( krate, resolver) ) ]
176+ fn configure_and_expand ( mut krate : ast:: Crate , resolver : & mut Resolver < ' _ , ' _ > ) -> ast:: Crate {
177+ let tcx = resolver. tcx ( ) ;
178+ let sess = tcx. sess ;
179+ let lint_store = unerased_lint_store ( tcx) ;
180+ let crate_name = tcx. crate_name ( LOCAL_CRATE ) ;
182181 pre_expansion_lint ( sess, lint_store, resolver. registered_tools ( ) , & krate, crate_name) ;
183182 rustc_builtin_macros:: register_builtin_macros ( resolver) ;
184183
@@ -249,20 +248,19 @@ pub fn configure_and_expand(
249248 ecx. check_unused_macros ( ) ;
250249 } ) ;
251250
252- let recursion_limit_hit = ecx. reduced_recursion_limit . is_some ( ) ;
251+ // If we hit a recursion limit, exit early to avoid later passes getting overwhelmed
252+ // with a large AST
253+ if ecx. reduced_recursion_limit . is_some ( ) {
254+ sess. abort_if_errors ( ) ;
255+ unreachable ! ( ) ;
256+ }
253257
254258 if cfg ! ( windows) {
255259 env:: set_var ( "PATH" , & old_path) ;
256260 }
257261
258- if recursion_limit_hit {
259- // If we hit a recursion limit, exit early to avoid later passes getting overwhelmed
260- // with a large AST
261- Err ( ErrorGuaranteed :: unchecked_claim_error_was_emitted ( ) )
262- } else {
263- Ok ( krate)
264- }
265- } ) ?;
262+ krate
263+ } ) ;
266264
267265 sess. time ( "maybe_building_test_harness" , || {
268266 rustc_builtin_macros:: test_harness:: inject ( sess, resolver, & mut krate)
@@ -365,7 +363,7 @@ pub fn configure_and_expand(
365363 )
366364 } ) ;
367365
368- Ok ( krate)
366+ krate
369367}
370368
371369// Returns all the paths that correspond to generated files.
@@ -564,6 +562,28 @@ fn write_out_deps(
564562 }
565563}
566564
565+ fn resolver_for_lowering < ' tcx > (
566+ tcx : TyCtxt < ' tcx > ,
567+ ( ) : ( ) ,
568+ ) -> & ' tcx Steal < ( ty:: ResolverAstLowering , Lrc < ast:: Crate > ) > {
569+ let arenas = Resolver :: arenas ( ) ;
570+ let krate = tcx. crate_for_resolver ( ( ) ) . steal ( ) ;
571+ let mut resolver = Resolver :: new ( tcx, & krate, & arenas) ;
572+ let krate = configure_and_expand ( krate, & mut resolver) ;
573+
574+ // Make sure we don't mutate the cstore from here on.
575+ tcx. untracked ( ) . cstore . leak ( ) ;
576+
577+ let ty:: ResolverOutputs {
578+ global_ctxt : untracked_resolutions,
579+ ast_lowering : untracked_resolver_for_lowering,
580+ } = resolver. into_outputs ( ) ;
581+
582+ let feed = tcx. feed_unit_query ( ) ;
583+ feed. resolutions ( tcx. arena . alloc ( untracked_resolutions) ) ;
584+ tcx. arena . alloc ( Steal :: new ( ( untracked_resolver_for_lowering, Lrc :: new ( krate) ) ) )
585+ }
586+
567587fn output_filenames ( tcx : TyCtxt < ' _ > , ( ) : ( ) ) -> Arc < OutputFilenames > {
568588 let sess = tcx. sess ;
569589 let _timer = sess. timer ( "prepare_outputs" ) ;
@@ -597,7 +617,7 @@ fn output_filenames(tcx: TyCtxt<'_>, (): ()) -> Arc<OutputFilenames> {
597617 }
598618 }
599619
600- write_out_deps ( sess, tcx. cstore_untracked ( ) , & outputs, & output_paths) ;
620+ write_out_deps ( sess, & * tcx. cstore_untracked ( ) , & outputs, & output_paths) ;
601621
602622 let only_dep_info = sess. opts . output_types . contains_key ( & OutputType :: DepInfo )
603623 && sess. opts . output_types . len ( ) == 1 ;
@@ -618,6 +638,7 @@ pub static DEFAULT_QUERY_PROVIDERS: LazyLock<Providers> = LazyLock::new(|| {
618638 providers. analysis = analysis;
619639 providers. hir_crate = rustc_ast_lowering:: lower_to_hir;
620640 providers. output_filenames = output_filenames;
641+ providers. resolver_for_lowering = resolver_for_lowering;
621642 proc_macro_decls:: provide ( providers) ;
622643 rustc_const_eval:: provide ( providers) ;
623644 rustc_middle:: hir:: provide ( providers) ;
0 commit comments