Skip to content

Commit de91711

Browse files
committedFeb 18, 2025
Auto merge of #137176 - matthiaskrgr:rollup-eht05gr, r=matthiaskrgr
Rollup of 9 pull requests Successful merges: - #136959 (Simplify switch sources) - #137020 (Pass vendored sources from bootstrap to generate-copyright) - #137073 (boostrap: skip no_std targets in Std doc step) - #137165 (Use `tell` for `<File as Seek>::stream_position`) - #137166 (Update default loongarch code model in docs) - #137168 (correct comment) - #137169 (CI: rfl: move job forward to Linux v6.14-rc3) - #137170 (Allow configuring jemalloc per target) - #137173 (Subtree update of `rust-analyzer`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents ce36a96 + fc82903 commit de91711

File tree

142 files changed

+9812
-3088
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

142 files changed

+9812
-3088
lines changed
 

‎compiler/rustc_middle/src/mir/basic_blocks.rs

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,22 @@ pub struct BasicBlocks<'tcx> {
2020
// Typically 95%+ of basic blocks have 4 or fewer predecessors.
2121
type Predecessors = IndexVec<BasicBlock, SmallVec<[BasicBlock; 4]>>;
2222

23-
type SwitchSources = FxHashMap<(BasicBlock, BasicBlock), SmallVec<[Option<u128>; 1]>>;
23+
/// Each `(target, switch)` entry in the map contains a list of switch values
24+
/// that lead to a `target` block from a `switch` block.
25+
///
26+
/// Note: this type is currently never instantiated, because it's only used for
27+
/// `BasicBlocks::switch_sources`, which is only called by backwards analyses
28+
/// that do `SwitchInt` handling, and we don't have any of those, not even in
29+
/// tests. See #95120 and #94576.
30+
type SwitchSources = FxHashMap<(BasicBlock, BasicBlock), SmallVec<[SwitchTargetValue; 1]>>;
31+
32+
#[derive(Debug, Clone, Copy)]
33+
pub enum SwitchTargetValue {
34+
// A normal switch value.
35+
Normal(u128),
36+
// The final "otherwise" fallback value.
37+
Otherwise,
38+
}
2439

2540
#[derive(Clone, Default, Debug)]
2641
struct Cache {
@@ -70,8 +85,8 @@ impl<'tcx> BasicBlocks<'tcx> {
7085
})
7186
}
7287

73-
/// `switch_sources()[&(target, switch)]` returns a list of switch
74-
/// values that lead to a `target` block from a `switch` block.
88+
/// Returns info about switch values that lead from one block to another
89+
/// block. See `SwitchSources`.
7590
#[inline]
7691
pub fn switch_sources(&self) -> &SwitchSources {
7792
self.cache.switch_sources.get_or_init(|| {
@@ -82,9 +97,15 @@ impl<'tcx> BasicBlocks<'tcx> {
8297
}) = &data.terminator
8398
{
8499
for (value, target) in targets.iter() {
85-
switch_sources.entry((target, bb)).or_default().push(Some(value));
100+
switch_sources
101+
.entry((target, bb))
102+
.or_default()
103+
.push(SwitchTargetValue::Normal(value));
86104
}
87-
switch_sources.entry((targets.otherwise(), bb)).or_default().push(None);
105+
switch_sources
106+
.entry((targets.otherwise(), bb))
107+
.or_default()
108+
.push(SwitchTargetValue::Otherwise);
88109
}
89110
}
90111
switch_sources

‎compiler/rustc_middle/src/mir/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::fmt::{self, Debug, Formatter};
77
use std::ops::{Index, IndexMut};
88
use std::{iter, mem};
99

10-
pub use basic_blocks::BasicBlocks;
10+
pub use basic_blocks::{BasicBlocks, SwitchTargetValue};
1111
use either::Either;
1212
use polonius_engine::Atom;
1313
use rustc_abi::{FieldIdx, VariantIdx};

0 commit comments

Comments
 (0)