[Lang] Make qd.static not bypass the pure-kernel purity check#733
[Lang] Make qd.static not bypass the pure-kernel purity check#733hughperkins wants to merge 9 commits into
Conversation
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.
…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.
…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).
|
running Genesis benchmarks and unit tests |
|
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 |
|
running Genesis enhmarks without warnings becoming errors: |
|
@codex review |
|
Genesis benchmarks run, in conjunction with Genesis-Embodied-AI/genesis-world#3034 :
|
There was a problem hiding this comment.
💡 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)): |
There was a problem hiding this comment.
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 👍 / 👎.

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 onlycontrols 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