@@ -8,11 +8,12 @@ use rustc_ast::{self as ast, visit};
8
8
use rustc_borrowck as mir_borrowck;
9
9
use rustc_codegen_ssa:: traits:: CodegenBackend ;
10
10
use rustc_data_structures:: parallel;
11
+ use rustc_data_structures:: steal:: Steal ;
11
12
use rustc_data_structures:: sync:: { Lrc , OnceCell , WorkerLocal } ;
12
- use rustc_errors:: { ErrorGuaranteed , PResult } ;
13
+ use rustc_errors:: PResult ;
13
14
use rustc_expand:: base:: { ExtCtxt , LintStoreExpand , ResolverExpand } ;
14
15
use rustc_hir:: def_id:: { StableCrateId , LOCAL_CRATE } ;
15
- use rustc_lint:: { BufferedEarlyLint , EarlyCheckNode , LintStore } ;
16
+ use rustc_lint:: { unerased_lint_store , BufferedEarlyLint , EarlyCheckNode , LintStore } ;
16
17
use rustc_metadata:: creader:: CStore ;
17
18
use rustc_middle:: arena:: Arena ;
18
19
use rustc_middle:: dep_graph:: DepGraph ;
@@ -171,14 +172,12 @@ impl LintStoreExpand for LintStoreExpandImpl<'_> {
171
172
/// syntax expansion, secondary `cfg` expansion, synthesis of a test
172
173
/// harness if one is to be provided, injection of a dependency on the
173
174
/// 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 ) ;
182
181
pre_expansion_lint ( sess, lint_store, resolver. registered_tools ( ) , & krate, crate_name) ;
183
182
rustc_builtin_macros:: register_builtin_macros ( resolver) ;
184
183
@@ -249,20 +248,19 @@ pub fn configure_and_expand(
249
248
ecx. check_unused_macros ( ) ;
250
249
} ) ;
251
250
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
+ }
253
257
254
258
if cfg ! ( windows) {
255
259
env:: set_var ( "PATH" , & old_path) ;
256
260
}
257
261
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
+ } ) ;
266
264
267
265
sess. time ( "maybe_building_test_harness" , || {
268
266
rustc_builtin_macros:: test_harness:: inject ( sess, resolver, & mut krate)
@@ -365,7 +363,7 @@ pub fn configure_and_expand(
365
363
)
366
364
} ) ;
367
365
368
- Ok ( krate)
366
+ krate
369
367
}
370
368
371
369
// Returns all the paths that correspond to generated files.
@@ -564,6 +562,28 @@ fn write_out_deps(
564
562
}
565
563
}
566
564
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
+
567
587
fn output_filenames ( tcx : TyCtxt < ' _ > , ( ) : ( ) ) -> Arc < OutputFilenames > {
568
588
let sess = tcx. sess ;
569
589
let _timer = sess. timer ( "prepare_outputs" ) ;
@@ -597,7 +617,7 @@ fn output_filenames(tcx: TyCtxt<'_>, (): ()) -> Arc<OutputFilenames> {
597
617
}
598
618
}
599
619
600
- write_out_deps ( sess, tcx. cstore_untracked ( ) , & outputs, & output_paths) ;
620
+ write_out_deps ( sess, & * tcx. cstore_untracked ( ) , & outputs, & output_paths) ;
601
621
602
622
let only_dep_info = sess. opts . output_types . contains_key ( & OutputType :: DepInfo )
603
623
&& sess. opts . output_types . len ( ) == 1 ;
@@ -618,6 +638,7 @@ pub static DEFAULT_QUERY_PROVIDERS: LazyLock<Providers> = LazyLock::new(|| {
618
638
providers. analysis = analysis;
619
639
providers. hir_crate = rustc_ast_lowering:: lower_to_hir;
620
640
providers. output_filenames = output_filenames;
641
+ providers. resolver_for_lowering = resolver_for_lowering;
621
642
proc_macro_decls:: provide ( providers) ;
622
643
rustc_const_eval:: provide ( providers) ;
623
644
rustc_middle:: hir:: provide ( providers) ;
0 commit comments