Skip to content

Commit

Permalink
feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
yihozhang committed Jan 31, 2025
1 parent 971fb22 commit 3ad8d7d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,9 @@ impl EGraph {
function.remove(args, self.timestamp);
}
Change::Subsume => {
if function.decl.subtype != FunctionSubtype::Constructor {
if function.decl.subtype != FunctionSubtype::Constructor
&& function.decl.subtype != FunctionSubtype::Relation
{
return Err(Error::SubsumeMergeError(*f));
}
function
Expand Down
28 changes: 26 additions & 2 deletions tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,8 +350,9 @@ fn test_subsume() {
}

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

let mut egraph = EGraph::default();
let res = egraph.parse_and_run_program(
Expand All @@ -365,6 +366,29 @@ fn test_subsume_primitive() {
assert!(res.is_err());
}

#[test]
fn test_subsume_ok() {
let mut egraph = EGraph::default();
let res = egraph.parse_and_run_program(
None,
r#"
(sort E)
(constructor one () E)
(constructor two () E)
(one)
(subsume (one))
;; subsuming a non-existent tuple
(subsume (two))
(relation R (i64))
(R 1)
(subsume (R 1))
(subsume (R 2))
"#,
);
assert!(res.is_ok());
}

#[test]
fn test_cant_subsume_merge() {
// Test that we can't subsume something with a merge function
Expand Down

0 comments on commit 3ad8d7d

Please sign in to comment.