MCPcopy Index your code
hub / github.com/RustPython/RustPython / specialize_class_load_attr

Method specialize_class_load_attr

crates/vm/src/frame.rs:7708–7813  ·  view source on GitHub ↗
(
        &mut self,
        _vm: &VirtualMachine,
        oparg: LoadAttr,
        instr_idx: usize,
        cache_base: usize,
    )

Source from the content-addressed store, hash-verified

7706 }
7707
7708 fn specialize_class_load_attr(
7709 &mut self,
7710 _vm: &VirtualMachine,
7711 oparg: LoadAttr,
7712 instr_idx: usize,
7713 cache_base: usize,
7714 ) {
7715 let obj = self.top_value();
7716 let owner_type = obj.downcast_ref::<PyType>().unwrap();
7717
7718 // Get or assign type version for the type object itself
7719 let mut type_version = owner_type.tp_version_tag.load(Acquire);
7720 if type_version == 0 {
7721 type_version = owner_type.assign_version_tag();
7722 }
7723 if type_version == 0 {
7724 unsafe {
7725 self.code.instructions.write_adaptive_counter(
7726 cache_base,
7727 bytecode::adaptive_counter_backoff(
7728 self.code.instructions.read_adaptive_counter(cache_base),
7729 ),
7730 );
7731 }
7732 return;
7733 }
7734
7735 let attr_name = self.code.names[oparg.name_idx() as usize];
7736
7737 // Check metaclass: ensure no data descriptor on metaclass for this name
7738 let mcl = obj.class();
7739 let mcl_attr = mcl.get_attr(attr_name);
7740 if let Some(ref attr) = mcl_attr {
7741 let attr_class = attr.class();
7742 if attr_class.slots.descr_set.load().is_some() {
7743 // Data descriptor on metaclass — can't specialize
7744 unsafe {
7745 self.code.instructions.write_adaptive_counter(
7746 cache_base,
7747 bytecode::adaptive_counter_backoff(
7748 self.code.instructions.read_adaptive_counter(cache_base),
7749 ),
7750 );
7751 }
7752 return;
7753 }
7754 }
7755 let mut metaclass_version = 0;
7756 if !mcl.slots.flags.has_feature(PyTypeFlags::IMMUTABLETYPE) {
7757 metaclass_version = mcl.tp_version_tag.load(Acquire);
7758 if metaclass_version == 0 {
7759 metaclass_version = mcl.assign_version_tag();
7760 }
7761 if metaclass_version == 0 {
7762 unsafe {
7763 self.code.instructions.write_adaptive_counter(
7764 cache_base,
7765 bytecode::adaptive_counter_backoff(

Callers 1

specialize_load_attrMethod · 0.80

Calls 14

adaptive_counter_backoffFunction · 0.85
top_valueMethod · 0.80
assign_version_tagMethod · 0.80
read_adaptive_counterMethod · 0.80
name_idxMethod · 0.80
has_featureMethod · 0.80
specialize_atMethod · 0.80
unwrapMethod · 0.45
loadMethod · 0.45

Tested by

no test coverage detected