Conversation
…line
Finalized the architectural overhaul of the JIT codegen module by extracting
monolithic logic into specialized submodules and decomposing massive
functions into maintainable handlers.
- Modularization:
- Extracted zero-copy buffer management to `buffer.rs`.
- Moved recursive AST evaluation and SIMD math logic to `eval.rs` and `math.rs`.
- Relocated execution orchestration and PyO3 bridging to `exec.rs`.
- Reduced `mod.rs` to a high-level router and glue file.
- Function Decomposition (De-godding):
- Refactored `gen_expr.rs`: Split the 800+ line `gen_expr` function into
specific handlers for variables, binary ops, calls, and various loop types
(AnyFor, AllFor, SumFor).
- Refactored `exec.rs`: Replaced the monolithic `execute_jit_func` with a
clean strategy-based router. Extracted logic into `try_exec_*` helpers and
centralized vectorized unrolling in `execute_views`.
- Performance & Safety Refinements:
- Centralized shared unrolling logic to eliminate code duplication between
profiled and generic vector paths.
- Moved core `JitEntry` methods to `jit_types.rs` for better visibility and
dependency flow.
- Fixed various compilation issues including missing trait imports (`Module`,
`AsPyPointer`) and silenced unused warnings in the quantum registry.
Co-authored-by: Iris Seravelle <iris.seravelle@gmail.com>
There was a problem hiding this comment.
Pull request overview
This PR completes a major refactor of the Python JIT codegen subsystem by splitting previously monolithic logic into focused submodules (buffer handling, math approximations, lowered-eval, and execution) and simplifying codegen/mod.rs into a routing/re-export layer. This aligns the JIT pipeline with a more maintainable architecture while preserving the existing public entry points used by the py::jit layer.
Changes:
- Introduced new internal codegen submodules (
buffer,math,eval,exec) and updatedcodegen/mod.rsto act as a high-level router and re-export hub. - Moved
JitEntrymethods intojit_types.rsand relocated SIMD/unrolling + execution logic intoexec.rs. - Refactored expression lowering (
gen_expr.rs) into smaller handlers, including dedicated implementations for loop constructs and call handling.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
src/py/jit/codegen/quantum.rs |
Formatting and visibility tweaks; adds dead_code allowances around lifecycle/query helpers. |
src/py/jit/codegen/mod.rs |
Converts module into a thin router with submodule declarations and re-exports; retains execute_registered_jit and adds codegen-focused tests. |
src/py/jit/codegen/math.rs |
New module encapsulating SIMD math mode selection and fast trig approximations (scalar + aarch64 pair NEON). |
src/py/jit/codegen/jit_types.rs |
Moves core JitEntry methods here and exposes strategy/unroll/math-mode helpers for execution. |
src/py/jit/codegen/jit_module.rs |
Thread-local JIT module setup and type-profile storage; minor import/formatting adjustments. |
src/py/jit/codegen/gen_expr.rs |
Decomposes the expression lowering pipeline into handlers (var/binop/unary/call/ternary/loops). |
src/py/jit/codegen/exec.rs |
New execution engine for JIT entries (profiles, buffer vectorization, reductions, and shared unrolling logic). |
src/py/jit/codegen/eval.rs |
New lowered-expression evaluator module (scalar + pair-eval helpers) used by vectorized lowered-kernel execution. |
src/py/jit/codegen/compiler.rs |
Pulls cranelift imports into this module and aligns code with the modularized codegen layout. |
src/py/jit/codegen/buffer.rs |
New module extracting zero-copy Python buffer acquisition and typed reads (BufferView, open_typed_buffer, read_buffer_f64). |
You can also share your feedback on Copilot code review. Take the survey.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Finalized the architectural overhaul of the JIT codegen module by extracting monolithic logic into specialized submodules and decomposing massive functions into maintainable handlers.
Modularization:
buffer.rs.eval.rsandmath.rs.exec.rs.mod.rsto a high-level router and glue file.Function Decomposition (De-godding):
gen_expr.rs: Split the 800+ linegen_exprfunction into specific handlers for variables, binary ops, calls, and various loop types (AnyFor, AllFor, SumFor).exec.rs: Replaced the monolithicexecute_jit_funcwith a clean strategy-based router. Extracted logic intotry_exec_*helpers and centralized vectorized unrolling inexecute_views.Performance & Safety Refinements:
JitEntrymethods tojit_types.rsfor better visibility and dependency flow.Module,AsPyPointer) and silenced unused warnings in the quantum registry.