@@ -31,9 +31,9 @@ use rustc_trait_selection::traits;
31
31
use crate :: const_eval:: ConstEvalErr ;
32
32
use crate :: interpret:: {
33
33
self , compile_time_machine, AllocId , Allocation , ConstValue , CtfeValidationMode , Frame , ImmTy ,
34
- Immediate , InterpCx , InterpError , InterpResult , LocalState , LocalValue , MemPlace , Memory ,
35
- MemoryKind , OpTy , Operand as InterpOperand , PlaceTy , Pointer , ResourceExhaustionInfo , Scalar ,
36
- ScalarMaybeUninit , StackPopCleanup , StackPopUnwind ,
34
+ Immediate , InterpCx , InterpResult , LocalState , LocalValue , MemPlace , Memory , MemoryKind , OpTy ,
35
+ Operand as InterpOperand , PlaceTy , Pointer , Scalar , ScalarMaybeUninit , StackPopCleanup ,
36
+ StackPopUnwind ,
37
37
} ;
38
38
use crate :: transform:: MirPass ;
39
39
@@ -393,12 +393,11 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
393
393
. filter ( |ret_layout| {
394
394
!ret_layout. is_zst ( ) && ret_layout. size < Size :: from_bytes ( MAX_ALLOC_LIMIT )
395
395
} )
396
- . and_then ( |ret_layout| {
397
- let alloc = ecx. allocate ( ret_layout, MemoryKind :: Stack ) ;
398
- Self :: check_interpresult ( tcx, & alloc) ;
399
- alloc. ok ( )
400
- } )
401
- . map ( Into :: into) ;
396
+ . map ( |ret_layout| {
397
+ ecx. allocate ( ret_layout, MemoryKind :: Stack )
398
+ . expect ( "couldn't perform small allocation" )
399
+ . into ( )
400
+ } ) ;
402
401
403
402
ecx. push_stack_frame (
404
403
Instance :: new ( def_id, substs) ,
@@ -421,27 +420,11 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
421
420
}
422
421
}
423
422
424
- /// Some `InterpError`s could be ignored but must not be to ensure that queries are stable.
425
- fn check_interpresult < T > ( tcx : TyCtxt < ' tcx > , error : & InterpResult < ' tcx , T > ) {
426
- if let Err ( e) = error {
427
- if matches ! (
428
- e. kind( ) ,
429
- InterpError :: ResourceExhaustion ( ResourceExhaustionInfo :: MemoryExhausted )
430
- ) {
431
- // Memory errors can't be ignored since otherwise the amount of available
432
- // memory influences the result of optimization and the build. The error
433
- // doesn't need to be fatal since no code will actually be generated anyways.
434
- tcx. sess . fatal ( "memory exhausted during optimization" ) ;
435
- }
436
- }
437
- }
438
-
439
423
fn get_const ( & self , place : Place < ' tcx > ) -> Option < OpTy < ' tcx > > {
440
424
let op = match self . ecx . eval_place_to_op ( place, None ) {
441
425
Ok ( op) => op,
442
426
Err ( e) => {
443
427
trace ! ( "get_const failed: {}" , e) ;
444
- Self :: check_interpresult :: < ( ) > ( self . tcx , & Err ( e) ) ;
445
428
return None ;
446
429
}
447
430
} ;
@@ -513,19 +496,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
513
496
} ,
514
497
ConstantKind :: Val ( _, ty) => ty. needs_subst ( ) ,
515
498
} ;
516
- // Memory errors can't be ignored since otherwise the amount of available
517
- // memory influences the result of optimization and the build. The error
518
- // doesn't need to be fatal since no code will actually be generated anyways.
519
- // FIXME(#86255): use err.error.is_hard_err(), but beware of backwards
520
- // compatibility and interactions with promoteds
521
- if lint_only
522
- && !matches ! (
523
- err. error,
524
- InterpError :: ResourceExhaustion (
525
- ResourceExhaustionInfo :: MemoryExhausted ,
526
- ) ,
527
- )
528
- {
499
+ if lint_only {
529
500
// Out of backwards compatibility we cannot report hard errors in unused
530
501
// generic functions using associated constants of the generic parameters.
531
502
err. report_as_lint ( tcx, "erroneous constant used" , lint_root, Some ( c. span ) ) ;
@@ -543,12 +514,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
543
514
/// Returns the value, if any, of evaluating `place`.
544
515
fn eval_place ( & mut self , place : Place < ' tcx > ) -> Option < OpTy < ' tcx > > {
545
516
trace ! ( "eval_place(place={:?})" , place) ;
546
- let tcx = self . tcx ;
547
- self . use_ecx ( |this| {
548
- let val = this. ecx . eval_place_to_op ( place, None ) ;
549
- Self :: check_interpresult ( tcx, & val) ;
550
- val
551
- } )
517
+ self . use_ecx ( |this| this. ecx . eval_place_to_op ( place, None ) )
552
518
}
553
519
554
520
/// Returns the value, if any, of evaluating `op`. Calls upon `eval_constant`
@@ -609,17 +575,8 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
609
575
right : & Operand < ' tcx > ,
610
576
source_info : SourceInfo ,
611
577
) -> Option < ( ) > {
612
- let tcx = self . tcx ;
613
- let r = self . use_ecx ( |this| {
614
- let val = this. ecx . read_immediate ( & this. ecx . eval_operand ( right, None ) ?) ;
615
- Self :: check_interpresult ( tcx, & val) ;
616
- val
617
- } ) ;
618
- let l = self . use_ecx ( |this| {
619
- let val = this. ecx . read_immediate ( & this. ecx . eval_operand ( left, None ) ?) ;
620
- Self :: check_interpresult ( tcx, & val) ;
621
- val
622
- } ) ;
578
+ let r = self . use_ecx ( |this| this. ecx . read_immediate ( & this. ecx . eval_operand ( right, None ) ?) ) ;
579
+ let l = self . use_ecx ( |this| this. ecx . read_immediate ( & this. ecx . eval_operand ( left, None ) ?) ) ;
623
580
// Check for exceeding shifts *even if* we cannot evaluate the LHS.
624
581
if op == BinOp :: Shr || op == BinOp :: Shl {
625
582
let r = r?;
@@ -785,24 +742,18 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
785
742
rvalue : & Rvalue < ' tcx > ,
786
743
place : Place < ' tcx > ,
787
744
) -> Option < ( ) > {
788
- let tcx = self . tcx ;
789
745
self . use_ecx ( |this| {
790
746
match rvalue {
791
747
Rvalue :: BinaryOp ( op, box ( left, right) )
792
748
| Rvalue :: CheckedBinaryOp ( op, box ( left, right) ) => {
793
749
let l = this. ecx . eval_operand ( left, None ) ;
794
750
let r = this. ecx . eval_operand ( right, None ) ;
795
- Self :: check_interpresult ( tcx, & l) ;
796
- Self :: check_interpresult ( tcx, & r) ;
797
751
798
752
let const_arg = match ( l, r) {
799
753
( Ok ( ref x) , Err ( _) ) | ( Err ( _) , Ok ( ref x) ) => this. ecx . read_immediate ( x) ?,
800
754
( Err ( e) , Err ( _) ) => return Err ( e) ,
801
755
( Ok ( _) , Ok ( _) ) => {
802
- Self :: check_interpresult (
803
- tcx,
804
- & this. ecx . eval_rvalue_into_place ( rvalue, place) ,
805
- ) ;
756
+ this. ecx . eval_rvalue_into_place ( rvalue, place) ?;
806
757
return Ok ( ( ) ) ;
807
758
}
808
759
} ;
@@ -838,16 +789,12 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
838
789
}
839
790
}
840
791
_ => {
841
- let res = this. ecx . eval_rvalue_into_place ( rvalue, place) ;
842
- Self :: check_interpresult ( tcx, & res) ;
843
- res?
792
+ this. ecx . eval_rvalue_into_place ( rvalue, place) ?;
844
793
}
845
794
}
846
795
}
847
796
_ => {
848
- let res = this. ecx . eval_rvalue_into_place ( rvalue, place) ;
849
- Self :: check_interpresult ( tcx, & res) ;
850
- res?
797
+ this. ecx . eval_rvalue_into_place ( rvalue, place) ?;
851
798
}
852
799
}
853
800
0 commit comments