Skip to content

Commit 9e905d8

Browse files
committed
Apply Alan's recommended rust-isms and re-add the test (but ignored)
1 parent 0193b23 commit 9e905d8

2 files changed

Lines changed: 29 additions & 2 deletions

File tree

zjit/src/hir.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6184,14 +6184,19 @@ impl Function {
61846184
let max_params = blocks.iter().copied().map(|id| self.blocks[id].params.len()).max().unwrap_or(0);
61856185
let mut trivial_indices: Vec<usize> = Vec::with_capacity(max_params);
61866186

6187+
// Prepare the initial param_values
6188+
for (row, block) in param_values.iter_mut().zip(&self.blocks) {
6189+
row.resize(block.params.len(), ParamValue::None);
6190+
}
6191+
61876192
let mut changed = true;
61886193

61896194
while changed {
61906195
changed = false;
61916196

61926197
for (row, block) in param_values.iter_mut().zip(&self.blocks) {
6193-
row.clear();
6194-
row.resize(block.params.len(), ParamValue::None);
6198+
row.truncate(block.params.len());
6199+
row.as_mut_slice().fill(ParamValue::None);
61956200
}
61966201

61976202
// Scan through each jump, collecting edges with params to analyze from CondBranch and Jump insns.

zjit/src/hir/opt_tests.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19235,6 +19235,28 @@ mod hir_opt_tests {
1923519235
");
1923619236
}
1923719237

19238+
#[ignore = "pass ordering issues cause this test to fail with an improvement to block param minimization."]
19239+
#[test]
19240+
fn test_dedup_guard_type_across_cfg_join() {
19241+
eval("
19242+
def test(n, cond)
19243+
if cond
19244+
a = n + 1
19245+
else
19246+
a = n + 2
19247+
end
19248+
n + a
19249+
end
19250+
test(1, true); test(1, false)
19251+
");
19252+
let hir = hir_string("test");
19253+
let guard_count = hir.matches("GuardType").count();
19254+
assert_eq!(
19255+
guard_count, 2,
19256+
"expected 2 GuardType instructions after cross-block dedup, found {guard_count}\n\nHIR:\n{hir}"
19257+
);
19258+
}
19259+
1923819260
#[test]
1923919261
fn test_forward_guard_through_conditional_branch() {
1924019262
eval("

0 commit comments

Comments
 (0)