Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subsume should succeed even when the tuple is not present in the database #478

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ impl EGraph {
if function.decl.merge.is_some() {
return Err(Error::SubsumeMergeError(*f));
}
function.subsume(args);
function.subsume(args, self.timestamp);
}
}
stack.truncate(new_len);
Expand Down
9 changes: 7 additions & 2 deletions src/function/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,13 @@ impl Function {
}

/// Mark the given inputs as subsumed.
pub fn subsume(&mut self, inputs: &[Value]) {
self.nodes.get_mut(inputs).unwrap().subsumed = true;
/// This will succeed no matter the tuple is already present or not.
/// In case the tuple is absent, it will use a dummy value for the output instead.
pub fn subsume(&mut self, inputs: &[Value], timestamp: u32) {
self.nodes
.insert_and_merge(inputs, timestamp, true, |prev| {
prev.unwrap_or(Value::fake())
});
}

/// Return a column index that contains (a superset of) the offsets for the
Expand Down
7 changes: 0 additions & 7 deletions src/function/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,6 @@ impl Table {
Some(&self.vals[off].1)
}

pub(crate) fn get_mut(&mut self, inputs: &[Value]) -> Option<&mut TupleOutput> {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get_mut() is unsafe because it does not require the caller to update the timestamp. Use insert_and_merge instead.

let hash: u64 = hash_values(inputs);
let &TableOffset { off, .. } = self.table.find(hash, search_for!(self, hash, inputs))?;
debug_assert!(self.vals[off].0.live());
Some(&mut self.vals[off].1)
}

/// Insert the given data into the table at the given timestamp. Return the
/// previous value, if there was one.
pub(crate) fn insert(&mut self, inputs: &[Value], out: Value, ts: u32) -> Option<Value> {
Expand Down
Loading