Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
3dfbaf51
Unverified
Kaydet (Commit)
3dfbaf51
authored
Ara 25, 2017
tarafından
Serhiy Storchaka
Kaydeden (comit)
GitHub
Ara 25, 2017
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
bpo-32372: Move __debug__ optimization to the AST level. (#4925)
üst
1b3029ac
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
47 additions
and
52 deletions
+47
-52
compile.h
Include/compile.h
+1
-1
ast_opt.c
Python/ast_opt.c
+38
-33
compile.c
Python/compile.c
+8
-18
No files found.
Include/compile.h
Dosyayı görüntüle @
3dfbaf51
...
...
@@ -75,7 +75,7 @@ PyAPI_FUNC(PyObject*) _Py_Mangle(PyObject *p, PyObject *name);
#define PY_INVALID_STACK_EFFECT INT_MAX
PyAPI_FUNC
(
int
)
PyCompile_OpcodeStackEffect
(
int
opcode
,
int
oparg
);
PyAPI_FUNC
(
int
)
_PyAST_Optimize
(
struct
_mod
*
,
PyArena
*
arena
);
PyAPI_FUNC
(
int
)
_PyAST_Optimize
(
struct
_mod
*
,
PyArena
*
arena
,
int
optimize
);
#ifdef __cplusplus
}
...
...
Python/ast_opt.c
Dosyayı görüntüle @
3dfbaf51
...
...
@@ -75,7 +75,7 @@ unary_not(PyObject *v)
}
static
int
fold_unaryop
(
expr_ty
node
,
PyArena
*
arena
)
fold_unaryop
(
expr_ty
node
,
PyArena
*
arena
,
int
optimize
)
{
expr_ty
arg
=
node
->
v
.
UnaryOp
.
operand
;
...
...
@@ -252,7 +252,7 @@ safe_mod(PyObject *v, PyObject *w)
}
static
int
fold_binop
(
expr_ty
node
,
PyArena
*
arena
)
fold_binop
(
expr_ty
node
,
PyArena
*
arena
,
int
optimize
)
{
expr_ty
lhs
,
rhs
;
lhs
=
node
->
v
.
BinOp
.
left
;
...
...
@@ -334,7 +334,7 @@ make_const_tuple(asdl_seq *elts)
}
static
int
fold_tuple
(
expr_ty
node
,
PyArena
*
arena
)
fold_tuple
(
expr_ty
node
,
PyArena
*
arena
,
int
optimize
)
{
PyObject
*
newval
;
...
...
@@ -346,7 +346,7 @@ fold_tuple(expr_ty node, PyArena *arena)
}
static
int
fold_subscr
(
expr_ty
node
,
PyArena
*
arena
)
fold_subscr
(
expr_ty
node
,
PyArena
*
arena
,
int
optimize
)
{
PyObject
*
newval
;
expr_ty
arg
,
idx
;
...
...
@@ -374,7 +374,7 @@ fold_subscr(expr_ty node, PyArena *arena)
in "for" loop and comprehensions.
*/
static
int
fold_iter
(
expr_ty
arg
,
PyArena
*
arena
)
fold_iter
(
expr_ty
arg
,
PyArena
*
arena
,
int
optimize
)
{
PyObject
*
newval
;
if
(
arg
->
kind
==
List_kind
)
{
...
...
@@ -393,7 +393,7 @@ fold_iter(expr_ty arg, PyArena *arena)
}
static
int
fold_compare
(
expr_ty
node
,
PyArena
*
arena
)
fold_compare
(
expr_ty
node
,
PyArena
*
arena
,
int
optimize
)
{
asdl_int_seq
*
ops
;
asdl_seq
*
args
;
...
...
@@ -407,29 +407,29 @@ fold_compare(expr_ty node, PyArena *arena)
i
=
asdl_seq_LEN
(
ops
)
-
1
;
int
op
=
asdl_seq_GET
(
ops
,
i
);
if
(
op
==
In
||
op
==
NotIn
)
{
if
(
!
fold_iter
((
expr_ty
)
asdl_seq_GET
(
args
,
i
),
arena
))
{
if
(
!
fold_iter
((
expr_ty
)
asdl_seq_GET
(
args
,
i
),
arena
,
optimize
))
{
return
0
;
}
}
return
1
;
}
static
int
astfold_mod
(
mod_ty
node_
,
PyArena
*
ctx
_
);
static
int
astfold_stmt
(
stmt_ty
node_
,
PyArena
*
ctx
_
);
static
int
astfold_expr
(
expr_ty
node_
,
PyArena
*
ctx
_
);
static
int
astfold_arguments
(
arguments_ty
node_
,
PyArena
*
ctx
_
);
static
int
astfold_comprehension
(
comprehension_ty
node_
,
PyArena
*
ctx
_
);
static
int
astfold_keyword
(
keyword_ty
node_
,
PyArena
*
ctx
_
);
static
int
astfold_slice
(
slice_ty
node_
,
PyArena
*
ctx
_
);
static
int
astfold_arg
(
arg_ty
node_
,
PyArena
*
ctx
_
);
static
int
astfold_withitem
(
withitem_ty
node_
,
PyArena
*
ctx
_
);
static
int
astfold_excepthandler
(
excepthandler_ty
node_
,
PyArena
*
ctx
_
);
static
int
astfold_mod
(
mod_ty
node_
,
PyArena
*
ctx_
,
int
optimize
_
);
static
int
astfold_stmt
(
stmt_ty
node_
,
PyArena
*
ctx_
,
int
optimize
_
);
static
int
astfold_expr
(
expr_ty
node_
,
PyArena
*
ctx_
,
int
optimize
_
);
static
int
astfold_arguments
(
arguments_ty
node_
,
PyArena
*
ctx_
,
int
optimize
_
);
static
int
astfold_comprehension
(
comprehension_ty
node_
,
PyArena
*
ctx_
,
int
optimize
_
);
static
int
astfold_keyword
(
keyword_ty
node_
,
PyArena
*
ctx_
,
int
optimize
_
);
static
int
astfold_slice
(
slice_ty
node_
,
PyArena
*
ctx_
,
int
optimize
_
);
static
int
astfold_arg
(
arg_ty
node_
,
PyArena
*
ctx_
,
int
optimize
_
);
static
int
astfold_withitem
(
withitem_ty
node_
,
PyArena
*
ctx_
,
int
optimize
_
);
static
int
astfold_excepthandler
(
excepthandler_ty
node_
,
PyArena
*
ctx_
,
int
optimize
_
);
#define CALL(FUNC, TYPE, ARG) \
if (!FUNC((ARG), ctx_)) \
if (!FUNC((ARG), ctx_
, optimize_
)) \
return 0;
#define CALL_OPT(FUNC, TYPE, ARG) \
if ((ARG) != NULL && !FUNC((ARG), ctx_)) \
if ((ARG) != NULL && !FUNC((ARG), ctx_
, optimize_
)) \
return 0;
#define CALL_SEQ(FUNC, TYPE, ARG) { \
...
...
@@ -437,7 +437,7 @@ static int astfold_excepthandler(excepthandler_ty node_, PyArena* ctx_);
asdl_seq *seq = (ARG);
/* avoid variable capture */
\
for (i = 0; i < asdl_seq_LEN(seq); i++) { \
TYPE elt = (TYPE)asdl_seq_GET(seq, i); \
if (elt != NULL && !FUNC(elt, ctx_)) \
if (elt != NULL && !FUNC(elt, ctx_
, optimize_
)) \
return 0; \
} \
}
...
...
@@ -447,13 +447,13 @@ static int astfold_excepthandler(excepthandler_ty node_, PyArena* ctx_);
asdl_int_seq *seq = (ARG);
/* avoid variable capture */
\
for (i = 0; i < asdl_seq_LEN(seq); i++) { \
TYPE elt = (TYPE)asdl_seq_GET(seq, i); \
if (!FUNC(elt, ctx_)) \
if (!FUNC(elt, ctx_
, optimize_
)) \
return 0; \
} \
}
static
int
astfold_mod
(
mod_ty
node_
,
PyArena
*
ctx
_
)
astfold_mod
(
mod_ty
node_
,
PyArena
*
ctx_
,
int
optimize
_
)
{
switch
(
node_
->
kind
)
{
case
Module_kind
:
...
...
@@ -475,7 +475,7 @@ astfold_mod(mod_ty node_, PyArena* ctx_)
}
static
int
astfold_expr
(
expr_ty
node_
,
PyArena
*
ctx
_
)
astfold_expr
(
expr_ty
node_
,
PyArena
*
ctx_
,
int
optimize
_
)
{
switch
(
node_
->
kind
)
{
case
BoolOp_kind
:
...
...
@@ -567,6 +567,11 @@ astfold_expr(expr_ty node_, PyArena* ctx_)
CALL_SEQ
(
astfold_expr
,
expr_ty
,
node_
->
v
.
Tuple
.
elts
);
CALL
(
fold_tuple
,
expr_ty
,
node_
);
break
;
case
Name_kind
:
if
(
_PyUnicode_EqualToASCIIString
(
node_
->
v
.
Name
.
id
,
"__debug__"
))
{
return
make_const
(
node_
,
PyBool_FromLong
(
!
optimize_
),
ctx_
);
}
break
;
default:
break
;
}
...
...
@@ -574,7 +579,7 @@ astfold_expr(expr_ty node_, PyArena* ctx_)
}
static
int
astfold_slice
(
slice_ty
node_
,
PyArena
*
ctx
_
)
astfold_slice
(
slice_ty
node_
,
PyArena
*
ctx_
,
int
optimize
_
)
{
switch
(
node_
->
kind
)
{
case
Slice_kind
:
...
...
@@ -595,14 +600,14 @@ astfold_slice(slice_ty node_, PyArena* ctx_)
}
static
int
astfold_keyword
(
keyword_ty
node_
,
PyArena
*
ctx
_
)
astfold_keyword
(
keyword_ty
node_
,
PyArena
*
ctx_
,
int
optimize
_
)
{
CALL
(
astfold_expr
,
expr_ty
,
node_
->
value
);
return
1
;
}
static
int
astfold_comprehension
(
comprehension_ty
node_
,
PyArena
*
ctx
_
)
astfold_comprehension
(
comprehension_ty
node_
,
PyArena
*
ctx_
,
int
optimize
_
)
{
CALL
(
astfold_expr
,
expr_ty
,
node_
->
target
);
CALL
(
astfold_expr
,
expr_ty
,
node_
->
iter
);
...
...
@@ -613,7 +618,7 @@ astfold_comprehension(comprehension_ty node_, PyArena* ctx_)
}
static
int
astfold_arguments
(
arguments_ty
node_
,
PyArena
*
ctx
_
)
astfold_arguments
(
arguments_ty
node_
,
PyArena
*
ctx_
,
int
optimize
_
)
{
CALL_SEQ
(
astfold_arg
,
arg_ty
,
node_
->
args
);
CALL_OPT
(
astfold_arg
,
arg_ty
,
node_
->
vararg
);
...
...
@@ -625,14 +630,14 @@ astfold_arguments(arguments_ty node_, PyArena* ctx_)
}
static
int
astfold_arg
(
arg_ty
node_
,
PyArena
*
ctx
_
)
astfold_arg
(
arg_ty
node_
,
PyArena
*
ctx_
,
int
optimize
_
)
{
CALL_OPT
(
astfold_expr
,
expr_ty
,
node_
->
annotation
);
return
1
;
}
static
int
astfold_stmt
(
stmt_ty
node_
,
PyArena
*
ctx
_
)
astfold_stmt
(
stmt_ty
node_
,
PyArena
*
ctx_
,
int
optimize
_
)
{
switch
(
node_
->
kind
)
{
case
FunctionDef_kind
:
...
...
@@ -728,7 +733,7 @@ astfold_stmt(stmt_ty node_, PyArena* ctx_)
}
static
int
astfold_excepthandler
(
excepthandler_ty
node_
,
PyArena
*
ctx
_
)
astfold_excepthandler
(
excepthandler_ty
node_
,
PyArena
*
ctx_
,
int
optimize
_
)
{
switch
(
node_
->
kind
)
{
case
ExceptHandler_kind
:
...
...
@@ -742,7 +747,7 @@ astfold_excepthandler(excepthandler_ty node_, PyArena* ctx_)
}
static
int
astfold_withitem
(
withitem_ty
node_
,
PyArena
*
ctx
_
)
astfold_withitem
(
withitem_ty
node_
,
PyArena
*
ctx_
,
int
optimize
_
)
{
CALL
(
astfold_expr
,
expr_ty
,
node_
->
context_expr
);
CALL_OPT
(
astfold_expr
,
expr_ty
,
node_
->
optional_vars
);
...
...
@@ -755,9 +760,9 @@ astfold_withitem(withitem_ty node_, PyArena* ctx_)
#undef CALL_INT_SEQ
int
_PyAST_Optimize
(
mod_ty
mod
,
PyArena
*
arena
)
_PyAST_Optimize
(
mod_ty
mod
,
PyArena
*
arena
,
int
optimize
)
{
int
ret
=
astfold_mod
(
mod
,
arena
);
int
ret
=
astfold_mod
(
mod
,
arena
,
optimize
);
assert
(
ret
||
PyErr_Occurred
());
return
ret
;
}
Python/compile.c
Dosyayı görüntüle @
3dfbaf51
...
...
@@ -191,7 +191,7 @@ static void compiler_pop_fblock(struct compiler *, enum fblocktype,
static
int
compiler_in_loop
(
struct
compiler
*
);
static
int
inplace_binop
(
struct
compiler
*
,
operator_ty
);
static
int
expr_constant
(
struct
compiler
*
,
expr_ty
);
static
int
expr_constant
(
expr_ty
);
static
int
compiler_with
(
struct
compiler
*
,
stmt_ty
,
int
);
static
int
compiler_async_with
(
struct
compiler
*
,
stmt_ty
,
int
);
...
...
@@ -331,7 +331,7 @@ PyAST_CompileObject(mod_ty mod, PyObject *filename, PyCompilerFlags *flags,
c
.
c_optimize
=
(
optimize
==
-
1
)
?
Py_OptimizeFlag
:
optimize
;
c
.
c_nestlevel
=
0
;
if
(
!
_PyAST_Optimize
(
mod
,
arena
))
{
if
(
!
_PyAST_Optimize
(
mod
,
arena
,
c
.
c_optimize
))
{
goto
finally
;
}
...
...
@@ -1332,15 +1332,13 @@ is_const(expr_ty e)
case
Ellipsis_kind
:
case
NameConstant_kind
:
return
1
;
case
Name_kind
:
return
_PyUnicode_EqualToASCIIString
(
e
->
v
.
Name
.
id
,
"__debug__"
);
default:
return
0
;
}
}
static
PyObject
*
get_const_value
(
struct
compiler
*
c
,
expr_ty
e
)
get_const_value
(
expr_ty
e
)
{
switch
(
e
->
kind
)
{
case
Constant_kind
:
...
...
@@ -1355,9 +1353,6 @@ get_const_value(struct compiler *c, expr_ty e)
return
Py_Ellipsis
;
case
NameConstant_kind
:
return
e
->
v
.
NameConstant
.
value
;
case
Name_kind
:
assert
(
_PyUnicode_EqualToASCIIString
(
e
->
v
.
Name
.
id
,
"__debug__"
));
return
c
->
c_optimize
?
Py_False
:
Py_True
;
default:
Py_UNREACHABLE
();
}
...
...
@@ -2217,7 +2212,7 @@ compiler_if(struct compiler *c, stmt_ty s)
if
(
end
==
NULL
)
return
0
;
constant
=
expr_constant
(
c
,
s
->
v
.
If
.
test
);
constant
=
expr_constant
(
s
->
v
.
If
.
test
);
/* constant = 0: "if 0"
* constant = 1: "if 1", "if 2", ...
* constant = -1: rest */
...
...
@@ -2363,7 +2358,7 @@ static int
compiler_while
(
struct
compiler
*
c
,
stmt_ty
s
)
{
basicblock
*
loop
,
*
orelse
,
*
end
,
*
anchor
=
NULL
;
int
constant
=
expr_constant
(
c
,
s
->
v
.
While
.
test
);
int
constant
=
expr_constant
(
s
->
v
.
While
.
test
);
if
(
constant
==
0
)
{
if
(
s
->
v
.
While
.
orelse
)
...
...
@@ -3098,11 +3093,6 @@ compiler_nameop(struct compiler *c, identifier name, expr_context_ty ctx)
!
_PyUnicode_EqualToASCIIString
(
name
,
"True"
)
&&
!
_PyUnicode_EqualToASCIIString
(
name
,
"False"
));
if
(
ctx
==
Load
&&
_PyUnicode_EqualToASCIIString
(
name
,
"__debug__"
))
{
ADDOP_O
(
c
,
LOAD_CONST
,
c
->
c_optimize
?
Py_False
:
Py_True
,
consts
);
return
1
;
}
mangled
=
_Py_Mangle
(
c
->
u
->
u_private
,
name
);
if
(
!
mangled
)
return
0
;
...
...
@@ -3370,7 +3360,7 @@ compiler_subdict(struct compiler *c, expr_ty e, Py_ssize_t begin, Py_ssize_t end
return
0
;
}
for
(
i
=
begin
;
i
<
end
;
i
++
)
{
key
=
get_const_value
(
c
,
(
expr_ty
)
asdl_seq_GET
(
e
->
v
.
Dict
.
keys
,
i
));
key
=
get_const_value
((
expr_ty
)
asdl_seq_GET
(
e
->
v
.
Dict
.
keys
,
i
));
Py_INCREF
(
key
);
PyTuple_SET_ITEM
(
keys
,
i
-
begin
,
key
);
}
...
...
@@ -4140,10 +4130,10 @@ compiler_visit_keyword(struct compiler *c, keyword_ty k)
*/
static
int
expr_constant
(
struct
compiler
*
c
,
expr_ty
e
)
expr_constant
(
expr_ty
e
)
{
if
(
is_const
(
e
))
{
return
PyObject_IsTrue
(
get_const_value
(
c
,
e
));
return
PyObject_IsTrue
(
get_const_value
(
e
));
}
return
-
1
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment