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