Skip to content

Document declaration-scoped jaxtyping (#4985) - #4985

Open
stroxler wants to merge 7 commits into
mainfrom
export-D120593117
Open

stroxler wants to merge 7 commits into
mainfrom
export-D120593117

Conversation

@stroxler

@stroxler stroxler commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

Summary:

Document static_jaxtyping as the explicit opt-in for experimental jaxtyping shape checking, including function and class scope, composition, supported syntax, and gradual behavior outside a declaration.

The reference describes the generic IntTuple-bounded integration only; the removed legacy ShapedArray bridge is not presented as supported.

Differential Revision: D120593117

@meta-cla meta-cla Bot added the cla signed label Sep 18, 2026
@meta-codesync

meta-codesync Bot commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

@stroxler has exported this pull request. If you are a Meta employee, you can view the originating Diff in D120593117.

@github-actions

This comment has been minimized.

Summary:
Implicit jaxtyping dimensions were created from shape-string uses during solving, so identity depended on solve order and was not scoped to the function that introduced the name.

When `static_jaxtyping` is present, resolve shape names to the source-anchored variables recorded by the binder. Function finalization binds variables declared by that exact definition, in declaration order. Undeclared names and scalar/variadic mismatches are errors; without a declaration, jaxtyping retains its ordinary gradual `Annotated` meaning.

Validate the resulting function parameters in the same transition: declaration names may not collide with written parameters, and a declared parameter may not follow a defaulted one.

Differential Revision: D120593109
Summary:
Jaxtyping annotations now resolve the source-anchored variables recorded by their declarations, leaving the mutable solve-time quantified cache unused.

Remove the cache, its synthetic identity constructors, and the field threaded through `AnswersSolver`. This is a behavior-preserving cleanup after the resolution change.

Differential Revision: D120709371
Summary:
The flag existed because jaxtyping support had no other switch: the syntax was
interpreted wherever it appeared, so the only way to not have it was to turn it
off for a whole project or sub-config. `static_jaxtyping` is a finer switch in
the same place the annotations are, and it is now the only way shape checking is
reached, which leaves the flag with nothing to decide. A project with the flag
set and no declarations behaved exactly as one without it.

Removing it takes out the option, its accessor and default, the `bool` threaded
through the solver context and the state steps, the test-environment toggle, and
the schema entry. The documentation loses the option's section and the two pages
that told readers to set it.

Differential Revision: D120593110
Summary:
A nested `static_jaxtyping` declaration should add local dimensions without hiding dimensions declared by an enclosing function.

Expose enclosing declaration scopes as an innermost-first iterator and resolve each dimension through it. The implementation does not allocate or thread a scope vector through parsing helpers; lookup occurs only when a shape name needs resolution. Only dimensions declared directly on a function contribute new callable type parameters.

Differential Revision: D120593111
Summary:
Class attributes and methods need to share symbolic dimensions, which jaxtyping annotations cannot express on their own. Allow `static_jaxtyping` on classes and add every declared dimension to the class generic parameters.

Build each quantified variable once at binding time and resolve it through an owner-aware scope table. Full class-statement ranges make declarations visible in their own headers while preventing capture across nested-class boundaries.

At runtime, use the shared legacy `_F` TypeVar so the decorator parses on Python 3.10. Decorated classes erase trailing shape arguments while preserving ordinary generic subscriptions and the origin of inherited subscriptions.

Differential Revision: D120593112
Summary:
The jaxtyping corpus grew as individual syntax cases were added, leaving related behavior spread across several small files.

Group successful lowering cases in `test_desugaring.py` and declaration failures in `test_declaration_errors.py`. This is a test-only reorganization with fewer files and no change to expected checker behavior.

Differential Revision: D120593113
Summary:
Pull Request resolved: #4985

Document `static_jaxtyping` as the explicit opt-in for experimental jaxtyping shape checking, including function and class scope, composition, supported syntax, and gradual behavior outside a declaration.

The reference describes the generic `IntTuple`-bounded integration only; the removed legacy `ShapedArray` bridge is not presented as supported.

Differential Revision: D120593117
@meta-codesync meta-codesync Bot changed the title Document declaration-scoped jaxtyping Document declaration-scoped jaxtyping (#4985) Sep 19, 2026
@github-actions github-actions Bot added size/xl and removed size/xl labels Sep 19, 2026
@github-actions

Copy link
Copy Markdown

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant