summaryrefslogtreecommitdiffstats
path: root/Include
diff options
context:
space:
mode:
authorCarl Meyer <carl@oddbird.net>2023-05-09 17:02:14 (GMT)
committerGitHub <noreply@github.com>2023-05-09 17:02:14 (GMT)
commitc3b595e73efac59360d6dc869802abc752092460 (patch)
tree5095460e4d502af2688c132562b7d8570f33d7b0 /Include
parent0aeda297931820436a50b78f4f7f0597274b5df4 (diff)
downloadcpython-c3b595e73efac59360d6dc869802abc752092460.zip
cpython-c3b595e73efac59360d6dc869802abc752092460.tar.gz
cpython-c3b595e73efac59360d6dc869802abc752092460.tar.bz2
gh-97933: (PEP 709) inline list/dict/set comprehensions (#101441)
Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com> Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
Diffstat (limited to 'Include')
-rw-r--r--Include/internal/pycore_code.h1
-rw-r--r--Include/internal/pycore_compile.h3
-rw-r--r--Include/internal/pycore_flowgraph.h2
-rw-r--r--Include/internal/pycore_opcode.h13
-rw-r--r--Include/internal/pycore_symtable.h1
-rw-r--r--Include/opcode.h21
6 files changed, 25 insertions, 16 deletions
diff --git a/Include/internal/pycore_code.h b/Include/internal/pycore_code.h
index 86fd48b..c1f017f 100644
--- a/Include/internal/pycore_code.h
+++ b/Include/internal/pycore_code.h
@@ -131,6 +131,7 @@ struct callable_cache {
// Note that these all fit within a byte, as do combinations.
// Later, we will use the smaller numbers to differentiate the different
// kinds of locals (e.g. pos-only arg, varkwargs, local-only).
+#define CO_FAST_HIDDEN 0x10
#define CO_FAST_LOCAL 0x20
#define CO_FAST_CELL 0x40
#define CO_FAST_FREE 0x80
diff --git a/Include/internal/pycore_compile.h b/Include/internal/pycore_compile.h
index d2b12c9..499f55f 100644
--- a/Include/internal/pycore_compile.h
+++ b/Include/internal/pycore_compile.h
@@ -70,6 +70,9 @@ typedef struct {
PyObject *u_varnames; /* local variables */
PyObject *u_cellvars; /* cell variables */
PyObject *u_freevars; /* free variables */
+ PyObject *u_fasthidden; /* dict; keys are names that are fast-locals only
+ temporarily within an inlined comprehension. When
+ value is True, treat as fast-local. */
Py_ssize_t u_argcount; /* number of arguments for block */
Py_ssize_t u_posonlyargcount; /* number of positional only arguments for block */
diff --git a/Include/internal/pycore_flowgraph.h b/Include/internal/pycore_flowgraph.h
index 883334f..720feb1 100644
--- a/Include/internal/pycore_flowgraph.h
+++ b/Include/internal/pycore_flowgraph.h
@@ -94,7 +94,7 @@ _PyCfgInstruction* _PyCfg_BasicblockLastInstr(const _PyCfgBasicblock *b);
int _PyCfg_OptimizeCodeUnit(_PyCfgBuilder *g, PyObject *consts, PyObject *const_cache,
int code_flags, int nlocals, int nparams, int firstlineno);
int _PyCfg_Stackdepth(_PyCfgBasicblock *entryblock, int code_flags);
-void _PyCfg_ConvertExceptionHandlersToNops(_PyCfgBasicblock *entryblock);
+void _PyCfg_ConvertPseudoOps(_PyCfgBasicblock *entryblock);
int _PyCfg_ResolveJumps(_PyCfgBuilder *g);
diff --git a/Include/internal/pycore_opcode.h b/Include/internal/pycore_opcode.h
index a828854..52ee70a 100644
--- a/Include/internal/pycore_opcode.h
+++ b/Include/internal/pycore_opcode.h
@@ -173,6 +173,7 @@ const uint8_t _PyOpcode_Deopt[256] = {
[LOAD_CONST__LOAD_FAST] = LOAD_CONST,
[LOAD_DEREF] = LOAD_DEREF,
[LOAD_FAST] = LOAD_FAST,
+ [LOAD_FAST_AND_CLEAR] = LOAD_FAST_AND_CLEAR,
[LOAD_FAST_CHECK] = LOAD_FAST_CHECK,
[LOAD_FAST__LOAD_CONST] = LOAD_FAST,
[LOAD_FAST__LOAD_FAST] = LOAD_FAST,
@@ -239,7 +240,7 @@ const uint8_t _PyOpcode_Deopt[256] = {
#endif // NEED_OPCODE_TABLES
#ifdef Py_DEBUG
-static const char *const _PyOpcode_OpName[266] = {
+static const char *const _PyOpcode_OpName[267] = {
[CACHE] = "CACHE",
[POP_TOP] = "POP_TOP",
[PUSH_NULL] = "PUSH_NULL",
@@ -383,7 +384,7 @@ static const char *const _PyOpcode_OpName[266] = {
[JUMP_BACKWARD] = "JUMP_BACKWARD",
[LOAD_SUPER_ATTR] = "LOAD_SUPER_ATTR",
[CALL_FUNCTION_EX] = "CALL_FUNCTION_EX",
- [STORE_FAST__LOAD_FAST] = "STORE_FAST__LOAD_FAST",
+ [LOAD_FAST_AND_CLEAR] = "LOAD_FAST_AND_CLEAR",
[EXTENDED_ARG] = "EXTENDED_ARG",
[LIST_APPEND] = "LIST_APPEND",
[SET_ADD] = "SET_ADD",
@@ -393,21 +394,21 @@ static const char *const _PyOpcode_OpName[266] = {
[YIELD_VALUE] = "YIELD_VALUE",
[RESUME] = "RESUME",
[MATCH_CLASS] = "MATCH_CLASS",
+ [STORE_FAST__LOAD_FAST] = "STORE_FAST__LOAD_FAST",
[STORE_FAST__STORE_FAST] = "STORE_FAST__STORE_FAST",
- [STORE_SUBSCR_DICT] = "STORE_SUBSCR_DICT",
[FORMAT_VALUE] = "FORMAT_VALUE",
[BUILD_CONST_KEY_MAP] = "BUILD_CONST_KEY_MAP",
[BUILD_STRING] = "BUILD_STRING",
+ [STORE_SUBSCR_DICT] = "STORE_SUBSCR_DICT",
[STORE_SUBSCR_LIST_INT] = "STORE_SUBSCR_LIST_INT",
[UNPACK_SEQUENCE_LIST] = "UNPACK_SEQUENCE_LIST",
[UNPACK_SEQUENCE_TUPLE] = "UNPACK_SEQUENCE_TUPLE",
- [UNPACK_SEQUENCE_TWO_TUPLE] = "UNPACK_SEQUENCE_TWO_TUPLE",
[LIST_EXTEND] = "LIST_EXTEND",
[SET_UPDATE] = "SET_UPDATE",
[DICT_MERGE] = "DICT_MERGE",
[DICT_UPDATE] = "DICT_UPDATE",
+ [UNPACK_SEQUENCE_TWO_TUPLE] = "UNPACK_SEQUENCE_TWO_TUPLE",
[SEND_GEN] = "SEND_GEN",
- [167] = "<167>",
[168] = "<168>",
[169] = "<169>",
[170] = "<170>",
@@ -506,11 +507,11 @@ static const char *const _PyOpcode_OpName[266] = {
[LOAD_SUPER_METHOD] = "LOAD_SUPER_METHOD",
[LOAD_ZERO_SUPER_METHOD] = "LOAD_ZERO_SUPER_METHOD",
[LOAD_ZERO_SUPER_ATTR] = "LOAD_ZERO_SUPER_ATTR",
+ [STORE_FAST_MAYBE_NULL] = "STORE_FAST_MAYBE_NULL",
};
#endif
#define EXTRA_CASES \
- case 167: \
case 168: \
case 169: \
case 170: \
diff --git a/Include/internal/pycore_symtable.h b/Include/internal/pycore_symtable.h
index 512c4c9..9a005be 100644
--- a/Include/internal/pycore_symtable.h
+++ b/Include/internal/pycore_symtable.h
@@ -64,6 +64,7 @@ typedef struct _symtable_entry {
unsigned ste_needs_class_closure : 1; /* for class scopes, true if a
closure over __class__
should be created */
+ unsigned ste_comp_inlined : 1; /* true if this comprehension is inlined */
unsigned ste_comp_iter_target : 1; /* true if visiting comprehension target */
int ste_comp_iter_expr; /* non-zero if visiting a comprehension range expression */
int ste_lineno; /* first line of block */
diff --git a/Include/opcode.h b/Include/opcode.h
index 37a9e9b..f6f4af8 100644
--- a/Include/opcode.h
+++ b/Include/opcode.h
@@ -97,6 +97,7 @@ extern "C" {
#define JUMP_BACKWARD 140
#define LOAD_SUPER_ATTR 141
#define CALL_FUNCTION_EX 142
+#define LOAD_FAST_AND_CLEAR 143
#define EXTENDED_ARG 144
#define LIST_APPEND 145
#define SET_ADD 146
@@ -146,7 +147,8 @@ extern "C" {
#define LOAD_SUPER_METHOD 263
#define LOAD_ZERO_SUPER_METHOD 264
#define LOAD_ZERO_SUPER_ATTR 265
-#define MAX_PSEUDO_OPCODE 265
+#define STORE_FAST_MAYBE_NULL 266
+#define MAX_PSEUDO_OPCODE 266
#define BINARY_OP_ADD_FLOAT 6
#define BINARY_OP_ADD_INT 7
#define BINARY_OP_ADD_UNICODE 8
@@ -202,14 +204,14 @@ extern "C" {
#define STORE_ATTR_INSTANCE_VALUE 111
#define STORE_ATTR_SLOT 112
#define STORE_ATTR_WITH_HINT 113
-#define STORE_FAST__LOAD_FAST 143
-#define STORE_FAST__STORE_FAST 153
-#define STORE_SUBSCR_DICT 154
-#define STORE_SUBSCR_LIST_INT 158
-#define UNPACK_SEQUENCE_LIST 159
-#define UNPACK_SEQUENCE_TUPLE 160
-#define UNPACK_SEQUENCE_TWO_TUPLE 161
-#define SEND_GEN 166
+#define STORE_FAST__LOAD_FAST 153
+#define STORE_FAST__STORE_FAST 154
+#define STORE_SUBSCR_DICT 158
+#define STORE_SUBSCR_LIST_INT 159
+#define UNPACK_SEQUENCE_LIST 160
+#define UNPACK_SEQUENCE_TUPLE 161
+#define UNPACK_SEQUENCE_TWO_TUPLE 166
+#define SEND_GEN 167
#define HAS_ARG(op) ((((op) >= HAVE_ARGUMENT) && (!IS_PSEUDO_OPCODE(op)))\
|| ((op) == JUMP) \
@@ -218,6 +220,7 @@ extern "C" {
|| ((op) == LOAD_SUPER_METHOD) \
|| ((op) == LOAD_ZERO_SUPER_METHOD) \
|| ((op) == LOAD_ZERO_SUPER_ATTR) \
+ || ((op) == STORE_FAST_MAYBE_NULL) \
)
#define HAS_CONST(op) (false\