Skip to content

PR-1d: extract CudaRenderCtx from LoweringCtx (Phase T-1)#81

Merged
StarGazerM merged 1 commit into
design/redesign-packagefrom
feat/pr-1d-cuda-render-ctx-extraction
May 20, 2026
Merged

PR-1d: extract CudaRenderCtx from LoweringCtx (Phase T-1)#81
StarGazerM merged 1 commit into
design/redesign-packagefrom
feat/pr-1d-cuda-render-ctx-extraction

Conversation

@StarGazerM

Copy link
Copy Markdown
Collaborator

Summary

Fourth of 5 splits of the original PR-1. Phase T-1 per spec § 3.2.1 — extracts CUDA-render-private fields out of the dialect-level LoweringCtx into a new CudaRenderCtx under src/srdatalog/ir/codegen/cuda/lower_ctx.py.

Extracted (10 fields)

view_var_names, output_var, output_var_overrides, view_slot_bases, rel_index_types, tiled_cartesian_valid_var, ws_cartesian_valid_var, neg_pre_narrow, debug, tile_var

Spec § 3.2.1 listed 9; agent verified against the actual monolith. dedup_hash_vars / ws_cartesian_bound_vars live on the legacy CodeGenContext, not LoweringCtx — documented + deferred to a later PR.

Back-compat shape

  • New: CudaRenderCtx plain @dataclass (no __slots__, not frozen — BG test path uses dynamic setattr)
  • LoweringCtx.render_ctx: CudaRenderCtx field added
  • 100+ existing call sites that read/write ctx.<extracted_field> keep working unchanged via forwarding properties
  • LoweringCtx is no longer @dataclass (it needed a custom __init__ accepting both flat legacy kwargs and render_ctx=; a dataclass field + property of the same name would collide). Behaves identically for external callers.
  • NegPreNarrowInfo moved to codegen/cuda/lower_ctx.py (its fields are pure CUDA C++ identifier scratch); re-exported from lowerings/__init__.py for back-compat to avoid a circular-import dance.

Test plan

  • Full suite: 1689 passed, 7 skipped (+26 new tests, no regressions)
  • Byte-equivalence (3 suites): 532 passed, 2 skipped
  • ruff check + format (CI v0.9.10): clean
  • mypy: 147 errors in 39 files — unchanged from baseline

Out of scope (later splits)

  • PR-1e (pragma scratch flags → kwargs — removes is_counting/dedup_hash/tiled_cartesian/ws_enabled/bg_enabled from both contexts)
  • Renaming CUDA-shaped IIR ops to semantic names (Phase T-2)

Zero conflict with PR-1c (#80)

PR-1c touches Compiler.run, InitialProg.target, KernelCtx.target (none in this PR's diff). PR-1d touches lower_ctx.py (NEW) + sorted_array/lowerings/__init__.py (file-disjoint). default_pipelines.py left untouched.

🤖 Generated with Claude Code

Per docs/phase_decomposition_redesign.md section 3.2.1. The dialect-
level LoweringCtx historically carried both structural lowering
state (counters, lexical-scope flags, handle aliasing) and CUDA C++
identifier scratch (view var names, OutputContext vars, ballot
validity vars, etc.). This PR splits the second bucket into a
target-private CudaRenderCtx (src/srdatalog/ir/codegen/cuda/lower_ctx.py).

Extracted fields (10 total):
  - view_var_names, output_var, output_var_overrides
  - view_slot_bases, rel_index_types
  - tiled_cartesian_valid_var, ws_cartesian_valid_var
  - neg_pre_narrow, debug, tile_var

LoweringCtx exposes the render-private fields as forwarding
properties (back-compat seam per D20) so 100+ existing call sites
that say ctx.view_var_names keep working without an edit. The
constructor still accepts the legacy flat kwargs; a new
render_ctx= kwarg routes a pre-built CudaRenderCtx straight in.

NegPreNarrowInfo moves to the new module (its fields are all CUDA
identifier scratch) and is re-exported from lowerings/__init__.py
for back-compat.

Pragma-scratch booleans (is_counting, dedup_hash, tiled_cartesian,
ws_enabled, bg_enabled) stay on LoweringCtx — their removal is
scheduled for PR-1e. The framework-level LowerCtx (5 fields) at
src/srdatalog/ir/core/lower_ctx.py is untouched per D10.

Quality gates:
  - pytest tests/ -x          : 1689 passed, 7 skipped (was 1663+7;
                                26 new tests in test_cuda_render_ctx_extraction.py)
  - byte-equivalence subset   : 532 passed, 2 skipped
  - mypy src/srdatalog/       : 147 errors (matches baseline; no regression)
  - ruff check + format       : clean

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@StarGazerM
StarGazerM merged commit 904f89f into design/redesign-package May 20, 2026
3 checks passed
StarGazerM added a commit that referenced this pull request May 20, 2026
StarGazerM added a commit that referenced this pull request May 20, 2026
Replaces § 3.2.1 ("Split LoweringCtx from CudaRenderCtx") with
"Dissolve LoweringCtx (no-context principle)". Adds a sub-clause
to § 1 (ACID test) codifying the three-bucket discipline:

1. Cross-pass data → typed IR op
2. Intra-pass scratch → function-local / explicit kwarg
3. Services → immutable Services handle

Adds amendment-log entry § 10.2. Refers forward to discipline rule
D22 (strict monotonic decrease of ctx-field count; to be codified
in code_discipline.md per the standard cadence).

Triggered by user review of merged PR-1d (#81) which introduced
CudaRenderCtx with 10 fixed-schema fields — the same anti-pattern
the redesign is supposed to eliminate. PR-1d reverted in #82.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
StarGazerM added a commit that referenced this pull request May 20, 2026
Replaces § 3.2.1 ("Split LoweringCtx from CudaRenderCtx") with
"Dissolve LoweringCtx (no-context principle)". Adds a sub-clause
to § 1 (ACID test) codifying the three-bucket discipline:

1. Cross-pass data → typed IR op
2. Intra-pass scratch → function-local / explicit kwarg
3. Services → immutable Services handle

Adds amendment-log entry § 10.2. Refers forward to discipline rule
D22 (strict monotonic decrease of ctx-field count; to be codified
in code_discipline.md per the standard cadence).

Triggered by user review of merged PR-1d (#81) which introduced
CudaRenderCtx with 10 fixed-schema fields — the same anti-pattern
the redesign is supposed to eliminate. PR-1d reverted in #82.

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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