| name | modify-shaped-array-dsl |
| description | Use when Pyrefly computes a wrong tensor shape (or is missing one that can't be expressed in a stub signature) and you need to add or fix a shape-DSL rule. Requires a Pyrefly checkout (fbsource or a clone); not usable from a pip/site-packages install. |
You are modifying Pyrefly's tensor-shape DSL — the logic that computes the
output shape of a torch op from its input shapes.
This skill points at code; it does not duplicate it. Read the files below to
learn the details. What follows is only the map and the invariant you must
uphold (add a unit test).
How the DSL works (the 30-second version)
A shape rule has two pieces. An IR function is a Python function in
tensor-shapes/pyrefly-torch-stubs/torch-stubs/_shapes.pyi, decorated @shape_dsl_function, that
computes shapes using a restricted Python subset (arithmetic + - * // %,
comprehensions, if, a few builtins, ShapedArray). It is traced, not
executed by CPython. A library stub attaches it to an op with
@uses_shape_dsl(ir_fn) (e.g. tensor-shapes/pyrefly-torch-stubs/torch-stubs/linalg.pyi); the
stub's declared return is a "fixture" (gives the base Tensor/tuple structure)
and the IR function fills in the actual dims.
There are two kinds of change. A stub-only change edits _shapes.pyi to add
or fix an IR function composing existing arithmetic — no rebuild needed, and it
covers the large majority of cases. A DSL-kernel change edits the Rust
evaluator to add a genuinely new primitive operation; reach for it only when the
arithmetic you need cannot be expressed by composing what _shapes.pyi already
has.
How the decorator is traced into the checker (follow this chain if you need to
touch the wiring): uses_shape_dsl/ are recognized in
; the binding step extracts the IR name in
; the solve step resolves it to a
in ; it's applied at call sites via
(). The Rust evaluator and all arithmetic primitives
live in , (the binop
arithmetic is ); the symbolic dim algebra it calls
() is in .