Skip to content

Commit

Permalink
save
Browse files Browse the repository at this point in the history
  • Loading branch information
clyben committed May 11, 2024
1 parent 5516f72 commit f47b1ee
Show file tree
Hide file tree
Showing 8 changed files with 579 additions and 347 deletions.
1 change: 1 addition & 0 deletions dag_in_context/src/add_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ impl Expr {
out_ty.clone(),
body.add_ctx_with_cache(current_ctx, cache),
)),
Expr::Symbolic(_) => panic!("found symbol"),
};
cache
.with_ctx
Expand Down
1 change: 1 addition & 0 deletions dag_in_context/src/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ impl<'a> VirtualMachine<'a> {
let e_val = self.interpret_expr(e, arg);
self.interpret_call(func_name, &e_val)
}
Expr::Symbolic(_) => panic!("found symbolic"),
};
self.eval_cache.insert(Rc::as_ptr(expr), res.clone());
res
Expand Down
1 change: 1 addition & 0 deletions dag_in_context/src/linearity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ impl<'a> Extractor<'a> {
self.find_effectful_nodes_in_region(body, linearity)
}
Expr::Const(_, _, _) => panic!("Const has no effect"),
Expr::Symbolic(_) => panic!("found symbolic"),
}
}

Expand Down
900 changes: 560 additions & 340 deletions dag_in_context/src/pretty_print.rs

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions dag_in_context/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pub enum Type {
/// `to_egglog` calls `with_arg_types`, so there are never any
/// unknown types in the egraph.
Unknown,
Symbolic(String),
}

#[derive(Debug, Clone, PartialEq, Eq, EnumIter, PartialOrd, Ord)]
Expand Down Expand Up @@ -103,6 +104,7 @@ pub enum Expr {
DoWhile(RcExpr, RcExpr),
Arg(Type, Assumption),
Function(String, Type, Type, RcExpr),
Symbolic(String), // now only used for pretty printer
}

#[derive(Debug, Clone, PartialEq, Eq)]
Expand Down
7 changes: 7 additions & 0 deletions dag_in_context/src/schema_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ impl Expr {
Expr::Empty(..) => Constructor::Empty,
Expr::Alloc(..) => Constructor::Alloc,
Expr::Top(..) => Constructor::Top,
Expr::Symbolic(_) => panic!("found symbolic"),
}
}
pub fn func_name(&self) -> Option<String> {
Expand Down Expand Up @@ -200,6 +201,7 @@ impl Expr {
Expr::Const(_, _, _) => vec![],
Expr::Empty(_, _) => vec![],
Expr::Arg(_, _) => vec![],
Expr::Symbolic(_) => panic!("found symbolic"),
}
}

Expand Down Expand Up @@ -228,6 +230,7 @@ impl Expr {
}
Expr::DoWhile(inputs, _body) => vec![inputs.clone()],
Expr::Arg(_, _) => vec![],
Expr::Symbolic(_) => panic!("found symbolic"),
}
}

Expand All @@ -248,6 +251,7 @@ impl Expr {
Expr::DoWhile(x, _) => x.get_arg_type(),
Expr::Arg(ty, _) => ty.clone(),
Expr::Function(_, ty, _, _) => ty.clone(),
Expr::Symbolic(_) => panic!("found symbolic"),
}
}

Expand All @@ -268,6 +272,7 @@ impl Expr {
Expr::DoWhile(x, _) => x.get_ctx(),
Expr::Arg(_, ctx) => ctx,
Expr::Function(_, _, _, x) => x.get_ctx(),
Expr::Symbolic(_) => panic!("found symbolic"),
}
}

Expand Down Expand Up @@ -383,6 +388,7 @@ impl Expr {
Rc::new(Expr::Const(c.clone(), arg_ty.clone(), arg_ctx.clone()))
}
Expr::Empty(_, _) => Rc::new(Expr::Empty(arg_ty.clone(), arg_ctx.clone())),
Expr::Symbolic(_) => panic!("found symbolic"),
};

// Add the substituted to cache
Expand Down Expand Up @@ -751,6 +757,7 @@ impl Type {
Type::Base(basety) => basety.contains_state(),
Type::TupleT(types) => types.iter().any(|ty| ty.contains_state()),
Type::Unknown => panic!("Unknown type"),
Type::Symbolic(_) => panic!("Symbolic type"),
}
}
}
4 changes: 3 additions & 1 deletion dag_in_context/src/to_egglog.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{collections::HashMap, rc::Rc};
use std::{collections::HashMap, rc::Rc, vec};

use egglog::{
ast::{Literal, Symbol},
Expand Down Expand Up @@ -99,6 +99,7 @@ impl Type {
// Unknown shouldn't show up in the egglog file, but is useful for printing
// before types are annotated.
Type::Unknown => term_dag.app("Unknown".into(), vec![]),
Type::Symbolic(str) => term_dag.var(str.into()),
}
}
}
Expand Down Expand Up @@ -257,6 +258,7 @@ impl Expr {
let name_lit = term_dag.lit(Literal::String(name.into()));
term_dag.app("Function".into(), vec![name_lit, ty_in, ty_out, body])
}
Expr::Symbolic(name) => term_dag.var(name.into()),
};

term_dag
Expand Down
10 changes: 4 additions & 6 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -634,11 +634,11 @@ impl Run {
RunType::PrettyPrint => {
let rvsdg = Optimizer::program_to_rvsdg(&self.prog_with_args.program)?;
let dag = rvsdg.to_dag_encoding(true);
let res = std::iter::once(PrettyPrinter { expr: dag.entry }.to_rust_default())
let res = std::iter::once(PrettyPrinter::from_expr(dag.entry).to_rust_default())
.chain(
dag.functions
.into_iter()
.map(|expr| PrettyPrinter { expr }.to_rust_default()),
.map(|expr| PrettyPrinter::from_expr(expr).to_rust_default()),
)
.collect::<Vec<_>>()
.join("\n\n");
Expand All @@ -656,16 +656,14 @@ impl Run {
let dag = rvsdg.to_dag_encoding(true);
let optimized = dag_in_context::optimize(&dag).map_err(EggCCError::EggLog)?;
let res = std::iter::once(
PrettyPrinter {
expr: optimized.entry,
}
PrettyPrinter::from_expr(optimized.entry)
.to_rust_default(),
)
.chain(
optimized
.functions
.into_iter()
.map(|expr| PrettyPrinter { expr }.to_rust_default()),
.map(|expr| PrettyPrinter::from_expr(expr).to_rust_default()),
)
.collect::<Vec<_>>()
.join("\n\n");
Expand Down

0 comments on commit f47b1ee

Please sign in to comment.