pub trait Subject {
type Node: Copy;
// Required methods
fn head(&self, node: Self::Node) -> Option<(&str, usize)>;
fn arg(&self, node: Self::Node, index: usize) -> Self::Node;
fn int(&self, node: Self::Node) -> Option<i128>;
fn same(&self, a: Self::Node, b: Self::Node) -> bool;
}Expand description
The bits of a term the automaton asks about.
A node is whatever the thing doing the matching calls one of its terms: an IR value, an index into an arena, a pointer. It has to be cheap to copy because the walk keeps a stack of them.
Required Associated Types§
Required Methods§
Sourcefn head(&self, node: Self::Node) -> Option<(&str, usize)>
fn head(&self, node: Self::Node) -> Option<(&str, usize)>
The head of a term and how many arguments it has, or nothing if the term is not an application. An IR instruction answers with its opcode and its width, spelled the way the rule file spells it.
Sourcefn arg(&self, node: Self::Node, index: usize) -> Self::Node
fn arg(&self, node: Self::Node, index: usize) -> Self::Node
One argument of a term, counted from zero. Only ever asked for an argument the answer to
Subject::head said was there.
Sourcefn int(&self, node: Self::Node) -> Option<i128>
fn int(&self, node: Self::Node) -> Option<i128>
The value of a term that is a constant, or nothing if it is not one. This is what a pattern matching a literal is asking, and what a guard reads.
Sourcefn same(&self, a: Self::Node, b: Self::Node) -> bool
fn same(&self, a: Self::Node, b: Self::Node) -> bool
Whether two terms are the same thing, which is what a pattern that writes one name in two places is asking.
This is a question for the subject rather than something the walk can answer by comparing
nodes, because a node is a place and two places can hold one value. In
(and.i32 (value.i32 x) (value.i32 x)) the two operands are operand zero and operand
one, which are different places, and what the rule wants to know is whether the same
value is in both. A subject that cannot tell may answer false, which costs the rule a
match it could have had and never gives it one it should not.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".