-
Notifications
You must be signed in to change notification settings - Fork 46
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
Move splitting primitives to serialize library #407
Changes from 2 commits
dc00449
a555b2f
405395d
bcff2a5
20a84f4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,3 +19,4 @@ _scratch.egg | |
|
||
# racket | ||
scripts/compiled | ||
tests/*.json |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,6 +43,9 @@ struct Args { | |
/// Maximum number of calls per function to render in dot/svg output | ||
#[clap(long, default_value = "40")] | ||
max_calls_per_function: usize, | ||
/// Number of times to inline leaves | ||
#[clap(long, default_value = "0")] | ||
serialize_n_inline_leaves: usize, | ||
Comment on lines
+46
to
+48
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added the ability to inline leaves via the egglog CLI when making visualizations/json |
||
} | ||
|
||
// test if the current command should be evaluated | ||
|
@@ -209,31 +212,25 @@ fn main() { | |
std::process::exit(1) | ||
} | ||
} | ||
// if we are splitting primitive outputs, add `-split` to the end of the file name | ||
let serialize_filename = if args.serialize_split_primitive_outputs { | ||
input.with_file_name(format!( | ||
"{}-split", | ||
input.file_stem().unwrap().to_str().unwrap() | ||
)) | ||
} else { | ||
input.clone() | ||
}; | ||
if args.to_json { | ||
let json_path = serialize_filename.with_extension("json"); | ||
let config = SerializeConfig { | ||
split_primitive_outputs: args.serialize_split_primitive_outputs, | ||
..SerializeConfig::default() | ||
}; | ||
let serialized = egraph.serialize(config); | ||
serialized.to_json_file(json_path).unwrap(); | ||
} | ||
|
||
if args.to_dot || args.to_svg { | ||
let serialized = egraph.serialize_for_graphviz( | ||
args.serialize_split_primitive_outputs, | ||
args.max_functions, | ||
args.max_calls_per_function, | ||
); | ||
if args.to_json || args.to_dot || args.to_svg { | ||
let mut serialized = egraph.serialize(SerializeConfig::default()); | ||
if args.serialize_split_primitive_outputs { | ||
serialized.split_e_classes(|id, _| egraph.from_node_id(id).is_primitive()) | ||
} | ||
for _ in 0..args.serialize_n_inline_leaves { | ||
serialized.inline_leaves(); | ||
} | ||
|
||
// if we are splitting primitive outputs, add `-split` to the end of the file name | ||
let serialize_filename = if args.serialize_split_primitive_outputs { | ||
input.with_file_name(format!( | ||
"{}-split", | ||
input.file_stem().unwrap().to_str().unwrap() | ||
)) | ||
} else { | ||
input.clone() | ||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I moved all this processing into one branch, so it would only be serialized once for JSON or for visualization. |
||
if args.to_dot { | ||
let dot_path = serialize_filename.with_extension("dot"); | ||
serialized.to_dot_file(dot_path).unwrap() | ||
|
@@ -242,6 +239,10 @@ fn main() { | |
let svg_path = serialize_filename.with_extension("svg"); | ||
serialized.to_svg_file(svg_path).unwrap() | ||
} | ||
if args.to_json { | ||
let json_path = serialize_filename.with_extension("json"); | ||
serialized.to_json_file(json_path).unwrap(); | ||
} | ||
} | ||
// no need to drop the egraph if we are going to exit | ||
if idx == args.inputs.len() - 1 { | ||
|
@@ -259,12 +260,12 @@ mod tests { | |
#[rustfmt::skip] | ||
let test_cases = vec![ | ||
vec![ | ||
"(extract", | ||
"\"1", | ||
")", | ||
"(", | ||
")))", | ||
"\"", | ||
"(extract", | ||
"\"1", | ||
")", | ||
"(", | ||
")))", | ||
"\"", | ||
";; )", | ||
")" | ||
], | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed this helper function since it wasn't really doing much