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

Add multisets #446

Merged
merged 7 commits into from
Oct 25, 2024
Merged
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
15 changes: 15 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ ordered-float = { version = "3.7" }
getrandom = { version = "0.2.10", features = ["js"], optional = true }

im-rc = "15.1.0"
saulshanabrook marked this conversation as resolved.
Show resolved Hide resolved
im = "15.1.0"


[build-dependencies]
Expand Down
7 changes: 5 additions & 2 deletions src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,11 @@ impl ResolvedCall {
}
}
}

assert!(resolved_call.len() == 1);
assert!(
resolved_call.len() == 1,
"Ambiguous resolution for {:?}",
head,
);
resolved_call.pop().unwrap()
}
}
Expand Down
40 changes: 23 additions & 17 deletions src/sort/fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ impl Eq for ValueFunction {}
#[derive(Debug)]
pub struct FunctionSort {
name: Symbol,
inputs: Vec<ArcSort>,
output: ArcSort,
// Public so that other primitive sorts (external or internal) can find a function sort by the sorts of its inputs/output
pub inputs: Vec<ArcSort>,
pub output: ArcSort,
functions: Mutex<IndexSet<ValueFunction>>,
}

Expand All @@ -58,6 +59,25 @@ impl FunctionSort {
let functions = self.functions.lock().unwrap();
functions.get_index(value.bits as usize).unwrap().clone()
}

/// Apply the function to the values
///
/// Public so that other primitive sorts (external or internal) can use this to apply functions
pub fn apply(&self, fn_value: &Value, arg_values: &[Value], egraph: &mut EGraph) -> Value {
let ValueFunction(name, args) = self.get_value(fn_value);
let types: Vec<_> = args
.iter()
.map(|(sort, _)| sort.clone())
.chain(self.inputs.clone())
.chain(once(self.output.clone()))
.collect();
let values = args
.iter()
.map(|(_, v)| *v)
.chain(arg_values.iter().cloned())
.collect();
call_fn(egraph, &name, types, values)
}
}

impl Presort for FunctionSort {
Expand Down Expand Up @@ -368,21 +388,7 @@ impl PrimitiveLike for Apply {

fn apply(&self, values: &[Value], egraph: Option<&mut EGraph>) -> Option<Value> {
let egraph = egraph.expect("`unstable-app` is not supported yet in facts.");
let ValueFunction(name, args) = ValueFunction::load(&self.function, &values[0]);
let types: Vec<_> = args
.iter()
// get the sorts of partially applied args
.map(|(sort, _)| sort.clone())
// combine with the args for the function call and then the output
.chain(self.function.inputs.clone())
.chain(once(self.function.output.clone()))
.collect();
let values = args
.iter()
.map(|(_, v)| *v)
.chain(values[1..].iter().copied())
.collect();
Some(call_fn(egraph, &name, types, values))
Some(self.function.apply(&values[0], &values[1..], egraph))
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/sort/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ mod vec;
pub use vec::*;
mod r#fn;
pub use r#fn::*;
mod multiset;
pub use multiset::*;

use crate::constraint::AllEqualTypeConstraint;
use crate::extract::{Cost, Extractor};
Expand Down
Loading
Loading