pub struct EGraph {
pub parser: Parser,
pub fact_directory: Option<PathBuf>,
pub seminaive: bool,
pub no_decomp: bool,
/* private fields */
}Fields§
§parser: Parser§fact_directory: Option<PathBuf>§seminaive: bool§no_decomp: boolImplementations§
Source§impl EGraph
impl EGraph
Source§impl EGraph
impl EGraph
Sourcepub fn extract_value(
&self,
sort: &ArcSort,
value: Value,
) -> Result<(TermDag, TermId, DefaultCost), Error>
pub fn extract_value( &self, sort: &ArcSort, value: Value, ) -> Result<(TermDag, TermId, DefaultCost), Error>
Extract a value to a TermDag and TermId in the TermDag using the default cost model.
See also EGraph::extract_value_with_cost_model for more control.
Sourcepub fn extract_value_with_cost_model<CM: CostModel<DefaultCost> + 'static>(
&self,
sort: &ArcSort,
value: Value,
cost_model: CM,
) -> Result<(TermDag, TermId, DefaultCost), Error>
pub fn extract_value_with_cost_model<CM: CostModel<DefaultCost> + 'static>( &self, sort: &ArcSort, value: Value, cost_model: CM, ) -> Result<(TermDag, TermId, DefaultCost), Error>
Extract a value to a TermDag and TermId in the TermDag.
Note that the TermDag may contain a superset of the nodes referenced by the returned TermId.
See also EGraph::extract_value_to_string for convenience.
Sourcepub fn extract_value_to_string(
&self,
sort: &ArcSort,
value: Value,
) -> Result<(String, DefaultCost), Error>
pub fn extract_value_to_string( &self, sort: &ArcSort, value: Value, ) -> Result<(String, DefaultCost), Error>
Extract a value to a string for printing.
See also EGraph::extract_value for more control.
Source§impl EGraph
impl EGraph
Sourcepub fn add_scheduler(&mut self, scheduler: Box<dyn Scheduler>) -> SchedulerId
pub fn add_scheduler(&mut self, scheduler: Box<dyn Scheduler>) -> SchedulerId
Register a new scheduler and return its id.
Sourcepub fn remove_scheduler(
&mut self,
scheduler_id: SchedulerId,
) -> Option<Box<dyn Scheduler>>
pub fn remove_scheduler( &mut self, scheduler_id: SchedulerId, ) -> Option<Box<dyn Scheduler>>
Removes a scheduler
Sourcepub fn step_rules_with_scheduler(
&mut self,
scheduler_id: SchedulerId,
ruleset: &str,
) -> Result<RunReport, Error>
pub fn step_rules_with_scheduler( &mut self, scheduler_id: SchedulerId, ruleset: &str, ) -> Result<RunReport, Error>
Runs a ruleset for one iteration using the given ruleset
Source§impl EGraph
impl EGraph
Sourcepub fn serialize(&self, config: SerializeConfig) -> SerializeOutput
pub fn serialize(&self, config: SerializeConfig) -> SerializeOutput
Serialize the egraph into a format that can be read by the egraph-serialize crate.
There are multiple different semantically valid ways to do this. This is how this implementation does it:
For node costs:
- Primitives: 1.0
- Function without costs: 1.0
- Function with costs: the cost
- Omitted nodes: infinite
For node IDs:
- Functions: Function name + hash of input values
- Args which are eq sorts: Choose one ID from the e-class, distribute roughly evenly.
- Args and outputs values which are primitives: Sort name + hash of value
For e-classes IDs:
- tag and value of canonicalized value
This is to achieve the following properties:
- Equivalent primitive values will show up once in the e-graph.
- Functions which return primitive values will be added to the e-class of that value.
- Nodes will have consistant IDs throughout execution of e-graph (used for animating changes in the visualization)
- Edges in the visualization will be well distributed (used for animating changes in the visualization)
(Note that this will be changed in
<https://github.com/egraphs-good/egglog/pull/158>so that edges point to exact nodes instead of looking up the e-class)
Sourcepub fn value_to_class_id(&self, sort: &ArcSort, value: Value) -> ClassId
pub fn value_to_class_id(&self, sort: &ArcSort, value: Value) -> ClassId
Gets the serialized class ID for a value.
Sourcepub fn class_id_to_value(&self, eclass_id: &ClassId) -> Value
pub fn class_id_to_value(&self, eclass_id: &ClassId) -> Value
Gets the value for a serialized class ID.
Sourcepub fn to_node_id(&self, sort: Option<&ArcSort>, node: SerializedNode) -> NodeId
pub fn to_node_id(&self, sort: Option<&ArcSort>, node: SerializedNode) -> NodeId
Gets the serialized node ID for the primitive, omitted, or function value.
Sourcepub fn from_node_id(&self, node_id: &NodeId) -> SerializedNode
pub fn from_node_id(&self, node_id: &NodeId) -> SerializedNode
Gets the serialized node for the node ID.
Source§impl EGraph
impl EGraph
Sourcepub fn add_sort<S: Sort + 'static>(
&mut self,
sort: S,
span: Span,
) -> Result<(), TypeError>
pub fn add_sort<S: Sort + 'static>( &mut self, sort: S, span: Span, ) -> Result<(), TypeError>
Add a user-defined sort to the e-graph.
Also look at prelude::add_base_sort for a convenience method for adding user-defined sorts
Sourcepub fn declare_sort(
&mut self,
name: impl Into<String>,
presort_and_args: &Option<(String, Vec<Expr>)>,
span: Span,
) -> Result<(), TypeError>
pub fn declare_sort( &mut self, name: impl Into<String>, presort_and_args: &Option<(String, Vec<Expr>)>, span: Span, ) -> Result<(), TypeError>
Declare a sort. This corresponds to the sort keyword in egglog.
It can either declares a new EqSort if presort_and_args is not provided,
or an instantiation of a presort (e.g., containers like Vec).
Sourcepub fn add_arcsort(
&mut self,
sort: ArcSort,
span: Span,
) -> Result<(), TypeError>
pub fn add_arcsort( &mut self, sort: ArcSort, span: Span, ) -> Result<(), TypeError>
Add a user-defined sort to the e-graph.
Sourcepub fn add_pure_primitive<T>(
&mut self,
x: T,
validator: Option<PrimitiveValidator>,
)
pub fn add_pure_primitive<T>( &mut self, x: T, validator: Option<PrimitiveValidator>, )
Register a PurePrim. Pass None for the validator if not
using the proof checker.
Pick the trait whose state wrapper matches the body’s needs:
PurePrim for pure ops, WritePrim for writes,
ReadPrim for table reads, FullPrim for both. The Rust
type checker enforces the body only uses methods the chosen
state allows.
Sourcepub fn add_write_primitive<T>(
&mut self,
x: T,
validator: Option<PrimitiveValidator>,
)
pub fn add_write_primitive<T>( &mut self, x: T, validator: Option<PrimitiveValidator>, )
Register a WritePrim. Pass None for the validator if not
using the proof checker.
Sourcepub fn add_read_primitive<T>(
&mut self,
x: T,
validator: Option<PrimitiveValidator>,
)
pub fn add_read_primitive<T>( &mut self, x: T, validator: Option<PrimitiveValidator>, )
Register a ReadPrim. Pass None for the validator if not
using the proof checker.
Sourcepub fn add_full_primitive<T>(
&mut self,
x: T,
validator: Option<PrimitiveValidator>,
)
pub fn add_full_primitive<T>( &mut self, x: T, validator: Option<PrimitiveValidator>, )
Register a FullPrim. Pass None for the validator if not
using the proof checker.
Source§impl EGraph
impl EGraph
Sourcepub fn new_with_term_encoding() -> Self
pub fn new_with_term_encoding() -> Self
Create a new e-graph with the term-encoding pipeline enabled.
In term-encoding mode the e-graph eagerly instruments every constructor and function with auxiliary term tables, view tables, and per-sort union-finds so that canonical representatives and their justifications are materialized explicitly. This makes it possible to record and emit equality proofs while preserving the observable behaviour of supported commands.
Sourcepub fn new_with_proofs() -> Self
pub fn new_with_proofs() -> Self
Create a new e-graph with proof generation enabled.
Sourcepub fn with_proof_testing(self) -> Self
pub fn with_proof_testing(self) -> Self
Enable testing of getting proofs for all check commands.
Sourcepub fn set_num_threads(num_threads: usize)
pub fn set_num_threads(num_threads: usize)
Set the number of threads used for parallel operations.
This is a helper that simply configures the global rayon thread pool. It can only be called once per process; subsequent calls will be ignored.
§Panics
Panics on wasm if num_threads > 1.
Sourcepub fn num_threads(&self) -> usize
pub fn num_threads(&self) -> usize
Return the number of threads in the rayon thread pool.
Sourcepub fn extension_state<T>(&self) -> Option<&T>
pub fn extension_state<T>(&self) -> Option<&T>
Return extension-owned state stored on this e-graph.
Extension state is keyed by Rust type and follows the same lifecycle as
the rest of the e-graph: cloning an EGraph clones the state, and
push/pop snapshots and restores it.
Sourcepub fn extension_state_or_default<T>(&mut self) -> &mut T
pub fn extension_state_or_default<T>(&mut self) -> &mut T
Return mutable extension-owned state, inserting T::default() when absent.
Sourcepub fn type_info(&mut self) -> &mut TypeInfo
pub fn type_info(&mut self) -> &mut TypeInfo
Add a user-defined command to the e-graph Get the type information for this e-graph
Sourcepub fn command_macros(&self) -> &CommandMacroRegistry
pub fn command_macros(&self) -> &CommandMacroRegistry
Get read-only access to the command macro registry
Sourcepub fn command_macros_mut(&mut self) -> &mut CommandMacroRegistry
pub fn command_macros_mut(&mut self) -> &mut CommandMacroRegistry
Get mutable access to the command macro registry
pub fn add_command( &mut self, name: String, command: Arc<dyn UserDefinedCommand>, ) -> Result<(), Error>
Sourcepub fn set_strict_mode(&mut self, strict_mode: bool)
pub fn set_strict_mode(&mut self, strict_mode: bool)
Configure whether globals missing the required $ prefix are treated as errors.
Sourcepub fn strict_mode(&self) -> bool
pub fn strict_mode(&self) -> bool
Returns true when missing $ prefixes on globals are treated as errors.
Sourcepub fn push(&mut self)
pub fn push(&mut self)
Push a snapshot of the e-graph into the stack.
See EGraph::pop.
Sourcepub fn pop(&mut self) -> Result<(), Error>
pub fn pop(&mut self) -> Result<(), Error>
Pop the current egraph off the stack, replacing it with the previously pushed egraph. It preserves the run report and messages from the popped egraph.
Sourcepub fn print_function(
&mut self,
sym: &str,
n: Option<usize>,
file: Option<File>,
mode: PrintFunctionMode,
) -> Result<Option<CommandOutput>, Error>
pub fn print_function( &mut self, sym: &str, n: Option<usize>, file: Option<File>, mode: PrintFunctionMode, ) -> Result<Option<CommandOutput>, Error>
Extract rows of a table using the default cost model with name sym
The include_output parameter controls whether the output column is always extracted
For functions, the output column is usually useful
Print up to n the tuples in a given function.
Print all tuples if n is not provided.
Sourcepub fn print_size(&self, sym: Option<&str>) -> Result<CommandOutput, Error>
pub fn print_size(&self, sym: Option<&str>) -> Result<CommandOutput, Error>
Print the size of a function. If no function name is provided,
print the size of all non-hidden functions as an s-expression list of
(name size) pairs, e.g. ((name size) ...).
Sourcepub fn step_rules(&mut self, ruleset: &str) -> Result<RunReport, Error>
pub fn step_rules(&mut self, ruleset: &str) -> Result<RunReport, Error>
Runs a ruleset for an iteration.
This applies every match it finds (under semi-naive).
See EGraph::step_rules_with_scheduler for more fine-grained control.
This will return an error if an egglog primitive returns None in an action.
Sourcepub fn get_function_names(&self) -> Vec<String>
pub fn get_function_names(&self) -> Vec<String>
Get the list of all functions in the e-graph.
Sourcepub fn functions_iter(&self) -> impl Iterator<Item = (&String, &Function)>
pub fn functions_iter(&self) -> impl Iterator<Item = (&String, &Function)>
Iterate over every (name, function) pair registered in the
e-graph, in registration order.
Sourcepub fn function_for_each(
&self,
func_name: &str,
f: impl FnMut(FunctionRow<'_>),
) -> Result<(), Error>
pub fn function_for_each( &self, func_name: &str, f: impl FnMut(FunctionRow<'_>), ) -> Result<(), Error>
Read the contents of the given function. The callback f is called with each row and its subsumption status.
Raises an error if the function does not exist.
Sourcepub fn clear_function(&mut self, func_name: &str) -> Result<(), Error>
pub fn clear_function(&mut self, func_name: &str) -> Result<(), Error>
Remove every row from the named function in bulk.
This is intended as a faster alternative to issuing a (delete …) for
every row of the function: it drops the backing row storage in
O(1)-in-row-count time, rather than O(n) per-row teardown. Any pending
staged inserts/removes for this function are dropped as part of the
clear, so callers that have staged updates they want to land first
should arrange for those to be flushed beforehand.
Cached indexes and subsets that reference this table are invalidated by a generation bump and are lazily rebuilt against the now-empty table on next access.
Raises an error if the function does not exist.
Sourcepub fn eval_expr(&mut self, expr: &Expr) -> Result<(ArcSort, Value), Error>
pub fn eval_expr(&mut self, expr: &Expr) -> Result<(ArcSort, Value), Error>
Evaluates an expression, returns the sort of the expression and the evaluation result.
Sourcepub fn are_proofs_enabled(&self) -> bool
pub fn are_proofs_enabled(&self) -> bool
Returns true if proofs are enabled.
Sourcepub fn run_program(
&mut self,
program: Vec<Command>,
) -> Result<Vec<CommandOutput>, Error>
pub fn run_program( &mut self, program: Vec<Command>, ) -> Result<Vec<CommandOutput>, Error>
Run a program, represented as an AST. Return a list of messages.
Sourcepub fn resolve_program(
&mut self,
filename: Option<String>,
input: &str,
) -> Result<Vec<ResolvedCommand>, Error>
pub fn resolve_program( &mut self, filename: Option<String>, input: &str, ) -> Result<Vec<ResolvedCommand>, Error>
Resolves an egglog program by parsing, typechecking, and desugaring each command.
Outputs a new egglog program without any syntactic sugar, either user provided (CommandMacro) or built-in (e.g., rewrite commands).
Also removes globals from the program by replacing with new constructors.
Sourcepub fn parse_program(
&mut self,
filename: Option<String>,
input: &str,
) -> Result<Vec<Command>, Error>
pub fn parse_program( &mut self, filename: Option<String>, input: &str, ) -> Result<Vec<Command>, Error>
Takes a source program input and parses it into a list of Commands.
Sourcepub fn parse_and_run_program(
&mut self,
filename: Option<String>,
input: &str,
) -> Result<Vec<CommandOutput>, Error>
pub fn parse_and_run_program( &mut self, filename: Option<String>, input: &str, ) -> Result<Vec<CommandOutput>, Error>
Takes a source program input, parses it, runs it, and returns a list of messages.
filename is an optional argument to indicate the source of
the program for error reporting. If filename is None,
a default name will be used.
Sourcepub fn num_tuples(&self) -> usize
pub fn num_tuples(&self) -> usize
Get the number of tuples in the database.
Sourcepub fn get_sort_by<S: Sort>(&self, f: impl Fn(&Arc<S>) -> bool) -> Arc<S>
pub fn get_sort_by<S: Sort>(&self, f: impl Fn(&Arc<S>) -> bool) -> Arc<S>
Returns a sort that satisfies the type and predicate.
Sourcepub fn get_sorts_by<S: Sort>(&self, f: impl Fn(&Arc<S>) -> bool) -> Vec<Arc<S>>
pub fn get_sorts_by<S: Sort>(&self, f: impl Fn(&Arc<S>) -> bool) -> Vec<Arc<S>>
Returns all sorts that satisfy the type and predicate.
Sourcepub fn get_arcsort_by(&self, f: impl Fn(&ArcSort) -> bool) -> ArcSort
pub fn get_arcsort_by(&self, f: impl Fn(&ArcSort) -> bool) -> ArcSort
Returns a sort based on the predicate.
Sourcepub fn get_arcsort_for_value_type<T: 'static>(&self) -> ArcSort
pub fn get_arcsort_for_value_type<T: 'static>(&self) -> ArcSort
Returns the unique sort whose runtime values have Rust type T.
Sourcepub fn get_arcsorts_by(&self, f: impl Fn(&ArcSort) -> bool) -> Vec<ArcSort> ⓘ
pub fn get_arcsorts_by(&self, f: impl Fn(&ArcSort) -> bool) -> Vec<ArcSort> ⓘ
Returns all sorts that satisfy the predicate.
Sourcepub fn get_sort_by_name(&self, sym: &str) -> Option<&ArcSort>
pub fn get_sort_by_name(&self, sym: &str) -> Option<&ArcSort>
Returns the sort with the given name if it exists.
Sourcepub fn get_overall_run_report(&self) -> &RunReport
pub fn get_overall_run_report(&self) -> &RunReport
Gets the overall run report and returns it.
Sourcepub fn value_to_base<T: BaseValue>(&self, x: Value) -> T
pub fn value_to_base<T: BaseValue>(&self, x: Value) -> T
Convert from an egglog value to a Rust type.
Sourcepub fn base_to_value<T: BaseValue>(&self, x: T) -> Value
pub fn base_to_value<T: BaseValue>(&self, x: T) -> Value
Convert from a Rust type to an egglog value.
Sourcepub fn value_to_container<T: ContainerValue>(
&self,
x: Value,
) -> Option<impl Deref<Target = T>>
pub fn value_to_container<T: ContainerValue>( &self, x: Value, ) -> Option<impl Deref<Target = T>>
Convert from an egglog value to a reference of a Rust container type.
Returns None if the value cannot be converted to the requested container type.
Warning: The return type of this function may contain lock guards. Attempts to modify the contents of the containers database may deadlock if the given guard has not been dropped.
Sourcepub fn container_to_value<T: ContainerValue>(&mut self, x: T) -> Value
pub fn container_to_value<T: ContainerValue>(&mut self, x: T) -> Value
Convert from a Rust container type to an egglog value.
Sourcepub fn get_size(&self, func: &str) -> usize
pub fn get_size(&self, func: &str) -> usize
Get the size of a function in the e-graph.
panics if the function does not exist.
Sourcepub fn lookup_function(&self, name: &str, key: &[Value]) -> Option<Value>
pub fn lookup_function(&self, name: &str, key: &[Value]) -> Option<Value>
Lookup a tuple in afunction in the e-graph.
Returns None if the tuple does not exist.
panics if the function does not exist.
Sourcepub fn get_function(&self, name: &str) -> Option<&Function>
pub fn get_function(&self, name: &str) -> Option<&Function>
Get a function by name.
Returns None if the function does not exist.
Sourcepub fn has_command(&self, name: &str) -> bool
pub fn has_command(&self, name: &str) -> bool
Returns true if a user-defined command with the given name is
registered in this e-graph.
Sourcepub fn run_user_defined_command(
&mut self,
name: &str,
args: &[Expr],
) -> Result<Vec<CommandOutput>, Error>
pub fn run_user_defined_command( &mut self, name: &str, args: &[Expr], ) -> Result<Vec<CommandOutput>, Error>
Invoke a registered user-defined command by name, passing the given unresolved expression arguments.
This is equivalent to writing (name args...) at the top level, but
callable directly from Rust. Returns an error if no command with the given
name is registered.
Sourcepub fn with_full_state<R>(
&mut self,
f: impl FnOnce(FullState<'_, '_>) -> R,
) -> R
pub fn with_full_state<R>( &mut self, f: impl FnOnce(FullState<'_, '_>) -> R, ) -> R
Run a closure with full read-write access to the database, then flush pending writes.
This is the top-level equivalent of FullPrim::apply, and the closure receives a
FullState.
Pending writes staged inside the closure are flushed (and the union-find rebuilt if necessary) before this method returns.
pub fn set_report_level(&mut self, level: ReportLevel)
Sourcepub fn dump_debug_info(&self)
pub fn dump_debug_info(&self)
A basic method for dumping the state of the database to log::info!.
For large tables, this is unlikely to give particularly useful output.
Sourcepub fn get_canonical_value(&self, val: Value, sort: &ArcSort) -> Value
pub fn get_canonical_value(&self, val: Value, sort: &ArcSort) -> Value
Get the canonical representation for val based on type.
Sourcepub fn new_union_action(&self) -> UnionAction
pub fn new_union_action(&self) -> UnionAction
Create a new union action that can be used to union two values.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for EGraph
impl !RefUnwindSafe for EGraph
impl Send for EGraph
impl Sync for EGraph
impl Unpin for EGraph
impl !UnwindSafe for EGraph
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more