| 
									
										
										
										
											2024-02-13 21:24:48 +08:00
										 |  |  | #include "Python.h"
 | 
					
						
							| 
									
										
										
										
											2024-02-27 13:25:02 +00:00
										 |  |  | #include "pycore_optimizer.h"
 | 
					
						
							| 
									
										
										
										
											2024-02-13 21:24:48 +08:00
										 |  |  | #include "pycore_uops.h"
 | 
					
						
							|  |  |  | #include "pycore_uop_ids.h"
 | 
					
						
							| 
									
										
										
										
											2024-02-22 14:48:25 +00:00
										 |  |  | #include "internal/pycore_moduleobject.h"
 | 
					
						
							| 
									
										
										
										
											2024-02-13 21:24:48 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | #define op(name, ...) /* NAME is ignored */
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | typedef struct _Py_UOpsAbstractFrame _Py_UOpsAbstractFrame; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-27 13:25:02 +00:00
										 |  |  | /* Shortened forms for convenience */ | 
					
						
							|  |  |  | #define sym_is_not_null _Py_uop_sym_is_not_null
 | 
					
						
							|  |  |  | #define sym_is_const _Py_uop_sym_is_const
 | 
					
						
							|  |  |  | #define sym_get_const _Py_uop_sym_get_const
 | 
					
						
							|  |  |  | #define sym_new_unknown _Py_uop_sym_new_unknown
 | 
					
						
							|  |  |  | #define sym_new_not_null _Py_uop_sym_new_not_null
 | 
					
						
							|  |  |  | #define sym_new_type _Py_uop_sym_new_type
 | 
					
						
							|  |  |  | #define sym_is_null _Py_uop_sym_is_null
 | 
					
						
							|  |  |  | #define sym_new_const _Py_uop_sym_new_const
 | 
					
						
							|  |  |  | #define sym_new_null _Py_uop_sym_new_null
 | 
					
						
							|  |  |  | #define sym_matches_type _Py_uop_sym_matches_type
 | 
					
						
							| 
									
										
										
										
											2024-06-08 05:41:45 -04:00
										 |  |  | #define sym_matches_type_version _Py_uop_sym_matches_type_version
 | 
					
						
							| 
									
										
										
										
											2024-04-22 13:34:06 +01:00
										 |  |  | #define sym_get_type _Py_uop_sym_get_type
 | 
					
						
							| 
									
										
										
										
											2024-03-05 15:06:00 +00:00
										 |  |  | #define sym_has_type _Py_uop_sym_has_type
 | 
					
						
							| 
									
										
										
										
											2024-05-10 17:43:23 +01:00
										 |  |  | #define sym_set_null(SYM) _Py_uop_sym_set_null(ctx, SYM)
 | 
					
						
							|  |  |  | #define sym_set_non_null(SYM) _Py_uop_sym_set_non_null(ctx, SYM)
 | 
					
						
							|  |  |  | #define sym_set_type(SYM, TYPE) _Py_uop_sym_set_type(ctx, SYM, TYPE)
 | 
					
						
							| 
									
										
										
										
											2024-06-08 05:41:45 -04:00
										 |  |  | #define sym_set_type_version(SYM, VERSION) _Py_uop_sym_set_type_version(ctx, SYM, VERSION)
 | 
					
						
							| 
									
										
										
										
											2024-05-10 17:43:23 +01:00
										 |  |  | #define sym_set_const(SYM, CNST) _Py_uop_sym_set_const(ctx, SYM, CNST)
 | 
					
						
							| 
									
										
										
										
											2024-02-28 14:38:01 -08:00
										 |  |  | #define sym_is_bottom _Py_uop_sym_is_bottom
 | 
					
						
							| 
									
										
										
										
											2024-02-27 13:25:02 +00:00
										 |  |  | #define frame_new _Py_uop_frame_new
 | 
					
						
							|  |  |  | #define frame_pop _Py_uop_frame_pop
 | 
					
						
							| 
									
										
										
										
											2025-01-20 15:49:15 +00:00
										 |  |  | #define sym_new_tuple _Py_uop_sym_new_tuple
 | 
					
						
							|  |  |  | #define sym_tuple_getitem _Py_uop_sym_tuple_getitem
 | 
					
						
							|  |  |  | #define sym_tuple_length _Py_uop_sym_tuple_length
 | 
					
						
							|  |  |  | #define sym_is_immortal _Py_uop_sym_is_immortal
 | 
					
						
							| 
									
										
										
										
											2025-03-02 13:21:34 -08:00
										 |  |  | #define sym_new_truthiness _Py_uop_sym_new_truthiness
 | 
					
						
							| 
									
										
										
										
											2024-02-27 13:25:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-05 11:23:46 +00:00
										 |  |  | extern int | 
					
						
							|  |  |  | optimize_to_bool( | 
					
						
							|  |  |  |     _PyUOpInstruction *this_instr, | 
					
						
							| 
									
										
										
										
											2025-01-20 15:49:15 +00:00
										 |  |  |     JitOptContext *ctx, | 
					
						
							|  |  |  |     JitOptSymbol *value, | 
					
						
							|  |  |  |     JitOptSymbol **result_ptr); | 
					
						
							| 
									
										
										
										
											2024-03-05 11:23:46 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-05 15:06:00 +00:00
										 |  |  | extern void | 
					
						
							| 
									
										
										
										
											2024-04-18 11:09:30 +01:00
										 |  |  | eliminate_pop_guard(_PyUOpInstruction *this_instr, bool exit); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | extern PyCodeObject *get_code(_PyUOpInstruction *op); | 
					
						
							| 
									
										
										
										
											2024-03-05 11:23:46 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-13 21:24:48 +08:00
										 |  |  | static int | 
					
						
							|  |  |  | dummy_func(void) { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-18 11:09:30 +01:00
										 |  |  |     PyCodeObject *co; | 
					
						
							| 
									
										
										
										
											2024-02-13 21:24:48 +08:00
										 |  |  |     int oparg; | 
					
						
							| 
									
										
										
										
											2025-01-20 15:49:15 +00:00
										 |  |  |     JitOptSymbol *flag; | 
					
						
							|  |  |  |     JitOptSymbol *left; | 
					
						
							|  |  |  |     JitOptSymbol *right; | 
					
						
							|  |  |  |     JitOptSymbol *value; | 
					
						
							|  |  |  |     JitOptSymbol *res; | 
					
						
							|  |  |  |     JitOptSymbol *iter; | 
					
						
							|  |  |  |     JitOptSymbol *top; | 
					
						
							|  |  |  |     JitOptSymbol *bottom; | 
					
						
							| 
									
										
										
										
											2024-02-13 21:24:48 +08:00
										 |  |  |     _Py_UOpsAbstractFrame *frame; | 
					
						
							| 
									
										
										
										
											2024-04-18 11:09:30 +01:00
										 |  |  |     _Py_UOpsAbstractFrame *new_frame; | 
					
						
							| 
									
										
										
										
											2025-01-20 15:49:15 +00:00
										 |  |  |     JitOptContext *ctx; | 
					
						
							| 
									
										
										
										
											2024-02-13 21:24:48 +08:00
										 |  |  |     _PyUOpInstruction *this_instr; | 
					
						
							|  |  |  |     _PyBloomFilter *dependencies; | 
					
						
							|  |  |  |     int modified; | 
					
						
							| 
									
										
										
										
											2024-04-18 11:09:30 +01:00
										 |  |  |     int curr_space; | 
					
						
							|  |  |  |     int max_space; | 
					
						
							|  |  |  |     _PyUOpInstruction *first_valid_check_stack; | 
					
						
							|  |  |  |     _PyUOpInstruction *corresponding_check_stack; | 
					
						
							| 
									
										
										
										
											2024-02-13 21:24:48 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | // BEGIN BYTECODES //
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     op(_LOAD_FAST_CHECK, (-- value)) { | 
					
						
							|  |  |  |         value = GETLOCAL(oparg); | 
					
						
							|  |  |  |         // We guarantee this will error - just bail and don't optimize it.
 | 
					
						
							| 
									
										
										
										
											2024-02-27 13:25:02 +00:00
										 |  |  |         if (sym_is_null(value)) { | 
					
						
							| 
									
										
										
										
											2024-05-10 17:43:23 +01:00
										 |  |  |             ctx->done = true; | 
					
						
							| 
									
										
										
										
											2024-02-13 21:24:48 +08:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     op(_LOAD_FAST, (-- value)) { | 
					
						
							|  |  |  |         value = GETLOCAL(oparg); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     op(_LOAD_FAST_AND_CLEAR, (-- value)) { | 
					
						
							|  |  |  |         value = GETLOCAL(oparg); | 
					
						
							| 
									
										
										
										
											2025-01-20 15:49:15 +00:00
										 |  |  |         JitOptSymbol *temp = sym_new_null(ctx); | 
					
						
							| 
									
										
										
										
											2024-02-13 21:24:48 +08:00
										 |  |  |         GETLOCAL(oparg) = temp; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     op(_STORE_FAST, (value --)) { | 
					
						
							|  |  |  |         GETLOCAL(oparg) = value; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     op(_PUSH_NULL, (-- res)) { | 
					
						
							| 
									
										
										
										
											2024-02-27 13:25:02 +00:00
										 |  |  |         res = sym_new_null(ctx); | 
					
						
							| 
									
										
										
										
											2024-02-13 21:24:48 +08:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     op(_GUARD_BOTH_INT, (left, right -- left, right)) { | 
					
						
							| 
									
										
										
										
											2024-04-22 13:34:06 +01:00
										 |  |  |         if (sym_matches_type(left, &PyLong_Type)) { | 
					
						
							|  |  |  |             if (sym_matches_type(right, &PyLong_Type)) { | 
					
						
							|  |  |  |                 REPLACE_OP(this_instr, _NOP, 0, 0); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             else { | 
					
						
							|  |  |  |                 REPLACE_OP(this_instr, _GUARD_TOS_INT, 0, 0); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         else { | 
					
						
							|  |  |  |             if (sym_matches_type(right, &PyLong_Type)) { | 
					
						
							|  |  |  |                 REPLACE_OP(this_instr, _GUARD_NOS_INT, 0, 0); | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2024-02-13 21:24:48 +08:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2024-05-10 17:43:23 +01:00
										 |  |  |         sym_set_type(left, &PyLong_Type); | 
					
						
							|  |  |  |         sym_set_type(right, &PyLong_Type); | 
					
						
							| 
									
										
										
										
											2024-02-13 21:24:48 +08:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-08 05:41:45 -04:00
										 |  |  |     op(_GUARD_TYPE_VERSION, (type_version/2, owner -- owner)) { | 
					
						
							|  |  |  |         assert(type_version); | 
					
						
							|  |  |  |         if (sym_matches_type_version(owner, type_version)) { | 
					
						
							|  |  |  |             REPLACE_OP(this_instr, _NOP, 0, 0); | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             // add watcher so that whenever the type changes we invalidate this
 | 
					
						
							|  |  |  |             PyTypeObject *type = _PyType_LookupByVersion(type_version); | 
					
						
							|  |  |  |             // if the type is null, it was not found in the cache (there was a conflict)
 | 
					
						
							|  |  |  |             // with the key, in which case we can't trust the version
 | 
					
						
							|  |  |  |             if (type) { | 
					
						
							|  |  |  |                 // if the type version was set properly, then add a watcher
 | 
					
						
							|  |  |  |                 // if it wasn't this means that the type version was previously set to something else
 | 
					
						
							|  |  |  |                 // and we set the owner to bottom, so we don't need to add a watcher because we must have
 | 
					
						
							|  |  |  |                 // already added one earlier.
 | 
					
						
							|  |  |  |                 if (sym_set_type_version(owner, type_version)) { | 
					
						
							|  |  |  |                     PyType_Watch(TYPE_WATCHER_ID, (PyObject *)type); | 
					
						
							|  |  |  |                     _Py_BloomFilter_Add(dependencies, type); | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-13 21:24:48 +08:00
										 |  |  |     op(_GUARD_BOTH_FLOAT, (left, right -- left, right)) { | 
					
						
							| 
									
										
										
										
											2024-04-22 13:34:06 +01:00
										 |  |  |         if (sym_matches_type(left, &PyFloat_Type)) { | 
					
						
							|  |  |  |             if (sym_matches_type(right, &PyFloat_Type)) { | 
					
						
							|  |  |  |                 REPLACE_OP(this_instr, _NOP, 0, 0); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             else { | 
					
						
							|  |  |  |                 REPLACE_OP(this_instr, _GUARD_TOS_FLOAT, 0, 0); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         else { | 
					
						
							|  |  |  |             if (sym_matches_type(right, &PyFloat_Type)) { | 
					
						
							|  |  |  |                 REPLACE_OP(this_instr, _GUARD_NOS_FLOAT, 0, 0); | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2024-02-13 21:24:48 +08:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2024-05-10 17:43:23 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         sym_set_type(left, &PyFloat_Type); | 
					
						
							|  |  |  |         sym_set_type(right, &PyFloat_Type); | 
					
						
							| 
									
										
										
										
											2024-02-13 21:24:48 +08:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-20 19:30:49 +08:00
										 |  |  |     op(_GUARD_BOTH_UNICODE, (left, right -- left, right)) { | 
					
						
							| 
									
										
										
										
											2024-02-27 13:25:02 +00:00
										 |  |  |         if (sym_matches_type(left, &PyUnicode_Type) && | 
					
						
							|  |  |  |             sym_matches_type(right, &PyUnicode_Type)) { | 
					
						
							| 
									
										
										
										
											2024-02-20 19:30:49 +08:00
										 |  |  |             REPLACE_OP(this_instr, _NOP, 0 ,0); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2024-05-10 17:43:23 +01:00
										 |  |  |         sym_set_type(left, &PyUnicode_Type); | 
					
						
							| 
									
										
										
										
											2025-03-06 22:11:08 +11:00
										 |  |  |         sym_set_type(right, &PyUnicode_Type); | 
					
						
							| 
									
										
										
										
											2024-02-20 19:30:49 +08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2024-02-13 21:24:48 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-22 13:34:06 +01:00
										 |  |  |     op(_BINARY_OP, (left, right -- res)) { | 
					
						
							| 
									
										
										
										
											2025-01-07 17:25:48 -08:00
										 |  |  |         bool lhs_int = sym_matches_type(left, &PyLong_Type); | 
					
						
							|  |  |  |         bool rhs_int = sym_matches_type(right, &PyLong_Type); | 
					
						
							|  |  |  |         bool lhs_float = sym_matches_type(left, &PyFloat_Type); | 
					
						
							|  |  |  |         bool rhs_float = sym_matches_type(right, &PyFloat_Type); | 
					
						
							|  |  |  |         if (!((lhs_int || lhs_float) && (rhs_int || rhs_float))) { | 
					
						
							|  |  |  |             // There's something other than an int or float involved:
 | 
					
						
							|  |  |  |             res = sym_new_unknown(ctx); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         else if (oparg == NB_POWER || oparg == NB_INPLACE_POWER) { | 
					
						
							|  |  |  |             // This one's fun... the *type* of the result depends on the
 | 
					
						
							|  |  |  |             // *values* being exponentiated. However, exponents with one
 | 
					
						
							|  |  |  |             // constant part are reasonably common, so it's probably worth
 | 
					
						
							|  |  |  |             // trying to infer some simple cases:
 | 
					
						
							|  |  |  |             // - A: 1 ** 1 -> 1 (int ** int -> int)
 | 
					
						
							|  |  |  |             // - B: 1 ** -1 -> 1.0 (int ** int -> float)
 | 
					
						
							|  |  |  |             // - C: 1.0 ** 1 -> 1.0 (float ** int -> float)
 | 
					
						
							|  |  |  |             // - D: 1 ** 1.0 -> 1.0 (int ** float -> float)
 | 
					
						
							|  |  |  |             // - E: -1 ** 0.5 ~> 1j (int ** float -> complex)
 | 
					
						
							|  |  |  |             // - F: 1.0 ** 1.0 -> 1.0 (float ** float -> float)
 | 
					
						
							|  |  |  |             // - G: -1.0 ** 0.5 ~> 1j (float ** float -> complex)
 | 
					
						
							|  |  |  |             if (rhs_float) { | 
					
						
							|  |  |  |                 // Case D, E, F, or G... can't know without the sign of the LHS
 | 
					
						
							|  |  |  |                 // or whether the RHS is whole, which isn't worth the effort:
 | 
					
						
							|  |  |  |                 res = sym_new_unknown(ctx); | 
					
						
							| 
									
										
										
										
											2024-04-22 13:34:06 +01:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2025-01-07 17:25:48 -08:00
										 |  |  |             else if (lhs_float) { | 
					
						
							|  |  |  |                 // Case C:
 | 
					
						
							|  |  |  |                 res = sym_new_type(ctx, &PyFloat_Type); | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2025-03-02 13:21:34 -08:00
										 |  |  |             else if (!sym_is_const(ctx, right)) { | 
					
						
							| 
									
										
										
										
											2025-01-07 17:25:48 -08:00
										 |  |  |                 // Case A or B... can't know without the sign of the RHS:
 | 
					
						
							|  |  |  |                 res = sym_new_unknown(ctx); | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2025-03-02 13:21:34 -08:00
										 |  |  |             else if (_PyLong_IsNegative((PyLongObject *)sym_get_const(ctx, right))) { | 
					
						
							| 
									
										
										
										
											2025-01-07 17:25:48 -08:00
										 |  |  |                 // Case B:
 | 
					
						
							| 
									
										
										
										
											2024-05-10 17:43:23 +01:00
										 |  |  |                 res = sym_new_type(ctx, &PyFloat_Type); | 
					
						
							| 
									
										
										
										
											2024-04-22 13:34:06 +01:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2025-01-07 17:25:48 -08:00
										 |  |  |             else { | 
					
						
							|  |  |  |                 // Case A:
 | 
					
						
							|  |  |  |                 res = sym_new_type(ctx, &PyLong_Type); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         else if (oparg == NB_TRUE_DIVIDE || oparg == NB_INPLACE_TRUE_DIVIDE) { | 
					
						
							|  |  |  |             res = sym_new_type(ctx, &PyFloat_Type); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         else if (lhs_int && rhs_int) { | 
					
						
							|  |  |  |             res = sym_new_type(ctx, &PyLong_Type); | 
					
						
							| 
									
										
										
										
											2024-04-22 13:34:06 +01:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2024-10-07 14:56:39 +01:00
										 |  |  |         else { | 
					
						
							| 
									
										
										
										
											2025-01-07 17:25:48 -08:00
										 |  |  |             res = sym_new_type(ctx, &PyFloat_Type); | 
					
						
							| 
									
										
										
										
											2024-10-07 14:56:39 +01:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2024-04-22 13:34:06 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-13 21:24:48 +08:00
										 |  |  |     op(_BINARY_OP_ADD_INT, (left, right -- res)) { | 
					
						
							| 
									
										
										
										
											2025-03-27 09:12:30 -07:00
										 |  |  |         if (sym_is_const(ctx, left) && sym_is_const(ctx, right)) { | 
					
						
							| 
									
										
										
										
											2025-03-02 13:21:34 -08:00
										 |  |  |             assert(PyLong_CheckExact(sym_get_const(ctx, left))); | 
					
						
							|  |  |  |             assert(PyLong_CheckExact(sym_get_const(ctx, right))); | 
					
						
							|  |  |  |             PyObject *temp = _PyLong_Add((PyLongObject *)sym_get_const(ctx, left), | 
					
						
							|  |  |  |                                          (PyLongObject *)sym_get_const(ctx, right)); | 
					
						
							| 
									
										
										
										
											2024-02-15 14:02:18 +08:00
										 |  |  |             if (temp == NULL) { | 
					
						
							|  |  |  |                 goto error; | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2024-02-28 14:38:01 -08:00
										 |  |  |             res = sym_new_const(ctx, temp); | 
					
						
							|  |  |  |             Py_DECREF(temp); | 
					
						
							| 
									
										
										
										
											2024-02-16 22:59:43 +08:00
										 |  |  |             // TODO gh-115506:
 | 
					
						
							|  |  |  |             // replace opcode with constant propagated one and add tests!
 | 
					
						
							| 
									
										
										
										
											2024-02-15 14:02:18 +08:00
										 |  |  |         } | 
					
						
							|  |  |  |         else { | 
					
						
							| 
									
										
										
										
											2024-05-10 17:43:23 +01:00
										 |  |  |             res = sym_new_type(ctx, &PyLong_Type); | 
					
						
							| 
									
										
										
										
											2024-02-15 14:02:18 +08:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     op(_BINARY_OP_SUBTRACT_INT, (left, right -- res)) { | 
					
						
							| 
									
										
										
										
											2025-03-27 09:12:30 -07:00
										 |  |  |         if (sym_is_const(ctx, left) && sym_is_const(ctx, right)) { | 
					
						
							| 
									
										
										
										
											2025-03-02 13:21:34 -08:00
										 |  |  |             assert(PyLong_CheckExact(sym_get_const(ctx, left))); | 
					
						
							|  |  |  |             assert(PyLong_CheckExact(sym_get_const(ctx, right))); | 
					
						
							|  |  |  |             PyObject *temp = _PyLong_Subtract((PyLongObject *)sym_get_const(ctx, left), | 
					
						
							|  |  |  |                                               (PyLongObject *)sym_get_const(ctx, right)); | 
					
						
							| 
									
										
										
										
											2024-02-15 14:02:18 +08:00
										 |  |  |             if (temp == NULL) { | 
					
						
							|  |  |  |                 goto error; | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2024-02-28 14:38:01 -08:00
										 |  |  |             res = sym_new_const(ctx, temp); | 
					
						
							|  |  |  |             Py_DECREF(temp); | 
					
						
							| 
									
										
										
										
											2024-02-16 22:59:43 +08:00
										 |  |  |             // TODO gh-115506:
 | 
					
						
							|  |  |  |             // replace opcode with constant propagated one and add tests!
 | 
					
						
							| 
									
										
										
										
											2024-02-15 14:02:18 +08:00
										 |  |  |         } | 
					
						
							|  |  |  |         else { | 
					
						
							| 
									
										
										
										
											2024-05-10 17:43:23 +01:00
										 |  |  |             res = sym_new_type(ctx, &PyLong_Type); | 
					
						
							| 
									
										
										
										
											2024-02-15 14:02:18 +08:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     op(_BINARY_OP_MULTIPLY_INT, (left, right -- res)) { | 
					
						
							| 
									
										
										
										
											2025-03-27 09:12:30 -07:00
										 |  |  |         if (sym_is_const(ctx, left) && sym_is_const(ctx, right)) { | 
					
						
							| 
									
										
										
										
											2025-03-02 13:21:34 -08:00
										 |  |  |             assert(PyLong_CheckExact(sym_get_const(ctx, left))); | 
					
						
							|  |  |  |             assert(PyLong_CheckExact(sym_get_const(ctx, right))); | 
					
						
							|  |  |  |             PyObject *temp = _PyLong_Multiply((PyLongObject *)sym_get_const(ctx, left), | 
					
						
							|  |  |  |                                               (PyLongObject *)sym_get_const(ctx, right)); | 
					
						
							| 
									
										
										
										
											2024-02-15 14:02:18 +08:00
										 |  |  |             if (temp == NULL) { | 
					
						
							|  |  |  |                 goto error; | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2024-02-28 14:38:01 -08:00
										 |  |  |             res = sym_new_const(ctx, temp); | 
					
						
							|  |  |  |             Py_DECREF(temp); | 
					
						
							| 
									
										
										
										
											2024-02-16 22:59:43 +08:00
										 |  |  |             // TODO gh-115506:
 | 
					
						
							|  |  |  |             // replace opcode with constant propagated one and add tests!
 | 
					
						
							| 
									
										
										
										
											2024-02-15 14:02:18 +08:00
										 |  |  |         } | 
					
						
							|  |  |  |         else { | 
					
						
							| 
									
										
										
										
											2024-05-10 17:43:23 +01:00
										 |  |  |             res = sym_new_type(ctx, &PyLong_Type); | 
					
						
							| 
									
										
										
										
											2024-02-13 21:24:48 +08:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-16 10:02:48 -08:00
										 |  |  |     op(_BINARY_OP_ADD_FLOAT, (left, right -- res)) { | 
					
						
							| 
									
										
										
										
											2025-03-27 09:12:30 -07:00
										 |  |  |         if (sym_is_const(ctx, left) && sym_is_const(ctx, right)) { | 
					
						
							| 
									
										
										
										
											2025-03-02 13:21:34 -08:00
										 |  |  |             assert(PyFloat_CheckExact(sym_get_const(ctx, left))); | 
					
						
							|  |  |  |             assert(PyFloat_CheckExact(sym_get_const(ctx, right))); | 
					
						
							| 
									
										
										
										
											2024-02-16 10:02:48 -08:00
										 |  |  |             PyObject *temp = PyFloat_FromDouble( | 
					
						
							| 
									
										
										
										
											2025-03-02 13:21:34 -08:00
										 |  |  |                 PyFloat_AS_DOUBLE(sym_get_const(ctx, left)) + | 
					
						
							|  |  |  |                 PyFloat_AS_DOUBLE(sym_get_const(ctx, right))); | 
					
						
							| 
									
										
										
										
											2024-02-16 10:02:48 -08:00
										 |  |  |             if (temp == NULL) { | 
					
						
							|  |  |  |                 goto error; | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2024-02-27 13:25:02 +00:00
										 |  |  |             res = sym_new_const(ctx, temp); | 
					
						
							| 
									
										
										
										
											2024-02-28 14:38:01 -08:00
										 |  |  |             Py_DECREF(temp); | 
					
						
							| 
									
										
										
										
											2024-02-16 10:02:48 -08:00
										 |  |  |             // TODO gh-115506:
 | 
					
						
							|  |  |  |             // replace opcode with constant propagated one and update tests!
 | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         else { | 
					
						
							| 
									
										
										
										
											2024-05-10 17:43:23 +01:00
										 |  |  |             res = sym_new_type(ctx, &PyFloat_Type); | 
					
						
							| 
									
										
										
										
											2024-02-16 10:02:48 -08:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     op(_BINARY_OP_SUBTRACT_FLOAT, (left, right -- res)) { | 
					
						
							| 
									
										
										
										
											2025-03-27 09:12:30 -07:00
										 |  |  |         if (sym_is_const(ctx, left) && sym_is_const(ctx, right)) { | 
					
						
							| 
									
										
										
										
											2025-03-02 13:21:34 -08:00
										 |  |  |             assert(PyFloat_CheckExact(sym_get_const(ctx, left))); | 
					
						
							|  |  |  |             assert(PyFloat_CheckExact(sym_get_const(ctx, right))); | 
					
						
							| 
									
										
										
										
											2024-02-16 10:02:48 -08:00
										 |  |  |             PyObject *temp = PyFloat_FromDouble( | 
					
						
							| 
									
										
										
										
											2025-03-02 13:21:34 -08:00
										 |  |  |                 PyFloat_AS_DOUBLE(sym_get_const(ctx, left)) - | 
					
						
							|  |  |  |                 PyFloat_AS_DOUBLE(sym_get_const(ctx, right))); | 
					
						
							| 
									
										
										
										
											2024-02-16 10:02:48 -08:00
										 |  |  |             if (temp == NULL) { | 
					
						
							|  |  |  |                 goto error; | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2024-02-27 13:25:02 +00:00
										 |  |  |             res = sym_new_const(ctx, temp); | 
					
						
							| 
									
										
										
										
											2024-02-28 14:38:01 -08:00
										 |  |  |             Py_DECREF(temp); | 
					
						
							| 
									
										
										
										
											2024-02-16 10:02:48 -08:00
										 |  |  |             // TODO gh-115506:
 | 
					
						
							|  |  |  |             // replace opcode with constant propagated one and update tests!
 | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         else { | 
					
						
							| 
									
										
										
										
											2024-05-10 17:43:23 +01:00
										 |  |  |             res = sym_new_type(ctx, &PyFloat_Type); | 
					
						
							| 
									
										
										
										
											2024-02-16 10:02:48 -08:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     op(_BINARY_OP_MULTIPLY_FLOAT, (left, right -- res)) { | 
					
						
							| 
									
										
										
										
											2025-03-27 09:12:30 -07:00
										 |  |  |         if (sym_is_const(ctx, left) && sym_is_const(ctx, right)) { | 
					
						
							| 
									
										
										
										
											2025-03-02 13:21:34 -08:00
										 |  |  |             assert(PyFloat_CheckExact(sym_get_const(ctx, left))); | 
					
						
							|  |  |  |             assert(PyFloat_CheckExact(sym_get_const(ctx, right))); | 
					
						
							| 
									
										
										
										
											2024-02-16 10:02:48 -08:00
										 |  |  |             PyObject *temp = PyFloat_FromDouble( | 
					
						
							| 
									
										
										
										
											2025-03-02 13:21:34 -08:00
										 |  |  |                 PyFloat_AS_DOUBLE(sym_get_const(ctx, left)) * | 
					
						
							|  |  |  |                 PyFloat_AS_DOUBLE(sym_get_const(ctx, right))); | 
					
						
							| 
									
										
										
										
											2024-02-16 10:02:48 -08:00
										 |  |  |             if (temp == NULL) { | 
					
						
							|  |  |  |                 goto error; | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2024-02-27 13:25:02 +00:00
										 |  |  |             res = sym_new_const(ctx, temp); | 
					
						
							| 
									
										
										
										
											2024-02-28 14:38:01 -08:00
										 |  |  |             Py_DECREF(temp); | 
					
						
							| 
									
										
										
										
											2024-02-16 10:02:48 -08:00
										 |  |  |             // TODO gh-115506:
 | 
					
						
							|  |  |  |             // replace opcode with constant propagated one and update tests!
 | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         else { | 
					
						
							| 
									
										
										
										
											2024-05-10 17:43:23 +01:00
										 |  |  |             res = sym_new_type(ctx, &PyFloat_Type); | 
					
						
							| 
									
										
										
										
											2024-02-16 10:02:48 -08:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2024-03-02 03:40:04 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     op(_BINARY_OP_ADD_UNICODE, (left, right -- res)) { | 
					
						
							| 
									
										
										
										
											2025-03-27 09:12:30 -07:00
										 |  |  |         if (sym_is_const(ctx, left) && sym_is_const(ctx, right)) { | 
					
						
							|  |  |  |             assert(PyUnicode_CheckExact(sym_get_const(ctx, left))); | 
					
						
							|  |  |  |             assert(PyUnicode_CheckExact(sym_get_const(ctx, right))); | 
					
						
							| 
									
										
										
										
											2025-03-02 13:21:34 -08:00
										 |  |  |             PyObject *temp = PyUnicode_Concat(sym_get_const(ctx, left), sym_get_const(ctx, right)); | 
					
						
							| 
									
										
										
										
											2024-03-02 03:40:04 +08:00
										 |  |  |             if (temp == NULL) { | 
					
						
							|  |  |  |                 goto error; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             res = sym_new_const(ctx, temp); | 
					
						
							|  |  |  |             Py_DECREF(temp); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         else { | 
					
						
							| 
									
										
										
										
											2024-05-10 17:43:23 +01:00
										 |  |  |             res = sym_new_type(ctx, &PyUnicode_Type); | 
					
						
							| 
									
										
										
										
											2024-03-02 03:40:04 +08:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2024-02-16 10:02:48 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-28 14:37:16 -07:00
										 |  |  |     op(_BINARY_OP_INPLACE_ADD_UNICODE, (left, right -- )) { | 
					
						
							| 
									
										
										
										
											2025-01-20 15:49:15 +00:00
										 |  |  |         JitOptSymbol *res; | 
					
						
							| 
									
										
										
										
											2025-03-27 09:12:30 -07:00
										 |  |  |         if (sym_is_const(ctx, left) && sym_is_const(ctx, right)) { | 
					
						
							|  |  |  |             assert(PyUnicode_CheckExact(sym_get_const(ctx, left))); | 
					
						
							|  |  |  |             assert(PyUnicode_CheckExact(sym_get_const(ctx, right))); | 
					
						
							| 
									
										
										
										
											2025-03-02 13:21:34 -08:00
										 |  |  |             PyObject *temp = PyUnicode_Concat(sym_get_const(ctx, left), sym_get_const(ctx, right)); | 
					
						
							| 
									
										
										
										
											2024-10-28 14:37:16 -07:00
										 |  |  |             if (temp == NULL) { | 
					
						
							|  |  |  |                 goto error; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             res = sym_new_const(ctx, temp); | 
					
						
							|  |  |  |             Py_DECREF(temp); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         else { | 
					
						
							|  |  |  |             res = sym_new_type(ctx, &PyUnicode_Type); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         // _STORE_FAST:
 | 
					
						
							| 
									
										
										
										
											2024-11-09 11:35:33 +08:00
										 |  |  |         GETLOCAL(this_instr->operand0) = res; | 
					
						
							| 
									
										
										
										
											2024-10-28 14:37:16 -07:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-02-07 22:39:54 +00:00
										 |  |  |     op(_BINARY_OP_SUBSCR_INIT_CALL, (container, sub, getitem  -- new_frame: _Py_UOpsAbstractFrame *)) { | 
					
						
							| 
									
										
										
										
											2024-08-12 18:35:52 +01:00
										 |  |  |         new_frame = NULL; | 
					
						
							|  |  |  |         ctx->done = true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-01 06:13:38 +08:00
										 |  |  |     op(_TO_BOOL, (value -- res)) { | 
					
						
							| 
									
										
										
										
											2024-05-10 17:43:23 +01:00
										 |  |  |         if (!optimize_to_bool(this_instr, ctx, value, &res)) { | 
					
						
							| 
									
										
										
										
											2025-03-02 13:21:34 -08:00
										 |  |  |             res = sym_new_truthiness(ctx, value, true); | 
					
						
							| 
									
										
										
										
											2024-03-05 11:23:46 +00:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2024-03-01 06:13:38 +08:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-05 11:23:46 +00:00
										 |  |  |     op(_TO_BOOL_BOOL, (value -- res)) { | 
					
						
							| 
									
										
										
										
											2024-05-10 17:43:23 +01:00
										 |  |  |         if (!optimize_to_bool(this_instr, ctx, value, &res)) { | 
					
						
							|  |  |  |             sym_set_type(value, &PyBool_Type); | 
					
						
							| 
									
										
										
										
											2025-03-02 13:21:34 -08:00
										 |  |  |             res = sym_new_truthiness(ctx, value, true); | 
					
						
							| 
									
										
										
										
											2024-03-01 06:13:38 +08:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     op(_TO_BOOL_INT, (value -- res)) { | 
					
						
							| 
									
										
										
										
											2024-05-10 17:43:23 +01:00
										 |  |  |         if (!optimize_to_bool(this_instr, ctx, value, &res)) { | 
					
						
							|  |  |  |             sym_set_type(value, &PyLong_Type); | 
					
						
							| 
									
										
										
										
											2025-03-04 12:44:09 -08:00
										 |  |  |             res = sym_new_truthiness(ctx, value, true); | 
					
						
							| 
									
										
										
										
											2024-03-01 06:13:38 +08:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     op(_TO_BOOL_LIST, (value -- res)) { | 
					
						
							| 
									
										
										
										
											2024-05-10 17:43:23 +01:00
										 |  |  |         if (!optimize_to_bool(this_instr, ctx, value, &res)) { | 
					
						
							|  |  |  |             sym_set_type(value, &PyList_Type); | 
					
						
							|  |  |  |             res = sym_new_type(ctx, &PyBool_Type); | 
					
						
							| 
									
										
										
										
											2024-03-01 06:13:38 +08:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     op(_TO_BOOL_NONE, (value -- res)) { | 
					
						
							| 
									
										
										
										
											2024-05-10 17:43:23 +01:00
										 |  |  |         if (!optimize_to_bool(this_instr, ctx, value, &res)) { | 
					
						
							|  |  |  |             sym_set_const(value, Py_None); | 
					
						
							|  |  |  |             res = sym_new_const(ctx, Py_False); | 
					
						
							| 
									
										
										
										
											2024-03-01 06:13:38 +08:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-03-30 16:07:25 -07:00
										 |  |  |     op(_GUARD_TOS_UNICODE, (value -- value)) { | 
					
						
							|  |  |  |         if (sym_matches_type(value, &PyUnicode_Type)) { | 
					
						
							|  |  |  |             REPLACE_OP(this_instr, _NOP, 0, 0); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         sym_set_type(value, &PyUnicode_Type); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-01 06:13:38 +08:00
										 |  |  |     op(_TO_BOOL_STR, (value -- res)) { | 
					
						
							| 
									
										
										
										
											2024-05-10 17:43:23 +01:00
										 |  |  |         if (!optimize_to_bool(this_instr, ctx, value, &res)) { | 
					
						
							| 
									
										
										
										
											2025-03-04 13:20:17 -08:00
										 |  |  |             res = sym_new_truthiness(ctx, value, true); | 
					
						
							| 
									
										
										
										
											2024-03-01 06:13:38 +08:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-03-02 13:21:34 -08:00
										 |  |  |     op(_UNARY_NOT, (value -- res)) { | 
					
						
							|  |  |  |         sym_set_type(value, &PyBool_Type); | 
					
						
							|  |  |  |         res = sym_new_truthiness(ctx, value, false); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-06 10:46:42 +00:00
										 |  |  |     op(_COMPARE_OP, (left, right -- res)) { | 
					
						
							|  |  |  |         if (oparg & 16) { | 
					
						
							| 
									
										
										
										
											2024-05-10 17:43:23 +01:00
										 |  |  |             res = sym_new_type(ctx, &PyBool_Type); | 
					
						
							| 
									
										
										
										
											2024-03-06 10:46:42 +00:00
										 |  |  |         } | 
					
						
							|  |  |  |         else { | 
					
						
							| 
									
										
										
										
											2024-05-10 17:43:23 +01:00
										 |  |  |             res = _Py_uop_sym_new_not_null(ctx); | 
					
						
							| 
									
										
										
										
											2024-03-06 10:46:42 +00:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     op(_COMPARE_OP_INT, (left, right -- res)) { | 
					
						
							| 
									
										
										
										
											2025-03-27 09:12:30 -07:00
										 |  |  |         if (sym_is_const(ctx, left) && sym_is_const(ctx, right)) { | 
					
						
							| 
									
										
										
										
											2025-03-21 11:23:12 -07:00
										 |  |  |             assert(PyLong_CheckExact(sym_get_const(ctx, left))); | 
					
						
							|  |  |  |             assert(PyLong_CheckExact(sym_get_const(ctx, right))); | 
					
						
							|  |  |  |             PyObject *tmp = PyObject_RichCompare(sym_get_const(ctx, left), | 
					
						
							|  |  |  |                                                  sym_get_const(ctx, right), | 
					
						
							|  |  |  |                                                  oparg >> 5); | 
					
						
							|  |  |  |             if (tmp == NULL) { | 
					
						
							|  |  |  |                 goto error; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             assert(PyBool_Check(tmp)); | 
					
						
							|  |  |  |             assert(_Py_IsImmortal(tmp)); | 
					
						
							|  |  |  |             REPLACE_OP(this_instr, _POP_TWO_LOAD_CONST_INLINE_BORROW, 0, (uintptr_t)tmp); | 
					
						
							|  |  |  |             res = sym_new_const(ctx, tmp); | 
					
						
							|  |  |  |             Py_DECREF(tmp); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         else { | 
					
						
							|  |  |  |             res = sym_new_type(ctx, &PyBool_Type); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2024-03-06 10:46:42 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     op(_COMPARE_OP_FLOAT, (left, right -- res)) { | 
					
						
							| 
									
										
										
										
											2024-05-10 17:43:23 +01:00
										 |  |  |         res = sym_new_type(ctx, &PyBool_Type); | 
					
						
							| 
									
										
										
										
											2024-03-06 10:46:42 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     op(_COMPARE_OP_STR, (left, right -- res)) { | 
					
						
							| 
									
										
										
										
											2024-05-10 17:43:23 +01:00
										 |  |  |         res = sym_new_type(ctx, &PyBool_Type); | 
					
						
							| 
									
										
										
										
											2024-03-06 10:46:42 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     op(_IS_OP, (left, right -- res)) { | 
					
						
							| 
									
										
										
										
											2024-05-10 17:43:23 +01:00
										 |  |  |         res = sym_new_type(ctx, &PyBool_Type); | 
					
						
							| 
									
										
										
										
											2024-03-06 10:46:42 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     op(_CONTAINS_OP, (left, right -- res)) { | 
					
						
							| 
									
										
										
										
											2024-05-10 17:43:23 +01:00
										 |  |  |         res = sym_new_type(ctx, &PyBool_Type); | 
					
						
							| 
									
										
										
										
											2024-03-06 10:46:42 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-13 21:24:48 +08:00
										 |  |  |     op(_LOAD_CONST, (-- value)) { | 
					
						
							| 
									
										
										
										
											2024-04-18 11:09:30 +01:00
										 |  |  |         PyObject *val = PyTuple_GET_ITEM(co->co_consts, this_instr->oparg); | 
					
						
							|  |  |  |         int opcode = _Py_IsImmortal(val) ? _LOAD_CONST_INLINE_BORROW : _LOAD_CONST_INLINE; | 
					
						
							|  |  |  |         REPLACE_OP(this_instr, opcode, 0, (uintptr_t)val); | 
					
						
							| 
									
										
										
										
											2024-05-10 17:43:23 +01:00
										 |  |  |         value = sym_new_const(ctx, val); | 
					
						
							| 
									
										
										
										
											2024-02-13 21:24:48 +08:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-01-13 10:30:28 +00:00
										 |  |  |     op(_LOAD_CONST_MORTAL, (-- value)) { | 
					
						
							|  |  |  |         PyObject *val = PyTuple_GET_ITEM(co->co_consts, this_instr->oparg); | 
					
						
							|  |  |  |         int opcode = _Py_IsImmortal(val) ? _LOAD_CONST_INLINE_BORROW : _LOAD_CONST_INLINE; | 
					
						
							|  |  |  |         REPLACE_OP(this_instr, opcode, 0, (uintptr_t)val); | 
					
						
							|  |  |  |         value = sym_new_const(ctx, val); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-29 11:15:42 +00:00
										 |  |  |     op(_LOAD_CONST_IMMORTAL, (-- value)) { | 
					
						
							|  |  |  |         PyObject *val = PyTuple_GET_ITEM(co->co_consts, this_instr->oparg); | 
					
						
							|  |  |  |         REPLACE_OP(this_instr, _LOAD_CONST_INLINE_BORROW, 0, (uintptr_t)val); | 
					
						
							|  |  |  |         value = sym_new_const(ctx, val); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     op(_LOAD_SMALL_INT, (-- value)) { | 
					
						
							|  |  |  |         PyObject *val = PyLong_FromLong(this_instr->oparg); | 
					
						
							|  |  |  |         value = sym_new_const(ctx, val); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-13 21:24:48 +08:00
										 |  |  |     op(_LOAD_CONST_INLINE, (ptr/4 -- value)) { | 
					
						
							| 
									
										
										
										
											2024-05-10 17:43:23 +01:00
										 |  |  |         value = sym_new_const(ctx, ptr); | 
					
						
							| 
									
										
										
										
											2024-02-13 21:24:48 +08:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     op(_LOAD_CONST_INLINE_BORROW, (ptr/4 -- value)) { | 
					
						
							| 
									
										
										
										
											2024-05-10 17:43:23 +01:00
										 |  |  |         value = sym_new_const(ctx, ptr); | 
					
						
							| 
									
										
										
										
											2024-02-13 21:24:48 +08:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-02-28 18:00:38 +00:00
										 |  |  |     op(_POP_TOP_LOAD_CONST_INLINE, (ptr/4, pop -- value)) { | 
					
						
							|  |  |  |         value = sym_new_const(ctx, ptr); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     op(_POP_TOP_LOAD_CONST_INLINE_BORROW, (ptr/4, pop -- value)) { | 
					
						
							|  |  |  |         value = sym_new_const(ctx, ptr); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-13 21:24:48 +08:00
										 |  |  |     op(_COPY, (bottom, unused[oparg-1] -- bottom, unused[oparg-1], top)) { | 
					
						
							|  |  |  |         assert(oparg > 0); | 
					
						
							|  |  |  |         top = bottom; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-02-03 12:41:32 +00:00
										 |  |  |     op(_SWAP, (bottom[1], unused[oparg-2], top[1] -- bottom[1], unused[oparg-2], top[1])) { | 
					
						
							|  |  |  |         JitOptSymbol *temp = bottom[0]; | 
					
						
							|  |  |  |         bottom[0] = top[0]; | 
					
						
							|  |  |  |         top[0] = temp; | 
					
						
							|  |  |  |         assert(oparg >= 2); | 
					
						
							| 
									
										
										
										
											2024-02-13 21:24:48 +08:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-01-27 16:24:48 +00:00
										 |  |  |     op(_LOAD_ATTR_INSTANCE_VALUE, (offset/1, owner -- attr)) { | 
					
						
							| 
									
										
										
										
											2024-05-10 17:43:23 +01:00
										 |  |  |         attr = sym_new_not_null(ctx); | 
					
						
							| 
									
										
										
										
											2024-08-21 15:52:04 +01:00
										 |  |  |         (void)offset; | 
					
						
							| 
									
										
										
										
											2024-02-13 21:24:48 +08:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-02-28 18:00:38 +00:00
										 |  |  |     op(_LOAD_ATTR_MODULE, (dict_version/2, owner, index/1 -- attr)) { | 
					
						
							| 
									
										
										
										
											2024-02-22 14:48:25 +00:00
										 |  |  |         (void)dict_version; | 
					
						
							| 
									
										
										
										
											2025-02-28 18:00:38 +00:00
										 |  |  |         (void)index; | 
					
						
							|  |  |  |         attr = NULL; | 
					
						
							| 
									
										
										
										
											2025-03-02 13:21:34 -08:00
										 |  |  |         if (sym_is_const(ctx, owner)) { | 
					
						
							|  |  |  |             PyModuleObject *mod = (PyModuleObject *)sym_get_const(ctx, owner); | 
					
						
							| 
									
										
										
										
											2025-02-28 18:00:38 +00:00
										 |  |  |             if (PyModule_CheckExact(mod)) { | 
					
						
							| 
									
										
										
										
											2024-02-22 14:48:25 +00:00
										 |  |  |                 PyObject *dict = mod->md_dict; | 
					
						
							|  |  |  |                 uint64_t watched_mutations = get_mutations(dict); | 
					
						
							|  |  |  |                 if (watched_mutations < _Py_MAX_ALLOWED_GLOBALS_MODIFICATIONS) { | 
					
						
							|  |  |  |                     PyDict_Watch(GLOBALS_WATCHER_ID, dict); | 
					
						
							|  |  |  |                     _Py_BloomFilter_Add(dependencies, dict); | 
					
						
							| 
									
										
										
										
											2025-02-28 18:00:38 +00:00
										 |  |  |                     PyObject *res = convert_global_to_const(this_instr, dict, true); | 
					
						
							|  |  |  |                     attr = sym_new_const(ctx, res); | 
					
						
							| 
									
										
										
										
											2024-02-22 14:48:25 +00:00
										 |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2025-02-28 18:00:38 +00:00
										 |  |  |         if (attr == NULL) { | 
					
						
							|  |  |  |             /* No conversion made. We don't know what `attr` is. */ | 
					
						
							|  |  |  |             attr = sym_new_not_null(ctx); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2024-02-22 14:48:25 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-03-20 15:39:38 +00:00
										 |  |  |     op (_PUSH_NULL_CONDITIONAL, ( -- null[oparg & 1])) { | 
					
						
							|  |  |  |         if (oparg & 1) { | 
					
						
							|  |  |  |             REPLACE_OP(this_instr, _PUSH_NULL, 0, 0); | 
					
						
							|  |  |  |             null[0] = sym_new_null(ctx); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         else { | 
					
						
							|  |  |  |             REPLACE_OP(this_instr, _NOP, 0, 0); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2025-01-27 16:24:48 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     op(_LOAD_ATTR, (owner -- attr, self_or_null[oparg&1])) { | 
					
						
							| 
									
										
										
										
											2024-03-13 20:57:48 +08:00
										 |  |  |         (void)owner; | 
					
						
							| 
									
										
										
										
											2024-05-10 17:43:23 +01:00
										 |  |  |         attr = sym_new_not_null(ctx); | 
					
						
							| 
									
										
										
										
											2025-01-27 16:24:48 +00:00
										 |  |  |         if (oparg &1) { | 
					
						
							|  |  |  |             self_or_null[0] = sym_new_unknown(ctx); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2024-03-13 20:57:48 +08:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-02-28 18:00:38 +00:00
										 |  |  |     op(_LOAD_ATTR_WITH_HINT, (hint/1, owner -- attr)) { | 
					
						
							| 
									
										
										
										
											2024-05-10 17:43:23 +01:00
										 |  |  |         attr = sym_new_not_null(ctx); | 
					
						
							| 
									
										
										
										
											2024-02-13 21:24:48 +08:00
										 |  |  |         (void)hint; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-01-27 16:24:48 +00:00
										 |  |  |     op(_LOAD_ATTR_SLOT, (index/1, owner -- attr)) { | 
					
						
							| 
									
										
										
										
											2024-05-10 17:43:23 +01:00
										 |  |  |         attr = sym_new_not_null(ctx); | 
					
						
							| 
									
										
										
										
											2024-02-13 21:24:48 +08:00
										 |  |  |         (void)index; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-01-27 16:24:48 +00:00
										 |  |  |     op(_LOAD_ATTR_CLASS, (descr/4, owner -- attr)) { | 
					
						
							| 
									
										
										
										
											2024-05-10 17:43:23 +01:00
										 |  |  |         attr = sym_new_not_null(ctx); | 
					
						
							| 
									
										
										
										
											2024-02-13 21:24:48 +08:00
										 |  |  |         (void)descr; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-01-27 16:24:48 +00:00
										 |  |  |     op(_LOAD_ATTR_METHOD_WITH_VALUES, (descr/4, owner -- attr, self)) { | 
					
						
							| 
									
										
										
										
											2024-02-23 23:41:10 +08:00
										 |  |  |         (void)descr; | 
					
						
							| 
									
										
										
										
											2024-05-10 17:43:23 +01:00
										 |  |  |         attr = sym_new_not_null(ctx); | 
					
						
							| 
									
										
										
										
											2024-02-23 23:41:10 +08:00
										 |  |  |         self = owner; | 
					
						
							| 
									
										
										
										
											2024-02-23 15:42:03 +08:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-01-27 16:24:48 +00:00
										 |  |  |     op(_LOAD_ATTR_METHOD_NO_DICT, (descr/4, owner -- attr, self)) { | 
					
						
							| 
									
										
										
										
											2024-02-23 23:41:10 +08:00
										 |  |  |         (void)descr; | 
					
						
							| 
									
										
										
										
											2024-05-10 17:43:23 +01:00
										 |  |  |         attr = sym_new_not_null(ctx); | 
					
						
							| 
									
										
										
										
											2024-02-23 23:41:10 +08:00
										 |  |  |         self = owner; | 
					
						
							| 
									
										
										
										
											2024-02-23 15:42:03 +08:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-01-27 16:24:48 +00:00
										 |  |  |     op(_LOAD_ATTR_METHOD_LAZY_DICT, (descr/4, owner -- attr, self)) { | 
					
						
							| 
									
										
										
										
											2024-02-23 23:41:10 +08:00
										 |  |  |         (void)descr; | 
					
						
							| 
									
										
										
										
											2024-05-10 17:43:23 +01:00
										 |  |  |         attr = sym_new_not_null(ctx); | 
					
						
							| 
									
										
										
										
											2024-02-23 23:41:10 +08:00
										 |  |  |         self = owner; | 
					
						
							| 
									
										
										
										
											2024-02-23 15:42:03 +08:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-12 18:35:52 +01:00
										 |  |  |     op(_LOAD_ATTR_PROPERTY_FRAME, (fget/4, owner -- new_frame: _Py_UOpsAbstractFrame *)) { | 
					
						
							|  |  |  |         (void)fget; | 
					
						
							|  |  |  |         new_frame = NULL; | 
					
						
							|  |  |  |         ctx->done = true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-02-03 12:41:32 +00:00
										 |  |  |     op(_INIT_CALL_BOUND_METHOD_EXACT_ARGS, (callable[1], self_or_null[1], unused[oparg] -- callable[1], self_or_null[1], unused[oparg])) { | 
					
						
							|  |  |  |         callable[0] = sym_new_not_null(ctx); | 
					
						
							|  |  |  |         self_or_null[0] = sym_new_not_null(ctx); | 
					
						
							| 
									
										
										
										
											2024-02-23 15:42:03 +08:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-11-09 11:35:33 +08:00
										 |  |  |     op(_CHECK_FUNCTION_VERSION, (func_version/2, callable, self_or_null, unused[oparg] -- callable, self_or_null, unused[oparg])) { | 
					
						
							| 
									
										
										
										
											2025-03-02 13:21:34 -08:00
										 |  |  |         if (sym_is_const(ctx, callable) && sym_matches_type(callable, &PyFunction_Type)) { | 
					
						
							|  |  |  |             assert(PyFunction_Check(sym_get_const(ctx, callable))); | 
					
						
							| 
									
										
										
										
											2024-11-09 11:35:33 +08:00
										 |  |  |             REPLACE_OP(this_instr, _CHECK_FUNCTION_VERSION_INLINE, 0, func_version); | 
					
						
							| 
									
										
										
										
											2025-03-02 13:21:34 -08:00
										 |  |  |             this_instr->operand1 = (uintptr_t)sym_get_const(ctx, callable); | 
					
						
							| 
									
										
										
										
											2024-11-09 11:35:33 +08:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2024-05-10 17:43:23 +01:00
										 |  |  |         sym_set_type(callable, &PyFunction_Type); | 
					
						
							| 
									
										
										
										
											2024-11-09 11:35:33 +08:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     op(_CHECK_FUNCTION_EXACT_ARGS, (callable, self_or_null, unused[oparg] -- callable, self_or_null, unused[oparg])) { | 
					
						
							|  |  |  |         assert(sym_matches_type(callable, &PyFunction_Type)); | 
					
						
							| 
									
										
										
										
											2025-03-02 13:21:34 -08:00
										 |  |  |         if (sym_is_const(ctx, callable)) { | 
					
						
							| 
									
										
										
										
											2024-11-09 11:35:33 +08:00
										 |  |  |             if (sym_is_null(self_or_null) || sym_is_not_null(self_or_null)) { | 
					
						
							| 
									
										
										
										
											2025-03-02 13:21:34 -08:00
										 |  |  |                 PyFunctionObject *func = (PyFunctionObject *)sym_get_const(ctx, callable); | 
					
						
							| 
									
										
										
										
											2024-11-09 11:35:33 +08:00
										 |  |  |                 PyCodeObject *co = (PyCodeObject *)func->func_code; | 
					
						
							|  |  |  |                 if (co->co_argcount == oparg + !sym_is_null(self_or_null)) { | 
					
						
							|  |  |  |                     REPLACE_OP(this_instr, _NOP, 0 ,0); | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2024-02-13 21:24:48 +08:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     op(_CHECK_CALL_BOUND_METHOD_EXACT_ARGS, (callable, null, unused[oparg] -- callable, null, unused[oparg])) { | 
					
						
							| 
									
										
										
										
											2024-05-10 17:43:23 +01:00
										 |  |  |         sym_set_null(null); | 
					
						
							|  |  |  |         sym_set_type(callable, &PyMethod_Type); | 
					
						
							| 
									
										
										
										
											2024-02-13 21:24:48 +08:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     op(_INIT_CALL_PY_EXACT_ARGS, (callable, self_or_null, args[oparg] -- new_frame: _Py_UOpsAbstractFrame *)) { | 
					
						
							|  |  |  |         int argcount = oparg; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
											  
											
												gh-117045: Add code object to function version cache (#117028)
Changes to the function version cache:
- In addition to the function object, also store the code object,
  and allow the latter to be retrieved even if the function has been evicted.
- Stop assigning new function versions after a critical attribute (e.g. `__code__`)
  has been modified; the version is permanently reset to zero in this case.
- Changes to `__annotations__` are no longer considered critical. (This fixes gh-109998.)
Changes to the Tier 2 optimization machinery:
- If we cannot map a function version to a function, but it is still mapped to a code object,
  we continue projecting the trace.
  The operand of the `_PUSH_FRAME` and `_POP_FRAME` opcodes can be either NULL,
  a function object, or a code object with the lowest bit set.
This allows us to trace through code that calls an ephemeral function,
i.e., a function that may not be alive when we are constructing the executor,
e.g. a generator expression or certain nested functions.
We will lose globals removal inside such functions,
but we can still do other peephole operations
(and even possibly [call inlining](https://github.com/python/cpython/pull/116290),
if we decide to do it), which only need the code object.
As before, if we cannot retrieve the code object from the cache, we stop projecting.
											
										 
											2024-03-21 12:37:41 -07:00
										 |  |  |         PyCodeObject *co = NULL; | 
					
						
							|  |  |  |         assert((this_instr + 2)->opcode == _PUSH_FRAME); | 
					
						
							| 
									
										
										
										
											2024-10-03 01:10:51 +08:00
										 |  |  |         co = get_code_with_logging((this_instr + 2)); | 
					
						
							|  |  |  |         if (co == NULL) { | 
					
						
							|  |  |  |             ctx->done = true; | 
					
						
							|  |  |  |             break; | 
					
						
							| 
									
										
											  
											
												gh-117045: Add code object to function version cache (#117028)
Changes to the function version cache:
- In addition to the function object, also store the code object,
  and allow the latter to be retrieved even if the function has been evicted.
- Stop assigning new function versions after a critical attribute (e.g. `__code__`)
  has been modified; the version is permanently reset to zero in this case.
- Changes to `__annotations__` are no longer considered critical. (This fixes gh-109998.)
Changes to the Tier 2 optimization machinery:
- If we cannot map a function version to a function, but it is still mapped to a code object,
  we continue projecting the trace.
  The operand of the `_PUSH_FRAME` and `_POP_FRAME` opcodes can be either NULL,
  a function object, or a code object with the lowest bit set.
This allows us to trace through code that calls an ephemeral function,
i.e., a function that may not be alive when we are constructing the executor,
e.g. a generator expression or certain nested functions.
We will lose globals removal inside such functions,
but we can still do other peephole operations
(and even possibly [call inlining](https://github.com/python/cpython/pull/116290),
if we decide to do it), which only need the code object.
As before, if we cannot retrieve the code object from the cache, we stop projecting.
											
										 
											2024-03-21 12:37:41 -07:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2024-02-13 21:24:48 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-03 01:10:51 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-13 21:24:48 +08:00
										 |  |  |         assert(self_or_null != NULL); | 
					
						
							|  |  |  |         assert(args != NULL); | 
					
						
							| 
									
										
										
										
											2024-02-27 13:25:02 +00:00
										 |  |  |         if (sym_is_not_null(self_or_null)) { | 
					
						
							| 
									
										
										
										
											2024-02-13 21:24:48 +08:00
										 |  |  |             // Bound method fiddling, same as _INIT_CALL_PY_EXACT_ARGS in VM
 | 
					
						
							|  |  |  |             args--; | 
					
						
							|  |  |  |             argcount++; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-27 13:25:02 +00:00
										 |  |  |         if (sym_is_null(self_or_null) || sym_is_not_null(self_or_null)) { | 
					
						
							| 
									
										
										
										
											2024-06-08 05:41:45 -04:00
										 |  |  |             new_frame = frame_new(ctx, co, 0, args, argcount); | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             new_frame = frame_new(ctx, co, 0, NULL, 0); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-13 21:24:48 +08:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-26 18:38:52 +01:00
										 |  |  |     op(_MAYBE_EXPAND_METHOD, (callable, self_or_null, args[oparg] -- func, maybe_self, args[oparg])) { | 
					
						
							|  |  |  |         (void)args; | 
					
						
							|  |  |  |         func = sym_new_not_null(ctx); | 
					
						
							|  |  |  |         maybe_self = sym_new_not_null(ctx); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-04 12:11:11 +01:00
										 |  |  |     op(_PY_FRAME_GENERAL, (callable, self_or_null, args[oparg] -- new_frame: _Py_UOpsAbstractFrame *)) { | 
					
						
							| 
									
										
										
										
											2024-10-03 01:10:51 +08:00
										 |  |  |         PyCodeObject *co = NULL; | 
					
						
							|  |  |  |         assert((this_instr + 2)->opcode == _PUSH_FRAME); | 
					
						
							|  |  |  |         co = get_code_with_logging((this_instr + 2)); | 
					
						
							|  |  |  |         if (co == NULL) { | 
					
						
							|  |  |  |             ctx->done = true; | 
					
						
							|  |  |  |             break; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         new_frame = frame_new(ctx, co, 0, NULL, 0); | 
					
						
							| 
									
										
										
										
											2024-05-04 12:11:11 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-20 16:52:58 +01:00
										 |  |  |     op(_PY_FRAME_KW, (callable, self_or_null, args[oparg], kwnames -- new_frame: _Py_UOpsAbstractFrame *)) { | 
					
						
							| 
									
										
										
										
											2024-08-16 17:11:24 +01:00
										 |  |  |         new_frame = NULL; | 
					
						
							|  |  |  |         ctx->done = true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-20 16:52:58 +01:00
										 |  |  |     op(_CHECK_AND_ALLOCATE_OBJECT, (type_version/2, callable, null, args[oparg] -- self, init, args[oparg])) { | 
					
						
							|  |  |  |         (void)type_version; | 
					
						
							|  |  |  |         (void)args; | 
					
						
							|  |  |  |         self = sym_new_not_null(ctx); | 
					
						
							|  |  |  |         init = sym_new_not_null(ctx); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     op(_CREATE_INIT_FRAME, (self, init, args[oparg] -- init_frame: _Py_UOpsAbstractFrame *)) { | 
					
						
							|  |  |  |         init_frame = NULL; | 
					
						
							|  |  |  |         ctx->done = true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-17 14:40:11 +01:00
										 |  |  |     op(_RETURN_VALUE, (retval -- res)) { | 
					
						
							| 
									
										
										
										
											2025-03-26 15:21:35 +00:00
										 |  |  |         JitOptSymbol *temp = retval; | 
					
						
							|  |  |  |         DEAD(retval); | 
					
						
							| 
									
										
										
										
											2024-10-07 14:56:39 +01:00
										 |  |  |         SAVE_STACK(); | 
					
						
							| 
									
										
										
										
											2024-02-13 21:24:48 +08:00
										 |  |  |         ctx->frame->stack_pointer = stack_pointer; | 
					
						
							| 
									
										
										
										
											2024-02-27 13:25:02 +00:00
										 |  |  |         frame_pop(ctx); | 
					
						
							| 
									
										
										
										
											2024-02-13 21:24:48 +08:00
										 |  |  |         stack_pointer = ctx->frame->stack_pointer; | 
					
						
							| 
									
										
										
										
											2024-04-18 11:09:30 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         /* Stack space handling */ | 
					
						
							|  |  |  |         assert(corresponding_check_stack == NULL); | 
					
						
							|  |  |  |         assert(co != NULL); | 
					
						
							|  |  |  |         int framesize = co->co_framesize; | 
					
						
							|  |  |  |         assert(framesize > 0); | 
					
						
							| 
									
										
										
										
											2024-04-25 11:32:47 +01:00
										 |  |  |         assert(framesize <= curr_space); | 
					
						
							|  |  |  |         curr_space -= framesize; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         co = get_code(this_instr); | 
					
						
							|  |  |  |         if (co == NULL) { | 
					
						
							|  |  |  |             // might be impossible, but bailing is still safe
 | 
					
						
							| 
									
										
										
										
											2024-05-10 17:43:23 +01:00
										 |  |  |             ctx->done = true; | 
					
						
							| 
									
										
										
										
											2024-04-25 11:32:47 +01:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2024-10-07 14:56:39 +01:00
										 |  |  |         RELOAD_STACK(); | 
					
						
							| 
									
										
										
										
											2025-03-26 15:21:35 +00:00
										 |  |  |         res = temp; | 
					
						
							| 
									
										
										
										
											2024-04-25 11:32:47 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     op(_RETURN_GENERATOR, ( -- res)) { | 
					
						
							|  |  |  |         SYNC_SP(); | 
					
						
							|  |  |  |         ctx->frame->stack_pointer = stack_pointer; | 
					
						
							|  |  |  |         frame_pop(ctx); | 
					
						
							|  |  |  |         stack_pointer = ctx->frame->stack_pointer; | 
					
						
							| 
									
										
										
										
											2024-05-10 17:43:23 +01:00
										 |  |  |         res = sym_new_unknown(ctx); | 
					
						
							| 
									
										
										
										
											2024-04-25 11:32:47 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         /* Stack space handling */ | 
					
						
							|  |  |  |         assert(corresponding_check_stack == NULL); | 
					
						
							|  |  |  |         assert(co != NULL); | 
					
						
							|  |  |  |         int framesize = co->co_framesize; | 
					
						
							|  |  |  |         assert(framesize > 0); | 
					
						
							| 
									
										
										
										
											2024-04-18 11:09:30 +01:00
										 |  |  |         assert(framesize <= curr_space); | 
					
						
							|  |  |  |         curr_space -= framesize; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         co = get_code(this_instr); | 
					
						
							|  |  |  |         if (co == NULL) { | 
					
						
							|  |  |  |             // might be impossible, but bailing is still safe
 | 
					
						
							| 
									
										
										
										
											2024-05-10 17:43:23 +01:00
										 |  |  |             ctx->done = true; | 
					
						
							| 
									
										
										
										
											2024-04-18 11:09:30 +01:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-30 11:33:13 +01:00
										 |  |  |     op(_YIELD_VALUE, (unused -- res)) { | 
					
						
							| 
									
										
										
										
											2024-05-10 17:43:23 +01:00
										 |  |  |         res = sym_new_unknown(ctx); | 
					
						
							| 
									
										
										
										
											2024-04-30 11:33:13 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     op(_FOR_ITER_GEN_FRAME, ( -- )) { | 
					
						
							|  |  |  |         /* We are about to hit the end of the trace */ | 
					
						
							| 
									
										
										
										
											2024-05-10 17:43:23 +01:00
										 |  |  |         ctx->done = true; | 
					
						
							| 
									
										
										
										
											2024-04-30 11:33:13 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-18 14:24:58 -07:00
										 |  |  |     op(_SEND_GEN_FRAME, ( -- )) { | 
					
						
							|  |  |  |         // We are about to hit the end of the trace:
 | 
					
						
							|  |  |  |         ctx->done = true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-18 11:09:30 +01:00
										 |  |  |     op(_CHECK_STACK_SPACE, ( --)) { | 
					
						
							|  |  |  |         assert(corresponding_check_stack == NULL); | 
					
						
							|  |  |  |         corresponding_check_stack = this_instr; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-02-07 09:52:49 -08:00
										 |  |  |     op (_CHECK_STACK_SPACE_OPERAND, (framesize/2 -- )) { | 
					
						
							| 
									
										
										
										
											2024-04-18 11:09:30 +01:00
										 |  |  |         (void)framesize; | 
					
						
							|  |  |  |         /* We should never see _CHECK_STACK_SPACE_OPERANDs.
 | 
					
						
							|  |  |  |         * They are only created at the end of this pass. */ | 
					
						
							|  |  |  |         Py_UNREACHABLE(); | 
					
						
							| 
									
										
										
										
											2024-02-13 21:24:48 +08:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-03-20 15:39:38 +00:00
										 |  |  |     op(_PUSH_FRAME, (new_frame: _Py_UOpsAbstractFrame * -- )) { | 
					
						
							| 
									
										
										
										
											2024-02-13 21:24:48 +08:00
										 |  |  |         SYNC_SP(); | 
					
						
							|  |  |  |         ctx->frame->stack_pointer = stack_pointer; | 
					
						
							|  |  |  |         ctx->frame = new_frame; | 
					
						
							|  |  |  |         ctx->curr_frame_depth++; | 
					
						
							|  |  |  |         stack_pointer = new_frame->stack_pointer; | 
					
						
							| 
									
										
										
										
											2024-04-18 11:09:30 +01:00
										 |  |  |         co = get_code(this_instr); | 
					
						
							|  |  |  |         if (co == NULL) { | 
					
						
							|  |  |  |             // should be about to _EXIT_TRACE anyway
 | 
					
						
							| 
									
										
										
										
											2024-05-10 17:43:23 +01:00
										 |  |  |             ctx->done = true; | 
					
						
							|  |  |  |             break; | 
					
						
							| 
									
										
										
										
											2024-04-18 11:09:30 +01:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         /* Stack space handling */ | 
					
						
							|  |  |  |         int framesize = co->co_framesize; | 
					
						
							|  |  |  |         assert(framesize > 0); | 
					
						
							|  |  |  |         curr_space += framesize; | 
					
						
							|  |  |  |         if (curr_space < 0 || curr_space > INT32_MAX) { | 
					
						
							|  |  |  |             // won't fit in signed 32-bit int
 | 
					
						
							| 
									
										
										
										
											2024-05-10 17:43:23 +01:00
										 |  |  |             ctx->done = true; | 
					
						
							|  |  |  |             break; | 
					
						
							| 
									
										
										
										
											2024-04-18 11:09:30 +01:00
										 |  |  |         } | 
					
						
							|  |  |  |         max_space = curr_space > max_space ? curr_space : max_space; | 
					
						
							|  |  |  |         if (first_valid_check_stack == NULL) { | 
					
						
							|  |  |  |             first_valid_check_stack = corresponding_check_stack; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2024-05-04 12:11:11 +01:00
										 |  |  |         else if (corresponding_check_stack) { | 
					
						
							| 
									
										
										
										
											2024-04-18 11:09:30 +01:00
										 |  |  |             // delete all but the first valid _CHECK_STACK_SPACE
 | 
					
						
							|  |  |  |             corresponding_check_stack->opcode = _NOP; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         corresponding_check_stack = NULL; | 
					
						
							| 
									
										
										
										
											2024-02-13 21:24:48 +08:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     op(_UNPACK_SEQUENCE, (seq -- values[oparg])) { | 
					
						
							|  |  |  |         /* This has to be done manually */ | 
					
						
							|  |  |  |         for (int i = 0; i < oparg; i++) { | 
					
						
							| 
									
										
										
										
											2024-05-10 17:43:23 +01:00
										 |  |  |             values[i] = sym_new_unknown(ctx); | 
					
						
							| 
									
										
										
										
											2024-02-13 21:24:48 +08:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     op(_UNPACK_EX, (seq -- values[oparg & 0xFF], unused, unused[oparg >> 8])) { | 
					
						
							|  |  |  |         /* This has to be done manually */ | 
					
						
							|  |  |  |         int totalargs = (oparg & 0xFF) + (oparg >> 8) + 1; | 
					
						
							|  |  |  |         for (int i = 0; i < totalargs; i++) { | 
					
						
							| 
									
										
										
										
											2024-05-10 17:43:23 +01:00
										 |  |  |             values[i] = sym_new_unknown(ctx); | 
					
						
							| 
									
										
										
										
											2024-02-13 21:24:48 +08:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     op(_ITER_NEXT_RANGE, (iter -- iter, next)) { | 
					
						
							| 
									
										
										
										
											2024-05-10 17:43:23 +01:00
										 |  |  |        next = sym_new_type(ctx, &PyLong_Type); | 
					
						
							| 
									
										
										
										
											2024-02-13 21:24:48 +08:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-05 15:06:00 +00:00
										 |  |  |     op(_GUARD_IS_TRUE_POP, (flag -- )) { | 
					
						
							| 
									
										
										
										
											2025-03-02 13:21:34 -08:00
										 |  |  |         if (sym_is_const(ctx, flag)) { | 
					
						
							|  |  |  |             PyObject *value = sym_get_const(ctx, flag); | 
					
						
							| 
									
										
										
										
											2024-03-05 15:06:00 +00:00
										 |  |  |             assert(value != NULL); | 
					
						
							|  |  |  |             eliminate_pop_guard(this_instr, value != Py_True); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2025-03-02 13:21:34 -08:00
										 |  |  |         sym_set_const(flag, Py_True); | 
					
						
							| 
									
										
										
										
											2024-03-05 15:06:00 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     op(_GUARD_IS_FALSE_POP, (flag -- )) { | 
					
						
							| 
									
										
										
										
											2025-03-02 13:21:34 -08:00
										 |  |  |         if (sym_is_const(ctx, flag)) { | 
					
						
							|  |  |  |             PyObject *value = sym_get_const(ctx, flag); | 
					
						
							| 
									
										
										
										
											2024-03-05 15:06:00 +00:00
										 |  |  |             assert(value != NULL); | 
					
						
							|  |  |  |             eliminate_pop_guard(this_instr, value != Py_False); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2025-03-02 13:21:34 -08:00
										 |  |  |         sym_set_const(flag, Py_False); | 
					
						
							| 
									
										
										
										
											2024-03-05 15:06:00 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     op(_GUARD_IS_NONE_POP, (flag -- )) { | 
					
						
							| 
									
										
										
										
											2025-03-02 13:21:34 -08:00
										 |  |  |         if (sym_is_const(ctx, flag)) { | 
					
						
							|  |  |  |             PyObject *value = sym_get_const(ctx, flag); | 
					
						
							| 
									
										
										
										
											2024-03-05 15:06:00 +00:00
										 |  |  |             assert(value != NULL); | 
					
						
							|  |  |  |             eliminate_pop_guard(this_instr, !Py_IsNone(value)); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         else if (sym_has_type(flag)) { | 
					
						
							|  |  |  |             assert(!sym_matches_type(flag, &_PyNone_Type)); | 
					
						
							|  |  |  |             eliminate_pop_guard(this_instr, true); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2025-03-02 13:21:34 -08:00
										 |  |  |         sym_set_const(flag, Py_None); | 
					
						
							| 
									
										
										
										
											2024-03-05 15:06:00 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2024-02-13 21:24:48 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-05 15:06:00 +00:00
										 |  |  |     op(_GUARD_IS_NOT_NONE_POP, (flag -- )) { | 
					
						
							| 
									
										
										
										
											2025-03-02 13:21:34 -08:00
										 |  |  |         if (sym_is_const(ctx, flag)) { | 
					
						
							|  |  |  |             PyObject *value = sym_get_const(ctx, flag); | 
					
						
							| 
									
										
										
										
											2024-03-05 15:06:00 +00:00
										 |  |  |             assert(value != NULL); | 
					
						
							|  |  |  |             eliminate_pop_guard(this_instr, Py_IsNone(value)); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         else if (sym_has_type(flag)) { | 
					
						
							|  |  |  |             assert(!sym_matches_type(flag, &_PyNone_Type)); | 
					
						
							|  |  |  |             eliminate_pop_guard(this_instr, false); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2024-02-13 21:24:48 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-18 11:09:30 +01:00
										 |  |  |     op(_CHECK_PEP_523, (--)) { | 
					
						
							|  |  |  |         /* Setting the eval frame function invalidates
 | 
					
						
							|  |  |  |         * all executors, so no need to check dynamically */ | 
					
						
							|  |  |  |         if (_PyInterpreterState_GET()->eval_frame == NULL) { | 
					
						
							|  |  |  |             REPLACE_OP(this_instr, _NOP, 0 ,0); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-18 12:17:46 +01:00
										 |  |  |     op(_LOAD_SPECIAL, (owner -- attr, self_or_null)) { | 
					
						
							|  |  |  |         attr = sym_new_not_null(ctx); | 
					
						
							|  |  |  |         self_or_null = sym_new_unknown(ctx); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-18 11:09:30 +01:00
										 |  |  |     op(_JUMP_TO_TOP, (--)) { | 
					
						
							| 
									
										
										
										
											2024-05-10 17:43:23 +01:00
										 |  |  |         ctx->done = true; | 
					
						
							| 
									
										
										
										
											2024-04-18 11:09:30 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-26 09:40:15 -07:00
										 |  |  |     op(_EXIT_TRACE, (exit_p/4 --)) { | 
					
						
							|  |  |  |         (void)exit_p; | 
					
						
							| 
									
										
										
										
											2024-05-10 17:43:23 +01:00
										 |  |  |         ctx->done = true; | 
					
						
							| 
									
										
										
										
											2024-04-18 11:09:30 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-23 22:17:47 +01:00
										 |  |  |     op(_REPLACE_WITH_TRUE, (value -- res)) { | 
					
						
							|  |  |  |         res = sym_new_const(ctx, Py_True); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-01-20 15:49:15 +00:00
										 |  |  |     op(_BUILD_TUPLE, (values[oparg] -- tup)) { | 
					
						
							|  |  |  |         tup = sym_new_tuple(ctx, oparg, values); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     op(_UNPACK_SEQUENCE_TWO_TUPLE, (seq -- val1, val0)) { | 
					
						
							|  |  |  |         val0 = sym_tuple_getitem(ctx, seq, 0); | 
					
						
							|  |  |  |         val1 = sym_tuple_getitem(ctx, seq, 1); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     op(_UNPACK_SEQUENCE_TUPLE, (seq -- values[oparg])) { | 
					
						
							|  |  |  |         for (int i = 0; i < oparg; i++) { | 
					
						
							|  |  |  |             values[i] = sym_tuple_getitem(ctx, seq, i); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-13 21:24:48 +08:00
										 |  |  | // END BYTECODES //
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-22 14:48:25 +00:00
										 |  |  | } |