@@ -37,7 +37,7 @@ use crate::ty::codec::{TyDecoder, TyEncoder};
3737use crate :: ty:: print:: { FmtPrinter , Printer , pretty_print_const, with_no_trimmed_paths} ;
3838use crate :: ty:: visit:: TypeVisitableExt ;
3939use crate :: ty:: {
40- self , AdtDef , GenericArg , GenericArgsRef , Instance , InstanceKind , List , Ty , TyCtxt , TypingEnv ,
40+ self , AdtDef , GenericArg , GenericArgsRef , InstanceKind , List , Ty , TyCtxt , TypingEnv ,
4141 UserTypeAnnotationIndex ,
4242} ;
4343
@@ -619,74 +619,6 @@ impl<'tcx> Body<'tcx> {
619619 self . injection_phase . is_some ( )
620620 }
621621
622- /// If this basic block ends with a [`TerminatorKind::SwitchInt`] for which we can evaluate the
623- /// discriminant in monomorphization, we return the discriminant bits and the
624- /// [`SwitchTargets`], just so the caller doesn't also have to match on the terminator.
625- fn try_const_mono_switchint < ' a > (
626- tcx : TyCtxt < ' tcx > ,
627- instance : Instance < ' tcx > ,
628- block : & ' a BasicBlockData < ' tcx > ,
629- ) -> Option < ( u128 , & ' a SwitchTargets ) > {
630- // There are two places here we need to evaluate a constant.
631- let eval_mono_const = |constant : & ConstOperand < ' tcx > | {
632- // FIXME(#132279): what is this, why are we using an empty environment here.
633- let typing_env = ty:: TypingEnv :: fully_monomorphized ( ) ;
634- let mono_literal = instance. instantiate_mir_and_normalize_erasing_regions (
635- tcx,
636- typing_env,
637- crate :: ty:: EarlyBinder :: bind ( constant. const_ ) ,
638- ) ;
639- mono_literal. try_eval_bits ( tcx, typing_env)
640- } ;
641-
642- let TerminatorKind :: SwitchInt { discr, targets } = & block. terminator ( ) . kind else {
643- return None ;
644- } ;
645-
646- // If this is a SwitchInt(const _), then we can just evaluate the constant and return.
647- let discr = match discr {
648- Operand :: Constant ( constant) => {
649- let bits = eval_mono_const ( constant) ?;
650- return Some ( ( bits, targets) ) ;
651- }
652- Operand :: Move ( place) | Operand :: Copy ( place) => place,
653- } ;
654-
655- // MIR for `if false` actually looks like this:
656- // _1 = const _
657- // SwitchInt(_1)
658- //
659- // And MIR for if intrinsics::ub_checks() looks like this:
660- // _1 = UbChecks()
661- // SwitchInt(_1)
662- //
663- // So we're going to try to recognize this pattern.
664- //
665- // If we have a SwitchInt on a non-const place, we find the most recent statement that
666- // isn't a storage marker. If that statement is an assignment of a const to our
667- // discriminant place, we evaluate and return the const, as if we've const-propagated it
668- // into the SwitchInt.
669-
670- let last_stmt = block. statements . iter ( ) . rev ( ) . find ( |stmt| {
671- !matches ! ( stmt. kind, StatementKind :: StorageDead ( _) | StatementKind :: StorageLive ( _) )
672- } ) ?;
673-
674- let ( place, rvalue) = last_stmt. kind . as_assign ( ) ?;
675-
676- if discr != place {
677- return None ;
678- }
679-
680- match rvalue {
681- Rvalue :: NullaryOp ( NullOp :: UbChecks , _) => Some ( ( tcx. sess . ub_checks ( ) as u128 , targets) ) ,
682- Rvalue :: Use ( Operand :: Constant ( constant) ) => {
683- let bits = eval_mono_const ( constant) ?;
684- Some ( ( bits, targets) )
685- }
686- _ => None ,
687- }
688- }
689-
690622 /// For a `Location` in this scope, determine what the "caller location" at that point is. This
691623 /// is interesting because of inlining: the `#[track_caller]` attribute of inlined functions
692624 /// must be honored. Falls back to the `tracked_caller` value for `#[track_caller]` functions,
@@ -1434,19 +1366,6 @@ impl<'tcx> BasicBlockData<'tcx> {
14341366 pub fn is_empty_unreachable ( & self ) -> bool {
14351367 self . statements . is_empty ( ) && matches ! ( self . terminator( ) . kind, TerminatorKind :: Unreachable )
14361368 }
1437-
1438- /// Like [`Terminator::successors`] but tries to use information available from the [`Instance`]
1439- /// to skip successors like the `false` side of an `if const {`.
1440- ///
1441- /// This is used to implement [`traversal::mono_reachable`] and
1442- /// [`traversal::mono_reachable_reverse_postorder`].
1443- pub fn mono_successors ( & self , tcx : TyCtxt < ' tcx > , instance : Instance < ' tcx > ) -> Successors < ' _ > {
1444- if let Some ( ( bits, targets) ) = Body :: try_const_mono_switchint ( tcx, instance, self ) {
1445- targets. successors_for_value ( bits)
1446- } else {
1447- self . terminator ( ) . successors ( )
1448- }
1449- }
14501369}
14511370
14521371///////////////////////////////////////////////////////////////////////////
0 commit comments