summaryrefslogtreecommitdiffstats
path: root/Include
diff options
context:
space:
mode:
authormpage <mpage@meta.com>2024-12-19 21:03:14 (GMT)
committerGitHub <noreply@github.com>2024-12-19 21:03:14 (GMT)
commit255762c09fe518757bb3e8ce1bb6e5d8eec9f466 (patch)
tree179d8f0893a0550d2f73359da6e20d4df05e01e2 /Include
parente163e8d4e1a9844b8615ef38b9917b887a377948 (diff)
downloadcpython-255762c09fe518757bb3e8ce1bb6e5d8eec9f466.zip
cpython-255762c09fe518757bb3e8ce1bb6e5d8eec9f466.tar.gz
cpython-255762c09fe518757bb3e8ce1bb6e5d8eec9f466.tar.bz2
gh-127274: Defer nested methods (#128012)
Methods (functions defined in class scope) are likely to be cleaned up by the GC anyway. Add a new code flag, `CO_METHOD`, that is set for functions defined in a class scope. Use that when deciding to defer functions.
Diffstat (limited to 'Include')
-rw-r--r--Include/cpython/code.h3
-rw-r--r--Include/internal/pycore_symtable.h1
2 files changed, 4 insertions, 0 deletions
diff --git a/Include/cpython/code.h b/Include/cpython/code.h
index c3c0165..cb6261d 100644
--- a/Include/cpython/code.h
+++ b/Include/cpython/code.h
@@ -199,6 +199,9 @@ struct PyCodeObject _PyCode_DEF(1);
*/
#define CO_HAS_DOCSTRING 0x4000000
+/* A function defined in class scope */
+#define CO_METHOD 0x8000000
+
/* This should be defined if a future statement modifies the syntax.
For example, when a keyword is added.
*/
diff --git a/Include/internal/pycore_symtable.h b/Include/internal/pycore_symtable.h
index 91dac76..b7e2742 100644
--- a/Include/internal/pycore_symtable.h
+++ b/Include/internal/pycore_symtable.h
@@ -124,6 +124,7 @@ typedef struct _symtable_entry {
unsigned ste_can_see_class_scope : 1; /* true if this block can see names bound in an
enclosing class scope */
unsigned ste_has_docstring : 1; /* true if docstring present */
+ unsigned ste_method : 1; /* true if block is a function block defined in class scope */
int ste_comp_iter_expr; /* non-zero if visiting a comprehension range expression */
_Py_SourceLocation ste_loc; /* source location of block */
struct _symtable_entry *ste_annotation_block; /* symbol table entry for this entry's annotations */