> Perhaps BUILD_CONST_KEY_MAP?
LGTM.
> Ideally the opcode could ellide the LOAD_CONST for the tuple. ie have LOAD_CONST 2 (1, 2, 3), BUILD_CONST_KEY_MAP 3 be BUILD_CONST_KEY_MAP 2 (1, 2, 3). However that'd require stack_effect to somehow lookup the const tuple
I like this idea. But PyCompile_OpcodeStackEffect() doesn't have an access to the consts dict.
> Relying on the peepholer seems unideal; it does more work than generating the tuple the first time & doing it eagerly will produce a more compact stack depth & co_consts
I thought that this would be not easy. But thanks to your encouraging I have tried to do this and the result is pretty simple.
In updated patch the opcode name was changed to BUILD_CONST_KEY_MAP, and the compiler no longer depends on the peephole optimizer for generating constant keys tuple. Thank you Demur. |