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