(&mut self, vm: &VirtualMachine, instr_idx: usize, cache_base: usize)
| 8791 | } |
| 8792 | |
| 8793 | fn specialize_to_bool(&mut self, vm: &VirtualMachine, instr_idx: usize, cache_base: usize) { |
| 8794 | if !matches!( |
| 8795 | self.code.instructions.read_op(instr_idx), |
| 8796 | Instruction::ToBool |
| 8797 | ) { |
| 8798 | return; |
| 8799 | } |
| 8800 | let obj = self.top_value(); |
| 8801 | let cls = obj.class(); |
| 8802 | |
| 8803 | let new_op = if cls.is(vm.ctx.types.bool_type) { |
| 8804 | Some(Instruction::ToBoolBool) |
| 8805 | } else if cls.is(PyInt::class(&vm.ctx)) { |
| 8806 | Some(Instruction::ToBoolInt) |
| 8807 | } else if cls.is(vm.ctx.types.none_type) { |
| 8808 | Some(Instruction::ToBoolNone) |
| 8809 | } else if cls.is(PyList::class(&vm.ctx)) { |
| 8810 | Some(Instruction::ToBoolList) |
| 8811 | } else if cls.is(PyStr::class(&vm.ctx)) { |
| 8812 | Some(Instruction::ToBoolStr) |
| 8813 | } else if cls.slots.flags.has_feature(PyTypeFlags::HEAPTYPE) |
| 8814 | && cls.slots.as_number.boolean.load().is_none() |
| 8815 | && cls.slots.as_mapping.length.load().is_none() |
| 8816 | && cls.slots.as_sequence.length.load().is_none() |
| 8817 | { |
| 8818 | // Cache type version for ToBoolAlwaysTrue guard |
| 8819 | let mut type_version = cls.tp_version_tag.load(Acquire); |
| 8820 | if type_version == 0 { |
| 8821 | type_version = cls.assign_version_tag(); |
| 8822 | } |
| 8823 | if type_version != 0 { |
| 8824 | unsafe { |
| 8825 | self.code |
| 8826 | .instructions |
| 8827 | .write_cache_u32(cache_base + 1, type_version); |
| 8828 | } |
| 8829 | self.specialize_at(instr_idx, cache_base, Instruction::ToBoolAlwaysTrue); |
| 8830 | } else { |
| 8831 | unsafe { |
| 8832 | self.code.instructions.write_adaptive_counter( |
| 8833 | cache_base, |
| 8834 | bytecode::adaptive_counter_backoff( |
| 8835 | self.code.instructions.read_adaptive_counter(cache_base), |
| 8836 | ), |
| 8837 | ); |
| 8838 | } |
| 8839 | } |
| 8840 | return; |
| 8841 | } else { |
| 8842 | None |
| 8843 | }; |
| 8844 | |
| 8845 | self.commit_specialization(instr_idx, cache_base, new_op); |
| 8846 | } |
| 8847 | |
| 8848 | fn specialize_for_iter( |
| 8849 | &mut self, |
no test coverage detected