Skip to content

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

Draft
hughperkins wants to merge 5 commits into
mainfrom
hp/pure-static-no-escape
Draft

[Lang] Make qd.static not bypass the pure-kernel purity check#733
hughperkins wants to merge 5 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

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant