Newtype ConstIdx, Constants#7358
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughReplaces raw u32 constant indices with a typed Changes
Sequence Diagram(s)sequenceDiagram
participant Codegen as Compiler/Codegen
participant Bytecode as Bytecode/CodeObject
participant VM as VM/Frame
participant Constants as Constants<C>
Codegen->>Bytecode: emit Instruction::LoadConst(Arg<ConstIdx>)
VM->>Bytecode: fetch Instruction at pc
VM->>Constants: index via ConstIdx (consti.get(arg))
Constants-->>VM: return Constant
VM->>VM: push constant on stack
VM->>Bytecode: replace instruction -> LoadConstMortal
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Sorry, something went wrong.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@crates/jit/tests/common.rs`:
- Line 197: The slice indexing uses a ConstIdx returned by consti.get(arg) which
can't index a slice; update the indexing in the LoadConst site so you convert
the ConstIdx to usize (e.g., call .as_usize() on the ConstIdx) before indexing
the constants slice; modify the expression that builds the pushed value (the
call in self.stack.push(...)) to index constants with consti.get(arg).as_usize()
(or an equivalent usize conversion) so the types match.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
Run ID: 2dab4afd-3b23-4617-90df-f8e9a46b76ce
📒 Files selected for processing (10)
crates/codegen/src/compile.rscrates/codegen/src/ir.rscrates/compiler-core/src/bytecode.rscrates/compiler-core/src/bytecode/instruction.rscrates/compiler-core/src/bytecode/oparg.rscrates/compiler-core/src/marshal.rscrates/jit/src/instructions.rscrates/jit/tests/common.rscrates/vm/src/builtins/code.rscrates/vm/src/frame.rs
Sorry, something went wrong.
There was a problem hiding this comment.
♻️ Duplicate comments (1)
crates/jit/tests/common.rs (1)
196-196: ⚠️ Potential issue | 🔴 CriticalFix slice indexing type mismatch at Line 196.
constantsis a slice (&[ConstantData]), but this line indexes it withConstIdx. Convert tousizebefore indexing (or change this API to accept the typed constants wrapper end-to-end). This matches the previously reported unresolved issue.Proposed fix
- self.stack.push(constants[consti.get(arg)].clone().into()) + self.stack + .push(constants[consti.get(arg).as_usize()].clone().into())#!/bin/bash set -euo pipefail # Verify the local function signature and indexing site in this file rg -n -C2 'fn process_instruction\(|constants:\s*&\[[^]]+\]|constants\[consti\.get\(arg\)\]' crates/jit/tests/common.rs # Check whether there is any repository-level indexing support for ConstIdx on slices rg -n 'impl\s+.*Index<\s*.*ConstIdx|impl\s+.*SliceIndex<.*ConstIdx' crates --type=rustExpected verification outcome: first command shows
constantsis a slice and the current indexing expression; second command should not reveal a slice-index impl makingConstIdxdirectly valid for slice indexing.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@crates/jit/tests/common.rs` at line 196, The slice indexing uses a ConstIdx value: change the indexing at self.stack.push(constants[consti.get(arg)].clone().into()) to convert the ConstIdx to usize before indexing (e.g. use consti.get(arg).into() / .to_usize() / as usize depending on the ConstIdx newtype implementation) so that constants[usize_index] is used; update the expression inside self.stack.push accordingly to preserve the clone().into() chain.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Duplicate comments:
In `@crates/jit/tests/common.rs`:
- Line 196: The slice indexing uses a ConstIdx value: change the indexing at
self.stack.push(constants[consti.get(arg)].clone().into()) to convert the
ConstIdx to usize before indexing (e.g. use consti.get(arg).into() / .to_usize()
/ as usize depending on the ConstIdx newtype implementation) so that
constants[usize_index] is used; update the expression inside self.stack.push
accordingly to preserve the clone().into() chain.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
Run ID: fbdaf0af-13e7-487f-8f81-9c76e274681e
📒 Files selected for processing (4)
crates/codegen/src/compile.rscrates/codegen/src/ir.rscrates/jit/tests/common.rscrates/vm/src/frame.rs
🚧 Files skipped from review as they are similar to previous changes (2)
- crates/codegen/src/compile.rs
- crates/codegen/src/ir.rs
Sorry, something went wrong.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@crates/codegen/src/ir.rs`:
- Around line 705-707: The indexing uses a ConstIdx directly; change it to
extract the ConstIdx value then convert to usize before indexing
self.metadata.consts: for the match arm (Instruction::LoadConst { consti },
Instruction::UnaryNot) use consti.get(curr.arg) to obtain the ConstIdx, cast or
call .into()/.0 to get a usize (same pattern used around lines 697–698), then
index self.metadata.consts[usize_index] when binding constant; update the
reference to consti/constant accordingly.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
Run ID: 76bc2939-013e-4379-a0e3-bede4853d7c8
📒 Files selected for processing (1)
crates/codegen/src/ir.rs
Sorry, something went wrong.
a986d55 to
aa607b2
Compare
March 6, 2026 08:45
82e9b5d
into
RustPython:main
Mar 9, 2026
* Newtype ConstIdx, Constants * Set generic
Summary by CodeRabbit