Both LOAD_FAST_CHECK and DELETE_FAST check for NULL and raise.
Replacing DELETE_FAST with LOAD_FAST_CHECK; POP_TOP DELETE_FAST could save some space.
How does replacing one instruction with three save space?
Although DELETE_FAST is dynamically rare, DELETE_FAST is statically much more common as it is used in every except Exception as name: block.
Currently at the end of named exception block we emit
LOAD_CONST None
STORE_FAST n
DELETE_FAST n
In the vast majority of these cases we could safely emit just the DELETE_FAST, using the same data flow analysis we use to convert almost all LOAD_FAST_CHECKs into LOAD_FAST
We can implement this by adding DELETE_FAST_CHECKED (for del) and DELETE_FAST_MAYBE_NULL (for the end of named exception blocks) virtual instructions to the compiler.
The data flow analysis would convert them to DELETE_FAST if it can prove that the local is defined.
The backend would convert the remaining DELETE_FAST_CHECKED to LOAD_FAST_CHECK; POP_TOP DELETE_FAST
and the remaining DELETE_FAST_MAYBE_NULL to LOAD_CONST None STORE_FAST DELETE_FAST.
@sweeneyde interested?
Both
LOAD_FAST_CHECKandDELETE_FASTcheck forNULLand raise.Replacing
DELETE_FASTwithLOAD_FAST_CHECK; POP_TOP DELETE_FASTcould save some space.How does replacing one instruction with three save space?
Although
DELETE_FASTis dynamically rare,DELETE_FASTis statically much more common as it is used in everyexcept Exception as name:block.Currently at the end of named exception block we emit
In the vast majority of these cases we could safely emit just the
DELETE_FAST, using the same data flow analysis we use to convert almost allLOAD_FAST_CHECKs intoLOAD_FASTWe can implement this by adding
DELETE_FAST_CHECKED(fordel) andDELETE_FAST_MAYBE_NULL(for the end of named exception blocks) virtual instructions to the compiler.The data flow analysis would convert them to
DELETE_FASTif it can prove that the local is defined.The backend would convert the remaining
DELETE_FAST_CHECKEDtoLOAD_FAST_CHECK; POP_TOP DELETE_FASTand the remaining
DELETE_FAST_MAYBE_NULLtoLOAD_CONST None STORE_FAST DELETE_FAST.@sweeneyde interested?