Skip to content

Commit

Permalink
Merge branch 'main' into yihozhang-recursive-datatype
Browse files Browse the repository at this point in the history
  • Loading branch information
yihozhang authored Oct 9, 2024
2 parents ebc31ec + b3a5416 commit 836a741
Show file tree
Hide file tree
Showing 16 changed files with 427 additions and 833 deletions.
20 changes: 9 additions & 11 deletions src/actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@ enum Instruction {
/// Pop function arguments off the stack, calls the function,
/// and push the result onto the stack. The bool indicates
/// whether to make defaults.
/// Currently, it is always set to true
///
/// This should be set to true after we disallow lookup in rule's actions and :default keyword
/// Currently, it's true when has_default() || is_datatype()
CallFunction(Symbol, bool),
/// Pop primitive arguments off the stack, calls the primitive,
/// and push the result onto the stack.
Expand Down Expand Up @@ -228,7 +230,7 @@ impl EGraph {
MergeFn::Expr(merge_prog) => {
let values = [old_value, new_value];
let mut stack = vec![];
self.run_actions(&mut stack, &values, &merge_prog, true)?;
self.run_actions(&mut stack, &values, &merge_prog)?;
stack.pop().unwrap()
}
};
Expand All @@ -243,7 +245,7 @@ impl EGraph {
let values = [old_value, new_value];
// We need to pass a new stack instead of reusing the old one
// because Load(Stack(idx)) use absolute index.
self.run_actions(&mut Vec::new(), &values, &prog, true)?;
self.run_actions(&mut Vec::new(), &values, &prog)?;
}
}
} else {
Expand All @@ -257,16 +259,14 @@ impl EGraph {
stack: &mut Vec<Value>,
subst: &[Value],
program: &Program,
make_defaults: bool,
) -> Result<(), Error> {
for instr in &program.0 {
match instr {
Instruction::Load(load) => match load {
Load::Stack(idx) => stack.push(stack[*idx]),
Load::Subst(idx) => stack.push(subst[*idx]),
},
Instruction::CallFunction(f, make_defaults_func) => {
let make_defaults = make_defaults && *make_defaults_func;
Instruction::CallFunction(f, make_defaults) => {
let function = self.functions.get_mut(f).unwrap();
let output_tag = function.schema.output.name();
let new_len = stack.len() - function.schema.input.len();
Expand All @@ -280,7 +280,7 @@ impl EGraph {

let value = if let Some(out) = function.nodes.get(values) {
out.value
} else if make_defaults {
} else if *make_defaults {
let ts = self.timestamp;
let out = &function.schema.output;
match function.decl.default.as_ref() {
Expand All @@ -296,7 +296,7 @@ impl EGraph {
}
Some(default) => {
let default = default.clone();
let value = self.eval_resolved_expr(&default, true)?;
let value = self.eval_resolved_expr(&default)?;
self.functions.get_mut(f).unwrap().insert(values, value, ts);
value
}
Expand Down Expand Up @@ -329,11 +329,9 @@ impl EGraph {
}
}
Instruction::Set(f) => {
assert!(make_defaults);
let function = self.functions.get_mut(f).unwrap();
// desugaring should have desugared
// set to union
// except for setting the parent relation
let new_value = stack.pop().unwrap();
let new_len = stack.len() - function.schema.input.len();

Expand Down Expand Up @@ -364,7 +362,7 @@ impl EGraph {
let (cost, term) = self.extract(
values[0],
&mut termdag,
self.type_info().sorts.get(&values[0].tag).unwrap(),
self.type_info.sorts.get(&values[0].tag).unwrap(),
);
let extracted = termdag.to_string(&term);
log::info!("extracted with cost {cost}: {extracted}");
Expand Down
Loading

0 comments on commit 836a741

Please sign in to comment.