Kaydet (Commit) 1dfd247c authored tarafından Benjamin Peterson's avatar Benjamin Peterson

remove the concept of an unoptimized function scope from the compiler, since it…

remove the concept of an unoptimized function scope from the compiler, since it can't happen anymore
üst 48050cbb
...@@ -43,7 +43,6 @@ typedef struct _symtable_entry { ...@@ -43,7 +43,6 @@ typedef struct _symtable_entry {
PyObject *ste_children; /* list of child blocks */ PyObject *ste_children; /* list of child blocks */
PyObject *ste_directives;/* locations of global and nonlocal statements */ PyObject *ste_directives;/* locations of global and nonlocal statements */
_Py_block_ty ste_type; /* module, class, or function */ _Py_block_ty ste_type; /* module, class, or function */
int ste_unoptimized; /* false if namespace is optimized */
int ste_nested; /* true if block is nested */ int ste_nested; /* true if block is nested */
unsigned ste_free : 1; /* true if block has free variables */ unsigned ste_free : 1; /* true if block has free variables */
unsigned ste_child_free : 1; /* true if a child block has free vars, unsigned ste_child_free : 1; /* true if a child block has free vars,
...@@ -108,10 +107,6 @@ PyAPI_FUNC(void) PySymtable_Free(struct symtable *); ...@@ -108,10 +107,6 @@ PyAPI_FUNC(void) PySymtable_Free(struct symtable *);
#define FREE 4 #define FREE 4
#define CELL 5 #define CELL 5
/* The following two names are used for the ste_unoptimized bit field */
#define OPT_IMPORT_STAR 1
#define OPT_TOPLEVEL 2 /* top-level names, including eval and exec */
#define GENERATOR 1 #define GENERATOR 1
#define GENERATOR_EXPRESSION 2 #define GENERATOR_EXPRESSION 2
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
import _symtable import _symtable
from _symtable import (USE, DEF_GLOBAL, DEF_LOCAL, DEF_PARAM, from _symtable import (USE, DEF_GLOBAL, DEF_LOCAL, DEF_PARAM,
DEF_IMPORT, DEF_BOUND, OPT_IMPORT_STAR, SCOPE_OFF, SCOPE_MASK, FREE, DEF_IMPORT, DEF_BOUND, SCOPE_OFF, SCOPE_MASK, FREE,
LOCAL, GLOBAL_IMPLICIT, GLOBAL_EXPLICIT, CELL) LOCAL, GLOBAL_IMPLICIT, GLOBAL_EXPLICIT, CELL)
import weakref import weakref
...@@ -74,8 +74,7 @@ class SymbolTable(object): ...@@ -74,8 +74,7 @@ class SymbolTable(object):
return self._table.lineno return self._table.lineno
def is_optimized(self): def is_optimized(self):
return bool(self._table.type == _symtable.TYPE_FUNCTION return bool(self._table.type == _symtable.TYPE_FUNCTION)
and not self._table.optimized)
def is_nested(self): def is_nested(self):
return bool(self._table.nested) return bool(self._table.nested)
...@@ -87,10 +86,6 @@ class SymbolTable(object): ...@@ -87,10 +86,6 @@ class SymbolTable(object):
"""Return true if the scope uses exec. Deprecated method.""" """Return true if the scope uses exec. Deprecated method."""
return False return False
def has_import_star(self):
"""Return true if the scope uses import *"""
return bool(self._table.optimized & OPT_IMPORT_STAR)
def get_identifiers(self): def get_identifiers(self):
return self._table.symbols.keys() return self._table.symbols.keys()
......
...@@ -84,9 +84,6 @@ PyInit__symtable(void) ...@@ -84,9 +84,6 @@ PyInit__symtable(void)
PyModule_AddIntConstant(m, "TYPE_CLASS", ClassBlock); PyModule_AddIntConstant(m, "TYPE_CLASS", ClassBlock);
PyModule_AddIntConstant(m, "TYPE_MODULE", ModuleBlock); PyModule_AddIntConstant(m, "TYPE_MODULE", ModuleBlock);
PyModule_AddIntMacro(m, OPT_IMPORT_STAR);
PyModule_AddIntMacro(m, OPT_TOPLEVEL);
PyModule_AddIntMacro(m, LOCAL); PyModule_AddIntMacro(m, LOCAL);
PyModule_AddIntMacro(m, GLOBAL_EXPLICIT); PyModule_AddIntMacro(m, GLOBAL_EXPLICIT);
PyModule_AddIntMacro(m, GLOBAL_IMPLICIT); PyModule_AddIntMacro(m, GLOBAL_IMPLICIT);
......
...@@ -2753,8 +2753,7 @@ compiler_nameop(struct compiler *c, identifier name, expr_context_ty ctx) ...@@ -2753,8 +2753,7 @@ compiler_nameop(struct compiler *c, identifier name, expr_context_ty ctx)
optype = OP_FAST; optype = OP_FAST;
break; break;
case GLOBAL_IMPLICIT: case GLOBAL_IMPLICIT:
if (c->u->u_ste->ste_type == FunctionBlock && if (c->u->u_ste->ste_type == FunctionBlock)
!c->u->u_ste->ste_unoptimized)
optype = OP_GLOBAL; optype = OP_GLOBAL;
break; break;
case GLOBAL_EXPLICIT: case GLOBAL_EXPLICIT:
...@@ -4185,9 +4184,7 @@ compute_code_flags(struct compiler *c) ...@@ -4185,9 +4184,7 @@ compute_code_flags(struct compiler *c)
int flags = 0; int flags = 0;
Py_ssize_t n; Py_ssize_t n;
if (ste->ste_type == FunctionBlock) { if (ste->ste_type == FunctionBlock) {
flags |= CO_NEWLOCALS; flags |= CO_NEWLOCALS | CO_OPTIMIZED;
if (!ste->ste_unoptimized)
flags |= CO_OPTIMIZED;
if (ste->ste_nested) if (ste->ste_nested)
flags |= CO_NESTED; flags |= CO_NESTED;
if (ste->ste_generator) if (ste->ste_generator)
......
...@@ -47,7 +47,6 @@ ste_new(struct symtable *st, identifier name, _Py_block_ty block, ...@@ -47,7 +47,6 @@ ste_new(struct symtable *st, identifier name, _Py_block_ty block,
ste->ste_directives = NULL; ste->ste_directives = NULL;
ste->ste_type = block; ste->ste_type = block;
ste->ste_unoptimized = 0;
ste->ste_nested = 0; ste->ste_nested = 0;
ste->ste_free = 0; ste->ste_free = 0;
ste->ste_varargs = 0; ste->ste_varargs = 0;
...@@ -113,7 +112,6 @@ static PyMemberDef ste_memberlist[] = { ...@@ -113,7 +112,6 @@ static PyMemberDef ste_memberlist[] = {
{"symbols", T_OBJECT, OFF(ste_symbols), READONLY}, {"symbols", T_OBJECT, OFF(ste_symbols), READONLY},
{"varnames", T_OBJECT, OFF(ste_varnames), READONLY}, {"varnames", T_OBJECT, OFF(ste_varnames), READONLY},
{"children", T_OBJECT, OFF(ste_children), READONLY}, {"children", T_OBJECT, OFF(ste_children), READONLY},
{"optimized",T_INT, OFF(ste_unoptimized), READONLY},
{"nested", T_INT, OFF(ste_nested), READONLY}, {"nested", T_INT, OFF(ste_nested), READONLY},
{"type", T_INT, OFF(ste_type), READONLY}, {"type", T_INT, OFF(ste_type), READONLY},
{"lineno", T_INT, OFF(ste_lineno), READONLY}, {"lineno", T_INT, OFF(ste_lineno), READONLY},
...@@ -271,7 +269,6 @@ PySymtable_BuildObject(mod_ty mod, PyObject *filename, PyFutureFeatures *future) ...@@ -271,7 +269,6 @@ PySymtable_BuildObject(mod_ty mod, PyObject *filename, PyFutureFeatures *future)
} }
st->st_top = st->st_cur; st->st_top = st->st_cur;
st->st_cur->ste_unoptimized = OPT_TOPLEVEL;
switch (mod->kind) { switch (mod->kind) {
case Module_kind: case Module_kind:
seq = mod->v.Module.body; seq = mod->v.Module.body;
...@@ -1245,21 +1242,9 @@ symtable_visit_stmt(struct symtable *st, stmt_ty s) ...@@ -1245,21 +1242,9 @@ symtable_visit_stmt(struct symtable *st, stmt_ty s)
break; break;
case Import_kind: case Import_kind:
VISIT_SEQ(st, alias, s->v.Import.names); VISIT_SEQ(st, alias, s->v.Import.names);
/* XXX Don't have the lineno available inside
visit_alias */
if (st->st_cur->ste_unoptimized && !st->st_cur->ste_opt_lineno) {
st->st_cur->ste_opt_lineno = s->lineno;
st->st_cur->ste_opt_col_offset = s->col_offset;
}
break; break;
case ImportFrom_kind: case ImportFrom_kind:
VISIT_SEQ(st, alias, s->v.ImportFrom.names); VISIT_SEQ(st, alias, s->v.ImportFrom.names);
/* XXX Don't have the lineno available inside
visit_alias */
if (st->st_cur->ste_unoptimized && !st->st_cur->ste_opt_lineno) {
st->st_cur->ste_opt_lineno = s->lineno;
st->st_cur->ste_opt_col_offset = s->col_offset;
}
break; break;
case Global_kind: { case Global_kind: {
int i; int i;
...@@ -1615,7 +1600,6 @@ symtable_visit_alias(struct symtable *st, alias_ty a) ...@@ -1615,7 +1600,6 @@ symtable_visit_alias(struct symtable *st, alias_ty a)
Py_DECREF(store_name); Py_DECREF(store_name);
return 0; return 0;
} }
st->st_cur->ste_unoptimized |= OPT_IMPORT_STAR;
Py_DECREF(store_name); Py_DECREF(store_name);
return 1; return 1;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment