Macro add_primitive
add_primitive!() { /* proc-macro */ }Expand description
This macro lets the user declare custom egglog primitives. It supports a few special features:
-
Failure: using
-?>instead of->before the return type will make the primitive fallible, requiring the body to return anOption<T>instead of justT. -
Varargs: using
[xs: T]as the argument list will cause the primitive to take a variable number of arguments, which will be passed to be body as anIterator<Item=T>. -
Polymorphism: using
#as a type will allow any type during typechecking. These will be given typeValuein the body. -
Containers: you must put an
@in front of container types. -
Specialized Constraints: using
T (E)as a type will use(E:expr).clone()in the type constraint butT:tyin the body. This is necessary because the relationship between Rust types and egglog sorts is not 1-to-1. -
Context: sometimes you want your primitive to reference information from the scope of the
add_primitive!call. Putting{x: T}between the=and the argument list will let you access the expressionxof typeTfrom inside the body asself.ctx.Tmust be the real Rust type ofx.Tmust beCloneand'static.