Skip to content

Commit d1dc3d6

Browse files
committed
vm: align builtin type call specializations with CPython guards
1 parent 43794da commit d1dc3d6

File tree

1 file changed

+3
-21
lines changed

1 file changed

+3
-21
lines changed

crates/vm/src/frame.rs

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3547,17 +3547,13 @@ impl ExecutingFrame<'_> {
35473547
self.execute_call(args, vm)
35483548
}
35493549
Instruction::CallType1 => {
3550-
let instr_idx = self.lasti() as usize - 1;
3551-
let cache_base = instr_idx + 1;
3552-
let cached_tag = self.code.instructions.read_cache_u32(cache_base + 1);
35533550
let nargs: u32 = arg.into();
35543551
if nargs == 1 {
35553552
// Stack: [callable, null, arg]
35563553
let obj = self.pop_value();
35573554
let _null = self.pop_value_opt();
35583555
let callable = self.pop_value();
3559-
let callable_tag = &*callable as *const PyObject as u32;
3560-
if cached_tag == callable_tag {
3556+
if callable.is(vm.ctx.types.type_type.as_object()) {
35613557
let tp = obj.class().to_owned().into();
35623558
self.push_value(tp);
35633559
return Ok(None);
@@ -3571,16 +3567,12 @@ impl ExecutingFrame<'_> {
35713567
self.execute_call(args, vm)
35723568
}
35733569
Instruction::CallStr1 => {
3574-
let instr_idx = self.lasti() as usize - 1;
3575-
let cache_base = instr_idx + 1;
3576-
let cached_tag = self.code.instructions.read_cache_u32(cache_base + 1);
35773570
let nargs: u32 = arg.into();
35783571
if nargs == 1 {
35793572
let obj = self.pop_value();
35803573
let _null = self.pop_value_opt();
35813574
let callable = self.pop_value();
3582-
let callable_tag = &*callable as *const PyObject as u32;
3583-
if cached_tag == callable_tag {
3575+
if callable.is(vm.ctx.types.str_type.as_object()) {
35843576
let result = obj.str(vm)?;
35853577
self.push_value(result.into());
35863578
return Ok(None);
@@ -3593,16 +3585,12 @@ impl ExecutingFrame<'_> {
35933585
self.execute_call(args, vm)
35943586
}
35953587
Instruction::CallTuple1 => {
3596-
let instr_idx = self.lasti() as usize - 1;
3597-
let cache_base = instr_idx + 1;
3598-
let cached_tag = self.code.instructions.read_cache_u32(cache_base + 1);
35993588
let nargs: u32 = arg.into();
36003589
if nargs == 1 {
36013590
let obj = self.pop_value();
36023591
let _null = self.pop_value_opt();
36033592
let callable = self.pop_value();
3604-
let callable_tag = &*callable as *const PyObject as u32;
3605-
if cached_tag == callable_tag {
3593+
if callable.is(vm.ctx.types.tuple_type.as_object()) {
36063594
// tuple(x) returns x as-is when x is already an exact tuple
36073595
if let Ok(tuple) = obj.clone().downcast_exact::<PyTuple>(vm) {
36083596
self.push_value(tuple.into_pyref().into());
@@ -6949,12 +6937,6 @@ impl ExecutingFrame<'_> {
69496937
None
69506938
};
69516939
if let Some(new_op) = new_op {
6952-
let callable_tag = callable as *const PyObject as u32;
6953-
unsafe {
6954-
self.code
6955-
.instructions
6956-
.write_cache_u32(cache_base + 1, callable_tag);
6957-
}
69586940
self.specialize_at(instr_idx, cache_base, new_op);
69596941
return;
69606942
}

0 commit comments

Comments
 (0)