| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
📝 Walkthrough
WalkthroughRefactored the Instruction::Resume opcode's operand type from Arg<u32> to Arg<oparg::ResumeType>, replacing the auto-generated ResumeType enum with a manually defined variant that includes a catch-all Other(u32) case, and updated all emission sites to pass enum values directly. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Suggested reviewers
Poem🚥 Pre-merge checks | ✅ 3 ✅ Passed checks (3 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. ❤️ ShareComment @coderabbitai help to get the list of available commands and usage tips. |
Sorry, something went wrong.
|
@youknowone I'm thinking to create a derive macro called: #[newtype_oparg] that can be defined on either struct or enums. this will help streamline the oparg definition while being able to handle slightly less straight forward cases like overriding the fmt::Display for specific enum variants like, like we do here: RustPython/crates/compiler-core/src/bytecode/oparg.rs Lines 265 to 277 in b11b8e6 and RustPython/crates/compiler-core/src/bytecode/oparg.rs Lines 575 to 585 in b11b8e6 (we have more places) Also with generate the From<u32> and From<OPARG_ENUM> for u32 for enums with a fallback variant, like here with "Other(u32)". Instruction::GetAwaitable oparg can also use this pattern lmk what you think:) |
Sorry, something went wrong.
There was a problem hiding this comment.
crates/compiler-core/src/bytecode/oparg.rs (1)🤖 Prompt for all review comments with AI agents313-317: Consider showing variant names in Display for better diagnostics.
The current Display impl shows only the numeric value. For disassembly output, showing variant names could improve readability.
🔧 Optional enhancement for Display🤖 Prompt for AI Agentsimpl core::fmt::Display for ResumeType { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - u32::from(*self).fmt(f) + match self { + Self::AtFuncStart => write!(f, "0 (AtFuncStart)"), + Self::AfterYield => write!(f, "1 (AfterYield)"), + Self::AfterYieldFrom => write!(f, "2 (AfterYieldFrom)"), + Self::AfterAwait => write!(f, "3 (AfterAwait)"), + Self::Other(v) => write!(f, "{v}"), + } } }Verify each finding against the current code and only fix it if needed. In `@crates/compiler-core/src/bytecode/oparg.rs` around lines 313 - 317, The Display impl for ResumeType currently prints only its numeric value (u32::from(*self).fmt(f)); change it to print human-friendly variant names for diagnostics by matching on ResumeType (in the impl core::fmt::Display for ResumeType, fn fmt) and write the variant identifier strings (e.g., "None", "Yield", etc.) to the formatter, optionally falling back to the numeric value for unknown/other variants to preserve behavior.
Verify each finding against the current code and only fix it if needed. Nitpick comments: In `@crates/compiler-core/src/bytecode/oparg.rs`: - Around line 313-317: The Display impl for ResumeType currently prints only its numeric value (u32::from(*self).fmt(f)); change it to print human-friendly variant names for diagnostics by matching on ResumeType (in the impl core::fmt::Display for ResumeType, fn fmt) and write the variant identifier strings (e.g., "None", "Yield", etc.) to the formatter, optionally falling back to the numeric value for unknown/other variants to preserve behavior.
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
Run ID: a841bb7a-52f4-4af9-85c5-31e89e5a26d1
📥 CommitsReviewing files that changed from the base of the PR and between b11b8e6 and adae369.
📒 Files selected for processing (3)
Sorry, something went wrong.
|
@ShaharNaveh sounds good to me. Could you show me an example how it will look like once the macro is introduced? |
Sorry, something went wrong.
I was thinking something like: #[newtype_oparg]
struct VarNum(u32);
#[newtype_oparg]
enum SpecialMethod {
/// `__enter__` for sync context manager
#[oparg(display = "__enter__")]
Enter = 0,
/// `__exit__` for sync context manager
#[oparg(display = "__exit__")]
Exit = 1,
...
}
#[newtype_oparg]
enum ResumeType {
AfterYield = 1
AfterYieldFrom = 2,
#[oparg(catch_all)]
Other(u32)
} |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Summary by CodeRabbit