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
dd96caaa
Commit
dd96caaa
authored
Sep 10, 2020
by
Xavier Thompson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Revert "Enforce const-correctness when locally aliasing const cypclass references"
This reverts commit
695049ee
.
parent
10d4601e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
4 additions
and
71 deletions
+4
-71
Cython/Compiler/CypclassTransforms.py
Cython/Compiler/CypclassTransforms.py
+3
-21
tests/errors/cypclass_lock_error.pyx
tests/errors/cypclass_lock_error.pyx
+1
-10
tests/run/cypclass_lock.pyx
tests/run/cypclass_lock.pyx
+0
-40
No files found.
Cython/Compiler/CypclassTransforms.py
View file @
dd96caaa
...
...
@@ -492,7 +492,6 @@ class CypclassLockTransform(Visitor.EnvTransform):
def
__call__
(
self
,
root
):
self
.
rlocked
=
defaultdict
(
int
)
self
.
wlocked
=
defaultdict
(
int
)
self
.
const
=
defaultdict
(
int
)
self
.
reading
=
False
self
.
writing
=
False
self
.
deleting
=
False
...
...
@@ -543,8 +542,8 @@ class CypclassLockTransform(Visitor.EnvTransform):
return
written_node
ref_id
=
self
.
reference_identifier
(
written_node
)
if
ref_id
:
if
self
.
const
[
ref_id
]
>
0
:
error
(
written_node
.
pos
,
"
Local r
eference '%s' is const but requires a write lock"
%
self
.
id_to_name
(
ref_id
))
if
ref_id
.
type
.
is_const
:
error
(
written_node
.
pos
,
"
R
eference '%s' is const but requires a write lock"
%
self
.
id_to_name
(
ref_id
))
return
written_node
if
not
self
.
wlocked
[
ref_id
]
>
0
:
if
lock_mode
==
"checklock"
:
...
...
@@ -581,28 +580,14 @@ class CypclassLockTransform(Visitor.EnvTransform):
# else: should have caused a previous error
return
rhs
def
mark_const_local_alias
(
self
,
lhs
,
rhs
):
lhs_ref_id
=
self
.
reference_identifier
(
lhs
)
rhs_ref_id
=
self
.
reference_identifier
(
rhs
)
if
not
lhs_ref_id
or
not
rhs_ref_id
:
return
if
self
.
const
[
rhs_ref_id
]
and
lhs_ref_id
.
is_local
:
self
.
const
[
lhs_ref_id
]
=
1
def
visit_CFuncDefNode
(
self
,
node
):
cyp_class_args
=
(
e
for
e
in
node
.
local_scope
.
arg_entries
if
e
.
type
.
is_cyp_class
)
arg_locks
=
[]
old_const
=
self
.
const
.
copy
()
for
arg
in
cyp_class_args
:
# Mark each cypclass arguments as locked within the function body
if
arg
.
type
.
is_const
:
arg_locks
.
append
(
self
.
stacklock
(
arg
,
"rlocked"
))
self
.
const
[
arg
]
=
1
else
:
arg_locks
.
append
(
self
.
stacklock
(
arg
,
"wlocked"
))
arg_locks
.
append
(
self
.
stacklock
(
arg
,
"rlocked"
if
arg
.
type
.
is_const
else
"wlocked"
))
with_body
=
lambda
:
self
.
visit
(
node
.
body
)
self
.
with_nested_stacklocks
(
iter
(
arg_locks
),
with_body
)
self
.
const
=
old_const
return
node
def
visit_LockCypclassNode
(
self
,
node
):
...
...
@@ -642,7 +627,6 @@ class CypclassLockTransform(Visitor.EnvTransform):
# Disallow re-binding a locked name
error
(
node
.
lhs
.
pos
,
"Assigning to a locked cypclass reference"
)
return
node
self
.
mark_const_local_alias
(
node
.
lhs
,
node
.
rhs
)
node
.
rhs
=
self
.
lockcheck_if_subscript_rhs
(
node
.
lhs
,
node
.
rhs
)
with
self
.
accesscontext
(
writing
=
True
):
self
.
visit
(
node
.
lhs
)
...
...
@@ -657,8 +641,6 @@ class CypclassLockTransform(Visitor.EnvTransform):
# Disallow re-binding a locked name
error
(
lhs
.
pos
,
"Assigning to a locked cypclass reference"
)
return
node
for
lhs
in
node
.
lhs_list
:
self
.
mark_const_local_alias
(
lhs
,
node
.
rhs
)
for
lhs
in
node
.
lhs_list
:
node
.
rhs
=
self
.
lockcheck_if_subscript_rhs
(
lhs
,
node
.
rhs
)
with
self
.
accesscontext
(
writing
=
True
):
...
...
tests/errors/cypclass_lock_error.pyx
View file @
dd96caaa
...
...
@@ -39,13 +39,6 @@ cdef take_non_const(A a):
cdef
take_const
(
const
A
a
):
take_non_const
(
a
)
cdef
propagate_local_const
(
const
A
a
):
cdef
A
b
=
a
c
=
a
take_non_const
(
b
)
take_non_const
(
c
)
_ERRORS
=
u"""
20:4: Reference 'obj' is not correctly locked in this expression (write lock required)
21:4: Reference 'obj' is not correctly locked in this expression (read lock required)
...
...
@@ -54,7 +47,5 @@ _ERRORS = u"""
25:4: Reference 'obj' is not correctly locked in this expression (read lock required)
26:21: Reference 'obj' is not correctly locked in this expression (read lock required)
32:17: Can only lock local variables or arguments
40:19: Local reference 'a' is const but requires a write lock
46:19: Local reference 'b' is const but requires a write lock
47:19: Local reference 'c' is const but requires a write lock
40:19: Reference 'a' is const but requires a write lock
"""
tests/run/cypclass_lock.pyx
View file @
dd96caaa
...
...
@@ -51,43 +51,3 @@ def test_lock_traversal(n):
with
wlocked
contained
:
argument_recursivity
(
contained
,
n
)
print
contained
.
getter
()
cdef
Container
global_container
cdef
int
non_const_aliasing
(
const
A
a
):
global
global_container
global_container
=
Container
()
global_container
.
object
=
a
b
=
global_container
.
object
with
wlocked
b
:
b
.
setter
(
42
)
return
b
.
getter
()
def
test_non_const_aliasing
():
"""
>>> test_non_const_aliasing()
42
"""
a
=
A
()
with
rlocked
a
:
return
non_const_aliasing
(
a
)
cdef
A
global_a
cdef
int
non_const_global_aliasing
(
const
A
a
):
global
global_a
global_a
=
a
b
=
global_a
with
wlocked
b
:
b
.
setter
(
42
)
return
b
.
getter
()
def
test_non_const_global_aliasing
():
"""
>>> test_non_const_global_aliasing()
42
"""
global
global_a
a
=
A
()
with
rlocked
a
:
return
non_const_global_aliasing
(
a
)
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