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
82190146
Commit
82190146
authored
Dec 14, 2018
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '0.29.x'
parents
96578f80
c9682a3e
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
65 additions
and
5 deletions
+65
-5
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+6
-3
tests/run/for_in_iter.py
tests/run/for_in_iter.py
+31
-0
tests/run/tuple_constants.pyx
tests/run/tuple_constants.pyx
+28
-2
No files found.
Cython/Compiler/ExprNodes.py
View file @
82190146
...
...
@@ -199,10 +199,11 @@ def make_dedup_key(outer_type, item_nodes):
"""
item_keys
=
[
(
py_object_type
,
None
)
if
node
is
None
else
make_dedup_key
(
node
.
type
,
node
.
args
)
if
node
.
is_sequence_constructor
# For sequences and their "mult_factor", see TupleNode.
else
make_dedup_key
(
node
.
type
,
[
node
.
mult_factor
if
node
.
is_literal
else
None
]
+
node
.
args
)
if
node
.
is_sequence_constructor
else
make_dedup_key
(
node
.
type
,
(
node
.
start
,
node
.
stop
,
node
.
step
))
if
node
.
is_slice
else
(
node
.
type
,
node
.
constant_result
)
if
node
.
has_constant_result
()
else
None
else
None
# something we cannot handle => short-circuit below
for
node
in
item_nodes
]
if
None
in
item_keys
:
...
...
@@ -7992,7 +7993,9 @@ class TupleNode(SequenceNode):
return
if
self
.
is_literal
or
self
.
is_partly_literal
:
dedup_key
=
make_dedup_key
(
self
.
type
,
self
.
args
)
if
self
.
is_literal
else
None
# The "mult_factor" is part of the deduplication if it is also constant, i.e. when
# we deduplicate the multiplied result. Otherwise, only deduplicate the constant part.
dedup_key
=
make_dedup_key
(
self
.
type
,
[
self
.
mult_factor
if
self
.
is_literal
else
None
]
+
self
.
args
)
tuple_target
=
code
.
get_py_const
(
py_object_type
,
'tuple'
,
cleanup_level
=
2
,
dedup_key
=
dedup_key
)
const_code
=
code
.
get_cached_constants_writer
(
tuple_target
)
if
const_code
is
not
None
:
...
...
tests/run/for_in_iter.py
View file @
82190146
...
...
@@ -61,6 +61,37 @@ def for_in_literal_mult_list():
l
.
append
(
i
)
return
l
def
listcomp_over_multiplied_constant_tuple
():
"""
>>> listcomp_over_multiplied_constant_tuple()
[[], [1, 2, 3], [1, 2, 3, 1, 2, 3], [1, 2, 3, 1, 2, 3, 1, 2, 3], [1, 2, 3, 1, 2, 3]]
"""
return
[
[
i
for
i
in
(
1
,
2
,
3
)
*
0
],
[
i
for
i
in
(
1
,
2
,
3
)
*
1
],
[
i
for
i
in
(
1
,
2
,
3
)
*
2
],
[
i
for
i
in
(
1
,
2
,
3
)
*
3
],
[
i
for
i
in
(
1
,
2
,
3
)
*
2
],
]
@
cython
.
test_assert_path_exists
(
'//ReturnStatNode//ForInStatNode//TupleNode'
)
@
cython
.
test_fail_if_path_exists
(
'//ReturnStatNode//ForInStatNode//ListNode'
)
def
listcomp_over_multiplied_constant_list
():
"""
>>> listcomp_over_multiplied_constant_list()
[[], [1, 2, 3], [1, 2, 3, 1, 2, 3], [1, 2, 3, 1, 2, 3, 1, 2, 3], [1, 2, 3, 1, 2, 3]]
"""
return
[
[
i
for
i
in
[
1
,
2
,
3
]
*
0
],
[
i
for
i
in
[
1
,
2
,
3
]
*
1
],
[
i
for
i
in
[
1
,
2
,
3
]
*
2
],
[
i
for
i
in
[
1
,
2
,
3
]
*
3
],
[
i
for
i
in
[
1
,
2
,
3
]
*
2
],
]
class
Iterable
(
object
):
"""
>>> for_in_pyiter(Iterable(5))
...
...
tests/run/tuple_constants.pyx
View file @
82190146
...
...
@@ -46,9 +46,9 @@ def return_folded_tuple():
def
return_nested_tuple
():
"""
>>> return_nested_tuple()
(1, (2, 3), (3, (4, 5)))
(1, (2, 3), (3, (4, 5)
, (2, 3, 2, 3)
))
"""
return
(
1
,
(
2
,
3
),
(
3
,
(
4
,
5
)))
return
(
1
,
(
2
,
3
),
(
3
,
(
4
,
5
)
,
(
2
,
3
)
*
2
))
@
cython
.
test_assert_path_exists
(
"//TupleNode"
,
"//TupleNode[@is_literal = true]"
)
...
...
@@ -71,6 +71,32 @@ def return_constant_tuple2():
"""
return
(
1
,
2
)
def
return_multiplied_constant_tuple
(
n
):
"""
>>> tuples = return_multiplied_constant_tuple(2)
>>> type(tuples) is tuple
True
>>> for t in tuples: print(t)
()
(1, 2, 3)
(1, 2, 3, 1, 2, 3)
(1, 2, 3, 1, 2, 3, 1, 2, 3)
(1, 2, 3, 1, 2, 3)
(1, 2, 3, 1, 2, 3)
((1, 2, 3, 1, 2, 3), (1, 2, 3), (1, 2, 3, 1, 2, 3))
"""
return
(
(
1
,
2
,
3
)
*
0
,
(
1
,
2
,
3
)
*
1
,
(
1
,
2
,
3
)
*
2
,
(
1
,
2
,
3
)
*
3
,
(
1
,
2
,
3
)
*
2
,
(
1
,
2
,
3
)
*
n
,
((
1
,
2
,
3
)
*
n
,
(
1
,
2
,
3
),
(
1
,
2
,
3
)
*
n
),
)
@
cython
.
test_assert_path_exists
(
"//TupleNode"
,
"//TupleNode[@is_literal = true]"
)
@
cython
.
test_fail_if_path_exists
(
"//TupleNode[@is_literal = false]"
)
...
...
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