Skip to content

[Lang] Make qd.static not bypass the pure-kernel purity check#733

Open
hughperkins wants to merge 9 commits into
mainfrom
hp/pure-static-no-escape
Open

[Lang] Make qd.static not bypass the pure-kernel purity check#733
hughperkins wants to merge 9 commits into
mainfrom
hp/pure-static-no-escape

Conversation

@hughperkins

Copy link
Copy Markdown
Collaborator

A captured module global wrapped in qd.static(...) previously skipped the
[PURE.VIOLATION] check because both purity gates were guarded by
not is_in_static_scope. That is unsound for fastcache: qd.static only
controls compile-time evaluation and never puts the value into the cache key,
so a static-wrapped global is still a purity violation (stale-cache hazard).

Remove the static-scope exemption from both gates (build_Name and
build_Attribute). Legitimate static metaprogramming over parameters/locals is
unaffected, since those never set violates_pure. Document in fastcache.md that
qd.static is not a purity escape hatch.Issue: #

Brief Summary

copilot:summary

Walkthrough

copilot:walkthrough

A captured module global wrapped in qd.static(...) previously skipped the
[PURE.VIOLATION] check because both purity gates were guarded by
`not is_in_static_scope`. That is unsound for fastcache: qd.static only
controls compile-time evaluation and never puts the value into the cache key,
so a static-wrapped global is still a purity violation (stale-cache hazard).

Remove the static-scope exemption from both gates (build_Name and
build_Attribute). Legitimate static metaprogramming over parameters/locals is
unaffected, since those never set violates_pure. Document in fastcache.md that
qd.static is not a purity escape hatch.
A captured string only affects a fastcache kernel through compile-time qd.static
branches, but its value never enters the cache key, so it is cache-unsafe in the
same way as a captured int/float. Add str to the flagged types in build_Name and
build_Attribute, and document it in fastcache.md.

Update the tile and src_ll_cache tests that captured globals (bools, strings)
inside qd.static in pure kernels to pass those values as template parameters so
the values enter the cache key.
@github-actions

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown

…ion)

During a transition period, a captured global accessed inside a qd.static
scope of a pure kernel now emits a warning rather than raising a
QuadrantsCompilationError, giving downstream code time to migrate such
constants to kernel parameters. Direct captured-global access (not wrapped
in qd.static) still raises. Adds a test covering both the captured-name and
captured-attribute paths, and updates the fastcache user guide.
@github-actions

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown

…erage, comment width

- test_pure_validation_static_scope_warns: restrict to a single (CPU) arch. The purity
  check is an arch-independent AST analysis; running it across multiple archs in one xdist
  worker let a fastcache hit from one arch suppress the warning on the next, making
  pytest.warns flaky on Mac (arm64 after vulkan).
- Add test_pure_validation_str covering the captured-str purity violation (str branch was
  previously untested).
- Wrap two transition-period comments to <=120 chars (drop the em-dash).
@github-actions

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown

@hughperkins

Copy link
Copy Markdown
Collaborator Author

running Genesis benchmarks and unit tests

@github-actions

Copy link
Copy Markdown

@hughperkins

Copy link
Copy Markdown
Collaborator Author

Note: next step for this is to run genesis benchmarks and unit tests with warnings tno converted to errors for static, and see how the output looks like

@github-actions

Copy link
Copy Markdown

@hughperkins

Copy link
Copy Markdown
Collaborator Author

running Genesis enhmarks without warnings becoming errors:

[branch]   /venv/lib/python3.10/site-packages/trimesh/triangles.py:325: RuntimeWarning: invalid value encountered in scalar multiply
[branch]     inertia[1, 2] = -(integrated[8] - (volume * np.prod(center_mass[[1, 2]])))
[branch]
[branch] git/genesis-hp-pure-violation-warn/tests/test_rigid_benchmarks.py: 11 warnings
[branch]   /venv/lib/python3.10/site-packages/quadrants/lang/ast/ast_transformer.py:112: UserWarning: [PURE.VIOLATION] WARNING: Accessing global variable _MASS_MAT_BLOCK <class 'int'> _MASS_MAT_BLOCK is in gl
obal vars, therefore violates pure
[branch]     warnings.warn(message)
[branch]
[branch] git/genesis-hp-pure-violation-warn/tests/test_rigid_benchmarks.py: 11 warnings
[branch]   /venv/lib/python3.10/site-packages/quadrants/lang/ast/ast_transformer.py:112: UserWarning: [PURE.VIOLATION] WARNING: Accessing global variable _P0_BLOCK <class 'int'> _P0_BLOCK is in global vars, t
herefore violates pure
[branch]     warnings.warn(message)
[branch]
[branch] git/genesis-hp-pure-violation-warn/tests/test_rigid_benchmarks.py: 11 warnings
[branch]   /venv/lib/python3.10/site-packages/quadrants/lang/ast/ast_transformer.py:112: UserWarning: [PURE.VIOLATION] WARNING: Accessing global variable LS_PARALLEL_K <class 'int'> LS_PARALLEL_K is in global
 vars, therefore violates pure
[branch]     warnings.warn(message)
[branch]
[branch] git/genesis-hp-pure-violation-warn/tests/test_rigid_benchmarks.py::test_speed[dex_hand-None-None-4096-gpu]
[branch] git/genesis-hp-pure-violation-warn/tests/test_rigid_benchmarks.py::test_speed[dex_hand-None-None-4096-gpu]
[branch]   /venv/lib/python3.10/site-packages/pygltflib/__init__.py:830: UserWarning: pygltflib currently does not remove image data from the buffer when converting to data uri.Please open an issue at https:/
/gitlab.com/dodgyville/pygltflib/issues
[branch]     warnings.warn("pygltflib currently does not remove image data "

@github-actions

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown

@hughperkins hughperkins marked this pull request as ready for review July 14, 2026 18:40
@hughperkins

Copy link
Copy Markdown
Collaborator Author

@codex review

@hughperkins

Copy link
Copy Markdown
Collaborator Author

Genesis benchmarks run, in conjunction with Genesis-Embodied-AI/genesis-world#3034 :

20260714_static_warn

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 84b9ce4aba

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

# ``str`` is included alongside the numeric/``Field`` types: a captured string only affects a kernel through
# compile-time ``qd.static`` branches, and its value never enters the fastcache key, so it is cache-unsafe
# in exactly the same way as a captured int/float.
if isinstance(node.ptr, (float, int, str, Field)):

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Treat static global containers as purity violations

When a fastcache kernel uses a captured container in qd.static, e.g. choices = [1, 2] followed by if qd.static(choices[idx]), the choices Name is marked violates_pure but its value is a list/dict/tuple, so this type guard skips the warning/error; the later Subscript only propagates the flag and does not enforce it. Because those container contents still are not included in the fastcache key, changing them can silently reuse stale compiled code even though the new docs say qd.static-wrapped captured globals are flagged.

Useful? React with 👍 / 👎.

@github-actions

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown

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