refactor: rvr extensions remove code duplication#2939
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
@claude please, review this pr, the original goal was to: Please, be prudent, and evaluate the correctness of the code that is in this pr, the quality and overall |
|
Claude finished @mansur20478's task in 3m 47s —— View job PR Review: Refactor RVR Extensions — Remove Code Duplication
SummaryThis PR consolidates duplicate code across the modular/fp2 algebra and pairing extensions. The changes are well-structured into 7 atomic commits, each addressing a distinct deduplication axis. Net result: 368 additions, 507 deletions (−139 lines). Correctness Verdict: Looks GoodI traced all refactored code paths against the base branch and the behavior is preserved: 1. 2.
3. 4. 5. 6. SuggestionsMinor:
OverallClean, well-scoped refactoring. The Verdict: Approve (modulo the minor suggestions above). |
This comment has been minimized.
This comment has been minimized.
7b16496 to
d74395c
Compare
This comment has been minimized.
This comment has been minimized.
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. |
|
@claude Is it good idea to unify IR for modular and fp2? what are the pros and the cons of the solution? |
|
Claude finished @mansur20478's task in 1m 21s —— View job Analysis: Should the IR for Modular and Fp2 be Unified?
Short answer: yes, for this codebase, it's a good design decision. The two IR node families (modular and fp2) had nearly identical structure — the only real differences were a string prefix ( Pros1. The duplication was real, not superficial. 2. The 3. Bugs fixed once instead of twice. 4. 5. The FFI macros ( Cons1. Indirection cost: reading the code requires a hop through 2. 3. 4. The type aliases can hide what's happening. 5. Adding a third field type with a different VerdictThe pros clearly outweigh the cons. The two most legitimate concerns (string slicing in |
… add ArithKind, SetupKind and IsEqKind
|
@claude please, perform review of this PR again |
|
Claude finished @mansur20478's task in 3m 59s —— View job PR Review: Refactor RVR Extensions — Remove Code Duplication
Net result: 470 additions, 549 deletions (−79 lines). Well-structured across 9 atomic commits, each addressing a distinct deduplication axis. Correctness: Looks GoodI traced all refactored code paths against the base branch (
CI Status
The lint failure must be fixed before merge. The Issues Found1. Formatting (blocking) — CI lint is failing. Run
2. Trait hierarchy is slightly over-engineered (non-blocking) — There are now four traits ( 3. 4. Visibility narrowing is correct (observation) — Suggestions
OverallClean, well-scoped refactoring that eliminates genuine mechanical duplication while keeping the abstraction narrow and crate-private. The Verdict: Approve after formatting fix. |
Note: cells_used metrics omitted because CUDA tracegen does not expose unpadded trace heights. Commit: 9099816 |
|
@claude please compare that there are no differences compared with before the refactoring, meaning that behavior and output of functions is the same as it was before the refactoring |
|
Claude finished @mansur20478's task in 4m 16s —— View job Behavioral Equivalence VerificationI read every line of the 8 changed files and compared each refactored function against its original implementation in the base branch (
1.
|
| Old | New | Same fields? |
|---|---|---|
ModArithInstr { op: ModOp::Add, rd_reg, rs1_reg, rs2_reg, num_limbs: info.num_limbs, modulus: info.modulus_bytes.clone() } |
ModArithInstr::new(ModOp::Add, rd_reg, rs1_reg, rs2_reg, info.num_limbs, info.modulus_bytes.clone()) |
✅ (constructor sets _kind: PhantomData) |
ModSetupInstr { rd_reg, rs1_reg, rs2_reg, num_limbs: info.num_limbs } |
ModSetupInstr::new(rd_reg, rs1_reg, rs2_reg, info.num_limbs) |
✅ |
ModIsEqInstr { rd_reg, rs1_reg, rs2_reg, num_limbs: info.num_limbs, modulus: info.modulus_bytes.clone() } |
ModIsEqInstr::new(rd_reg, rs1_reg, rs2_reg, info.num_limbs, info.modulus_bytes.clone()) |
✅ |
All remaining logic (opcode dispatch, phantom handling, extension trait methods) is byte-for-byte unchanged. ✅
Fp2 (6 match arms — ADD, SUB, SETUP_ADDSUB, MUL, DIV, SETUP_MULDIV):
Same pattern — Fp2ArithInstr { ... } → Fp2ArithInstr::new(...), Fp2SetupInstr { ... } → Fp2SetupInstr::new(...). All fields are passed in the same order. ✅
9. Unchanged code (verified not touched)
The following are byte-for-byte identical between old and new:
HintNonQrInstrstruct +ExtInstrimpl ✅HintSqrtInstrstruct +ExtInstrimpl ✅ModularRvrExtensionstruct +RvrExtensionimpl (c_headers, c_sources, staticlib_files, extra_c_sources, extra_c_include_files, extra_cflags) ✅Fp2RvrExtensionstruct +RvrExtensionimpl ✅ModOpenum +c_name()✅KnownFieldenum +c_suffix()+fp2_c_suffix()✅KNOWN_FIELDSstatic table ✅detect_known_field()✅format_c_byte_array()✅UnknownPrimeFieldFieldArithimpl ✅UnknownComplexFieldFieldArithimpl ✅exec_iseq()helper ✅rvr_ext_mod_iseq(unknown fallback) ✅rvr_ext_mod_setup✅rvr_ext_fp2_setup✅mod_sqrt_impl+rvr_ext_algebra_hint_sqrt✅- All pairing FFI entry points (
rvr_ext_pairing_hint_final_exp_bn254,rvr_ext_pairing_hint_final_exp_bls12_381) ✅
Final verdict
No behavioral differences found. Every refactored function produces the same output as its original implementation. Specifically:
- All generated C code (function names, arguments, control flow) is identical
- All FFI symbol names and signatures are identical
- All arithmetic operations produce the same results
- All I/O (read_elem/write_elem) paths are identical
- All opcode dispatch logic is identical
- All constructor call sites pass the same values in the same order, with
PhantomDatabeing the only added (zero-size) field
The refactoring is purely structural — introducing type-level parameterization (ArithKind, SetupKind, IsEqKind) and a blanket impl (KnownFieldArith) to eliminate mechanical duplication, without changing any observable behavior.
Refactor rvr algebra extension to remove code duplication. Also removes code duplication between Algebra/ECC/Pairing extensions for common computation.
Changes:
resolves INT-7215