| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| Expand Up | @@ -4,10 +4,6 @@ | |
|
|
||
| _specializations = {} | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
| _specialized_opmap = {} | ||
|
|
||
| opmap = { | ||
| Expand Down | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| Expand Up | @@ -84,6 +84,20 @@ pub fn find_exception_handler(table: &[u8], offset: u32) -> Option<ExceptionTabl | |
| None | ||
| } | ||
|
|
||
| /// Encode LOAD_ATTR oparg: bit 0 = method flag, bits 1+ = name index. | ||
| #[inline] | ||
| pub const fn encode_load_attr_arg(name_idx: u32, is_method: bool) -> u32 { | ||
| (name_idx << 1) | (is_method as u32) | ||
| } | ||
|
|
||
| /// Decode LOAD_ATTR oparg: returns (name_idx, is_method). | ||
| #[inline] | ||
| pub const fn decode_load_attr_arg(oparg: u32) -> (u32, bool) { | ||
| let is_method = (oparg & 1) == 1; | ||
| let name_idx = oparg >> 1; | ||
| (name_idx, is_method) | ||
| } | ||
|
Comment thread
Comment on lines
+87
to
+99
Copy link
Copy Markdown
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality⚠️ Potential issue | 🟡 Minor LOAD_ATTR oparg encoding needs an explicit size invariant (avoid silent truncation). pub const fn encode_load_attr_arg(name_idx: u32, is_method: bool) -> u32 {
- (name_idx << 1) | (is_method as u32)
+ // name_idx uses bits 1..; bit0 is reserved for is_method.
+ debug_assert!(name_idx < (1 << 31));
+ (name_idx << 1) | (is_method as u32)
}In @crates/compiler-core/src/bytecode.rs around lines 87 - 99, The encode_load_attr_arg function can silently truncate when name_idx has its top bit set; add an explicit size invariant check (e.g., assert or debug_assert) that name_idx fits in 31 bits before shifting, and document this invariant in the function comment; keep decode_load_attr_arg unchanged but ensure the pair of functions' contract/comments state the 31-bit limit so callers cannot pass larger values.
Sorry, something went wrong.
All reactions
|
||
|
|
||
| /// Oparg values for [`Instruction::ConvertValue`]. | ||
| /// | ||
| /// ## See also | ||
| Expand Down Expand Up | @@ -1740,6 +1754,9 @@ impl Instruction { | |
| pub const fn label_arg(&self) -> Option<Arg<Label>> { | ||
| match self { | ||
| Jump { target: l } | ||
| | JumpBackward { target: l } | ||
| | JumpBackwardNoInterrupt { target: l } | ||
| | JumpForward { target: l } | ||
| | JumpIfNotExcMatch(l) | ||
| | PopJumpIfTrue { target: l } | ||
| | PopJumpIfFalse { target: l } | ||
| Expand All | @@ -1766,6 +1783,9 @@ impl Instruction { | |
| matches!( | ||
| self, | ||
| Jump { .. } | ||
| | JumpForward { .. } | ||
| | JumpBackward { .. } | ||
| | JumpBackwardNoInterrupt { .. } | ||
| | Continue { .. } | ||
| | Break { .. } | ||
| | ReturnValue | ||
| Expand Down Expand Up | @@ -2060,11 +2080,27 @@ impl Instruction { | |
| ImportName { idx } => w!(IMPORT_NAME, name = idx), | ||
| IsOp(inv) => w!(IS_OP, ?inv), | ||
| Jump { target } => w!(JUMP, target), | ||
| JumpBackward { target } => w!(JUMP_BACKWARD, target), | ||
| JumpBackwardNoInterrupt { target } => w!(JUMP_BACKWARD_NO_INTERRUPT, target), | ||
| JumpForward { target } => w!(JUMP_FORWARD, target), | ||
| JumpIfFalseOrPop { target } => w!(JUMP_IF_FALSE_OR_POP, target), | ||
| JumpIfNotExcMatch(target) => w!(JUMP_IF_NOT_EXC_MATCH, target), | ||
| JumpIfTrueOrPop { target } => w!(JUMP_IF_TRUE_OR_POP, target), | ||
| ListAppend { i } => w!(LIST_APPEND, i), | ||
| LoadAttr { idx } => w!(LOAD_ATTR, name = idx), | ||
| LoadAttr { idx } => { | ||
| let encoded = idx.get(arg); | ||
| let (name_idx, is_method) = decode_load_attr_arg(encoded); | ||
| let attr_name = name(name_idx); | ||
| if is_method { | ||
| write!( | ||
| f, | ||
| "{:pad$}({}, {}, method=true)", | ||
| "LOAD_ATTR", encoded, attr_name | ||
| ) | ||
| } else { | ||
| write!(f, "{:pad$}({}, {})", "LOAD_ATTR", encoded, attr_name) | ||
| } | ||
| } | ||
| LoadAttrMethod { idx } => w!(LOAD_ATTR_METHOD, name = idx), | ||
| LoadBuildClass => w!(LOAD_BUILD_CLASS), | ||
| LoadClassDeref(idx) => w!(LOAD_CLASSDEREF, cell_name = idx), | ||
| Expand Down | ||
| Back | FazBrowse Home | New Git URL |
Uh oh!
There was an error while loading. Please reload this page.