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
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Gwenaël Samain
cython
Commits
5ff75cda
Commit
5ff75cda
authored
Feb 22, 2019
by
Noam Hershtig
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow condition in GILStatNode
parent
605cc214
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
41 additions
and
2 deletions
+41
-2
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+3
-1
Cython/Compiler/Optimize.py
Cython/Compiler/Optimize.py
+24
-0
Cython/Compiler/ParseTreeTransforms.py
Cython/Compiler/ParseTreeTransforms.py
+5
-0
Cython/Compiler/Parsing.py
Cython/Compiler/Parsing.py
+9
-1
No files found.
Cython/Compiler/Nodes.py
View file @
5ff75cda
...
...
@@ -7794,10 +7794,12 @@ class GILStatNode(NogilTryFinallyStatNode):
#
# state string 'gil' or 'nogil'
child_attrs
=
[
"body"
,
"condition"
,
"finally_clause"
,
"finally_except_clause"
]
state_temp
=
None
def
__init__
(
self
,
pos
,
state
,
body
):
def
__init__
(
self
,
pos
,
state
,
body
,
condition
=
None
):
self
.
state
=
state
self
.
condition
=
condition
self
.
create_state_temp_if_needed
(
pos
,
state
,
body
)
TryFinallyStatNode
.
__init__
(
self
,
pos
,
...
...
Cython/Compiler/Optimize.py
View file @
5ff75cda
...
...
@@ -4688,6 +4688,30 @@ class ConstantFolding(Visitor.VisitorTransform, SkipDeclarations):
return
None
return
node
def
visit_GILStatNode
(
self
,
node
):
self
.
visitchildren
(
node
)
if
node
.
condition
is
None
:
return
node
if
node
.
condition
.
has_constant_result
():
# Condition is True - Modify node to be a normal
# GILStatNode with condition=None
if
node
.
condition
.
constant_result
:
node
.
condition
=
None
# Condition is False - the body of the GILStatNode
# should run without changing changing the state of the gil
# return the body of the GILStatNode
else
:
return
node
.
body
# If condition is not constant we keep the GILStatNode as it is.
# Either it will later become constant (e.g. a `numeric is int`
# expression in a fused typed function) and then when ConstantFolding
# runs again it will be handled or a later transform (i.e. GilCheck)
# will raise an error
return
node
# in the future, other nodes can have their own handler method here
# that can replace them with a constant result node
...
...
Cython/Compiler/ParseTreeTransforms.py
View file @
5ff75cda
...
...
@@ -2915,6 +2915,11 @@ class GilCheck(VisitorTransform):
return
node
def
visit_GILStatNode
(
self
,
node
):
if
node
.
condition
is
not
None
:
error
(
node
.
pos
,
"Non-constant condition in a "
"`with %s(<condition>)` statement"
%
node
.
state
)
return
node
if
self
.
nogil
and
node
.
nogil_check
:
node
.
nogil_check
()
...
...
Cython/Compiler/Parsing.py
View file @
5ff75cda
...
...
@@ -2055,12 +2055,20 @@ def p_with_items(s, is_async=False):
s
.
error
(
"with gil/nogil cannot be async"
)
state
=
s
.
systring
s
.
next
()
# support conditional gil/nogil
condition
=
None
if
s
.
sy
==
'('
:
s
.
next
()
condition
=
p_test
(
s
)
s
.
expect
(
')'
)
if
s
.
sy
==
','
:
s
.
next
()
body
=
p_with_items
(
s
)
else
:
body
=
p_suite
(
s
)
return
Nodes
.
GILStatNode
(
pos
,
state
=
state
,
body
=
body
)
return
Nodes
.
GILStatNode
(
pos
,
state
=
state
,
body
=
body
,
condition
=
condition
)
else
:
manager
=
p_test
(
s
)
target
=
None
...
...
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