1
Fork 0

Rollup merge of #136610 - Jarcho:range_idx, r=Noratrieb

Allow `IndexSlice` to be indexed by ranges.

This comes with some annoyances as the index type can no longer inferred from indexing expressions. The biggest offender for this is `IndexVec::from_fn_n(|idx| ..., n)` where the index type won't be inferred from the call site or any index expressions inside the closure.

My main use case for this is mapping a `Place` to `Range<Idx>` for value tracking where the range represents all the values the place contains.
This commit is contained in:
Jacob Pratt 2025-02-24 02:11:32 -05:00 committed by GitHub
commit 6aa015ae9d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 144 additions and 42 deletions

View file

@ -71,8 +71,7 @@ pub(crate) fn check_pointers<'tcx, F>(
// statements/blocks after. Iterating or visiting the MIR in order would require updating
// our current location after every insertion. By iterating backwards, we dodge this issue:
// The only Locations that an insertion changes have already been handled.
for block in (0..basic_blocks.len()).rev() {
let block = block.into();
for block in basic_blocks.indices().rev() {
for statement_index in (0..basic_blocks[block].statements.len()).rev() {
let location = Location { block, statement_index };
let statement = &basic_blocks[block].statements[statement_index];

View file

@ -50,7 +50,7 @@ fn make_node_flow_priority_list(
// A "reloop" node has exactly one out-edge, which jumps back to the top
// of an enclosing loop. Reloop nodes are typically visited more times
// than loop-exit nodes, so try to avoid giving them physical counters.
let is_reloop_node = IndexVec::from_fn_n(
let is_reloop_node = IndexVec::<BasicCoverageBlock, _>::from_fn_n(
|node| match graph.successors[node].as_slice() {
&[succ] => graph.dominates(succ, node),
_ => false,

View file

@ -42,7 +42,7 @@ impl CoverageGraph {
// `SwitchInt` to have multiple targets to the same destination `BasicBlock`, so
// de-duplication is required. This is done without reordering the successors.
let successors = IndexVec::from_fn_n(
let successors = IndexVec::<BasicCoverageBlock, _>::from_fn_n(
|bcb| {
let mut seen_bcbs = FxHashSet::default();
let terminator = mir_body[bcbs[bcb].last_bb()].terminator();

View file

@ -1259,7 +1259,7 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
let layout = self.ecx.layout_of(lhs_ty).ok()?;
let as_bits = |value| {
let as_bits = |value: VnIndex| {
let constant = self.evaluated[value].as_ref()?;
if layout.backend_repr.is_scalar() {
let scalar = self.ecx.read_scalar(constant).discard_err()?;