Auto merge of #123272 - saethlin:reachable-mono-cleanup, r= · rust-lang/rust@93c3b66 (original) (raw)

`@@ -30,7 +30,6 @@ pub use rustc_ast::Mutability;

`

30

30

`use rustc_data_structures::fx::FxHashMap;

`

31

31

`use rustc_data_structures::fx::FxHashSet;

`

32

32

`use rustc_data_structures::graph::dominators::Dominators;

`

33

``

`-

use rustc_data_structures::stack::ensure_sufficient_stack;

`

34

33

`use rustc_index::bit_set::BitSet;

`

35

34

`use rustc_index::{Idx, IndexSlice, IndexVec};

`

36

35

`use rustc_serialize::{Decodable, Encodable};

`

`@@ -687,57 +686,6 @@ impl<'tcx> Body<'tcx> {

`

687

686

`self.injection_phase.is_some()

`

688

687

`}

`

689

688

``

690

``

`-

/// Finds which basic blocks are actually reachable for a specific

`

691

``

`-

/// monomorphization of this body.

`

692

``

`-

///

`

693

``

`-

/// This is allowed to have false positives; just because this says a block

`

694

``

`-

/// is reachable doesn't mean that's necessarily true. It's thus always

`

695

``

`-

/// legal for this to return a filled set.

`

696

``

`-

///

`

697

``

`` -

/// Regardless, the [BitSet::domain_size] of the returned set will always

``

698

``

`` -

/// exactly match the number of blocks in the body so that contains

``

699

``

`-

/// checks can be done without worrying about panicking.

`

700

``

`-

///

`

701

``

`` -

/// This is mostly useful because it lets us skip lowering the false side

``

702

``

`` -

/// of if <T as Trait>::CONST, as well as intrinsics::debug_assertions.

``

703

``

`-

pub fn reachable_blocks_in_mono(

`

704

``

`-

&self,

`

705

``

`-

tcx: TyCtxt<'tcx>,

`

706

``

`-

instance: Instance<'tcx>,

`

707

``

`-

) -> BitSet {

`

708

``

`-

let mut set = BitSet::new_empty(self.basic_blocks.len());

`

709

``

`-

self.reachable_blocks_in_mono_from(tcx, instance, &mut set, START_BLOCK);

`

710

``

`-

set

`

711

``

`-

}

`

712

``

-

713

``

`-

fn reachable_blocks_in_mono_from(

`

714

``

`-

&self,

`

715

``

`-

tcx: TyCtxt<'tcx>,

`

716

``

`-

instance: Instance<'tcx>,

`

717

``

`-

set: &mut BitSet,

`

718

``

`-

bb: BasicBlock,

`

719

``

`-

) {

`

720

``

`-

if !set.insert(bb) {

`

721

``

`-

return;

`

722

``

`-

}

`

723

``

-

724

``

`-

let data = &self.basic_blocks[bb];

`

725

``

-

726

``

`-

if let Some((bits, targets)) = Self::try_const_mono_switchint(tcx, instance, data) {

`

727

``

`-

let target = targets.target_for_value(bits);

`

728

``

`-

ensure_sufficient_stack(|| {

`

729

``

`-

self.reachable_blocks_in_mono_from(tcx, instance, set, target)

`

730

``

`-

});

`

731

``

`-

return;

`

732

``

`-

}

`

733

``

-

734

``

`-

for target in data.terminator().successors() {

`

735

``

`-

ensure_sufficient_stack(|| {

`

736

``

`-

self.reachable_blocks_in_mono_from(tcx, instance, set, target)

`

737

``

`-

});

`

738

``

`-

}

`

739

``

`-

}

`

740

``

-

741

689

`` /// If this basic block ends with a [TerminatorKind::SwitchInt] for which we can evaluate the

``

742

690

`/// dimscriminant in monomorphization, we return the discriminant bits and the

`

743

691

`` /// [SwitchTargets], just so the caller doesn't also have to match on the terminator.

``