Skip to content

Commit 1dfd247

Browse files
committed
remove the concept of an unoptimized function scope from the compiler, since it can't happen anymore
1 parent 48050cb commit 1dfd247

File tree

5 files changed

+4
-36
lines changed

5 files changed

+4
-36
lines changed

Include/symtable.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ typedef struct _symtable_entry {
4343
PyObject *ste_children; /* list of child blocks */
4444
PyObject *ste_directives;/* locations of global and nonlocal statements */
4545
_Py_block_ty ste_type; /* module, class, or function */
46-
int ste_unoptimized; /* false if namespace is optimized */
4746
int ste_nested; /* true if block is nested */
4847
unsigned ste_free : 1; /* true if block has free variables */
4948
unsigned ste_child_free : 1; /* true if a child block has free vars,
@@ -108,10 +107,6 @@ PyAPI_FUNC(void) PySymtable_Free(struct symtable *);
108107
#define FREE 4
109108
#define CELL 5
110109

111-
/* The following two names are used for the ste_unoptimized bit field */
112-
#define OPT_IMPORT_STAR 1
113-
#define OPT_TOPLEVEL 2 /* top-level names, including eval and exec */
114-
115110
#define GENERATOR 1
116111
#define GENERATOR_EXPRESSION 2
117112

Lib/symtable.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import _symtable
44
from _symtable import (USE, DEF_GLOBAL, DEF_LOCAL, DEF_PARAM,
5-
DEF_IMPORT, DEF_BOUND, OPT_IMPORT_STAR, SCOPE_OFF, SCOPE_MASK, FREE,
5+
DEF_IMPORT, DEF_BOUND, SCOPE_OFF, SCOPE_MASK, FREE,
66
LOCAL, GLOBAL_IMPLICIT, GLOBAL_EXPLICIT, CELL)
77

88
import weakref
@@ -74,8 +74,7 @@ def get_lineno(self):
7474
return self._table.lineno
7575

7676
def is_optimized(self):
77-
return bool(self._table.type == _symtable.TYPE_FUNCTION
78-
and not self._table.optimized)
77+
return bool(self._table.type == _symtable.TYPE_FUNCTION)
7978

8079
def is_nested(self):
8180
return bool(self._table.nested)
@@ -87,10 +86,6 @@ def has_exec(self):
8786
"""Return true if the scope uses exec. Deprecated method."""
8887
return False
8988

90-
def has_import_star(self):
91-
"""Return true if the scope uses import *"""
92-
return bool(self._table.optimized & OPT_IMPORT_STAR)
93-
9489
def get_identifiers(self):
9590
return self._table.symbols.keys()
9691

Modules/symtablemodule.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,6 @@ PyInit__symtable(void)
8484
PyModule_AddIntConstant(m, "TYPE_CLASS", ClassBlock);
8585
PyModule_AddIntConstant(m, "TYPE_MODULE", ModuleBlock);
8686

87-
PyModule_AddIntMacro(m, OPT_IMPORT_STAR);
88-
PyModule_AddIntMacro(m, OPT_TOPLEVEL);
89-
9087
PyModule_AddIntMacro(m, LOCAL);
9188
PyModule_AddIntMacro(m, GLOBAL_EXPLICIT);
9289
PyModule_AddIntMacro(m, GLOBAL_IMPLICIT);

Python/compile.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2753,8 +2753,7 @@ compiler_nameop(struct compiler *c, identifier name, expr_context_ty ctx)
27532753
optype = OP_FAST;
27542754
break;
27552755
case GLOBAL_IMPLICIT:
2756-
if (c->u->u_ste->ste_type == FunctionBlock &&
2757-
!c->u->u_ste->ste_unoptimized)
2756+
if (c->u->u_ste->ste_type == FunctionBlock)
27582757
optype = OP_GLOBAL;
27592758
break;
27602759
case GLOBAL_EXPLICIT:
@@ -4185,9 +4184,7 @@ compute_code_flags(struct compiler *c)
41854184
int flags = 0;
41864185
Py_ssize_t n;
41874186
if (ste->ste_type == FunctionBlock) {
4188-
flags |= CO_NEWLOCALS;
4189-
if (!ste->ste_unoptimized)
4190-
flags |= CO_OPTIMIZED;
4187+
flags |= CO_NEWLOCALS | CO_OPTIMIZED;
41914188
if (ste->ste_nested)
41924189
flags |= CO_NESTED;
41934190
if (ste->ste_generator)

Python/symtable.c

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ ste_new(struct symtable *st, identifier name, _Py_block_ty block,
4747
ste->ste_directives = NULL;
4848

4949
ste->ste_type = block;
50-
ste->ste_unoptimized = 0;
5150
ste->ste_nested = 0;
5251
ste->ste_free = 0;
5352
ste->ste_varargs = 0;
@@ -113,7 +112,6 @@ static PyMemberDef ste_memberlist[] = {
113112
{"symbols", T_OBJECT, OFF(ste_symbols), READONLY},
114113
{"varnames", T_OBJECT, OFF(ste_varnames), READONLY},
115114
{"children", T_OBJECT, OFF(ste_children), READONLY},
116-
{"optimized",T_INT, OFF(ste_unoptimized), READONLY},
117115
{"nested", T_INT, OFF(ste_nested), READONLY},
118116
{"type", T_INT, OFF(ste_type), READONLY},
119117
{"lineno", T_INT, OFF(ste_lineno), READONLY},
@@ -271,7 +269,6 @@ PySymtable_BuildObject(mod_ty mod, PyObject *filename, PyFutureFeatures *future)
271269
}
272270

273271
st->st_top = st->st_cur;
274-
st->st_cur->ste_unoptimized = OPT_TOPLEVEL;
275272
switch (mod->kind) {
276273
case Module_kind:
277274
seq = mod->v.Module.body;
@@ -1245,21 +1242,9 @@ symtable_visit_stmt(struct symtable *st, stmt_ty s)
12451242
break;
12461243
case Import_kind:
12471244
VISIT_SEQ(st, alias, s->v.Import.names);
1248-
/* XXX Don't have the lineno available inside
1249-
visit_alias */
1250-
if (st->st_cur->ste_unoptimized && !st->st_cur->ste_opt_lineno) {
1251-
st->st_cur->ste_opt_lineno = s->lineno;
1252-
st->st_cur->ste_opt_col_offset = s->col_offset;
1253-
}
12541245
break;
12551246
case ImportFrom_kind:
12561247
VISIT_SEQ(st, alias, s->v.ImportFrom.names);
1257-
/* XXX Don't have the lineno available inside
1258-
visit_alias */
1259-
if (st->st_cur->ste_unoptimized && !st->st_cur->ste_opt_lineno) {
1260-
st->st_cur->ste_opt_lineno = s->lineno;
1261-
st->st_cur->ste_opt_col_offset = s->col_offset;
1262-
}
12631248
break;
12641249
case Global_kind: {
12651250
int i;
@@ -1615,7 +1600,6 @@ symtable_visit_alias(struct symtable *st, alias_ty a)
16151600
Py_DECREF(store_name);
16161601
return 0;
16171602
}
1618-
st->st_cur->ste_unoptimized |= OPT_IMPORT_STAR;
16191603
Py_DECREF(store_name);
16201604
return 1;
16211605
}

0 commit comments

Comments
 (0)