@@ -200,6 +200,7 @@ use rustc_middle::ty::{self, GenericParamDefKind, Instance, Ty, TyCtxt, TypeFold
200
200
use rustc_middle:: { middle:: codegen_fn_attrs:: CodegenFnAttrFlags , mir:: visit:: TyContext } ;
201
201
use rustc_session:: config:: EntryFnType ;
202
202
use rustc_session:: lint:: builtin:: LARGE_ASSIGNMENTS ;
203
+ use rustc_session:: Limit ;
203
204
use rustc_span:: source_map:: { dummy_spanned, respan, Span , Spanned , DUMMY_SP } ;
204
205
use rustc_target:: abi:: Size ;
205
206
use smallvec:: SmallVec ;
@@ -294,6 +295,7 @@ pub fn collect_crate_mono_items(
294
295
295
296
let mut visited = MTLock :: new ( FxHashSet :: default ( ) ) ;
296
297
let mut inlining_map = MTLock :: new ( InliningMap :: new ( ) ) ;
298
+ let recursion_limit = tcx. recursion_limit ( ) ;
297
299
298
300
{
299
301
let visited: MTRef < ' _ , _ > = & mut visited;
@@ -307,6 +309,7 @@ pub fn collect_crate_mono_items(
307
309
dummy_spanned ( root) ,
308
310
visited,
309
311
& mut recursion_depths,
312
+ recursion_limit,
310
313
inlining_map,
311
314
) ;
312
315
} ) ;
@@ -350,6 +353,7 @@ fn collect_items_rec<'tcx>(
350
353
starting_point : Spanned < MonoItem < ' tcx > > ,
351
354
visited : MTRef < ' _ , MTLock < FxHashSet < MonoItem < ' tcx > > > > ,
352
355
recursion_depths : & mut DefIdMap < usize > ,
356
+ recursion_limit : Limit ,
353
357
inlining_map : MTRef < ' _ , MTLock < InliningMap < ' tcx > > > ,
354
358
) {
355
359
if !visited. lock_mut ( ) . insert ( starting_point. node ) {
@@ -409,8 +413,13 @@ fn collect_items_rec<'tcx>(
409
413
debug_assert ! ( should_codegen_locally( tcx, & instance) ) ;
410
414
411
415
// Keep track of the monomorphization recursion depth
412
- recursion_depth_reset =
413
- Some ( check_recursion_limit ( tcx, instance, starting_point. span , recursion_depths) ) ;
416
+ recursion_depth_reset = Some ( check_recursion_limit (
417
+ tcx,
418
+ instance,
419
+ starting_point. span ,
420
+ recursion_depths,
421
+ recursion_limit,
422
+ ) ) ;
414
423
check_type_length_limit ( tcx, instance) ;
415
424
416
425
rustc_data_structures:: stack:: ensure_sufficient_stack ( || {
@@ -455,7 +464,7 @@ fn collect_items_rec<'tcx>(
455
464
record_accesses ( tcx, starting_point. node , neighbors. iter ( ) . map ( |i| & i. node ) , inlining_map) ;
456
465
457
466
for neighbour in neighbors {
458
- collect_items_rec ( tcx, neighbour, visited, recursion_depths, inlining_map) ;
467
+ collect_items_rec ( tcx, neighbour, visited, recursion_depths, recursion_limit , inlining_map) ;
459
468
}
460
469
461
470
if let Some ( ( def_id, depth) ) = recursion_depth_reset {
@@ -523,6 +532,7 @@ fn check_recursion_limit<'tcx>(
523
532
instance : Instance < ' tcx > ,
524
533
span : Span ,
525
534
recursion_depths : & mut DefIdMap < usize > ,
535
+ recursion_limit : Limit ,
526
536
) -> ( DefId , usize ) {
527
537
let def_id = instance. def_id ( ) ;
528
538
let recursion_depth = recursion_depths. get ( & def_id) . cloned ( ) . unwrap_or ( 0 ) ;
@@ -539,7 +549,7 @@ fn check_recursion_limit<'tcx>(
539
549
// Code that needs to instantiate the same function recursively
540
550
// more than the recursion limit is assumed to be causing an
541
551
// infinite expansion.
542
- if !tcx . sess . recursion_limit ( ) . value_within_limit ( adjusted_recursion_depth) {
552
+ if !recursion_limit. value_within_limit ( adjusted_recursion_depth) {
543
553
let ( shrunk, written_to_path) = shrunk_instance_name ( tcx, & instance, 32 , 32 ) ;
544
554
let error = format ! ( "reached the recursion limit while instantiating `{}`" , shrunk) ;
545
555
let mut err = tcx. sess . struct_span_fatal ( span, & error) ;
@@ -577,7 +587,7 @@ fn check_type_length_limit<'tcx>(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) {
577
587
// which means that rustc basically hangs.
578
588
//
579
589
// Bail out in these cases to avoid that bad user experience.
580
- if !tcx. sess . type_length_limit ( ) . value_within_limit ( type_length) {
590
+ if !tcx. type_length_limit ( ) . value_within_limit ( type_length) {
581
591
let ( shrunk, written_to_path) = shrunk_instance_name ( tcx, & instance, 32 , 32 ) ;
582
592
let msg = format ! ( "reached the type-length limit while instantiating `{}`" , shrunk) ;
583
593
let mut diag = tcx. sess . struct_span_fatal ( tcx. def_span ( instance. def_id ( ) ) , & msg) ;
@@ -814,7 +824,7 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> {
814
824
815
825
fn visit_operand ( & mut self , operand : & mir:: Operand < ' tcx > , location : Location ) {
816
826
self . super_operand ( operand, location) ;
817
- let limit = self . tcx . sess . move_size_limit ( ) ;
827
+ let limit = self . tcx . move_size_limit ( ) . 0 ;
818
828
if limit == 0 {
819
829
return ;
820
830
}
0 commit comments