Beaver.Pattern.Native (beaver v0.4.8)

Copy Markdown

An explicitly callback-backed rewrite DSL.

defrewrite/3 binds selected pieces of an operation before running an Elixir callback through Beaver.MLIR.RewritePattern. It does not build PDL and never switches between the native and PDL execution engines.

A declaration generates a zero- and one-arity builder. For example, fold_add/0 returns a Beaver.Pattern.Native.Descriptor, while fold_add/1 can override lifecycle options such as :benefit and :init_state.

Summary

Functions

Defines a native rewrite and generates a descriptor builder.

Functions

defrewrite(call, opts_or_block, block \\ nil)

(macro)

Defines a native rewrite and generates a descriptor builder.

The declaration must name the callback's operation, borrowed pattern rewriter, and state arguments with three variables. Destructure state inside the body when needed. :root is required. Optional :operands, :results, and :attributes declarations are Elixir patterns; a mismatch returns no-match without evaluating the body.

The body may return :ok, :no_match, {:ok, new_state}, or {:error, new_state}.