Skip to content

Commit

Permalink
Remove Option in side table creation (#718)
Browse files Browse the repository at this point in the history
#46

---------

Co-authored-by: Zhou Fang <33002388+zhou-w-fang@users.noreply.github.com>
  • Loading branch information
zhouwfang and zhouwfang authored Jan 8, 2025
1 parent b9de9e9 commit 009a15d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
10 changes: 9 additions & 1 deletion crates/interpreter/src/side_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use crate::bit_field::*;
use crate::error::*;

#[derive(Default, Copy, Clone, Debug)]
#[derive(Copy, Clone, Debug)]
#[repr(transparent)]
pub struct SideTableEntry(u64);

Expand Down Expand Up @@ -52,4 +52,12 @@ impl SideTableEntry {
let pop_cnt = from_field(Self::POP_CNT_MASK, self.0);
SideTableEntryView { delta_ip, delta_stp, val_cnt, pop_cnt }
}

pub fn is_invalid(self) -> bool {
self.0 == 0
}

pub fn invalid() -> Self {
SideTableEntry(0)
}
}
14 changes: 7 additions & 7 deletions crates/interpreter/src/valid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -414,8 +414,7 @@ struct Expr<'a, 'm> {

#[derive(Default)]
struct SideTable {
// TODO(dev/fast-interp): Consider removing `Option` if confident.
entries: Vec<Option<SideTableEntryView>>,
entries: Vec<SideTableEntry>,
}

impl SideTable {
Expand All @@ -424,7 +423,7 @@ impl SideTable {
}

fn branch(&mut self) {
self.entries.push(None);
self.entries.push(SideTableEntry::invalid());
}

fn stitch(&mut self, source: SideTableBranch, target: SideTableBranch) -> CheckResult {
Expand All @@ -436,9 +435,9 @@ impl SideTable {
unsupported(if_debug!(Unsupported::SideTable))
})?;
let pop_cnt = Self::pop_cnt(source, target)?;
let entry = &mut self.entries[source.side_table];
assert!(entry.is_none());
*entry = Some(SideTableEntryView { delta_ip, delta_stp, val_cnt, pop_cnt });
debug_assert!(self.entries[source.side_table].is_invalid());
self.entries[source.side_table] =
SideTableEntry::new(SideTableEntryView { delta_ip, delta_stp, val_cnt, pop_cnt })?;
Ok(())
}

Expand Down Expand Up @@ -478,7 +477,8 @@ impl SideTable {
}

fn persist(self) -> MResult<Vec<SideTableEntry>, Check> {
self.entries.into_iter().map(|entry| SideTableEntry::new(entry.unwrap())).collect()
debug_assert!(self.entries.iter().all(|x| !x.is_invalid()));
Ok(self.entries)
}
}

Expand Down

0 comments on commit 009a15d

Please sign in to comment.