diff --git a/Doc/library/dis.rst b/Doc/library/dis.rst index 755d681b9df2be..33229842b456c3 100644 --- a/Doc/library/dis.rst +++ b/Doc/library/dis.rst @@ -1752,6 +1752,25 @@ iterations of the loop. .. versionadded:: 3.13 +.. opcode:: MATCH_CLASS_ISINSTANCE + + Read match subject ``Stack[-2]`` and the type object ``Stack[-1]`` from stack. + Pop ``Stack[-1]`` and push ``True`` or ``False`` for the result of :func:`isinstance`. + + .. versionadded:: 3.15 + + +.. opcode:: MATCH_CLASS_GET_OPT_ATTR (namei) + + Replaces ``STACK[-1]`` with ``getattr(STACK[-1], co_names[namei])`` and get + optional attribute from match subject ``STACK[-2]``. + + Pop ``Stack[-1]``. If attribute is found, push it and ``True`` onto the stack. + Otherwise push ``None`` and ``False``. + + .. versionadded:: 3.15 + + .. opcode:: MATCH_CLASS (count) ``STACK[-1]`` is a tuple of keyword attribute names, ``STACK[-2]`` is the class diff --git a/Include/internal/pycore_magic_number.h b/Include/internal/pycore_magic_number.h index eb2e03829e28e1..d54405ecfb39bc 100644 --- a/Include/internal/pycore_magic_number.h +++ b/Include/internal/pycore_magic_number.h @@ -290,6 +290,7 @@ Known values: Python 3.15a4 3657 (Add BINARY_OP_SUBSCR_USTR_INT) Python 3.15a4 3658 (Optimize bytecode for list/set called on genexp) Python 3.15a4 3659 (Add CALL_FUNCTION_EX specialization) + Python 3.15a4 3660 (Add MATCH_CLASS_ISINSTANCE & MATCH_CLASS_GET_OPT_ATTR) Python 3.16 will start with 3700 @@ -303,7 +304,7 @@ PC/launcher.c must also be updated. */ -#define PYC_MAGIC_NUMBER 3659 +#define PYC_MAGIC_NUMBER 3660 /* This is equivalent to converting PYC_MAGIC_NUMBER to 2 bytes (little-endian) and then appending b'\r\n'. */ #define PYC_MAGIC_NUMBER_TOKEN \ diff --git a/Include/internal/pycore_opcode_metadata.h b/Include/internal/pycore_opcode_metadata.h index e225ccbf6ee7d4..f20e129abbe8df 100644 --- a/Include/internal/pycore_opcode_metadata.h +++ b/Include/internal/pycore_opcode_metadata.h @@ -386,6 +386,10 @@ int _PyOpcode_num_popped(int opcode, int oparg) { return 3 + (oparg - 1); case MATCH_CLASS: return 3; + case MATCH_CLASS_GET_OPT_ATTR: + return 1; + case MATCH_CLASS_ISINSTANCE: + return 2; case MATCH_KEYS: return 2; case MATCH_MAPPING: @@ -877,6 +881,10 @@ int _PyOpcode_num_pushed(int opcode, int oparg) { return 1 + (oparg - 1); case MATCH_CLASS: return 1; + case MATCH_CLASS_GET_OPT_ATTR: + return 3; + case MATCH_CLASS_ISINSTANCE: + return 2; case MATCH_KEYS: return 3; case MATCH_MAPPING: @@ -1259,6 +1267,8 @@ const struct opcode_metadata _PyOpcode_opcode_metadata[267] = { [MAKE_FUNCTION] = { true, INSTR_FMT_IX, HAS_ERROR_FLAG | HAS_ESCAPES_FLAG }, [MAP_ADD] = { true, INSTR_FMT_IB, HAS_ARG_FLAG | HAS_ERROR_FLAG | HAS_ESCAPES_FLAG }, [MATCH_CLASS] = { true, INSTR_FMT_IB, HAS_ARG_FLAG | HAS_ERROR_FLAG | HAS_ESCAPES_FLAG }, + [MATCH_CLASS_GET_OPT_ATTR] = { true, INSTR_FMT_IB, HAS_ARG_FLAG | HAS_NAME_FLAG | HAS_ERROR_FLAG | HAS_ESCAPES_FLAG }, + [MATCH_CLASS_ISINSTANCE] = { true, INSTR_FMT_IX, HAS_ERROR_FLAG | HAS_ESCAPES_FLAG }, [MATCH_KEYS] = { true, INSTR_FMT_IX, HAS_ERROR_FLAG | HAS_ESCAPES_FLAG }, [MATCH_MAPPING] = { true, INSTR_FMT_IX, 0 }, [MATCH_SEQUENCE] = { true, INSTR_FMT_IX, 0 }, @@ -1477,6 +1487,8 @@ _PyOpcode_macro_expansion[256] = { [MAKE_FUNCTION] = { .nuops = 1, .uops = { { _MAKE_FUNCTION, OPARG_SIMPLE, 0 } } }, [MAP_ADD] = { .nuops = 1, .uops = { { _MAP_ADD, OPARG_SIMPLE, 0 } } }, [MATCH_CLASS] = { .nuops = 1, .uops = { { _MATCH_CLASS, OPARG_SIMPLE, 0 } } }, + [MATCH_CLASS_GET_OPT_ATTR] = { .nuops = 1, .uops = { { _MATCH_CLASS_GET_OPT_ATTR, OPARG_SIMPLE, 0 } } }, + [MATCH_CLASS_ISINSTANCE] = { .nuops = 1, .uops = { { _MATCH_CLASS_ISINSTANCE, OPARG_SIMPLE, 0 } } }, [MATCH_KEYS] = { .nuops = 1, .uops = { { _MATCH_KEYS, OPARG_SIMPLE, 0 } } }, [MATCH_MAPPING] = { .nuops = 1, .uops = { { _MATCH_MAPPING, OPARG_SIMPLE, 0 } } }, [MATCH_SEQUENCE] = { .nuops = 1, .uops = { { _MATCH_SEQUENCE, OPARG_SIMPLE, 0 } } }, @@ -1712,6 +1724,8 @@ const char *_PyOpcode_OpName[267] = { [MAKE_FUNCTION] = "MAKE_FUNCTION", [MAP_ADD] = "MAP_ADD", [MATCH_CLASS] = "MATCH_CLASS", + [MATCH_CLASS_GET_OPT_ATTR] = "MATCH_CLASS_GET_OPT_ATTR", + [MATCH_CLASS_ISINSTANCE] = "MATCH_CLASS_ISINSTANCE", [MATCH_KEYS] = "MATCH_KEYS", [MATCH_MAPPING] = "MATCH_MAPPING", [MATCH_SEQUENCE] = "MATCH_SEQUENCE", @@ -1809,8 +1823,6 @@ const uint8_t _PyOpcode_Caches[256] = { extern const uint8_t _PyOpcode_Deopt[256]; #ifdef NEED_OPCODE_METADATA const uint8_t _PyOpcode_Deopt[256] = { - [121] = 121, - [122] = 122, [123] = 123, [124] = 124, [125] = 125, @@ -2005,6 +2017,8 @@ const uint8_t _PyOpcode_Deopt[256] = { [MAKE_FUNCTION] = MAKE_FUNCTION, [MAP_ADD] = MAP_ADD, [MATCH_CLASS] = MATCH_CLASS, + [MATCH_CLASS_GET_OPT_ATTR] = MATCH_CLASS_GET_OPT_ATTR, + [MATCH_CLASS_ISINSTANCE] = MATCH_CLASS_ISINSTANCE, [MATCH_KEYS] = MATCH_KEYS, [MATCH_MAPPING] = MATCH_MAPPING, [MATCH_SEQUENCE] = MATCH_SEQUENCE, @@ -2070,8 +2084,6 @@ const uint8_t _PyOpcode_Deopt[256] = { #endif // NEED_OPCODE_METADATA #define EXTRA_CASES \ - case 121: \ - case 122: \ case 123: \ case 124: \ case 125: \ diff --git a/Include/internal/pycore_uop_ids.h b/Include/internal/pycore_uop_ids.h index b9297f37602a77..65fb0e333a7632 100644 --- a/Include/internal/pycore_uop_ids.h +++ b/Include/internal/pycore_uop_ids.h @@ -275,6 +275,8 @@ extern "C" { #define _MAKE_WARM 501 #define _MAP_ADD MAP_ADD #define _MATCH_CLASS MATCH_CLASS +#define _MATCH_CLASS_GET_OPT_ATTR MATCH_CLASS_GET_OPT_ATTR +#define _MATCH_CLASS_ISINSTANCE MATCH_CLASS_ISINSTANCE #define _MATCH_KEYS MATCH_KEYS #define _MATCH_MAPPING MATCH_MAPPING #define _MATCH_SEQUENCE MATCH_SEQUENCE @@ -971,216 +973,218 @@ extern "C" { #define _MAKE_WARM_r33 1167 #define _MAP_ADD_r20 1168 #define _MATCH_CLASS_r31 1169 -#define _MATCH_KEYS_r23 1170 -#define _MATCH_MAPPING_r02 1171 -#define _MATCH_MAPPING_r12 1172 -#define _MATCH_MAPPING_r23 1173 -#define _MATCH_SEQUENCE_r02 1174 -#define _MATCH_SEQUENCE_r12 1175 -#define _MATCH_SEQUENCE_r23 1176 -#define _MAYBE_EXPAND_METHOD_r00 1177 -#define _MAYBE_EXPAND_METHOD_KW_r11 1178 -#define _MONITOR_CALL_r00 1179 -#define _MONITOR_CALL_KW_r11 1180 -#define _MONITOR_JUMP_BACKWARD_r00 1181 -#define _MONITOR_JUMP_BACKWARD_r11 1182 -#define _MONITOR_JUMP_BACKWARD_r22 1183 -#define _MONITOR_JUMP_BACKWARD_r33 1184 -#define _MONITOR_RESUME_r00 1185 -#define _NOP_r00 1186 -#define _NOP_r11 1187 -#define _NOP_r22 1188 -#define _NOP_r33 1189 -#define _POP_CALL_r20 1190 -#define _POP_CALL_LOAD_CONST_INLINE_BORROW_r21 1191 -#define _POP_CALL_ONE_r30 1192 -#define _POP_CALL_ONE_LOAD_CONST_INLINE_BORROW_r31 1193 -#define _POP_CALL_TWO_r30 1194 -#define _POP_CALL_TWO_LOAD_CONST_INLINE_BORROW_r31 1195 -#define _POP_EXCEPT_r10 1196 -#define _POP_ITER_r20 1197 -#define _POP_JUMP_IF_FALSE_r00 1198 -#define _POP_JUMP_IF_FALSE_r10 1199 -#define _POP_JUMP_IF_FALSE_r21 1200 -#define _POP_JUMP_IF_FALSE_r32 1201 -#define _POP_JUMP_IF_TRUE_r00 1202 -#define _POP_JUMP_IF_TRUE_r10 1203 -#define _POP_JUMP_IF_TRUE_r21 1204 -#define _POP_JUMP_IF_TRUE_r32 1205 -#define _POP_TOP_r10 1206 -#define _POP_TOP_FLOAT_r00 1207 -#define _POP_TOP_FLOAT_r10 1208 -#define _POP_TOP_FLOAT_r21 1209 -#define _POP_TOP_FLOAT_r32 1210 -#define _POP_TOP_INT_r00 1211 -#define _POP_TOP_INT_r10 1212 -#define _POP_TOP_INT_r21 1213 -#define _POP_TOP_INT_r32 1214 -#define _POP_TOP_LOAD_CONST_INLINE_r11 1215 -#define _POP_TOP_LOAD_CONST_INLINE_BORROW_r11 1216 -#define _POP_TOP_NOP_r00 1217 -#define _POP_TOP_NOP_r10 1218 -#define _POP_TOP_NOP_r21 1219 -#define _POP_TOP_NOP_r32 1220 -#define _POP_TOP_UNICODE_r00 1221 -#define _POP_TOP_UNICODE_r10 1222 -#define _POP_TOP_UNICODE_r21 1223 -#define _POP_TOP_UNICODE_r32 1224 -#define _POP_TWO_r20 1225 -#define _POP_TWO_LOAD_CONST_INLINE_BORROW_r21 1226 -#define _PUSH_EXC_INFO_r02 1227 -#define _PUSH_EXC_INFO_r12 1228 -#define _PUSH_EXC_INFO_r23 1229 -#define _PUSH_FRAME_r10 1230 -#define _PUSH_NULL_r01 1231 -#define _PUSH_NULL_r12 1232 -#define _PUSH_NULL_r23 1233 -#define _PUSH_NULL_CONDITIONAL_r00 1234 -#define _PY_FRAME_EX_r31 1235 -#define _PY_FRAME_GENERAL_r01 1236 -#define _PY_FRAME_KW_r11 1237 -#define _QUICKEN_RESUME_r00 1238 -#define _QUICKEN_RESUME_r11 1239 -#define _QUICKEN_RESUME_r22 1240 -#define _QUICKEN_RESUME_r33 1241 -#define _REPLACE_WITH_TRUE_r02 1242 -#define _REPLACE_WITH_TRUE_r12 1243 -#define _REPLACE_WITH_TRUE_r23 1244 -#define _RESUME_CHECK_r00 1245 -#define _RESUME_CHECK_r11 1246 -#define _RESUME_CHECK_r22 1247 -#define _RESUME_CHECK_r33 1248 -#define _RETURN_GENERATOR_r01 1249 -#define _RETURN_VALUE_r11 1250 -#define _SAVE_RETURN_OFFSET_r00 1251 -#define _SAVE_RETURN_OFFSET_r11 1252 -#define _SAVE_RETURN_OFFSET_r22 1253 -#define _SAVE_RETURN_OFFSET_r33 1254 -#define _SEND_r22 1255 -#define _SEND_GEN_FRAME_r22 1256 -#define _SETUP_ANNOTATIONS_r00 1257 -#define _SET_ADD_r10 1258 -#define _SET_FUNCTION_ATTRIBUTE_r01 1259 -#define _SET_FUNCTION_ATTRIBUTE_r11 1260 -#define _SET_FUNCTION_ATTRIBUTE_r21 1261 -#define _SET_FUNCTION_ATTRIBUTE_r32 1262 -#define _SET_IP_r00 1263 -#define _SET_IP_r11 1264 -#define _SET_IP_r22 1265 -#define _SET_IP_r33 1266 -#define _SET_UPDATE_r10 1267 -#define _SHUFFLE_2_LOAD_CONST_INLINE_BORROW_r02 1268 -#define _SHUFFLE_2_LOAD_CONST_INLINE_BORROW_r12 1269 -#define _SHUFFLE_2_LOAD_CONST_INLINE_BORROW_r22 1270 -#define _SHUFFLE_2_LOAD_CONST_INLINE_BORROW_r32 1271 -#define _SHUFFLE_3_LOAD_CONST_INLINE_BORROW_r03 1272 -#define _SHUFFLE_3_LOAD_CONST_INLINE_BORROW_r13 1273 -#define _SHUFFLE_3_LOAD_CONST_INLINE_BORROW_r23 1274 -#define _SHUFFLE_3_LOAD_CONST_INLINE_BORROW_r33 1275 -#define _SPILL_OR_RELOAD_r01 1276 -#define _SPILL_OR_RELOAD_r02 1277 -#define _SPILL_OR_RELOAD_r03 1278 -#define _SPILL_OR_RELOAD_r10 1279 -#define _SPILL_OR_RELOAD_r12 1280 -#define _SPILL_OR_RELOAD_r13 1281 -#define _SPILL_OR_RELOAD_r20 1282 -#define _SPILL_OR_RELOAD_r21 1283 -#define _SPILL_OR_RELOAD_r23 1284 -#define _SPILL_OR_RELOAD_r30 1285 -#define _SPILL_OR_RELOAD_r31 1286 -#define _SPILL_OR_RELOAD_r32 1287 -#define _START_EXECUTOR_r00 1288 -#define _STORE_ATTR_r20 1289 -#define _STORE_ATTR_INSTANCE_VALUE_r21 1290 -#define _STORE_ATTR_SLOT_r21 1291 -#define _STORE_ATTR_WITH_HINT_r21 1292 -#define _STORE_DEREF_r10 1293 -#define _STORE_FAST_LOAD_FAST_r11 1294 -#define _STORE_FAST_STORE_FAST_r20 1295 -#define _STORE_GLOBAL_r10 1296 -#define _STORE_NAME_r10 1297 -#define _STORE_SLICE_r30 1298 -#define _STORE_SUBSCR_r30 1299 -#define _STORE_SUBSCR_DICT_r31 1300 -#define _STORE_SUBSCR_LIST_INT_r32 1301 -#define _SWAP_r11 1302 -#define _SWAP_2_r02 1303 -#define _SWAP_2_r12 1304 -#define _SWAP_2_r22 1305 -#define _SWAP_2_r33 1306 -#define _SWAP_3_r03 1307 -#define _SWAP_3_r13 1308 -#define _SWAP_3_r23 1309 -#define _SWAP_3_r33 1310 -#define _SWAP_FAST_r01 1311 -#define _SWAP_FAST_r11 1312 -#define _SWAP_FAST_r22 1313 -#define _SWAP_FAST_r33 1314 -#define _SWAP_FAST_0_r01 1315 -#define _SWAP_FAST_0_r11 1316 -#define _SWAP_FAST_0_r22 1317 -#define _SWAP_FAST_0_r33 1318 -#define _SWAP_FAST_1_r01 1319 -#define _SWAP_FAST_1_r11 1320 -#define _SWAP_FAST_1_r22 1321 -#define _SWAP_FAST_1_r33 1322 -#define _SWAP_FAST_2_r01 1323 -#define _SWAP_FAST_2_r11 1324 -#define _SWAP_FAST_2_r22 1325 -#define _SWAP_FAST_2_r33 1326 -#define _SWAP_FAST_3_r01 1327 -#define _SWAP_FAST_3_r11 1328 -#define _SWAP_FAST_3_r22 1329 -#define _SWAP_FAST_3_r33 1330 -#define _SWAP_FAST_4_r01 1331 -#define _SWAP_FAST_4_r11 1332 -#define _SWAP_FAST_4_r22 1333 -#define _SWAP_FAST_4_r33 1334 -#define _SWAP_FAST_5_r01 1335 -#define _SWAP_FAST_5_r11 1336 -#define _SWAP_FAST_5_r22 1337 -#define _SWAP_FAST_5_r33 1338 -#define _SWAP_FAST_6_r01 1339 -#define _SWAP_FAST_6_r11 1340 -#define _SWAP_FAST_6_r22 1341 -#define _SWAP_FAST_6_r33 1342 -#define _SWAP_FAST_7_r01 1343 -#define _SWAP_FAST_7_r11 1344 -#define _SWAP_FAST_7_r22 1345 -#define _SWAP_FAST_7_r33 1346 -#define _TIER2_RESUME_CHECK_r00 1347 -#define _TIER2_RESUME_CHECK_r11 1348 -#define _TIER2_RESUME_CHECK_r22 1349 -#define _TIER2_RESUME_CHECK_r33 1350 -#define _TO_BOOL_r11 1351 -#define _TO_BOOL_BOOL_r01 1352 -#define _TO_BOOL_BOOL_r11 1353 -#define _TO_BOOL_BOOL_r22 1354 -#define _TO_BOOL_BOOL_r33 1355 -#define _TO_BOOL_INT_r11 1356 -#define _TO_BOOL_LIST_r11 1357 -#define _TO_BOOL_NONE_r01 1358 -#define _TO_BOOL_NONE_r11 1359 -#define _TO_BOOL_NONE_r22 1360 -#define _TO_BOOL_NONE_r33 1361 -#define _TO_BOOL_STR_r02 1362 -#define _TO_BOOL_STR_r12 1363 -#define _TO_BOOL_STR_r23 1364 -#define _TRACE_RECORD_r00 1365 -#define _UNARY_INVERT_r12 1366 -#define _UNARY_NEGATIVE_r12 1367 -#define _UNARY_NOT_r01 1368 -#define _UNARY_NOT_r11 1369 -#define _UNARY_NOT_r22 1370 -#define _UNARY_NOT_r33 1371 -#define _UNPACK_EX_r10 1372 -#define _UNPACK_SEQUENCE_r10 1373 -#define _UNPACK_SEQUENCE_LIST_r10 1374 -#define _UNPACK_SEQUENCE_TUPLE_r10 1375 -#define _UNPACK_SEQUENCE_TWO_TUPLE_r12 1376 -#define _WITH_EXCEPT_START_r33 1377 -#define _YIELD_VALUE_r11 1378 -#define MAX_UOP_REGS_ID 1378 +#define _MATCH_CLASS_GET_OPT_ATTR_r13 1170 +#define _MATCH_CLASS_ISINSTANCE_r22 1171 +#define _MATCH_KEYS_r23 1172 +#define _MATCH_MAPPING_r02 1173 +#define _MATCH_MAPPING_r12 1174 +#define _MATCH_MAPPING_r23 1175 +#define _MATCH_SEQUENCE_r02 1176 +#define _MATCH_SEQUENCE_r12 1177 +#define _MATCH_SEQUENCE_r23 1178 +#define _MAYBE_EXPAND_METHOD_r00 1179 +#define _MAYBE_EXPAND_METHOD_KW_r11 1180 +#define _MONITOR_CALL_r00 1181 +#define _MONITOR_CALL_KW_r11 1182 +#define _MONITOR_JUMP_BACKWARD_r00 1183 +#define _MONITOR_JUMP_BACKWARD_r11 1184 +#define _MONITOR_JUMP_BACKWARD_r22 1185 +#define _MONITOR_JUMP_BACKWARD_r33 1186 +#define _MONITOR_RESUME_r00 1187 +#define _NOP_r00 1188 +#define _NOP_r11 1189 +#define _NOP_r22 1190 +#define _NOP_r33 1191 +#define _POP_CALL_r20 1192 +#define _POP_CALL_LOAD_CONST_INLINE_BORROW_r21 1193 +#define _POP_CALL_ONE_r30 1194 +#define _POP_CALL_ONE_LOAD_CONST_INLINE_BORROW_r31 1195 +#define _POP_CALL_TWO_r30 1196 +#define _POP_CALL_TWO_LOAD_CONST_INLINE_BORROW_r31 1197 +#define _POP_EXCEPT_r10 1198 +#define _POP_ITER_r20 1199 +#define _POP_JUMP_IF_FALSE_r00 1200 +#define _POP_JUMP_IF_FALSE_r10 1201 +#define _POP_JUMP_IF_FALSE_r21 1202 +#define _POP_JUMP_IF_FALSE_r32 1203 +#define _POP_JUMP_IF_TRUE_r00 1204 +#define _POP_JUMP_IF_TRUE_r10 1205 +#define _POP_JUMP_IF_TRUE_r21 1206 +#define _POP_JUMP_IF_TRUE_r32 1207 +#define _POP_TOP_r10 1208 +#define _POP_TOP_FLOAT_r00 1209 +#define _POP_TOP_FLOAT_r10 1210 +#define _POP_TOP_FLOAT_r21 1211 +#define _POP_TOP_FLOAT_r32 1212 +#define _POP_TOP_INT_r00 1213 +#define _POP_TOP_INT_r10 1214 +#define _POP_TOP_INT_r21 1215 +#define _POP_TOP_INT_r32 1216 +#define _POP_TOP_LOAD_CONST_INLINE_r11 1217 +#define _POP_TOP_LOAD_CONST_INLINE_BORROW_r11 1218 +#define _POP_TOP_NOP_r00 1219 +#define _POP_TOP_NOP_r10 1220 +#define _POP_TOP_NOP_r21 1221 +#define _POP_TOP_NOP_r32 1222 +#define _POP_TOP_UNICODE_r00 1223 +#define _POP_TOP_UNICODE_r10 1224 +#define _POP_TOP_UNICODE_r21 1225 +#define _POP_TOP_UNICODE_r32 1226 +#define _POP_TWO_r20 1227 +#define _POP_TWO_LOAD_CONST_INLINE_BORROW_r21 1228 +#define _PUSH_EXC_INFO_r02 1229 +#define _PUSH_EXC_INFO_r12 1230 +#define _PUSH_EXC_INFO_r23 1231 +#define _PUSH_FRAME_r10 1232 +#define _PUSH_NULL_r01 1233 +#define _PUSH_NULL_r12 1234 +#define _PUSH_NULL_r23 1235 +#define _PUSH_NULL_CONDITIONAL_r00 1236 +#define _PY_FRAME_EX_r31 1237 +#define _PY_FRAME_GENERAL_r01 1238 +#define _PY_FRAME_KW_r11 1239 +#define _QUICKEN_RESUME_r00 1240 +#define _QUICKEN_RESUME_r11 1241 +#define _QUICKEN_RESUME_r22 1242 +#define _QUICKEN_RESUME_r33 1243 +#define _REPLACE_WITH_TRUE_r02 1244 +#define _REPLACE_WITH_TRUE_r12 1245 +#define _REPLACE_WITH_TRUE_r23 1246 +#define _RESUME_CHECK_r00 1247 +#define _RESUME_CHECK_r11 1248 +#define _RESUME_CHECK_r22 1249 +#define _RESUME_CHECK_r33 1250 +#define _RETURN_GENERATOR_r01 1251 +#define _RETURN_VALUE_r11 1252 +#define _SAVE_RETURN_OFFSET_r00 1253 +#define _SAVE_RETURN_OFFSET_r11 1254 +#define _SAVE_RETURN_OFFSET_r22 1255 +#define _SAVE_RETURN_OFFSET_r33 1256 +#define _SEND_r22 1257 +#define _SEND_GEN_FRAME_r22 1258 +#define _SETUP_ANNOTATIONS_r00 1259 +#define _SET_ADD_r10 1260 +#define _SET_FUNCTION_ATTRIBUTE_r01 1261 +#define _SET_FUNCTION_ATTRIBUTE_r11 1262 +#define _SET_FUNCTION_ATTRIBUTE_r21 1263 +#define _SET_FUNCTION_ATTRIBUTE_r32 1264 +#define _SET_IP_r00 1265 +#define _SET_IP_r11 1266 +#define _SET_IP_r22 1267 +#define _SET_IP_r33 1268 +#define _SET_UPDATE_r10 1269 +#define _SHUFFLE_2_LOAD_CONST_INLINE_BORROW_r02 1270 +#define _SHUFFLE_2_LOAD_CONST_INLINE_BORROW_r12 1271 +#define _SHUFFLE_2_LOAD_CONST_INLINE_BORROW_r22 1272 +#define _SHUFFLE_2_LOAD_CONST_INLINE_BORROW_r32 1273 +#define _SHUFFLE_3_LOAD_CONST_INLINE_BORROW_r03 1274 +#define _SHUFFLE_3_LOAD_CONST_INLINE_BORROW_r13 1275 +#define _SHUFFLE_3_LOAD_CONST_INLINE_BORROW_r23 1276 +#define _SHUFFLE_3_LOAD_CONST_INLINE_BORROW_r33 1277 +#define _SPILL_OR_RELOAD_r01 1278 +#define _SPILL_OR_RELOAD_r02 1279 +#define _SPILL_OR_RELOAD_r03 1280 +#define _SPILL_OR_RELOAD_r10 1281 +#define _SPILL_OR_RELOAD_r12 1282 +#define _SPILL_OR_RELOAD_r13 1283 +#define _SPILL_OR_RELOAD_r20 1284 +#define _SPILL_OR_RELOAD_r21 1285 +#define _SPILL_OR_RELOAD_r23 1286 +#define _SPILL_OR_RELOAD_r30 1287 +#define _SPILL_OR_RELOAD_r31 1288 +#define _SPILL_OR_RELOAD_r32 1289 +#define _START_EXECUTOR_r00 1290 +#define _STORE_ATTR_r20 1291 +#define _STORE_ATTR_INSTANCE_VALUE_r21 1292 +#define _STORE_ATTR_SLOT_r21 1293 +#define _STORE_ATTR_WITH_HINT_r21 1294 +#define _STORE_DEREF_r10 1295 +#define _STORE_FAST_LOAD_FAST_r11 1296 +#define _STORE_FAST_STORE_FAST_r20 1297 +#define _STORE_GLOBAL_r10 1298 +#define _STORE_NAME_r10 1299 +#define _STORE_SLICE_r30 1300 +#define _STORE_SUBSCR_r30 1301 +#define _STORE_SUBSCR_DICT_r31 1302 +#define _STORE_SUBSCR_LIST_INT_r32 1303 +#define _SWAP_r11 1304 +#define _SWAP_2_r02 1305 +#define _SWAP_2_r12 1306 +#define _SWAP_2_r22 1307 +#define _SWAP_2_r33 1308 +#define _SWAP_3_r03 1309 +#define _SWAP_3_r13 1310 +#define _SWAP_3_r23 1311 +#define _SWAP_3_r33 1312 +#define _SWAP_FAST_r01 1313 +#define _SWAP_FAST_r11 1314 +#define _SWAP_FAST_r22 1315 +#define _SWAP_FAST_r33 1316 +#define _SWAP_FAST_0_r01 1317 +#define _SWAP_FAST_0_r11 1318 +#define _SWAP_FAST_0_r22 1319 +#define _SWAP_FAST_0_r33 1320 +#define _SWAP_FAST_1_r01 1321 +#define _SWAP_FAST_1_r11 1322 +#define _SWAP_FAST_1_r22 1323 +#define _SWAP_FAST_1_r33 1324 +#define _SWAP_FAST_2_r01 1325 +#define _SWAP_FAST_2_r11 1326 +#define _SWAP_FAST_2_r22 1327 +#define _SWAP_FAST_2_r33 1328 +#define _SWAP_FAST_3_r01 1329 +#define _SWAP_FAST_3_r11 1330 +#define _SWAP_FAST_3_r22 1331 +#define _SWAP_FAST_3_r33 1332 +#define _SWAP_FAST_4_r01 1333 +#define _SWAP_FAST_4_r11 1334 +#define _SWAP_FAST_4_r22 1335 +#define _SWAP_FAST_4_r33 1336 +#define _SWAP_FAST_5_r01 1337 +#define _SWAP_FAST_5_r11 1338 +#define _SWAP_FAST_5_r22 1339 +#define _SWAP_FAST_5_r33 1340 +#define _SWAP_FAST_6_r01 1341 +#define _SWAP_FAST_6_r11 1342 +#define _SWAP_FAST_6_r22 1343 +#define _SWAP_FAST_6_r33 1344 +#define _SWAP_FAST_7_r01 1345 +#define _SWAP_FAST_7_r11 1346 +#define _SWAP_FAST_7_r22 1347 +#define _SWAP_FAST_7_r33 1348 +#define _TIER2_RESUME_CHECK_r00 1349 +#define _TIER2_RESUME_CHECK_r11 1350 +#define _TIER2_RESUME_CHECK_r22 1351 +#define _TIER2_RESUME_CHECK_r33 1352 +#define _TO_BOOL_r11 1353 +#define _TO_BOOL_BOOL_r01 1354 +#define _TO_BOOL_BOOL_r11 1355 +#define _TO_BOOL_BOOL_r22 1356 +#define _TO_BOOL_BOOL_r33 1357 +#define _TO_BOOL_INT_r11 1358 +#define _TO_BOOL_LIST_r11 1359 +#define _TO_BOOL_NONE_r01 1360 +#define _TO_BOOL_NONE_r11 1361 +#define _TO_BOOL_NONE_r22 1362 +#define _TO_BOOL_NONE_r33 1363 +#define _TO_BOOL_STR_r02 1364 +#define _TO_BOOL_STR_r12 1365 +#define _TO_BOOL_STR_r23 1366 +#define _TRACE_RECORD_r00 1367 +#define _UNARY_INVERT_r12 1368 +#define _UNARY_NEGATIVE_r12 1369 +#define _UNARY_NOT_r01 1370 +#define _UNARY_NOT_r11 1371 +#define _UNARY_NOT_r22 1372 +#define _UNARY_NOT_r33 1373 +#define _UNPACK_EX_r10 1374 +#define _UNPACK_SEQUENCE_r10 1375 +#define _UNPACK_SEQUENCE_LIST_r10 1376 +#define _UNPACK_SEQUENCE_TUPLE_r10 1377 +#define _UNPACK_SEQUENCE_TWO_TUPLE_r12 1378 +#define _WITH_EXCEPT_START_r33 1379 +#define _YIELD_VALUE_r11 1380 +#define MAX_UOP_REGS_ID 1380 #ifdef __cplusplus } diff --git a/Include/internal/pycore_uop_metadata.h b/Include/internal/pycore_uop_metadata.h index bce5bda8ff066c..dd5e2ddcd882ef 100644 --- a/Include/internal/pycore_uop_metadata.h +++ b/Include/internal/pycore_uop_metadata.h @@ -218,6 +218,8 @@ const uint32_t _PyUop_Flags[MAX_UOP_ID+1] = { [_IMPORT_FROM] = HAS_ARG_FLAG | HAS_NAME_FLAG | HAS_ERROR_FLAG | HAS_ESCAPES_FLAG, [_IS_NONE] = HAS_ESCAPES_FLAG, [_GET_LEN] = HAS_ERROR_FLAG | HAS_ESCAPES_FLAG, + [_MATCH_CLASS_ISINSTANCE] = HAS_ERROR_FLAG | HAS_ESCAPES_FLAG, + [_MATCH_CLASS_GET_OPT_ATTR] = HAS_ARG_FLAG | HAS_NAME_FLAG | HAS_ERROR_FLAG | HAS_ESCAPES_FLAG, [_MATCH_CLASS] = HAS_ARG_FLAG | HAS_ERROR_FLAG | HAS_ESCAPES_FLAG, [_MATCH_MAPPING] = 0, [_MATCH_SEQUENCE] = 0, @@ -2023,6 +2025,24 @@ const _PyUopCachingInfo _PyUop_Caching[MAX_UOP_ID+1] = { { -1, -1, -1 }, }, }, + [_MATCH_CLASS_ISINSTANCE] = { + .best = { 2, 2, 2, 2 }, + .entries = { + { -1, -1, -1 }, + { -1, -1, -1 }, + { 2, 2, _MATCH_CLASS_ISINSTANCE_r22 }, + { -1, -1, -1 }, + }, + }, + [_MATCH_CLASS_GET_OPT_ATTR] = { + .best = { 1, 1, 1, 1 }, + .entries = { + { -1, -1, -1 }, + { 3, 1, _MATCH_CLASS_GET_OPT_ATTR_r13 }, + { -1, -1, -1 }, + { -1, -1, -1 }, + }, + }, [_MATCH_CLASS] = { .best = { 3, 3, 3, 3 }, .entries = { @@ -3723,6 +3743,8 @@ const uint16_t _PyUop_Uncached[MAX_UOP_REGS_ID+1] = { [_IMPORT_FROM_r12] = _IMPORT_FROM, [_IS_NONE_r11] = _IS_NONE, [_GET_LEN_r12] = _GET_LEN, + [_MATCH_CLASS_ISINSTANCE_r22] = _MATCH_CLASS_ISINSTANCE, + [_MATCH_CLASS_GET_OPT_ATTR_r13] = _MATCH_CLASS_GET_OPT_ATTR, [_MATCH_CLASS_r31] = _MATCH_CLASS, [_MATCH_MAPPING_r02] = _MATCH_MAPPING, [_MATCH_MAPPING_r12] = _MATCH_MAPPING, @@ -4873,6 +4895,10 @@ const char *const _PyOpcode_uop_name[MAX_UOP_REGS_ID+1] = { [_MAP_ADD_r20] = "_MAP_ADD_r20", [_MATCH_CLASS] = "_MATCH_CLASS", [_MATCH_CLASS_r31] = "_MATCH_CLASS_r31", + [_MATCH_CLASS_GET_OPT_ATTR] = "_MATCH_CLASS_GET_OPT_ATTR", + [_MATCH_CLASS_GET_OPT_ATTR_r13] = "_MATCH_CLASS_GET_OPT_ATTR_r13", + [_MATCH_CLASS_ISINSTANCE] = "_MATCH_CLASS_ISINSTANCE", + [_MATCH_CLASS_ISINSTANCE_r22] = "_MATCH_CLASS_ISINSTANCE_r22", [_MATCH_KEYS] = "_MATCH_KEYS", [_MATCH_KEYS_r23] = "_MATCH_KEYS_r23", [_MATCH_MAPPING] = "_MATCH_MAPPING", @@ -5514,6 +5540,10 @@ int _PyUop_num_popped(int opcode, int oparg) return 1; case _GET_LEN: return 0; + case _MATCH_CLASS_ISINSTANCE: + return 1; + case _MATCH_CLASS_GET_OPT_ATTR: + return 0; case _MATCH_CLASS: return 3; case _MATCH_MAPPING: diff --git a/Include/opcode_ids.h b/Include/opcode_ids.h index c46368444f4c59..0640dec8233f10 100644 --- a/Include/opcode_ids.h +++ b/Include/opcode_ids.h @@ -34,103 +34,105 @@ extern "C" { #define LOAD_BUILD_CLASS 21 #define LOAD_LOCALS 22 #define MAKE_FUNCTION 23 -#define MATCH_KEYS 24 -#define MATCH_MAPPING 25 -#define MATCH_SEQUENCE 26 -#define NOP 27 -#define NOT_TAKEN 28 -#define POP_EXCEPT 29 -#define POP_ITER 30 -#define POP_TOP 31 -#define PUSH_EXC_INFO 32 -#define PUSH_NULL 33 -#define RETURN_GENERATOR 34 -#define RETURN_VALUE 35 -#define SETUP_ANNOTATIONS 36 -#define STORE_SLICE 37 -#define STORE_SUBSCR 38 -#define TO_BOOL 39 -#define UNARY_INVERT 40 -#define UNARY_NEGATIVE 41 -#define UNARY_NOT 42 -#define WITH_EXCEPT_START 43 -#define BINARY_OP 44 -#define BUILD_INTERPOLATION 45 -#define BUILD_LIST 46 -#define BUILD_MAP 47 -#define BUILD_SET 48 -#define BUILD_SLICE 49 -#define BUILD_STRING 50 -#define BUILD_TUPLE 51 -#define CALL 52 -#define CALL_INTRINSIC_1 53 -#define CALL_INTRINSIC_2 54 -#define CALL_KW 55 -#define COMPARE_OP 56 -#define CONTAINS_OP 57 -#define CONVERT_VALUE 58 -#define COPY 59 -#define COPY_FREE_VARS 60 -#define DELETE_ATTR 61 -#define DELETE_DEREF 62 -#define DELETE_FAST 63 -#define DELETE_GLOBAL 64 -#define DELETE_NAME 65 -#define DICT_MERGE 66 -#define DICT_UPDATE 67 -#define END_ASYNC_FOR 68 -#define EXTENDED_ARG 69 -#define FOR_ITER 70 -#define GET_AWAITABLE 71 -#define IMPORT_FROM 72 -#define IMPORT_NAME 73 -#define IS_OP 74 -#define JUMP_BACKWARD 75 -#define JUMP_BACKWARD_NO_INTERRUPT 76 -#define JUMP_FORWARD 77 -#define LIST_APPEND 78 -#define LIST_EXTEND 79 -#define LOAD_ATTR 80 -#define LOAD_COMMON_CONSTANT 81 -#define LOAD_CONST 82 -#define LOAD_DEREF 83 -#define LOAD_FAST 84 -#define LOAD_FAST_AND_CLEAR 85 -#define LOAD_FAST_BORROW 86 -#define LOAD_FAST_BORROW_LOAD_FAST_BORROW 87 -#define LOAD_FAST_CHECK 88 -#define LOAD_FAST_LOAD_FAST 89 -#define LOAD_FROM_DICT_OR_DEREF 90 -#define LOAD_FROM_DICT_OR_GLOBALS 91 -#define LOAD_GLOBAL 92 -#define LOAD_NAME 93 -#define LOAD_SMALL_INT 94 -#define LOAD_SPECIAL 95 -#define LOAD_SUPER_ATTR 96 -#define MAKE_CELL 97 -#define MAP_ADD 98 -#define MATCH_CLASS 99 -#define POP_JUMP_IF_FALSE 100 -#define POP_JUMP_IF_NONE 101 -#define POP_JUMP_IF_NOT_NONE 102 -#define POP_JUMP_IF_TRUE 103 -#define RAISE_VARARGS 104 -#define RERAISE 105 -#define SEND 106 -#define SET_ADD 107 -#define SET_FUNCTION_ATTRIBUTE 108 -#define SET_UPDATE 109 -#define STORE_ATTR 110 -#define STORE_DEREF 111 -#define STORE_FAST 112 -#define STORE_FAST_LOAD_FAST 113 -#define STORE_FAST_STORE_FAST 114 -#define STORE_GLOBAL 115 -#define STORE_NAME 116 -#define SWAP 117 -#define UNPACK_EX 118 -#define UNPACK_SEQUENCE 119 -#define YIELD_VALUE 120 +#define MATCH_CLASS_ISINSTANCE 24 +#define MATCH_KEYS 25 +#define MATCH_MAPPING 26 +#define MATCH_SEQUENCE 27 +#define NOP 28 +#define NOT_TAKEN 29 +#define POP_EXCEPT 30 +#define POP_ITER 31 +#define POP_TOP 32 +#define PUSH_EXC_INFO 33 +#define PUSH_NULL 34 +#define RETURN_GENERATOR 35 +#define RETURN_VALUE 36 +#define SETUP_ANNOTATIONS 37 +#define STORE_SLICE 38 +#define STORE_SUBSCR 39 +#define TO_BOOL 40 +#define UNARY_INVERT 41 +#define UNARY_NEGATIVE 42 +#define UNARY_NOT 43 +#define WITH_EXCEPT_START 44 +#define BINARY_OP 45 +#define BUILD_INTERPOLATION 46 +#define BUILD_LIST 47 +#define BUILD_MAP 48 +#define BUILD_SET 49 +#define BUILD_SLICE 50 +#define BUILD_STRING 51 +#define BUILD_TUPLE 52 +#define CALL 53 +#define CALL_INTRINSIC_1 54 +#define CALL_INTRINSIC_2 55 +#define CALL_KW 56 +#define COMPARE_OP 57 +#define CONTAINS_OP 58 +#define CONVERT_VALUE 59 +#define COPY 60 +#define COPY_FREE_VARS 61 +#define DELETE_ATTR 62 +#define DELETE_DEREF 63 +#define DELETE_FAST 64 +#define DELETE_GLOBAL 65 +#define DELETE_NAME 66 +#define DICT_MERGE 67 +#define DICT_UPDATE 68 +#define END_ASYNC_FOR 69 +#define EXTENDED_ARG 70 +#define FOR_ITER 71 +#define GET_AWAITABLE 72 +#define IMPORT_FROM 73 +#define IMPORT_NAME 74 +#define IS_OP 75 +#define JUMP_BACKWARD 76 +#define JUMP_BACKWARD_NO_INTERRUPT 77 +#define JUMP_FORWARD 78 +#define LIST_APPEND 79 +#define LIST_EXTEND 80 +#define LOAD_ATTR 81 +#define LOAD_COMMON_CONSTANT 82 +#define LOAD_CONST 83 +#define LOAD_DEREF 84 +#define LOAD_FAST 85 +#define LOAD_FAST_AND_CLEAR 86 +#define LOAD_FAST_BORROW 87 +#define LOAD_FAST_BORROW_LOAD_FAST_BORROW 88 +#define LOAD_FAST_CHECK 89 +#define LOAD_FAST_LOAD_FAST 90 +#define LOAD_FROM_DICT_OR_DEREF 91 +#define LOAD_FROM_DICT_OR_GLOBALS 92 +#define LOAD_GLOBAL 93 +#define LOAD_NAME 94 +#define LOAD_SMALL_INT 95 +#define LOAD_SPECIAL 96 +#define LOAD_SUPER_ATTR 97 +#define MAKE_CELL 98 +#define MAP_ADD 99 +#define MATCH_CLASS 100 +#define MATCH_CLASS_GET_OPT_ATTR 101 +#define POP_JUMP_IF_FALSE 102 +#define POP_JUMP_IF_NONE 103 +#define POP_JUMP_IF_NOT_NONE 104 +#define POP_JUMP_IF_TRUE 105 +#define RAISE_VARARGS 106 +#define RERAISE 107 +#define SEND 108 +#define SET_ADD 109 +#define SET_FUNCTION_ATTRIBUTE 110 +#define SET_UPDATE 111 +#define STORE_ATTR 112 +#define STORE_DEREF 113 +#define STORE_FAST 114 +#define STORE_FAST_LOAD_FAST 115 +#define STORE_FAST_STORE_FAST 116 +#define STORE_GLOBAL 117 +#define STORE_NAME 118 +#define SWAP 119 +#define UNPACK_EX 120 +#define UNPACK_SEQUENCE 121 +#define YIELD_VALUE 122 #define RESUME 128 #define BINARY_OP_ADD_FLOAT 129 #define BINARY_OP_ADD_INT 130 @@ -251,7 +253,7 @@ extern "C" { #define SETUP_WITH 265 #define STORE_FAST_MAYBE_NULL 266 -#define HAVE_ARGUMENT 43 +#define HAVE_ARGUMENT 44 #define MIN_SPECIALIZED_OPCODE 129 #define MIN_INSTRUMENTED_OPCODE 233 diff --git a/Lib/_opcode_metadata.py b/Lib/_opcode_metadata.py index 8f14d81a43ee75..1cae30df65999b 100644 --- a/Lib/_opcode_metadata.py +++ b/Lib/_opcode_metadata.py @@ -242,103 +242,105 @@ 'LOAD_BUILD_CLASS': 21, 'LOAD_LOCALS': 22, 'MAKE_FUNCTION': 23, - 'MATCH_KEYS': 24, - 'MATCH_MAPPING': 25, - 'MATCH_SEQUENCE': 26, - 'NOP': 27, - 'NOT_TAKEN': 28, - 'POP_EXCEPT': 29, - 'POP_ITER': 30, - 'POP_TOP': 31, - 'PUSH_EXC_INFO': 32, - 'PUSH_NULL': 33, - 'RETURN_GENERATOR': 34, - 'RETURN_VALUE': 35, - 'SETUP_ANNOTATIONS': 36, - 'STORE_SLICE': 37, - 'STORE_SUBSCR': 38, - 'TO_BOOL': 39, - 'UNARY_INVERT': 40, - 'UNARY_NEGATIVE': 41, - 'UNARY_NOT': 42, - 'WITH_EXCEPT_START': 43, - 'BINARY_OP': 44, - 'BUILD_INTERPOLATION': 45, - 'BUILD_LIST': 46, - 'BUILD_MAP': 47, - 'BUILD_SET': 48, - 'BUILD_SLICE': 49, - 'BUILD_STRING': 50, - 'BUILD_TUPLE': 51, - 'CALL': 52, - 'CALL_INTRINSIC_1': 53, - 'CALL_INTRINSIC_2': 54, - 'CALL_KW': 55, - 'COMPARE_OP': 56, - 'CONTAINS_OP': 57, - 'CONVERT_VALUE': 58, - 'COPY': 59, - 'COPY_FREE_VARS': 60, - 'DELETE_ATTR': 61, - 'DELETE_DEREF': 62, - 'DELETE_FAST': 63, - 'DELETE_GLOBAL': 64, - 'DELETE_NAME': 65, - 'DICT_MERGE': 66, - 'DICT_UPDATE': 67, - 'END_ASYNC_FOR': 68, - 'EXTENDED_ARG': 69, - 'FOR_ITER': 70, - 'GET_AWAITABLE': 71, - 'IMPORT_FROM': 72, - 'IMPORT_NAME': 73, - 'IS_OP': 74, - 'JUMP_BACKWARD': 75, - 'JUMP_BACKWARD_NO_INTERRUPT': 76, - 'JUMP_FORWARD': 77, - 'LIST_APPEND': 78, - 'LIST_EXTEND': 79, - 'LOAD_ATTR': 80, - 'LOAD_COMMON_CONSTANT': 81, - 'LOAD_CONST': 82, - 'LOAD_DEREF': 83, - 'LOAD_FAST': 84, - 'LOAD_FAST_AND_CLEAR': 85, - 'LOAD_FAST_BORROW': 86, - 'LOAD_FAST_BORROW_LOAD_FAST_BORROW': 87, - 'LOAD_FAST_CHECK': 88, - 'LOAD_FAST_LOAD_FAST': 89, - 'LOAD_FROM_DICT_OR_DEREF': 90, - 'LOAD_FROM_DICT_OR_GLOBALS': 91, - 'LOAD_GLOBAL': 92, - 'LOAD_NAME': 93, - 'LOAD_SMALL_INT': 94, - 'LOAD_SPECIAL': 95, - 'LOAD_SUPER_ATTR': 96, - 'MAKE_CELL': 97, - 'MAP_ADD': 98, - 'MATCH_CLASS': 99, - 'POP_JUMP_IF_FALSE': 100, - 'POP_JUMP_IF_NONE': 101, - 'POP_JUMP_IF_NOT_NONE': 102, - 'POP_JUMP_IF_TRUE': 103, - 'RAISE_VARARGS': 104, - 'RERAISE': 105, - 'SEND': 106, - 'SET_ADD': 107, - 'SET_FUNCTION_ATTRIBUTE': 108, - 'SET_UPDATE': 109, - 'STORE_ATTR': 110, - 'STORE_DEREF': 111, - 'STORE_FAST': 112, - 'STORE_FAST_LOAD_FAST': 113, - 'STORE_FAST_STORE_FAST': 114, - 'STORE_GLOBAL': 115, - 'STORE_NAME': 116, - 'SWAP': 117, - 'UNPACK_EX': 118, - 'UNPACK_SEQUENCE': 119, - 'YIELD_VALUE': 120, + 'MATCH_CLASS_ISINSTANCE': 24, + 'MATCH_KEYS': 25, + 'MATCH_MAPPING': 26, + 'MATCH_SEQUENCE': 27, + 'NOP': 28, + 'NOT_TAKEN': 29, + 'POP_EXCEPT': 30, + 'POP_ITER': 31, + 'POP_TOP': 32, + 'PUSH_EXC_INFO': 33, + 'PUSH_NULL': 34, + 'RETURN_GENERATOR': 35, + 'RETURN_VALUE': 36, + 'SETUP_ANNOTATIONS': 37, + 'STORE_SLICE': 38, + 'STORE_SUBSCR': 39, + 'TO_BOOL': 40, + 'UNARY_INVERT': 41, + 'UNARY_NEGATIVE': 42, + 'UNARY_NOT': 43, + 'WITH_EXCEPT_START': 44, + 'BINARY_OP': 45, + 'BUILD_INTERPOLATION': 46, + 'BUILD_LIST': 47, + 'BUILD_MAP': 48, + 'BUILD_SET': 49, + 'BUILD_SLICE': 50, + 'BUILD_STRING': 51, + 'BUILD_TUPLE': 52, + 'CALL': 53, + 'CALL_INTRINSIC_1': 54, + 'CALL_INTRINSIC_2': 55, + 'CALL_KW': 56, + 'COMPARE_OP': 57, + 'CONTAINS_OP': 58, + 'CONVERT_VALUE': 59, + 'COPY': 60, + 'COPY_FREE_VARS': 61, + 'DELETE_ATTR': 62, + 'DELETE_DEREF': 63, + 'DELETE_FAST': 64, + 'DELETE_GLOBAL': 65, + 'DELETE_NAME': 66, + 'DICT_MERGE': 67, + 'DICT_UPDATE': 68, + 'END_ASYNC_FOR': 69, + 'EXTENDED_ARG': 70, + 'FOR_ITER': 71, + 'GET_AWAITABLE': 72, + 'IMPORT_FROM': 73, + 'IMPORT_NAME': 74, + 'IS_OP': 75, + 'JUMP_BACKWARD': 76, + 'JUMP_BACKWARD_NO_INTERRUPT': 77, + 'JUMP_FORWARD': 78, + 'LIST_APPEND': 79, + 'LIST_EXTEND': 80, + 'LOAD_ATTR': 81, + 'LOAD_COMMON_CONSTANT': 82, + 'LOAD_CONST': 83, + 'LOAD_DEREF': 84, + 'LOAD_FAST': 85, + 'LOAD_FAST_AND_CLEAR': 86, + 'LOAD_FAST_BORROW': 87, + 'LOAD_FAST_BORROW_LOAD_FAST_BORROW': 88, + 'LOAD_FAST_CHECK': 89, + 'LOAD_FAST_LOAD_FAST': 90, + 'LOAD_FROM_DICT_OR_DEREF': 91, + 'LOAD_FROM_DICT_OR_GLOBALS': 92, + 'LOAD_GLOBAL': 93, + 'LOAD_NAME': 94, + 'LOAD_SMALL_INT': 95, + 'LOAD_SPECIAL': 96, + 'LOAD_SUPER_ATTR': 97, + 'MAKE_CELL': 98, + 'MAP_ADD': 99, + 'MATCH_CLASS': 100, + 'MATCH_CLASS_GET_OPT_ATTR': 101, + 'POP_JUMP_IF_FALSE': 102, + 'POP_JUMP_IF_NONE': 103, + 'POP_JUMP_IF_NOT_NONE': 104, + 'POP_JUMP_IF_TRUE': 105, + 'RAISE_VARARGS': 106, + 'RERAISE': 107, + 'SEND': 108, + 'SET_ADD': 109, + 'SET_FUNCTION_ATTRIBUTE': 110, + 'SET_UPDATE': 111, + 'STORE_ATTR': 112, + 'STORE_DEREF': 113, + 'STORE_FAST': 114, + 'STORE_FAST_LOAD_FAST': 115, + 'STORE_FAST_STORE_FAST': 116, + 'STORE_GLOBAL': 117, + 'STORE_NAME': 118, + 'SWAP': 119, + 'UNPACK_EX': 120, + 'UNPACK_SEQUENCE': 121, + 'YIELD_VALUE': 122, 'INSTRUMENTED_END_FOR': 233, 'INSTRUMENTED_POP_ITER': 234, 'INSTRUMENTED_END_SEND': 235, @@ -372,5 +374,5 @@ 'STORE_FAST_MAYBE_NULL': 266, } -HAVE_ARGUMENT = 43 +HAVE_ARGUMENT = 44 MIN_INSTRUMENTED_OPCODE = 233 diff --git a/Lib/test/test_dis.py b/Lib/test/test_dis.py index 902bcdd196ec93..7f44cbd9a7e3fb 100644 --- a/Lib/test/test_dis.py +++ b/Lib/test/test_dis.py @@ -1035,7 +1035,8 @@ def test_widths(self): long_opcodes = set(['JUMP_BACKWARD_NO_INTERRUPT', 'LOAD_FAST_BORROW_LOAD_FAST_BORROW', 'INSTRUMENTED_CALL_FUNCTION_EX', - 'ANNOTATIONS_PLACEHOLDER']) + 'ANNOTATIONS_PLACEHOLDER', + 'MATCH_CLASS_ISINSTANCE']) for op, opname in enumerate(dis.opname): if opname in long_opcodes or opname.startswith("INSTRUMENTED"): continue diff --git a/Lib/test/test_peepholer.py b/Lib/test/test_peepholer.py index 1caf6de4a14e39..f98bfc4797f734 100644 --- a/Lib/test/test_peepholer.py +++ b/Lib/test/test_peepholer.py @@ -781,6 +781,14 @@ def test_static_swaps_match_mapping(self): self.assertNotInBytecode(code, "SWAP") def test_static_swaps_match_class(self): + swaps = { + "C(a=a, b=_, c=_)", + "C(a=a, b=_, c=c)", + "C(a=a, b=b, c=_)", + "C(a=a, b=b, c=c)", + "C(a=_, b=b, c=_)", + "C(a=_, b=b, c=c)", + } forms = [ "C({}, {}, {})", "C({}, {}, c={})", @@ -792,7 +800,12 @@ def test_static_swaps_match_class(self): pattern = form.format(a, b, c) with self.subTest(pattern): code = compile_pattern_with_fast_locals(pattern) - self.assertNotInBytecode(code, "SWAP") + if pattern in swaps: + # Swaps are expected here. Class patterns without + # positional sub-patterns are evaluated depth first. + self.assertInBytecode(code, "SWAP") + else: + self.assertNotInBytecode(code, "SWAP") def test_static_swaps_match_sequence(self): swaps = {"*_, b, c", "a, *_, c", "a, b, *_"} diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2025-09-17-22-12-38.gh-issue-138912.PijFSS.rst b/Misc/NEWS.d/next/Core_and_Builtins/2025-09-17-22-12-38.gh-issue-138912.PijFSS.rst new file mode 100644 index 00000000000000..0fbc17a6e4b59f --- /dev/null +++ b/Misc/NEWS.d/next/Core_and_Builtins/2025-09-17-22-12-38.gh-issue-138912.PijFSS.rst @@ -0,0 +1,3 @@ +Add :opcode:`MATCH_CLASS_ISINSTANCE` and :opcode:`MATCH_CLASS_GET_OPT_ATTR` +to improve the performance of :keyword:`match` class patterns without any +positional sub-patterns by ~60%. Patch by Marc Mueller. diff --git a/Programs/test_frozenmain.h b/Programs/test_frozenmain.h index dbeedb7ffe0ce6..2f09817778cfb3 100644 --- a/Programs/test_frozenmain.h +++ b/Programs/test_frozenmain.h @@ -1,19 +1,19 @@ // Auto-generated by Programs/freeze_test_frozenmain.py unsigned char M_test_frozenmain[] = { 227,0,0,0,0,0,0,0,0,0,0,0,0,9,0,0, - 0,0,0,0,0,243,184,0,0,0,128,0,94,0,82,1, - 73,0,116,0,94,0,82,1,73,1,116,1,93,2,33,0, - 82,2,52,1,0,0,0,0,0,0,31,0,93,2,33,0, - 82,3,93,0,80,6,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,52,2,0,0,0,0,0,0, - 31,0,93,1,80,8,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,33,0,52,0,0,0,0,0, - 0,0,82,4,44,26,0,0,0,0,0,0,0,0,0,0, - 116,5,82,7,16,0,70,24,0,0,116,6,93,2,33,0, - 82,5,93,6,12,0,82,6,93,5,93,6,44,26,0,0, - 0,0,0,0,0,0,0,0,12,0,50,4,52,1,0,0, - 0,0,0,0,31,0,75,26,0,0,9,0,30,0,82,1, - 35,0,41,8,233,0,0,0,0,78,122,18,70,114,111,122, + 0,0,0,0,0,243,184,0,0,0,128,0,95,0,83,1, + 74,0,118,0,95,0,83,1,74,1,118,1,94,2,34,0, + 83,2,53,1,0,0,0,0,0,0,32,0,94,2,34,0, + 83,3,94,0,81,6,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,53,2,0,0,0,0,0,0, + 32,0,94,1,81,8,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,34,0,53,0,0,0,0,0, + 0,0,83,4,45,26,0,0,0,0,0,0,0,0,0,0, + 118,5,83,7,16,0,71,24,0,0,118,6,94,2,34,0, + 83,5,94,6,12,0,83,6,94,5,94,6,45,26,0,0, + 0,0,0,0,0,0,0,0,12,0,51,4,53,1,0,0, + 0,0,0,0,32,0,76,26,0,0,9,0,31,0,83,1, + 36,0,41,8,233,0,0,0,0,78,122,18,70,114,111,122, 101,110,32,72,101,108,108,111,32,87,111,114,108,100,122,8, 115,121,115,46,97,114,103,118,218,6,99,111,110,102,105,103, 122,7,99,111,110,102,105,103,32,122,2,58,32,41,5,218, diff --git a/Python/bytecodes.c b/Python/bytecodes.c index 0156fb3d06d854..b88d3252ddad9e 100644 --- a/Python/bytecodes.c +++ b/Python/bytecodes.c @@ -3135,6 +3135,39 @@ dummy_func( len = PyStackRef_FromPyObjectSteal(len_o); } + inst(MATCH_CLASS_ISINSTANCE, (subject, type -- subject, res)) { + PyObject *subject_o = PyStackRef_AsPyObjectBorrow(subject); + PyObject *type_o = PyStackRef_AsPyObjectBorrow(type); + if (!PyType_Check(type_o)) { + const char *e = "called match pattern must be a class"; + _PyErr_Format(tstate, PyExc_TypeError, e); + PyStackRef_CLOSE(type); + ERROR_IF(true); + } + int retval = PyObject_IsInstance(subject_o, type_o); + PyStackRef_CLOSE(type); + ERROR_IF(retval < 0); + assert(!_PyErr_Occurred(tstate)); + res = retval ? PyStackRef_True : PyStackRef_False; + } + + inst(MATCH_CLASS_GET_OPT_ATTR, (subject -- subject, attr, res)) { + PyObject *name = GETITEM(FRAME_CO_NAMES, oparg); + assert(PyUnicode_CheckExact(name)); + PyObject *subject_o = PyStackRef_AsPyObjectBorrow(subject); + PyObject *attr_o; + (void)PyObject_GetOptionalAttr(subject_o, name, &attr_o); + if (attr_o) { + assert(!_PyErr_Occurred(tstate)); // Success! + attr = PyStackRef_FromPyObjectSteal(attr_o); + res = PyStackRef_True; + } else { + ERROR_IF(_PyErr_Occurred(tstate)); // Error! + attr = PyStackRef_FromPyObjectSteal(Py_None); // No attribute found! + res = PyStackRef_False; + } + } + inst(MATCH_CLASS, (subject, type, names -- attrs)) { // Pop TOS and TOS1. Set TOS to a tuple of attributes on success, or // None on failure. diff --git a/Python/ceval.c b/Python/ceval.c index e67ff082ef9fac..7a38fa591c7289 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -862,6 +862,7 @@ PyObject* _PyEval_MatchClass(PyThreadState *tstate, PyObject *subject, PyObject *type, Py_ssize_t nargs, PyObject *kwargs) { + assert(nargs > 0); if (!PyType_Check(type)) { const char *e = "called match pattern must be a class"; _PyErr_Format(tstate, PyExc_TypeError, e); diff --git a/Python/codegen.c b/Python/codegen.c index acd8d84bc9ec6d..bfd08e4d2defda 100644 --- a/Python/codegen.c +++ b/Python/codegen.c @@ -5904,6 +5904,64 @@ validate_kwd_attrs(compiler *c, asdl_identifier_seq *attrs, asdl_pattern_seq* pa return SUCCESS; } +static int +codegen_addop_name_match_class_attr(compiler *c, location loc, int opcode, + PyObject *name) +{ + // No name mangling for match attributes + Py_ssize_t arg = _PyCompile_DictAddObj(METADATA(c)->u_names, name); + if (arg < 0) { + return ERROR; + } + ADDOP_I(c, loc, opcode, arg); + return SUCCESS; +} + +static int +codegen_pattern_class_fast(compiler *c, pattern_ty p, pattern_context *pc) +{ + NEW_JUMP_TARGET_LABEL(c, end); + assert(p->kind == MatchClass_kind); + assert(!asdl_seq_LEN(p->v.MatchClass.patterns)); + asdl_identifier_seq *kwd_attrs = p->v.MatchClass.kwd_attrs; + asdl_pattern_seq *kwd_patterns = p->v.MatchClass.kwd_patterns; + Py_ssize_t nattrs = asdl_seq_LEN(kwd_attrs); + VISIT(c, expr, p->v.MatchClass.cls); + ADDOP(c, LOC(p), MATCH_CLASS_ISINSTANCE); + // TOS is now subject: + pc->on_top++; + RETURN_IF_ERROR(jump_to_fail_pop(c, LOC(p), pc, POP_JUMP_IF_FALSE)); + if (!nattrs) { + ADDOP_JUMP(c, NO_LOCATION, JUMP, end); + } + + Py_ssize_t i; + identifier name; + pattern_ty pattern; + for (i = 0; i < nattrs; i++) { + name = asdl_seq_GET(kwd_attrs, i); + RETURN_IF_ERROR(codegen_addop_name_match_class_attr(c, LOC(p), + MATCH_CLASS_GET_OPT_ATTR, name)); + // TOS is now attribute: + pc->on_top++; + RETURN_IF_ERROR(jump_to_fail_pop(c, LOC(p), pc, POP_JUMP_IF_FALSE)); + pc->on_top--; + + pattern = asdl_seq_GET(kwd_patterns, i); + if (WILDCARD_CHECK(pattern)) { + ADDOP(c, LOC(p), POP_TOP); + continue; + } + RETURN_IF_ERROR(codegen_pattern_subpattern(c, pattern, pc)); + } + + USE_LABEL(c, end); + pc->on_top--; + // Success! POP subject: + ADDOP(c, LOC(p), POP_TOP); + return SUCCESS; +} + static int codegen_pattern_class(compiler *c, pattern_ty p, pattern_context *pc) { @@ -5927,6 +5985,10 @@ codegen_pattern_class(compiler *c, pattern_ty p, pattern_context *pc) if (nattrs) { RETURN_IF_ERROR(validate_kwd_attrs(c, kwd_attrs, kwd_patterns)); } + if (!nargs) { + // Fast path if there are no positional sub-patterns + return codegen_pattern_class_fast(c, p, pc); + } VISIT(c, expr, p->v.MatchClass.cls); PyObject *attr_names = PyTuple_New(nattrs); if (attr_names == NULL) { diff --git a/Python/executor_cases.c.h b/Python/executor_cases.c.h index a4d4c4882118e3..5935ccc6d134f4 100644 --- a/Python/executor_cases.c.h +++ b/Python/executor_cases.c.h @@ -10637,6 +10637,104 @@ break; } + case _MATCH_CLASS_ISINSTANCE_r22: { + CHECK_CURRENT_CACHED_VALUES(2); + assert(WITHIN_STACK_BOUNDS_IGNORING_CACHE()); + _PyStackRef type; + _PyStackRef subject; + _PyStackRef res; + _PyStackRef _stack_item_0 = _tos_cache0; + _PyStackRef _stack_item_1 = _tos_cache1; + type = _stack_item_1; + subject = _stack_item_0; + PyObject *subject_o = PyStackRef_AsPyObjectBorrow(subject); + PyObject *type_o = PyStackRef_AsPyObjectBorrow(type); + if (!PyType_Check(type_o)) { + const char *e = "called match pattern must be a class"; + stack_pointer[0] = subject; + stack_pointer[1] = type; + stack_pointer += 2; + ASSERT_WITHIN_STACK_BOUNDS(__FILE__, __LINE__); + _PyFrame_SetStackPointer(frame, stack_pointer); + _PyErr_Format(tstate, PyExc_TypeError, e); + stack_pointer = _PyFrame_GetStackPointer(frame); + stack_pointer += -1; + ASSERT_WITHIN_STACK_BOUNDS(__FILE__, __LINE__); + _PyFrame_SetStackPointer(frame, stack_pointer); + PyStackRef_CLOSE(type); + stack_pointer = _PyFrame_GetStackPointer(frame); + SET_CURRENT_CACHED_VALUES(0); + JUMP_TO_ERROR(); + } + stack_pointer[0] = subject; + stack_pointer[1] = type; + stack_pointer += 2; + ASSERT_WITHIN_STACK_BOUNDS(__FILE__, __LINE__); + _PyFrame_SetStackPointer(frame, stack_pointer); + int retval = PyObject_IsInstance(subject_o, type_o); + stack_pointer = _PyFrame_GetStackPointer(frame); + stack_pointer += -1; + ASSERT_WITHIN_STACK_BOUNDS(__FILE__, __LINE__); + _PyFrame_SetStackPointer(frame, stack_pointer); + PyStackRef_CLOSE(type); + stack_pointer = _PyFrame_GetStackPointer(frame); + if (retval < 0) { + SET_CURRENT_CACHED_VALUES(0); + JUMP_TO_ERROR(); + } + assert(!_PyErr_Occurred(tstate)); + res = retval ? PyStackRef_True : PyStackRef_False; + _tos_cache1 = res; + _tos_cache0 = subject; + _tos_cache2 = PyStackRef_ZERO_BITS; + SET_CURRENT_CACHED_VALUES(2); + stack_pointer += -1; + ASSERT_WITHIN_STACK_BOUNDS(__FILE__, __LINE__); + assert(WITHIN_STACK_BOUNDS_IGNORING_CACHE()); + break; + } + + case _MATCH_CLASS_GET_OPT_ATTR_r13: { + CHECK_CURRENT_CACHED_VALUES(1); + assert(WITHIN_STACK_BOUNDS_IGNORING_CACHE()); + _PyStackRef subject; + _PyStackRef attr; + _PyStackRef res; + _PyStackRef _stack_item_0 = _tos_cache0; + oparg = CURRENT_OPARG(); + subject = _stack_item_0; + PyObject *name = GETITEM(FRAME_CO_NAMES, oparg); + assert(PyUnicode_CheckExact(name)); + PyObject *subject_o = PyStackRef_AsPyObjectBorrow(subject); + PyObject *attr_o; + stack_pointer[0] = subject; + stack_pointer += 1; + ASSERT_WITHIN_STACK_BOUNDS(__FILE__, __LINE__); + _PyFrame_SetStackPointer(frame, stack_pointer); + (void)PyObject_GetOptionalAttr(subject_o, name, &attr_o); + stack_pointer = _PyFrame_GetStackPointer(frame); + if (attr_o) { + assert(!_PyErr_Occurred(tstate)); + attr = PyStackRef_FromPyObjectSteal(attr_o); + res = PyStackRef_True; + } else { + if (_PyErr_Occurred(tstate)) { + SET_CURRENT_CACHED_VALUES(0); + JUMP_TO_ERROR(); + } + attr = PyStackRef_FromPyObjectSteal(Py_None); + res = PyStackRef_False; + } + _tos_cache2 = res; + _tos_cache1 = attr; + _tos_cache0 = subject; + SET_CURRENT_CACHED_VALUES(3); + stack_pointer += -1; + ASSERT_WITHIN_STACK_BOUNDS(__FILE__, __LINE__); + assert(WITHIN_STACK_BOUNDS_IGNORING_CACHE()); + break; + } + case _MATCH_CLASS_r31: { CHECK_CURRENT_CACHED_VALUES(3); assert(WITHIN_STACK_BOUNDS_IGNORING_CACHE()); diff --git a/Python/generated_cases.c.h b/Python/generated_cases.c.h index e5e6d30f9c22f0..71253359863858 100644 --- a/Python/generated_cases.c.h +++ b/Python/generated_cases.c.h @@ -9863,6 +9863,89 @@ DISPATCH(); } + TARGET(MATCH_CLASS_GET_OPT_ATTR) { + #if _Py_TAIL_CALL_INTERP + int opcode = MATCH_CLASS_GET_OPT_ATTR; + (void)(opcode); + #endif + frame->instr_ptr = next_instr; + next_instr += 1; + INSTRUCTION_STATS(MATCH_CLASS_GET_OPT_ATTR); + _PyStackRef subject; + _PyStackRef attr; + _PyStackRef res; + subject = stack_pointer[-1]; + PyObject *name = GETITEM(FRAME_CO_NAMES, oparg); + assert(PyUnicode_CheckExact(name)); + PyObject *subject_o = PyStackRef_AsPyObjectBorrow(subject); + PyObject *attr_o; + _PyFrame_SetStackPointer(frame, stack_pointer); + (void)PyObject_GetOptionalAttr(subject_o, name, &attr_o); + stack_pointer = _PyFrame_GetStackPointer(frame); + if (attr_o) { + assert(!_PyErr_Occurred(tstate)); + attr = PyStackRef_FromPyObjectSteal(attr_o); + res = PyStackRef_True; + } else { + if (_PyErr_Occurred(tstate)) { + JUMP_TO_LABEL(error); + } + attr = PyStackRef_FromPyObjectSteal(Py_None); + res = PyStackRef_False; + } + stack_pointer[0] = attr; + stack_pointer[1] = res; + stack_pointer += 2; + ASSERT_WITHIN_STACK_BOUNDS(__FILE__, __LINE__); + DISPATCH(); + } + + TARGET(MATCH_CLASS_ISINSTANCE) { + #if _Py_TAIL_CALL_INTERP + int opcode = MATCH_CLASS_ISINSTANCE; + (void)(opcode); + #endif + frame->instr_ptr = next_instr; + next_instr += 1; + INSTRUCTION_STATS(MATCH_CLASS_ISINSTANCE); + _PyStackRef subject; + _PyStackRef type; + _PyStackRef res; + type = stack_pointer[-1]; + subject = stack_pointer[-2]; + PyObject *subject_o = PyStackRef_AsPyObjectBorrow(subject); + PyObject *type_o = PyStackRef_AsPyObjectBorrow(type); + if (!PyType_Check(type_o)) { + const char *e = "called match pattern must be a class"; + _PyFrame_SetStackPointer(frame, stack_pointer); + _PyErr_Format(tstate, PyExc_TypeError, e); + stack_pointer = _PyFrame_GetStackPointer(frame); + stack_pointer += -1; + ASSERT_WITHIN_STACK_BOUNDS(__FILE__, __LINE__); + _PyFrame_SetStackPointer(frame, stack_pointer); + PyStackRef_CLOSE(type); + stack_pointer = _PyFrame_GetStackPointer(frame); + JUMP_TO_LABEL(error); + } + _PyFrame_SetStackPointer(frame, stack_pointer); + int retval = PyObject_IsInstance(subject_o, type_o); + stack_pointer = _PyFrame_GetStackPointer(frame); + stack_pointer += -1; + ASSERT_WITHIN_STACK_BOUNDS(__FILE__, __LINE__); + _PyFrame_SetStackPointer(frame, stack_pointer); + PyStackRef_CLOSE(type); + stack_pointer = _PyFrame_GetStackPointer(frame); + if (retval < 0) { + JUMP_TO_LABEL(error); + } + assert(!_PyErr_Occurred(tstate)); + res = retval ? PyStackRef_True : PyStackRef_False; + stack_pointer[0] = res; + stack_pointer += 1; + ASSERT_WITHIN_STACK_BOUNDS(__FILE__, __LINE__); + DISPATCH(); + } + TARGET(MATCH_KEYS) { #if _Py_TAIL_CALL_INTERP int opcode = MATCH_KEYS; diff --git a/Python/opcode_targets.h b/Python/opcode_targets.h index f57c33feec2ac2..54c97dd75a40ce 100644 --- a/Python/opcode_targets.h +++ b/Python/opcode_targets.h @@ -24,6 +24,7 @@ static void *opcode_targets_table[256] = { &&TARGET_LOAD_BUILD_CLASS, &&TARGET_LOAD_LOCALS, &&TARGET_MAKE_FUNCTION, + &&TARGET_MATCH_CLASS_ISINSTANCE, &&TARGET_MATCH_KEYS, &&TARGET_MATCH_MAPPING, &&TARGET_MATCH_SEQUENCE, @@ -100,6 +101,7 @@ static void *opcode_targets_table[256] = { &&TARGET_MAKE_CELL, &&TARGET_MAP_ADD, &&TARGET_MATCH_CLASS, + &&TARGET_MATCH_CLASS_GET_OPT_ATTR, &&TARGET_POP_JUMP_IF_FALSE, &&TARGET_POP_JUMP_IF_NONE, &&TARGET_POP_JUMP_IF_NOT_NONE, @@ -126,8 +128,6 @@ static void *opcode_targets_table[256] = { &&_unknown_opcode, &&_unknown_opcode, &&_unknown_opcode, - &&_unknown_opcode, - &&_unknown_opcode, &&TARGET_RESUME, &&TARGET_BINARY_OP_ADD_FLOAT, &&TARGET_BINARY_OP_ADD_INT, @@ -380,8 +380,8 @@ static void *opcode_tracing_targets_table[256] = { &&TARGET_TRACE_RECORD, &&TARGET_TRACE_RECORD, &&TARGET_TRACE_RECORD, - &&_unknown_opcode, - &&_unknown_opcode, + &&TARGET_TRACE_RECORD, + &&TARGET_TRACE_RECORD, &&_unknown_opcode, &&_unknown_opcode, &&_unknown_opcode, @@ -699,6 +699,8 @@ static PyObject *Py_PRESERVE_NONE_CC _TAIL_CALL_MAKE_CELL(TAIL_CALL_PARAMS); static PyObject *Py_PRESERVE_NONE_CC _TAIL_CALL_MAKE_FUNCTION(TAIL_CALL_PARAMS); static PyObject *Py_PRESERVE_NONE_CC _TAIL_CALL_MAP_ADD(TAIL_CALL_PARAMS); static PyObject *Py_PRESERVE_NONE_CC _TAIL_CALL_MATCH_CLASS(TAIL_CALL_PARAMS); +static PyObject *Py_PRESERVE_NONE_CC _TAIL_CALL_MATCH_CLASS_GET_OPT_ATTR(TAIL_CALL_PARAMS); +static PyObject *Py_PRESERVE_NONE_CC _TAIL_CALL_MATCH_CLASS_ISINSTANCE(TAIL_CALL_PARAMS); static PyObject *Py_PRESERVE_NONE_CC _TAIL_CALL_MATCH_KEYS(TAIL_CALL_PARAMS); static PyObject *Py_PRESERVE_NONE_CC _TAIL_CALL_MATCH_MAPPING(TAIL_CALL_PARAMS); static PyObject *Py_PRESERVE_NONE_CC _TAIL_CALL_MATCH_SEQUENCE(TAIL_CALL_PARAMS); @@ -940,6 +942,8 @@ static py_tail_call_funcptr instruction_funcptr_handler_table[256] = { [MAKE_FUNCTION] = _TAIL_CALL_MAKE_FUNCTION, [MAP_ADD] = _TAIL_CALL_MAP_ADD, [MATCH_CLASS] = _TAIL_CALL_MATCH_CLASS, + [MATCH_CLASS_GET_OPT_ATTR] = _TAIL_CALL_MATCH_CLASS_GET_OPT_ATTR, + [MATCH_CLASS_ISINSTANCE] = _TAIL_CALL_MATCH_CLASS_ISINSTANCE, [MATCH_KEYS] = _TAIL_CALL_MATCH_KEYS, [MATCH_MAPPING] = _TAIL_CALL_MATCH_MAPPING, [MATCH_SEQUENCE] = _TAIL_CALL_MATCH_SEQUENCE, @@ -1000,8 +1004,6 @@ static py_tail_call_funcptr instruction_funcptr_handler_table[256] = { [UNPACK_SEQUENCE_TWO_TUPLE] = _TAIL_CALL_UNPACK_SEQUENCE_TWO_TUPLE, [WITH_EXCEPT_START] = _TAIL_CALL_WITH_EXCEPT_START, [YIELD_VALUE] = _TAIL_CALL_YIELD_VALUE, - [121] = _TAIL_CALL_UNKNOWN_OPCODE, - [122] = _TAIL_CALL_UNKNOWN_OPCODE, [123] = _TAIL_CALL_UNKNOWN_OPCODE, [124] = _TAIL_CALL_UNKNOWN_OPCODE, [125] = _TAIL_CALL_UNKNOWN_OPCODE, @@ -1198,6 +1200,8 @@ static py_tail_call_funcptr instruction_funcptr_tracing_table[256] = { [MAKE_FUNCTION] = _TAIL_CALL_TRACE_RECORD, [MAP_ADD] = _TAIL_CALL_TRACE_RECORD, [MATCH_CLASS] = _TAIL_CALL_TRACE_RECORD, + [MATCH_CLASS_GET_OPT_ATTR] = _TAIL_CALL_TRACE_RECORD, + [MATCH_CLASS_ISINSTANCE] = _TAIL_CALL_TRACE_RECORD, [MATCH_KEYS] = _TAIL_CALL_TRACE_RECORD, [MATCH_MAPPING] = _TAIL_CALL_TRACE_RECORD, [MATCH_SEQUENCE] = _TAIL_CALL_TRACE_RECORD, @@ -1258,8 +1262,6 @@ static py_tail_call_funcptr instruction_funcptr_tracing_table[256] = { [UNPACK_SEQUENCE_TWO_TUPLE] = _TAIL_CALL_TRACE_RECORD, [WITH_EXCEPT_START] = _TAIL_CALL_TRACE_RECORD, [YIELD_VALUE] = _TAIL_CALL_TRACE_RECORD, - [121] = _TAIL_CALL_UNKNOWN_OPCODE, - [122] = _TAIL_CALL_UNKNOWN_OPCODE, [123] = _TAIL_CALL_UNKNOWN_OPCODE, [124] = _TAIL_CALL_UNKNOWN_OPCODE, [125] = _TAIL_CALL_UNKNOWN_OPCODE, diff --git a/Python/optimizer_cases.c.h b/Python/optimizer_cases.c.h index 0a3f04fe0ab88f..7b70990f2c8425 100644 --- a/Python/optimizer_cases.c.h +++ b/Python/optimizer_cases.c.h @@ -2416,6 +2416,26 @@ break; } + case _MATCH_CLASS_ISINSTANCE: { + JitOptRef res; + res = sym_new_not_null(ctx); + stack_pointer[-1] = res; + break; + } + + case _MATCH_CLASS_GET_OPT_ATTR: { + JitOptRef attr; + JitOptRef res; + attr = sym_new_not_null(ctx); + res = sym_new_not_null(ctx); + CHECK_STACK_BOUNDS(2); + stack_pointer[0] = attr; + stack_pointer[1] = res; + stack_pointer += 2; + ASSERT_WITHIN_STACK_BOUNDS(__FILE__, __LINE__); + break; + } + case _MATCH_CLASS: { JitOptRef attrs; attrs = sym_new_not_null(ctx);