From 119c6285be78dffb548e9d788c68ceeab7e00885 Mon Sep 17 00:00:00 2001 From: jkchandalia Date: Sat, 29 Apr 2023 19:05:20 -0700 Subject: [PATCH 01/15] Add intrinsic names to opcode.py --- Lib/opcode.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Lib/opcode.py b/Lib/opcode.py index aef8407948df15..8753e61b28c654 100644 --- a/Lib/opcode.py +++ b/Lib/opcode.py @@ -306,6 +306,21 @@ def pseudo_op(name, op, real_ops): ("NB_INPLACE_XOR", "^="), ] +_intrinsic_1_descs = [ + "INTRINSIC_INVALID", + "INTRINSIC_PRINT", + "INTRINSIC_IMPORT_STAR", + "INTRINSIC_STOPITERATION_ERROR", + "INTRINSIC_ASYNC_GEN_WRAP", + "INTRINSIC_UNARY_POSITIVE", + "INTRINSIC_LIST_TO_TUPLE", +] + +_intrinsic_2_descs = [ + 'INTRINSIC_INVALID', + 'INTRINSIC_PREP_RERAISE_STAR', + ] + _specializations = { "BINARY_OP": [ "BINARY_OP_ADD_FLOAT", From 74ddc3e6b7de7d27ea20e67b0c18012ed34cb3c1 Mon Sep 17 00:00:00 2001 From: jkchandalia Date: Sat, 29 Apr 2023 19:06:14 -0700 Subject: [PATCH 02/15] Use intrinsics names define in opcode.py in dis.py --- Lib/dis.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Lib/dis.py b/Lib/dis.py index 85c109584bf94f..3a8e6ac3bf5ace 100644 --- a/Lib/dis.py +++ b/Lib/dis.py @@ -11,6 +11,8 @@ _cache_format, _inline_cache_entries, _nb_ops, + _intrinsic_1_descs, + _intrinsic_2_descs, _specializations, _specialized_instructions, ) @@ -42,6 +44,8 @@ SEND = opmap['SEND'] LOAD_ATTR = opmap['LOAD_ATTR'] LOAD_SUPER_ATTR = opmap['LOAD_SUPER_ATTR'] +CALL_INTRINSIC_1 = opmap['CALL_INTRINSIC_1'] +CALL_INTRINSIC_2 = opmap['CALL_INTRINSIC_2'] CACHE = opmap["CACHE"] @@ -506,6 +510,10 @@ def _get_instructions_bytes(code, varname_from_oparg=None, if arg & (1< Date: Sat, 29 Apr 2023 19:07:35 -0700 Subject: [PATCH 03/15] Add single test for 3 CALL_INTRINSIC_1 codes and update one existing test --- Lib/test/test_dis.py | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/Lib/test/test_dis.py b/Lib/test/test_dis.py index 5262c5c257cb89..ce387adc500986 100644 --- a/Lib/test/test_dis.py +++ b/Lib/test/test_dis.py @@ -247,6 +247,35 @@ def wrap_func_w_kwargs(): """ % (wrap_func_w_kwargs.__code__.co_firstlineno, wrap_func_w_kwargs.__code__.co_firstlineno + 1) +dis_intrinsic_1_2 = """\ + 0 RESUME 0 + + 1 LOAD_CONST 0 (0) + LOAD_CONST 1 (('*',)) + IMPORT_NAME 0 (math) + CALL_INTRINSIC_1 2 (INTRINSIC_IMPORT_STAR) + POP_TOP + RETURN_CONST 2 (None) +""" + +dis_intrinsic_1_5 = """\ + 0 RESUME 0 + + 1 LOAD_NAME 0 (a) + CALL_INTRINSIC_1 5 (INTRINSIC_UNARY_POSITIVE) + RETURN_VALUE +""" + +dis_intrinsic_1_6 = """\ + 0 RESUME 0 + + 1 BUILD_LIST 0 + LOAD_NAME 0 (a) + LIST_EXTEND 1 + CALL_INTRINSIC_1 6 (INTRINSIC_LIST_TO_TUPLE) + RETURN_VALUE +""" + _BIG_LINENO_FORMAT = """\ 1 RESUME 0 @@ -549,7 +578,7 @@ async def _asyncwith(c): >> COPY 3 POP_EXCEPT RERAISE 1 - >> CALL_INTRINSIC_1 3 + >> CALL_INTRINSIC_1 3 (INTRINSIC_STOPITERATION_ERROR) RERAISE 1 ExceptionTable: 12 rows @@ -942,6 +971,12 @@ def test_kw_names(self): # Test that value is displayed for KW_NAMES self.do_disassembly_test(wrap_func_w_kwargs, dis_kw_names) + def test_intrinsic_1(self): + # Test that argrepr is displayed for CALL_INTRINSIC_1 + self.do_disassembly_test('from math import *', dis_intrinsic_1_2) + self.do_disassembly_test('+a', dis_intrinsic_1_5) + self.do_disassembly_test('(*a,)', dis_intrinsic_1_6) + def test_big_linenos(self): def func(count): namespace = {} From 9d93d89ccde4491dd9a2844da206c955a8f600d0 Mon Sep 17 00:00:00 2001 From: jkchandalia Date: Sat, 29 Apr 2023 19:08:07 -0700 Subject: [PATCH 04/15] Update opcode.h generation to include intrinsics codes --- Tools/build/generate_opcode_h.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Tools/build/generate_opcode_h.py b/Tools/build/generate_opcode_h.py index 645b9f1de1170b..3f0feb21f16b7a 100644 --- a/Tools/build/generate_opcode_h.py +++ b/Tools/build/generate_opcode_h.py @@ -172,6 +172,14 @@ def main(opcode_py, outfile='Include/opcode.h', internaloutfile='Include/interna for i, (op, _) in enumerate(opcode["_nb_ops"]): fobj.write(DEFINE.format(op, i)) + fobj.write("\n") + for i, op in enumerate(opcode["_intrinsic_1_descs"]): + fobj.write(DEFINE.format(op, i)) + + fobj.write("\n") + for i, op in enumerate(opcode["_intrinsic_2_descs"]): + fobj.write(DEFINE.format(op, i)) + fobj.write("\n") fobj.write("/* Defined in Lib/opcode.py */\n") fobj.write(f"#define ENABLE_SPECIALIZATION {int(ENABLE_SPECIALIZATION)}") From 3056de5a82a0c3ec3d02f0689c4b868266b0a02d Mon Sep 17 00:00:00 2001 From: jkchandalia Date: Sat, 29 Apr 2023 19:08:45 -0700 Subject: [PATCH 05/15] Update opcode.h to include the new intrinsics sections --- Include/opcode.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Include/opcode.h b/Include/opcode.h index 37a9e9bffa4cb7..841094f8758020 100644 --- a/Include/opcode.h +++ b/Include/opcode.h @@ -253,6 +253,17 @@ extern "C" { #define NB_INPLACE_TRUE_DIVIDE 24 #define NB_INPLACE_XOR 25 +#define INTRINSIC_INVALID 0 +#define INTRINSIC_PRINT 1 +#define INTRINSIC_IMPORT_STAR 2 +#define INTRINSIC_STOPITERATION_ERROR 3 +#define INTRINSIC_ASYNC_GEN_WRAP 4 +#define INTRINSIC_UNARY_POSITIVE 5 +#define INTRINSIC_LIST_TO_TUPLE 6 + +#define INTRINSIC_INVALID 0 +#define INTRINSIC_PREP_RERAISE_STAR 1 + /* Defined in Lib/opcode.py */ #define ENABLE_SPECIALIZATION 1 From be813ee029147219ae7204b36b67510a17bf34d2 Mon Sep 17 00:00:00 2001 From: jkchandalia Date: Sun, 30 Apr 2023 11:59:51 -0700 Subject: [PATCH 06/15] Revert changes to opcode.h for intrinsics --- Include/opcode.h | 11 ----------- Tools/build/generate_opcode_h.py | 8 -------- 2 files changed, 19 deletions(-) diff --git a/Include/opcode.h b/Include/opcode.h index 841094f8758020..37a9e9bffa4cb7 100644 --- a/Include/opcode.h +++ b/Include/opcode.h @@ -253,17 +253,6 @@ extern "C" { #define NB_INPLACE_TRUE_DIVIDE 24 #define NB_INPLACE_XOR 25 -#define INTRINSIC_INVALID 0 -#define INTRINSIC_PRINT 1 -#define INTRINSIC_IMPORT_STAR 2 -#define INTRINSIC_STOPITERATION_ERROR 3 -#define INTRINSIC_ASYNC_GEN_WRAP 4 -#define INTRINSIC_UNARY_POSITIVE 5 -#define INTRINSIC_LIST_TO_TUPLE 6 - -#define INTRINSIC_INVALID 0 -#define INTRINSIC_PREP_RERAISE_STAR 1 - /* Defined in Lib/opcode.py */ #define ENABLE_SPECIALIZATION 1 diff --git a/Tools/build/generate_opcode_h.py b/Tools/build/generate_opcode_h.py index 3f0feb21f16b7a..645b9f1de1170b 100644 --- a/Tools/build/generate_opcode_h.py +++ b/Tools/build/generate_opcode_h.py @@ -172,14 +172,6 @@ def main(opcode_py, outfile='Include/opcode.h', internaloutfile='Include/interna for i, (op, _) in enumerate(opcode["_nb_ops"]): fobj.write(DEFINE.format(op, i)) - fobj.write("\n") - for i, op in enumerate(opcode["_intrinsic_1_descs"]): - fobj.write(DEFINE.format(op, i)) - - fobj.write("\n") - for i, op in enumerate(opcode["_intrinsic_2_descs"]): - fobj.write(DEFINE.format(op, i)) - fobj.write("\n") fobj.write("/* Defined in Lib/opcode.py */\n") fobj.write(f"#define ENABLE_SPECIALIZATION {int(ENABLE_SPECIALIZATION)}") From 0f10791ceec91d54c4446c2c817ec627a7276c13 Mon Sep 17 00:00:00 2001 From: jkchandalia Date: Sun, 30 Apr 2023 20:54:18 -0700 Subject: [PATCH 07/15] Add test for CALL_INTRINSIC_2 --- Lib/test/test_dis.py | 46 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 43 insertions(+), 3 deletions(-) diff --git a/Lib/test/test_dis.py b/Lib/test/test_dis.py index ce387adc500986..bec3beecad5385 100644 --- a/Lib/test/test_dis.py +++ b/Lib/test/test_dis.py @@ -275,6 +275,43 @@ def wrap_func_w_kwargs(): CALL_INTRINSIC_1 6 (INTRINSIC_LIST_TO_TUPLE) RETURN_VALUE """ +dis_intrinsic_2_1 = """\ + 0 RESUME 0 + + 1 RETURN_CONST 0 (None) + PUSH_EXC_INFO + + 2 BUILD_LIST 0 + COPY 2 + LOAD_NAME 0 (Exception) + CHECK_EG_MATCH + COPY 1 + POP_JUMP_IF_NONE 8 (to 34) + POP_TOP + LOAD_NAME 1 (x) + POP_TOP + JUMP_FORWARD 3 (to 32) + >> LIST_APPEND 3 + POP_TOP + JUMP_FORWARD 2 (to 36) + >> JUMP_FORWARD 1 (to 36) + >> POP_TOP + >> LIST_APPEND 1 + CALL_INTRINSIC_2 1 (INTRINSIC_PREP_RERAISE_STAR) + COPY 1 + POP_JUMP_IF_NOT_NONE 3 (to 50) + POP_TOP + POP_EXCEPT + RETURN_CONST 0 (None) + >> SWAP 2 + POP_EXCEPT + RERAISE 0 + >> COPY 3 + POP_EXCEPT + RERAISE 1 +ExceptionTable: +3 rows +""" _BIG_LINENO_FORMAT = """\ 1 RESUME 0 @@ -973,9 +1010,12 @@ def test_kw_names(self): def test_intrinsic_1(self): # Test that argrepr is displayed for CALL_INTRINSIC_1 - self.do_disassembly_test('from math import *', dis_intrinsic_1_2) - self.do_disassembly_test('+a', dis_intrinsic_1_5) - self.do_disassembly_test('(*a,)', dis_intrinsic_1_6) + self.do_disassembly_test("from math import *", dis_intrinsic_1_2) + self.do_disassembly_test("+a", dis_intrinsic_1_5) + self.do_disassembly_test("(*a,)", dis_intrinsic_1_6) + + def test_intrinsic_2(self): + self.do_disassembly_test("try: pass\nexcept* Exception: x", dis_intrinsic_2_1) def test_big_linenos(self): def func(count): From 89bfd1218228168bd6d8536e58d1c6b1b8a846c9 Mon Sep 17 00:00:00 2001 From: jkchandalia Date: Sun, 30 Apr 2023 21:43:07 -0700 Subject: [PATCH 08/15] Update generate_opcode to generate intrinsics header file --- Tools/build/generate_opcode_h.py | 39 ++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/Tools/build/generate_opcode_h.py b/Tools/build/generate_opcode_h.py index 645b9f1de1170b..0055b4fcc22e99 100644 --- a/Tools/build/generate_opcode_h.py +++ b/Tools/build/generate_opcode_h.py @@ -52,6 +52,11 @@ #endif // !Py_INTERNAL_OPCODE_H """ +intrinsic_header = f""" +// Auto-generated by {SCRIPT_NAME} from {PYTHON_OPCODE} + +""".lstrip() + DEFINE = "#define {:<38} {:>3}\n" UINT32_MASK = (1<<32)-1 @@ -67,7 +72,9 @@ def write_int_array_from_ops(name, ops, out): assert bits == 0 out.write(f"}};\n") -def main(opcode_py, outfile='Include/opcode.h', internaloutfile='Include/internal/pycore_opcode.h'): +def main(opcode_py, outfile='Include/opcode.h', + internaloutfile='Include/internal/pycore_opcode.h', + intrinsicoutfile='Include/internal/pycore_intrinsics2.h'): opcode = {} if hasattr(tokenize, 'open'): fp = tokenize.open(opcode_py) # Python 3.2+ @@ -107,9 +114,11 @@ def main(opcode_py, outfile='Include/opcode.h', internaloutfile='Include/interna opname_including_specialized[next_op] = name used[next_op] = True - with open(outfile, 'w') as fobj, open(internaloutfile, 'w') as iobj: + with open(outfile, 'w') as fobj, open(internaloutfile, 'w') as iobj, open( + intrinsicoutfile, "w") as nobj: fobj.write(header) iobj.write(internal_header) + nobj.write(intrinsic_header) for name in opname: if name in opmap: @@ -172,6 +181,32 @@ def main(opcode_py, outfile='Include/opcode.h', internaloutfile='Include/interna for i, (op, _) in enumerate(opcode["_nb_ops"]): fobj.write(DEFINE.format(op, i)) + nobj.write("/* Unary Functions: */") + nobj.write("\n") + for i, op in enumerate(opcode["_intrinsic_1_descs"]): + nobj.write(DEFINE.format(op, i)) + nobj.write("\n") + nobj.write(DEFINE.format("MAX_INTRINSIC_1", i)) + + nobj.write("\n\n") + nobj.write("/* Binary Functions: */\n") + for i, op in enumerate(opcode["_intrinsic_2_descs"]): + nobj.write(DEFINE.format(op, i)) + nobj.write("\n") + nobj.write(DEFINE.format("MAX_INTRINSIC_2", i)) + + nobj.write( + "typedef PyObject *(*instrinsic_func1)(PyThreadState* tstate, PyObject *value);" + ) + nobj.write("\n") + nobj.write( + "typedef PyObject *(*instrinsic_func2)(PyThreadState* tstate, PyObject *value1, PyObject *value2);" + ) + nobj.write("\n") + nobj.write("extern const instrinsic_func1 _PyIntrinsics_UnaryFunctions[];") + nobj.write("\n") + nobj.write("extern const instrinsic_func2 _PyIntrinsics_BinaryFunctions[];") + fobj.write("\n") fobj.write("/* Defined in Lib/opcode.py */\n") fobj.write(f"#define ENABLE_SPECIALIZATION {int(ENABLE_SPECIALIZATION)}") From e10dae15dd0d25f825c5b0d05cf1415796fbc9dc Mon Sep 17 00:00:00 2001 From: jkchandalia Date: Sun, 30 Apr 2023 22:00:44 -0700 Subject: [PATCH 09/15] Update intrinsics outfile --- Tools/build/generate_opcode_h.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tools/build/generate_opcode_h.py b/Tools/build/generate_opcode_h.py index 0055b4fcc22e99..284737c11e192f 100644 --- a/Tools/build/generate_opcode_h.py +++ b/Tools/build/generate_opcode_h.py @@ -74,7 +74,7 @@ def write_int_array_from_ops(name, ops, out): def main(opcode_py, outfile='Include/opcode.h', internaloutfile='Include/internal/pycore_opcode.h', - intrinsicoutfile='Include/internal/pycore_intrinsics2.h'): + intrinsicoutfile='Include/internal/pycore_intrinsics.h'): opcode = {} if hasattr(tokenize, 'open'): fp = tokenize.open(opcode_py) # Python 3.2+ From f78e70e9e452cb0107c59bb6d05f65064aa90bb2 Mon Sep 17 00:00:00 2001 From: jkchandalia Date: Sun, 30 Apr 2023 22:01:25 -0700 Subject: [PATCH 10/15] Regenerate intrinsics header file --- Include/internal/pycore_intrinsics.h | 29 +++++++++++++--------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/Include/internal/pycore_intrinsics.h b/Include/internal/pycore_intrinsics.h index 46a52740eb8a0c..ec4731330b677e 100644 --- a/Include/internal/pycore_intrinsics.h +++ b/Include/internal/pycore_intrinsics.h @@ -1,26 +1,23 @@ +// Auto-generated by Tools/build/generate_opcode_h.py from Lib/opcode.py /* Unary Functions: */ +#define INTRINSIC_INVALID 0 +#define INTRINSIC_PRINT 1 +#define INTRINSIC_IMPORT_STAR 2 +#define INTRINSIC_STOPITERATION_ERROR 3 +#define INTRINSIC_ASYNC_GEN_WRAP 4 +#define INTRINSIC_UNARY_POSITIVE 5 +#define INTRINSIC_LIST_TO_TUPLE 6 -#define INTRINSIC_PRINT 1 -#define INTRINSIC_IMPORT_STAR 2 -#define INTRINSIC_STOPITERATION_ERROR 3 -#define INTRINSIC_ASYNC_GEN_WRAP 4 -#define INTRINSIC_UNARY_POSITIVE 5 -#define INTRINSIC_LIST_TO_TUPLE 6 - -#define MAX_INTRINSIC_1 6 +#define MAX_INTRINSIC_1 6 /* Binary Functions: */ +#define INTRINSIC_INVALID 0 +#define INTRINSIC_PREP_RERAISE_STAR 1 -#define INTRINSIC_PREP_RERAISE_STAR 1 - -#define MAX_INTRINSIC_2 1 - - +#define MAX_INTRINSIC_2 1 typedef PyObject *(*instrinsic_func1)(PyThreadState* tstate, PyObject *value); typedef PyObject *(*instrinsic_func2)(PyThreadState* tstate, PyObject *value1, PyObject *value2); - extern const instrinsic_func1 _PyIntrinsics_UnaryFunctions[]; -extern const instrinsic_func2 _PyIntrinsics_BinaryFunctions[]; - +extern const instrinsic_func2 _PyIntrinsics_BinaryFunctions[]; \ No newline at end of file From 22679337ce23c6cc9121f5043db6d275ef2fafeb Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Mon, 1 May 2023 17:58:29 +0000 Subject: [PATCH 11/15] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20b?= =?UTF-8?q?lurb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../next/Library/2023-05-01-17-58-28.gh-issue-103963.XWlHx7.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2023-05-01-17-58-28.gh-issue-103963.XWlHx7.rst diff --git a/Misc/NEWS.d/next/Library/2023-05-01-17-58-28.gh-issue-103963.XWlHx7.rst b/Misc/NEWS.d/next/Library/2023-05-01-17-58-28.gh-issue-103963.XWlHx7.rst new file mode 100644 index 00000000000000..cb06ad5d22e8a9 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2023-05-01-17-58-28.gh-issue-103963.XWlHx7.rst @@ -0,0 +1 @@ +Make :mod:`dis` display the names of the args for :opcode:`CALL_INTRINSIC_*`. From db9a1e9dec1cb3a1d5dbaf0eaa80ef772a31829c Mon Sep 17 00:00:00 2001 From: jkchandalia Date: Mon, 1 May 2023 19:50:39 -0700 Subject: [PATCH 12/15] Move static statements to footer and add newline --- Include/internal/pycore_intrinsics.h | 3 ++- Tools/build/generate_opcode_h.py | 19 ++++++++----------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/Include/internal/pycore_intrinsics.h b/Include/internal/pycore_intrinsics.h index ec4731330b677e..aa23f8f1af400d 100644 --- a/Include/internal/pycore_intrinsics.h +++ b/Include/internal/pycore_intrinsics.h @@ -17,7 +17,8 @@ #define INTRINSIC_PREP_RERAISE_STAR 1 #define MAX_INTRINSIC_2 1 + typedef PyObject *(*instrinsic_func1)(PyThreadState* tstate, PyObject *value); typedef PyObject *(*instrinsic_func2)(PyThreadState* tstate, PyObject *value1, PyObject *value2); extern const instrinsic_func1 _PyIntrinsics_UnaryFunctions[]; -extern const instrinsic_func2 _PyIntrinsics_BinaryFunctions[]; \ No newline at end of file +extern const instrinsic_func2 _PyIntrinsics_BinaryFunctions[]; diff --git a/Tools/build/generate_opcode_h.py b/Tools/build/generate_opcode_h.py index 284737c11e192f..adcbaf2b8e08bf 100644 --- a/Tools/build/generate_opcode_h.py +++ b/Tools/build/generate_opcode_h.py @@ -57,6 +57,13 @@ """.lstrip() +intrinsic_footer = """ +typedef PyObject *(*instrinsic_func1)(PyThreadState* tstate, PyObject *value); +typedef PyObject *(*instrinsic_func2)(PyThreadState* tstate, PyObject *value1, PyObject *value2); +extern const instrinsic_func1 _PyIntrinsics_UnaryFunctions[]; +extern const instrinsic_func2 _PyIntrinsics_BinaryFunctions[]; +""" + DEFINE = "#define {:<38} {:>3}\n" UINT32_MASK = (1<<32)-1 @@ -195,17 +202,7 @@ def main(opcode_py, outfile='Include/opcode.h', nobj.write("\n") nobj.write(DEFINE.format("MAX_INTRINSIC_2", i)) - nobj.write( - "typedef PyObject *(*instrinsic_func1)(PyThreadState* tstate, PyObject *value);" - ) - nobj.write("\n") - nobj.write( - "typedef PyObject *(*instrinsic_func2)(PyThreadState* tstate, PyObject *value1, PyObject *value2);" - ) - nobj.write("\n") - nobj.write("extern const instrinsic_func1 _PyIntrinsics_UnaryFunctions[];") - nobj.write("\n") - nobj.write("extern const instrinsic_func2 _PyIntrinsics_BinaryFunctions[];") + nobj.write(intrinsic_footer) fobj.write("\n") fobj.write("/* Defined in Lib/opcode.py */\n") From f034688b7fc2f7051ecf585777c4d0c3698ba8b3 Mon Sep 17 00:00:00 2001 From: jkchandalia Date: Mon, 1 May 2023 19:51:29 -0700 Subject: [PATCH 13/15] Test CALL_INTRINSIC_2 arg name with less hardcoded bytecode --- Lib/test/test_dis.py | 40 ++-------------------------------------- 1 file changed, 2 insertions(+), 38 deletions(-) diff --git a/Lib/test/test_dis.py b/Lib/test/test_dis.py index bec3beecad5385..d29e32a4b2a59c 100644 --- a/Lib/test/test_dis.py +++ b/Lib/test/test_dis.py @@ -275,43 +275,6 @@ def wrap_func_w_kwargs(): CALL_INTRINSIC_1 6 (INTRINSIC_LIST_TO_TUPLE) RETURN_VALUE """ -dis_intrinsic_2_1 = """\ - 0 RESUME 0 - - 1 RETURN_CONST 0 (None) - PUSH_EXC_INFO - - 2 BUILD_LIST 0 - COPY 2 - LOAD_NAME 0 (Exception) - CHECK_EG_MATCH - COPY 1 - POP_JUMP_IF_NONE 8 (to 34) - POP_TOP - LOAD_NAME 1 (x) - POP_TOP - JUMP_FORWARD 3 (to 32) - >> LIST_APPEND 3 - POP_TOP - JUMP_FORWARD 2 (to 36) - >> JUMP_FORWARD 1 (to 36) - >> POP_TOP - >> LIST_APPEND 1 - CALL_INTRINSIC_2 1 (INTRINSIC_PREP_RERAISE_STAR) - COPY 1 - POP_JUMP_IF_NOT_NONE 3 (to 50) - POP_TOP - POP_EXCEPT - RETURN_CONST 0 (None) - >> SWAP 2 - POP_EXCEPT - RERAISE 0 - >> COPY 3 - POP_EXCEPT - RERAISE 1 -ExceptionTable: -3 rows -""" _BIG_LINENO_FORMAT = """\ 1 RESUME 0 @@ -1015,7 +978,8 @@ def test_intrinsic_1(self): self.do_disassembly_test("(*a,)", dis_intrinsic_1_6) def test_intrinsic_2(self): - self.do_disassembly_test("try: pass\nexcept* Exception: x", dis_intrinsic_2_1) + assert "CALL_INTRINSIC_2 1 (INTRINSIC_PREP_RERAISE_STAR)" \ + in self.get_disassembly("try: pass\nexcept* Exception: x") def test_big_linenos(self): def func(count): From cca18e950352ee9acfcab24646bd00ccd05bad82 Mon Sep 17 00:00:00 2001 From: jkchandalia Date: Mon, 1 May 2023 20:16:23 -0700 Subject: [PATCH 14/15] Use assertIn --- Lib/test/test_dis.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_dis.py b/Lib/test/test_dis.py index d29e32a4b2a59c..2f5d67fde86170 100644 --- a/Lib/test/test_dis.py +++ b/Lib/test/test_dis.py @@ -978,8 +978,8 @@ def test_intrinsic_1(self): self.do_disassembly_test("(*a,)", dis_intrinsic_1_6) def test_intrinsic_2(self): - assert "CALL_INTRINSIC_2 1 (INTRINSIC_PREP_RERAISE_STAR)" \ - in self.get_disassembly("try: pass\nexcept* Exception: x") + self.assertIn("CALL_INTRINSIC_2 1 (INTRINSIC_PREP_RERAISE_STAR)", + self.get_disassembly("try: pass\nexcept* Exception: x")) def test_big_linenos(self): def func(count): From abd3ff1094c6b3429712b45e8570d09f32167fcb Mon Sep 17 00:00:00 2001 From: jkchandalia Date: Tue, 2 May 2023 11:44:42 -0700 Subject: [PATCH 15/15] Differentiate between intrinsic invalid args --- Include/internal/pycore_intrinsics.h | 4 ++-- Lib/opcode.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Include/internal/pycore_intrinsics.h b/Include/internal/pycore_intrinsics.h index aa23f8f1af400d..3902059a04b9da 100644 --- a/Include/internal/pycore_intrinsics.h +++ b/Include/internal/pycore_intrinsics.h @@ -1,7 +1,7 @@ // Auto-generated by Tools/build/generate_opcode_h.py from Lib/opcode.py /* Unary Functions: */ -#define INTRINSIC_INVALID 0 +#define INTRINSIC_1_INVALID 0 #define INTRINSIC_PRINT 1 #define INTRINSIC_IMPORT_STAR 2 #define INTRINSIC_STOPITERATION_ERROR 3 @@ -13,7 +13,7 @@ /* Binary Functions: */ -#define INTRINSIC_INVALID 0 +#define INTRINSIC_2_INVALID 0 #define INTRINSIC_PREP_RERAISE_STAR 1 #define MAX_INTRINSIC_2 1 diff --git a/Lib/opcode.py b/Lib/opcode.py index 8753e61b28c654..ad54bd27fba3d9 100644 --- a/Lib/opcode.py +++ b/Lib/opcode.py @@ -307,7 +307,7 @@ def pseudo_op(name, op, real_ops): ] _intrinsic_1_descs = [ - "INTRINSIC_INVALID", + "INTRINSIC_1_INVALID", "INTRINSIC_PRINT", "INTRINSIC_IMPORT_STAR", "INTRINSIC_STOPITERATION_ERROR", @@ -317,7 +317,7 @@ def pseudo_op(name, op, real_ops): ] _intrinsic_2_descs = [ - 'INTRINSIC_INVALID', + 'INTRINSIC_2_INVALID', 'INTRINSIC_PREP_RERAISE_STAR', ]