(
&mut self,
vm: &VirtualMachine,
oparg: u32,
instr_idx: usize,
cache_base: usize,
)
| 8962 | } |
| 8963 | |
| 8964 | fn specialize_load_global( |
| 8965 | &mut self, |
| 8966 | vm: &VirtualMachine, |
| 8967 | oparg: u32, |
| 8968 | instr_idx: usize, |
| 8969 | cache_base: usize, |
| 8970 | ) { |
| 8971 | if !matches!( |
| 8972 | self.code.instructions.read_op(instr_idx), |
| 8973 | Instruction::LoadGlobal { .. } |
| 8974 | ) { |
| 8975 | return; |
| 8976 | } |
| 8977 | let name = self.code.names[(oparg >> 1) as usize]; |
| 8978 | let Ok(globals_version) = u16::try_from(self.globals.version()) else { |
| 8979 | unsafe { |
| 8980 | self.code.instructions.write_adaptive_counter( |
| 8981 | cache_base, |
| 8982 | bytecode::adaptive_counter_backoff( |
| 8983 | self.code.instructions.read_adaptive_counter(cache_base), |
| 8984 | ), |
| 8985 | ); |
| 8986 | } |
| 8987 | return; |
| 8988 | }; |
| 8989 | |
| 8990 | if let Ok(Some(globals_hint)) = self.globals.hint_for_key(name, vm) { |
| 8991 | unsafe { |
| 8992 | self.code |
| 8993 | .instructions |
| 8994 | .write_cache_u16(cache_base + 1, globals_version); |
| 8995 | self.code.instructions.write_cache_u16(cache_base + 2, 0); |
| 8996 | self.code |
| 8997 | .instructions |
| 8998 | .write_cache_u16(cache_base + 3, globals_hint); |
| 8999 | } |
| 9000 | self.specialize_at(instr_idx, cache_base, Instruction::LoadGlobalModule); |
| 9001 | return; |
| 9002 | } |
| 9003 | |
| 9004 | if let Some(builtins_dict) = self.builtins.downcast_ref_if_exact::<PyDict>(vm) |
| 9005 | && let Ok(Some(builtins_hint)) = builtins_dict.hint_for_key(name, vm) |
| 9006 | && let Ok(builtins_version) = u16::try_from(builtins_dict.version()) |
| 9007 | { |
| 9008 | unsafe { |
| 9009 | self.code |
| 9010 | .instructions |
| 9011 | .write_cache_u16(cache_base + 1, globals_version); |
| 9012 | self.code |
| 9013 | .instructions |
| 9014 | .write_cache_u16(cache_base + 2, builtins_version); |
| 9015 | self.code |
| 9016 | .instructions |
| 9017 | .write_cache_u16(cache_base + 3, builtins_hint); |
| 9018 | } |
| 9019 | self.specialize_at(instr_idx, cache_base, Instruction::LoadGlobalBuiltin); |
| 9020 | return; |
| 9021 | } |
no test coverage detected