Repository navigation
Tidy codegen::ir::BlockIdx api - #6413
Conversation
Walkthrough
Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ 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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
crates/codegen/src/ir.rs (1)
50-54:From<BlockIdx> for u32is a good interop hook.
Consider also adding a smallas_u32()inherent if you want to avoid sprinklingu32::from(...)at call sites, but current approach is fine.crates/codegen/src/compile.rs (1)
5403-5420: Prefer comparing againstBlockIdx::NULL(avoid re-encoding the sentinel asu32::MAX).
This keeps the “NULL == u32::MAX” detail encapsulated insideBlockIdx.- assert_eq!( - u32::from(prev_block.next), - u32::MAX, - "switching {prev:?} -> {block:?} from block that's already got a next" - ); + assert_eq!( + prev_block.next, + BlockIdx::NULL, + "switching {prev:?} -> {block:?} from block that's already got a next" + );
📜 Review details
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
crates/codegen/src/compile.rs(9 hunks)crates/codegen/src/ir.rs(1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.rs
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
**/*.rs: Follow the default rustfmt code style by runningcargo fmtto format Rust code
Always run clippy to lint Rust code (cargo clippy) before completing tasks and fix any warnings or lints introduced by changes
Follow Rust best practices for error handling and memory management
Use the macro system (pyclass,pymodule,pyfunction, etc.) when implementing Python functionality in Rust
Files:
crates/codegen/src/ir.rscrates/codegen/src/compile.rs
🧬 Code graph analysis (2)
crates/codegen/src/ir.rs (1)
crates/codegen/src/compile.rs (2)
new(325-332)new(353-395)
crates/codegen/src/compile.rs (1)
crates/codegen/src/ir.rs (4)
new(39-41)idx(45-47)default(104-109)from(51-53)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (10)
- GitHub Check: Run rust tests (macos-latest)
- GitHub Check: Run rust tests (ubuntu-latest)
- GitHub Check: Run snippets and cpython tests (macos-latest)
- GitHub Check: Run snippets and cpython tests (windows-latest)
- GitHub Check: Run snippets and cpython tests (ubuntu-latest)
- GitHub Check: Run snippets and cpython tests on wasm-wasi
- GitHub Check: Check Rust code with clippy
- GitHub Check: Run rust tests (windows-latest)
- GitHub Check: Check the WASM package and demo
- GitHub Check: Ensure compilation on various targets
🔇 Additional comments (7)
crates/codegen/src/ir.rs (1)
32-48: Nice encapsulation ofBlockIdx+ clearer construction API.
Private inner field +const fn new()keeps invariants local and forces call sites away from tuple-field access.crates/codegen/src/compile.rs (6)
124-128: Good:loop_datanow carriesBlockIdxdirectly (noir::noise).
359-360: Good: construction sites moved toBlockIdx::new(0).
Keeps call sites compatible now that the inner field is private.Also applies to: 748-749
5331-5349: Good:_emit/emit_no_argconsistently useBlockIdx::NULL.
5396-5401: Good:new_block()returnsBlockIdxand constructs viaBlockIdx::new.
5708-5726:EmitArgreturning aBlockIdxtarget is a clean separation of “arg vs jump target”.
TheEmitArg<bytecode::Label> for BlockIdxspecialization reads well at call sites.
32-33: Runcargo fmtandcargo clippybefore merging.cargo fmt --all cargo clippy --all-targets --all-features -- -D warnings
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (3)
crates/codegen/src/ir.rs (3)
31-48: Nice encapsulation ofBlockIdx+const fnconstructor/accessor.
This tightens the API surface cleanly and keeps call sites ergonomic (NULL,new,idx). Consider adding#[repr(transparent)]if you ever rely on layout/FFI (optional).Ensure
cargo fmt+cargo clippystay clean per repo guidelines.
50-54:From<BlockIdx> for u32is good; consider symmetricFrom<u32> for BlockIdxfor.into().
Not required sinceBlockIdx::newexists, but symmetry often improves readability at call sites.
176-217: Avoid directBlockIdx(0)/.0usage inside this module to fully realize the “tidy API” goal.
Even though it’s legal within the defining module, usingBlockIdx::new(0)andu32::from(...)makes the encapsulation intent consistent and reduces future refactor footguns.- let mut next_block = BlockIdx(0); + let mut next_block = BlockIdx::new(0); - stack.push(BlockIdx(0)); + stack.push(BlockIdx::new(0)); - eprintln!("===BLOCK {}===", block.0); + eprintln!("===BLOCK {}===", u32::from(block)); - OpArg(ins.target.0) + OpArg(u32::from(ins.target)) -fn iter_blocks(blocks: &[Block]) -> impl Iterator<Item = (BlockIdx, &Block)> + '_ { - let mut next = BlockIdx(0); +fn iter_blocks(blocks: &[Block]) -> impl Iterator<Item = (BlockIdx, &Block)> + '_ { + let mut next = BlockIdx::new(0);Also applies to: 292-366, 402-412
📜 Review details
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
crates/codegen/src/ir.rs(1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.rs
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
**/*.rs: Follow the default rustfmt code style by runningcargo fmtto format Rust code
Always run clippy to lint Rust code (cargo clippy) before completing tasks and fix any warnings or lints introduced by changes
Follow Rust best practices for error handling and memory management
Use the macro system (pyclass,pymodule,pyfunction, etc.) when implementing Python functionality in Rust
Files:
crates/codegen/src/ir.rs
🧬 Code graph analysis (1)
crates/codegen/src/ir.rs (1)
crates/codegen/src/compile.rs (2)
new(325-332)new(353-395)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (11)
- GitHub Check: Run snippets and cpython tests on wasm-wasi
- GitHub Check: Run rust tests (macos-latest)
- GitHub Check: Run tests under miri
- GitHub Check: Run rust tests (windows-latest)
- GitHub Check: Run snippets and cpython tests (macos-latest)
- GitHub Check: Run snippets and cpython tests (windows-latest)
- GitHub Check: Run rust tests (ubuntu-latest)
- GitHub Check: Run snippets and cpython tests (ubuntu-latest)
- GitHub Check: Check Rust code with clippy
- GitHub Check: Check the WASM package and demo
- GitHub Check: Ensure compilation on various targets
🔇 Additional comments (1)
crates/codegen/src/ir.rs (1)
56-82: Indexing impls look correct and keepBlockIdx-based indexing readable.
Usingidx.idx()avoids exposing internals and doesn’t recurse (it indexes viausize).
IMO this looks cleaner, but not something critical. Generally, I prefer to not have a tuple struct with a |
|
@youknowone https://www.howtocodeit.com/guides/ultimate-guide-rust-newtypes this is an excellent article imo, he explains my motivations better lol |
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.