Skip to content

Commit 9e6ecb6

Browse files
Merge pull request #487 from egraphs-good/yihozhang-fix-subsume2
Subsume should succeed even when the tuple is not present
2 parents 71ecd99 + 3ad8d7d commit 9e6ecb6

File tree

4 files changed

+39
-17
lines changed

4 files changed

+39
-17
lines changed

src/actions.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,10 +392,20 @@ impl EGraph {
392392
function.remove(args, self.timestamp);
393393
}
394394
Change::Subsume => {
395-
if function.decl.merge.is_some() {
395+
if function.decl.subtype != FunctionSubtype::Constructor
396+
&& function.decl.subtype != FunctionSubtype::Relation
397+
{
396398
return Err(Error::SubsumeMergeError(*f));
397399
}
398-
function.subsume(args);
400+
function
401+
.nodes
402+
.insert_and_merge(args, self.timestamp, true, |old| {
403+
old.unwrap_or_else(|| Value {
404+
#[cfg(debug_assertions)]
405+
tag: function.schema.output.name(),
406+
bits: self.unionfind.make_set(),
407+
})
408+
});
399409
}
400410
}
401411
stack.truncate(new_len);

src/function/mod.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -212,11 +212,6 @@ impl Function {
212212
res
213213
}
214214

215-
/// Mark the given inputs as subsumed.
216-
pub fn subsume(&mut self, inputs: &[Value]) {
217-
self.nodes.get_mut(inputs).unwrap().subsumed = true;
218-
}
219-
220215
/// Return a column index that contains (a superset of) the offsets for the
221216
/// given column. This method can return nothing if the indexes available
222217
/// contain too many irrelevant offsets.

src/function/table.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,6 @@ impl Table {
108108
Some(&self.vals[off].1)
109109
}
110110

111-
pub(crate) fn get_mut(&mut self, inputs: &[Value]) -> Option<&mut TupleOutput> {
112-
let hash: u64 = hash_values(inputs);
113-
let &TableOffset { off, .. } = self.table.find(hash, self.search_for(hash, inputs))?;
114-
debug_assert!(self.vals[off].0.live());
115-
Some(&mut self.vals[off].1)
116-
}
117-
118111
/// Insert the given data into the table at the given timestamp. Return the
119112
/// previous value, if there was one.
120113
pub(crate) fn insert(&mut self, inputs: &[Value], out: Value, ts: u32) -> Option<Value> {

tests/integration_test.rs

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -350,8 +350,9 @@ fn test_subsume() {
350350
}
351351

352352
#[test]
353-
fn test_subsume_primitive() {
354-
// Test that we can subsume a primitive
353+
fn test_subsume_custom() {
354+
// Test that we can't subsume a custom function
355+
// Only relations and constructors are allowed to be subsumed
355356

356357
let mut egraph = EGraph::default();
357358
let res = egraph.parse_and_run_program(
@@ -362,6 +363,29 @@ fn test_subsume_primitive() {
362363
(subsume (one))
363364
"#,
364365
);
366+
assert!(res.is_err());
367+
}
368+
369+
#[test]
370+
fn test_subsume_ok() {
371+
let mut egraph = EGraph::default();
372+
let res = egraph.parse_and_run_program(
373+
None,
374+
r#"
375+
(sort E)
376+
(constructor one () E)
377+
(constructor two () E)
378+
(one)
379+
(subsume (one))
380+
;; subsuming a non-existent tuple
381+
(subsume (two))
382+
383+
(relation R (i64))
384+
(R 1)
385+
(subsume (R 1))
386+
(subsume (R 2))
387+
"#,
388+
);
365389
assert!(res.is_ok());
366390
}
367391

@@ -432,7 +456,7 @@ fn test_serialize_subsume_status() {
432456
None,
433457
egglog::SerializedNode::Function {
434458
name: ("a").into(),
435-
offset: 0,
459+
offset: 1,
436460
},
437461
);
438462
let b_id = egraph.to_node_id(

0 commit comments

Comments
 (0)