Skip to content

Commit 4112577

Browse files
committed
Collapse duplicated branch tails and use checked_sub in CALL_KW
- Collapse conditional deopt + unconditional vectorcall pattern in CallBuiltinClass, CallNonPyGeneral, CallKwNonPy - Use checked_sub for nargs_usize - kw_count in execute_call_kw_vectorcall to prevent silent underflow in release builds
1 parent 4a91e0a commit 4112577

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

crates/vm/src/frame.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4117,10 +4117,9 @@ impl ExecutingFrame<'_> {
41174117
let nargs: u32 = arg.into();
41184118
let callable = self.nth_value(nargs + 1);
41194119
let callable_tag = callable as *const PyObject as u32;
4120-
if cached_tag == callable_tag && callable.downcast_ref::<PyType>().is_some() {
4121-
return self.execute_call_vectorcall(nargs, vm);
4120+
if !(cached_tag == callable_tag && callable.downcast_ref::<PyType>().is_some()) {
4121+
self.deoptimize_call();
41224122
}
4123-
self.deoptimize_call();
41244123
self.execute_call_vectorcall(nargs, vm)
41254124
}
41264125
Instruction::CallMethodDescriptorFastWithKeywords => {
@@ -4198,10 +4197,9 @@ impl ExecutingFrame<'_> {
41984197
let nargs: u32 = arg.into();
41994198
let callable = self.nth_value(nargs + 1);
42004199
let callable_tag = callable as *const PyObject as u32;
4201-
if cached_tag == callable_tag {
4202-
return self.execute_call_vectorcall(nargs, vm);
4200+
if cached_tag != callable_tag {
4201+
self.deoptimize_call();
42034202
}
4204-
self.deoptimize_call();
42054203
self.execute_call_vectorcall(nargs, vm)
42064204
}
42074205
Instruction::CallKwPy => {
@@ -4289,10 +4287,9 @@ impl ExecutingFrame<'_> {
42894287
let nargs: u32 = arg.into();
42904288
let callable = self.nth_value(nargs + 2);
42914289
let callable_tag = callable as *const PyObject as u32;
4292-
if cached_tag == callable_tag {
4293-
return self.execute_call_kw_vectorcall(nargs, vm);
4290+
if cached_tag != callable_tag {
4291+
self.deoptimize_call_kw();
42944292
}
4295-
self.deoptimize_call_kw();
42964293
self.execute_call_kw_vectorcall(nargs, vm)
42974294
}
42984295
Instruction::LoadSuperAttrAttr => {
@@ -5738,7 +5735,9 @@ impl ExecutingFrame<'_> {
57385735
.map(|sr| sr.to_pyobj());
57395736
let has_self = self_or_null.is_some();
57405737

5741-
let pos_count = nargs_usize - kw_count;
5738+
let pos_count = nargs_usize
5739+
.checked_sub(kw_count)
5740+
.expect("CALL_KW: kw_count exceeds nargs");
57425741
let effective_nargs = if has_self { pos_count + 1 } else { pos_count };
57435742

57445743
// Build the full args slice: positional (including self) + kwarg values

0 commit comments

Comments
 (0)