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

Method specialize_store_attr

crates/vm/src/frame.rs:9124–9249  ·  view source on GitHub ↗
(
        &mut self,
        vm: &VirtualMachine,
        attr_idx: bytecode::NameIdx,
        instr_idx: usize,
        cache_base: usize,
    )

Source from the content-addressed store, hash-verified

9122 }
9123
9124 fn specialize_store_attr(
9125 &mut self,
9126 vm: &VirtualMachine,
9127 attr_idx: bytecode::NameIdx,
9128 instr_idx: usize,
9129 cache_base: usize,
9130 ) {
9131 if !matches!(
9132 self.code.instructions.read_op(instr_idx),
9133 Instruction::StoreAttr { .. }
9134 ) {
9135 return;
9136 }
9137 // TOS = owner (the object being assigned to)
9138 let owner = self.top_value();
9139 let cls = owner.class();
9140
9141 // Only specialize if setattr is the default (generic_setattr)
9142 let is_default_setattr = cls
9143 .slots
9144 .setattro
9145 .load()
9146 .is_some_and(|f| f as usize == PyBaseObject::slot_setattro as *const () as usize);
9147 if !is_default_setattr {
9148 unsafe {
9149 self.code.instructions.write_adaptive_counter(
9150 cache_base,
9151 bytecode::adaptive_counter_backoff(
9152 self.code.instructions.read_adaptive_counter(cache_base),
9153 ),
9154 );
9155 }
9156 return;
9157 }
9158
9159 // Get or assign type version
9160 let mut type_version = cls.tp_version_tag.load(Acquire);
9161 if type_version == 0 {
9162 type_version = cls.assign_version_tag();
9163 }
9164 if type_version == 0 {
9165 unsafe {
9166 self.code.instructions.write_adaptive_counter(
9167 cache_base,
9168 bytecode::adaptive_counter_backoff(
9169 self.code.instructions.read_adaptive_counter(cache_base),
9170 ),
9171 );
9172 }
9173 return;
9174 }
9175
9176 // Check for data descriptor
9177 let attr_name = self.code.names[attr_idx as usize];
9178 let cls_attr = cls.get_attr(attr_name);
9179 let has_data_descr = cls_attr.as_ref().is_some_and(|descr| {
9180 let descr_cls = descr.class();
9181 descr_cls.slots.descr_get.load().is_some() && descr_cls.slots.descr_set.load().is_some()

Callers 1

execute_instructionMethod · 0.80

Calls 14

adaptive_counter_backoffFunction · 0.85
top_valueMethod · 0.80
read_adaptive_counterMethod · 0.80
assign_version_tagMethod · 0.80
write_cache_u32Method · 0.80
write_cache_u16Method · 0.80
specialize_atMethod · 0.80
get_item_optMethod · 0.80
classMethod · 0.45
loadMethod · 0.45
get_attrMethod · 0.45

Tested by

no test coverage detected