Skip to content

Commit a424c6b

Browse files
zhouwfangia0
andauthored
Simplify pop_cnt() (#770)
The previous implementation was unnecessarily complicated. I hope it is convincing now. #46 --------- Co-authored-by: Zhou Fang <[email protected]> Co-authored-by: Julien Cretin <[email protected]>
1 parent b7d8eb1 commit a424c6b

File tree

1 file changed

+4
-13
lines changed

1 file changed

+4
-13
lines changed

crates/interpreter/src/valid.rs

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1152,21 +1152,12 @@ fn delta(
11521152
}
11531153

11541154
fn pop_cnt(source: SideTableBranch, target: SideTableBranch) -> MResult<u32, Check> {
1155-
let source = source.stack;
11561155
// TODO(dev/fast-interp): Figure out why we can't simply source.stack - target.stack and
1157-
// document it.
1158-
let target_without_result = target.stack - target.result;
1159-
let Some(delta) = source.checked_sub(target_without_result) else {
1156+
// document it. We're losing information by saturating.
1157+
let res = source.stack.saturating_sub(target.stack);
1158+
u32::try_from(res).map_err(|_| {
11601159
#[cfg(feature = "debug")]
1161-
eprintln!("side-table negative stack delta {source} - {target_without_result}");
1162-
return Err(unsupported(if_debug!(Unsupported::SideTable)));
1163-
};
1164-
if delta < target.result {
1165-
return Ok(0);
1166-
}
1167-
u32::try_from(delta - target.result).map_err(|_| {
1168-
#[cfg(feature = "debug")]
1169-
eprintln!("side-table pop_cnt overflow {delta}");
1160+
eprintln!("side-table pop_cnt overflow {res}");
11701161
unsupported(if_debug!(Unsupported::SideTable))
11711162
})
11721163
}

0 commit comments

Comments
 (0)