Skip to content

Commit

Permalink
fix bad build
Browse files Browse the repository at this point in the history
  • Loading branch information
yihozhang committed Oct 9, 2024
1 parent d4fdef4 commit dd8bc67
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 31 deletions.
38 changes: 19 additions & 19 deletions src/ast/desugar.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use hashbrown::HashMap;

use super::{Rewrite, Rule};
use crate::*;

Expand Down Expand Up @@ -46,17 +44,12 @@ pub(crate) fn desugar_command(
name,
variants,
} => desugar_datatype(span, name, variants),
Command::Rewrite(ruleset, rewrite, subsume) => desugar_rewrite(
ruleset,
rewrite_name(&rewrite).into(),
&rewrite,
subsume,
),
Command::BiRewrite(ruleset, rewrite) => desugar_birewrite(
ruleset,
rewrite_name(&rewrite).into(),
&rewrite,
),
Command::Rewrite(ruleset, rewrite, subsume) => {
desugar_rewrite(ruleset, rewrite_name(&rewrite).into(), &rewrite, subsume)
}
Command::BiRewrite(ruleset, rewrite) => {
desugar_birewrite(ruleset, rewrite_name(&rewrite).into(), &rewrite)
}
Command::Include(span, file) => {
let s = std::fs::read_to_string(&file)
.unwrap_or_else(|_| panic!("{} Failed to read file {file}", span.get_quote()));
Expand All @@ -68,24 +61,30 @@ pub(crate) fn desugar_command(
}
Command::Rule {
ruleset,
mut name,
name,
rule,
} => {
if name == "".into() {
name = rule.to_string().replace('\"', "'").into();
}
let name = if name.as_str() == "" {
// Adding a unique prefix because there may be duplicate rules (e.g., when
// processing a resugared egglog program).
let prefix: Symbol = symbol_gen.fresh(&"rule".into());
prefix.to_string() + &rule.to_string().replace('\"', "'")
} else {
name.to_string()
};

let mut result = vec![NCommand::NormRule {
ruleset,
name,
name: name.clone().into(),
rule: rule.clone(),
}];

if seminaive_transform {
if let Some(new_rule) = add_semi_naive_rule(symbol_gen, rule) {
let prefix: Symbol = symbol_gen.fresh(&"seminaive".into());
result.push(NCommand::NormRule {
ruleset,
name,
name: (prefix.to_string() + "-" + &name).into(),
rule: new_rule,
});
}
Expand Down Expand Up @@ -144,6 +143,7 @@ pub(crate) fn desugar_command(
Expr::Var(span.clone(), fresh),
variants,
)),
props: Default::default(),
};
vec![
NCommand::Check(span.clone(), vec![Fact::Fact(expr.clone())]),
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ mod value;
use ast::remove_globals::remove_globals;
use extract::Extractor;
use index::ColumnIndex;
use indexmap::map::Entry;
use instant::Instant;
use scheduler::RunReport;
use indexmap::map::Entry;
pub use serialize::SerializeConfig;
pub use serialize::SerializedNode;
use sort::*;
Expand Down
17 changes: 9 additions & 8 deletions src/scheduler.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::IndexMap;
use instant::{Duration, Instant};
use std::fmt::{Display, Formatter};
use std::mem;
Expand Down Expand Up @@ -260,7 +261,7 @@ pub trait Scheduler {
ResolvedSchedule::WithScheduler(span, scheduler, args, sched) => {
let args = args
.iter()
.map(|arg| egraph.eval_resolved_expr(arg, true))
.map(|arg| egraph.eval_resolved_expr(arg))
.collect::<Result<Vec<_>, _>>()?;
let f = egraph
.scheduler_constructors
Expand Down Expand Up @@ -342,7 +343,7 @@ pub trait Scheduler {
&mut self,
egraph: &EGraph,
span: &Span,
rulesets: &HashMap<Symbol, Ruleset>,
rulesets: &IndexMap<Symbol, Ruleset>,
ruleset: Symbol,
report: &mut RunReport,
search_results: &mut HashMap<Symbol, SearchResult>,
Expand Down Expand Up @@ -428,7 +429,7 @@ pub trait Scheduler {
&mut self,
egraph: &mut EGraph,
span: &Span,
rulesets: &HashMap<Symbol, Ruleset>,
rulesets: &IndexMap<Symbol, Ruleset>,
ruleset: Symbol,
report: &mut RunReport,
search_results: &HashMap<Symbol, SearchResult>,
Expand Down Expand Up @@ -494,11 +495,11 @@ pub trait Scheduler {
// here we handle that case
if num_vars == 0 {
if *did_match {
egraph.run_actions(&[], &rule.program, true)?;
egraph.run_actions(&[], &rule.program)?;
}
} else {
for values in all_matches.chunks(num_vars) {
egraph.run_actions(values, &rule.program, true)?;
egraph.run_actions(values, &rule.program)?;
}
}

Expand All @@ -512,7 +513,7 @@ pub trait Scheduler {
/// used to detect if the scheduler is still active.
///
/// Similar to `RewriteScheduler::can_stop` in the egg library.
fn is_active(&mut self, _rulesets: &HashMap<Symbol, Ruleset>, _ruleset: Symbol) -> bool {
fn is_active(&mut self, _rulesets: &IndexMap<Symbol, Ruleset>, _ruleset: Symbol) -> bool {
false
}
}
Expand Down Expand Up @@ -664,8 +665,8 @@ impl Scheduler for BackoffScheduler {
search_results.insert(rule_name, search_result);
}

fn is_active(&mut self, rulesets: &HashMap<Symbol, Ruleset>, ruleset: Symbol) -> bool {
fn collect_rules(rulesets: &HashMap<Symbol, Ruleset>, ruleset: Symbol) -> Vec<Symbol> {
fn is_active(&mut self, rulesets: &IndexMap<Symbol, Ruleset>, ruleset: Symbol) -> bool {
fn collect_rules(rulesets: &IndexMap<Symbol, Ruleset>, ruleset: Symbol) -> Vec<Symbol> {
let rules = rulesets.get(&ruleset).unwrap();
match rules {
Ruleset::Rules(_name, rule_names) => rule_names.iter().map(|(k, _)| *k).collect(),
Expand Down
11 changes: 8 additions & 3 deletions src/typechecking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,9 +339,9 @@ impl TypeInfo {
span.clone(),
*scheduler,
args.iter()
.map(|arg| self.typecheck_expr(arg, &Default::default()))
.map(|arg| self.typecheck_expr(symbol_gen, arg, &Default::default()))
.collect::<Result<Vec<_>, _>>()?,
Box::new(self.typecheck_schedule(schedule)?),
Box::new(self.typecheck_schedule(symbol_gen, schedule)?),
)
}
};
Expand Down Expand Up @@ -378,7 +378,12 @@ impl TypeInfo {
symbol_gen: &mut SymbolGen,
rule: &Rule,
) -> Result<ResolvedRule, TypeError> {
let Rule { span, head, body, props } = rule;
let Rule {
span,
head,
body,
props,
} = rule;
let mut constraints = vec![];

let (query, mapped_query) = Facts(body.clone()).to_query(self, symbol_gen);
Expand Down

0 comments on commit dd8bc67

Please sign in to comment.