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
0aded093
Commit
0aded093
authored
Mar 24, 2016
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
remove dead left-over code in any()/all() optimisation that issued an "unreachable code" warning
Conflicts: CHANGES.rst
parent
8c7da550
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
79 additions
and
21 deletions
+79
-21
CHANGES.rst
CHANGES.rst
+3
-0
Cython/Compiler/Optimize.py
Cython/Compiler/Optimize.py
+4
-21
tests/run/all.pyx
tests/run/all.pyx
+17
-0
tests/run/control_flow_loop.pyx
tests/run/control_flow_loop.pyx
+55
-0
No files found.
CHANGES.rst
View file @
0aded093
...
@@ -22,6 +22,9 @@ Bugs fixed
...
@@ -22,6 +22,9 @@ Bugs fixed
* Fix prange() to behave identically to range(). The end condition was
* Fix prange() to behave identically to range(). The end condition was
miscalculated when the range was not exactly divisible by the step.
miscalculated when the range was not exactly divisible by the step.
* Optimised `all(genexpr)`/`any(genexpr)` calls could warn about unused code.
This fixes ticket 876.
0.23.4 (2015-10-10)
0.23.4 (2015-10-10)
===================
===================
...
...
Cython/Compiler/Optimize.py
View file @
0aded093
...
@@ -1510,13 +1510,9 @@ class EarlyReplaceBuiltinCalls(Visitor.EnvTransform):
...
@@ -1510,13 +1510,9 @@ class EarlyReplaceBuiltinCalls(Visitor.EnvTransform):
for L in LL:
for L in LL:
for x in L:
for x in L:
if not p(x):
if not p(x):
_result = False
return False
break
else:
continue
break
else:
else:
_result =
True
return
True
"""
"""
return
self
.
_transform_any_all
(
node
,
pos_args
,
False
)
return
self
.
_transform_any_all
(
node
,
pos_args
,
False
)
...
@@ -1530,13 +1526,9 @@ class EarlyReplaceBuiltinCalls(Visitor.EnvTransform):
...
@@ -1530,13 +1526,9 @@ class EarlyReplaceBuiltinCalls(Visitor.EnvTransform):
for L in LL:
for L in LL:
for x in L:
for x in L:
if p(x):
if p(x):
_result = True
return True
break
else:
continue
break
else:
else:
_result =
False
return
False
"""
"""
return
self
.
_transform_any_all
(
node
,
pos_args
,
True
)
return
self
.
_transform_any_all
(
node
,
pos_args
,
True
)
...
@@ -1567,15 +1559,6 @@ class EarlyReplaceBuiltinCalls(Visitor.EnvTransform):
...
@@ -1567,15 +1559,6 @@ class EarlyReplaceBuiltinCalls(Visitor.EnvTransform):
value
=
ExprNodes
.
BoolNode
(
yield_expression
.
pos
,
value
=
is_any
,
constant_result
=
is_any
))
value
=
ExprNodes
.
BoolNode
(
yield_expression
.
pos
,
value
=
is_any
,
constant_result
=
is_any
))
)]
)]
)
)
loop
=
loop_node
while
isinstance
(
loop
.
body
,
Nodes
.
LoopNode
):
next_loop
=
loop
.
body
loop
.
body
=
Nodes
.
StatListNode
(
loop
.
body
.
pos
,
stats
=
[
loop
.
body
,
Nodes
.
BreakStatNode
(
yield_expression
.
pos
)
])
next_loop
.
else_clause
=
Nodes
.
ContinueStatNode
(
yield_expression
.
pos
)
loop
=
next_loop
loop_node
.
else_clause
=
Nodes
.
ReturnStatNode
(
loop_node
.
else_clause
=
Nodes
.
ReturnStatNode
(
node
.
pos
,
node
.
pos
,
value
=
ExprNodes
.
BoolNode
(
yield_expression
.
pos
,
value
=
not
is_any
,
constant_result
=
not
is_any
))
value
=
ExprNodes
.
BoolNode
(
yield_expression
.
pos
,
value
=
not
is_any
,
constant_result
=
not
is_any
))
...
...
tests/run/all.pyx
View file @
0aded093
# mode: run
# tag: all, builtins, werror
cdef
class
VerboseGetItem
(
object
):
cdef
class
VerboseGetItem
(
object
):
cdef
object
sequence
cdef
object
sequence
...
@@ -53,6 +55,7 @@ def all_item(x):
...
@@ -53,6 +55,7 @@ def all_item(x):
"""
"""
return
all
(
x
)
return
all
(
x
)
@
cython
.
test_assert_path_exists
(
@
cython
.
test_assert_path_exists
(
"//ForInStatNode"
,
"//ForInStatNode"
,
"//InlinedGeneratorExpressionNode"
"//InlinedGeneratorExpressionNode"
...
@@ -86,6 +89,7 @@ def all_in_simple_gen(seq):
...
@@ -86,6 +89,7 @@ def all_in_simple_gen(seq):
"""
"""
return
all
(
x
for
x
in
seq
)
return
all
(
x
for
x
in
seq
)
@
cython
.
test_assert_path_exists
(
@
cython
.
test_assert_path_exists
(
"//ForInStatNode"
,
"//ForInStatNode"
,
"//InlinedGeneratorExpressionNode"
"//InlinedGeneratorExpressionNode"
...
@@ -122,6 +126,7 @@ def all_in_simple_gen_scope(seq):
...
@@ -122,6 +126,7 @@ def all_in_simple_gen_scope(seq):
assert
x
==
'abc'
assert
x
==
'abc'
return
result
return
result
@
cython
.
test_assert_path_exists
(
@
cython
.
test_assert_path_exists
(
"//ForInStatNode"
,
"//ForInStatNode"
,
"//InlinedGeneratorExpressionNode"
"//InlinedGeneratorExpressionNode"
...
@@ -158,10 +163,12 @@ def all_in_conditional_gen(seq):
...
@@ -158,10 +163,12 @@ def all_in_conditional_gen(seq):
"""
"""
return
all
(
x
%
3
for
x
in
seq
if
x
%
2
==
1
)
return
all
(
x
%
3
for
x
in
seq
if
x
%
2
==
1
)
mixed_ustring
=
u'AbcDefGhIjKlmnoP'
mixed_ustring
=
u'AbcDefGhIjKlmnoP'
lower_ustring
=
mixed_ustring
.
lower
()
lower_ustring
=
mixed_ustring
.
lower
()
upper_ustring
=
mixed_ustring
.
upper
()
upper_ustring
=
mixed_ustring
.
upper
()
@
cython
.
test_assert_path_exists
(
@
cython
.
test_assert_path_exists
(
'//PythonCapiCallNode'
,
'//PythonCapiCallNode'
,
'//ForFromStatNode'
'//ForFromStatNode'
...
@@ -181,6 +188,7 @@ def all_lower_case_characters(unicode ustring):
...
@@ -181,6 +188,7 @@ def all_lower_case_characters(unicode ustring):
"""
"""
return
all
(
uchar
.
islower
()
for
uchar
in
ustring
)
return
all
(
uchar
.
islower
()
for
uchar
in
ustring
)
@
cython
.
test_assert_path_exists
(
@
cython
.
test_assert_path_exists
(
"//ForInStatNode"
,
"//ForInStatNode"
,
"//InlinedGeneratorExpressionNode"
,
"//InlinedGeneratorExpressionNode"
,
...
@@ -217,6 +225,7 @@ def all_in_typed_gen(seq):
...
@@ -217,6 +225,7 @@ def all_in_typed_gen(seq):
cdef
int
x
cdef
int
x
return
all
(
x
for
x
in
seq
)
return
all
(
x
for
x
in
seq
)
@
cython
.
test_assert_path_exists
(
@
cython
.
test_assert_path_exists
(
"//ForInStatNode"
,
"//ForInStatNode"
,
"//InlinedGeneratorExpressionNode"
,
"//InlinedGeneratorExpressionNode"
,
...
@@ -268,6 +277,14 @@ def all_in_double_gen(seq):
...
@@ -268,6 +277,14 @@ def all_in_double_gen(seq):
1
1
2
2
False
False
>>> all_in_double_gen([VerboseGetItem([1,1,1]),VerboseGetItem([1,0,1]),VerboseGetItem([1,1])])
0
1
2
3
0
1
False
"""
"""
cdef
int
x
cdef
int
x
return
all
(
x
for
L
in
seq
for
x
in
L
)
return
all
(
x
for
L
in
seq
for
x
in
L
)
tests/run/control_flow_loop.pyx
0 → 100644
View file @
0aded093
# mode: run
# tag: forin, control-flow, werror
def
for_in_break
(
LL
,
p
=
bool
):
"""
>>> for_in_break([[1,2,3], [4,5,6]])
True
>>> for_in_break([[1,2,3], [4,5,0]])
False
>>> for_in_break([[1,2,3], [0,4,5]])
False
>>> for_in_break([[1,2,3], [0,4,5], [6,7,8]])
False
>>> def collect(x):
... v.append(x)
... return x
>>> v = []
>>> for_in_break([[1,2,3], [4,5,6]], p=collect)
True
>>> v
[1, 2, 3, 4, 5, 6]
>>> v = []
>>> for_in_break([[1,2,3], [4,5,0]], p=collect)
False
>>> v
[1, 2, 3, 4, 5, 0]
>>> v = []
>>> for_in_break([[1,2,3], [0,4,5]], p=collect)
False
>>> v
[1, 2, 3, 0]
>>> v = []
>>> for_in_break([[1,2,3], [0,4,5], [6,7,8]], p=collect)
False
>>> v
[1, 2, 3, 0]
"""
result
=
'NOK'
# implements the builtin all()
for
L
in
LL
:
for
x
in
L
:
if
not
p
(
x
):
result
=
False
break
else
:
continue
break
else
:
result
=
True
return
result
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