◐ Shell
clean mode source ↗

Specialized ops by youknowone · Pull Request #7301 · RustPython/RustPython

* Add debug_assert to invoke_exact_args, lazy func_version reassignment

- Add debug_assert preconditions in invoke_exact_args
- Add get_version_for_current_state() for lazy version reassignment
  after func_version invalidation
- Document NEXT_TYPE_VERSION overflow policy

* working

* Add COMPARE_OP, TO_BOOL, FOR_ITER, LOAD_GLOBAL specialization

- COMPARE_OP: CompareOpInt, CompareOpFloat, CompareOpStr
- TO_BOOL: ToBoolBool, ToBoolInt, ToBoolNone, ToBoolList, ToBoolStr
- FOR_ITER: ForIterRange, ForIterList, ForIterTuple with fast_next()
- LOAD_GLOBAL: LoadGlobalModule, LoadGlobalBuiltin with dict version guard
- Add version counter to Dict for mutation tracking

* Add BINARY_SUBSCR, CONTAINS_OP, UNPACK_SEQUENCE, STORE_ATTR specialization

- BinaryOpSubscrListInt, BinaryOpSubscrTupleInt, BinaryOpSubscrDict
- ContainsOpDict, ContainsOpSet
- UnpackSequenceTwoTuple, UnpackSequenceTuple, UnpackSequenceList
- StoreAttrInstanceValue with type_version guard
- Deoptimize bytecode for marshal serialization (original_bytes)
- Separate co_code (deoptimized) from _co_code_adaptive (quickened)

* Add STORE_SUBSCR, BinaryOpAddUnicode, ToBoolAlwaysTrue, CallLen, CallIsinstance, CallType1 specialization

* Add BinaryOpSubscrStrInt, CallStr1, CallTuple1 specialization

* Add BinaryOpInplaceAddUnicode specialization

* Add LoadAttrModule, CallBuiltinO, CallPyGeneral, CallBoundMethodGeneral, ForIterGen, CallListAppend specialization

* Add LoadAttrNondescriptor*, CallMethodDescriptor* specialization

- LoadAttrNondescriptorNoDict: plain class attr on objects without dict
- LoadAttrNondescriptorWithValues: plain class attr with dict fallback
- LoadAttrClass: handler for type attribute access (not yet routed)
- CallMethodDescriptorNoargs: method descriptor with 0 args
- CallMethodDescriptorO: method descriptor with 1 arg
- CallMethodDescriptorFast: method descriptor with multiple args
- Use HAS_DICT flag instead of obj.dict().is_some() for method/nondescriptor routing

* Add CallBuiltinFast, CallNonPyGeneral specialization

- CallBuiltinFast: native function calls with arbitrary positional args
- CallNonPyGeneral: fallback for unmatched callables (custom __call__, etc.)
- All builtin function calls now specialize (CallBuiltinFast as default)
- specialize_call now always produces a specialized instruction

* Add SendGen specialization for generator/coroutine send

- SendGen: direct coro.send() for generator/coroutine receivers
- Add adaptive counter to Send instruction
- specialize_send checks builtin_coro for PyGenerator/PyCoroutine

* Add LoadAttrSlot, StoreAttrSlot specialization for __slots__ access

- LoadAttrSlot: direct obj.get_slot(offset) bypassing descriptor protocol
- StoreAttrSlot: direct obj.set_slot(offset, value) bypassing descriptor protocol
- Detect PyMemberDescriptor with MemberGetter::Offset in specialize_load_attr/store_attr
- Cache slot offset in cache_base+3

* Add LoadSuperAttrAttr, LoadSuperAttrMethod, CallBuiltinClass, CallBuiltinFastWithKeywords, CallMethodDescriptorFastWithKeywords specialization

* Add LoadAttrProperty specialization for property descriptor access

* Add LoadAttrClass specialization for class attribute access

* Add BinaryOpSubscrListSlice specialization

* Add CallKwPy, CallKwBoundMethod, CallKwNonPy specialization

Fix LoadSuperAttrMethod to push unbound descriptor + self
instead of bound method + self which caused double self binding.
Fix LoadSuperAttrAttr obj_arg condition for classmethod detection.

* Clean up comments in specialization code

Remove unnecessary CPython references, FIXME→TODO,
redundant Note: prefix, and "Same as" cross-references.

* fix check_signals

* fix import