Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
cython
Commits
5690000c
Commit
5690000c
authored
Dec 29, 2012
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix cross-closure analysis for names redefined inside of a closure function
parent
61e4baf6
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
30 additions
and
5 deletions
+30
-5
Cython/Compiler/FlowControl.py
Cython/Compiler/FlowControl.py
+2
-0
Cython/Compiler/Optimize.py
Cython/Compiler/Optimize.py
+6
-5
tests/run/closure_inlining.pyx
tests/run/closure_inlining.pyx
+22
-0
No files found.
Cython/Compiler/FlowControl.py
View file @
5690000c
...
@@ -536,6 +536,8 @@ def check_definitions(flow, compiler_directives):
...
@@ -536,6 +536,8 @@ def check_definitions(flow, compiler_directives):
node
.
cf_is_null
=
True
node
.
cf_is_null
=
True
if
node
.
allow_null
or
entry
.
from_closure
or
entry
.
is_pyclass_attr
:
if
node
.
allow_null
or
entry
.
from_closure
or
entry
.
is_pyclass_attr
:
pass
# Can be uninitialized here
pass
# Can be uninitialized here
elif
entry
.
in_closure
:
pass
# not smart enough to get this right
elif
node
.
cf_is_null
:
elif
node
.
cf_is_null
:
if
(
entry
.
type
.
is_pyobject
or
entry
.
type
.
is_unspecified
or
if
(
entry
.
type
.
is_pyobject
or
entry
.
type
.
is_unspecified
or
entry
.
error_on_uninitialized
):
entry
.
error_on_uninitialized
):
...
...
Cython/Compiler/Optimize.py
View file @
5690000c
...
@@ -1657,7 +1657,7 @@ class EarlyReplaceBuiltinCalls(Visitor.EnvTransform):
...
@@ -1657,7 +1657,7 @@ class EarlyReplaceBuiltinCalls(Visitor.EnvTransform):
return
node
return
node
return
kwargs
return
kwargs
class
InlineDefNodeCalls
(
Visitor
.
Cython
Transform
):
class
InlineDefNodeCalls
(
Visitor
.
Env
Transform
):
visit_Node
=
Visitor
.
VisitorTransform
.
recurse_to_children
visit_Node
=
Visitor
.
VisitorTransform
.
recurse_to_children
def
visit_SimpleCallNode
(
self
,
node
):
def
visit_SimpleCallNode
(
self
,
node
):
...
@@ -1665,12 +1665,13 @@ class InlineDefNodeCalls(Visitor.CythonTransform):
...
@@ -1665,12 +1665,13 @@ class InlineDefNodeCalls(Visitor.CythonTransform):
if
not
self
.
current_directives
.
get
(
'optimize.inline_defnode_calls'
):
if
not
self
.
current_directives
.
get
(
'optimize.inline_defnode_calls'
):
return
node
return
node
function_name
=
node
.
function
function_name
=
node
.
function
if
not
function_name
.
is_name
:
if
not
function_name
.
is_name
or
function_name
.
cf_state
is
None
:
return
node
return
node
if
(
function_name
.
cf_state
is
None
# global scope
entry
=
self
.
current_env
().
lookup
(
function_name
.
name
)
or
not
function_name
.
cf_state
.
is_single
):
if
not
entry
or
(
not
entry
.
cf_assignments
or
len
(
entry
.
cf_assignments
)
!=
1
):
return
node
return
node
function
=
function_name
.
cf_state
.
one
()
.
rhs
function
=
entry
.
cf_assignments
[
0
]
.
rhs
if
not
isinstance
(
function
,
ExprNodes
.
PyCFunctionNode
):
if
not
isinstance
(
function
,
ExprNodes
.
PyCFunctionNode
):
return
node
return
node
inlined
=
ExprNodes
.
InlinedDefNodeCallNode
(
inlined
=
ExprNodes
.
InlinedDefNodeCallNode
(
...
...
tests/run/closure_inlining.pyx
View file @
5690000c
...
@@ -106,3 +106,25 @@ def test_sideeffect_call_order():
...
@@ -106,3 +106,25 @@ def test_sideeffect_call_order():
pass
pass
call
(
1
,
sideeffect
(
2
),
3
,
sideeffect
(
4
),
sideeffect
(
5
))
call
(
1
,
sideeffect
(
2
),
3
,
sideeffect
(
4
),
sideeffect
(
5
))
return
L
return
L
def
test_redef
(
redefine
):
"""
>>> test_redef(False)
1
>>> test_redef(True)
2
"""
def
inner
():
return
1
def
inner2
():
return
2
def
redef
():
nonlocal
inner
inner
=
inner2
if
redefine
:
redef
()
assert
inner
==
inner2
else
:
assert
inner
!=
inner2
return
inner
()
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