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
03d7c50c
Commit
03d7c50c
authored
Nov 03, 2020
by
Xavier Thompson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor coercion to locked cypclass nodes
parent
f72728e7
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
35 deletions
+28
-35
Cython/Compiler/CypclassTransforms.py
Cython/Compiler/CypclassTransforms.py
+7
-7
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+21
-28
No files found.
Cython/Compiler/CypclassTransforms.py
View file @
03d7c50c
...
...
@@ -502,7 +502,7 @@ class CypclassLockTransform(Visitor.EnvTransform):
return
super
(
CypclassLockTransform
,
self
).
__call__
(
root
)
def
reference_identifier
(
self
,
node
):
while
isinstance
(
node
,
ExprNodes
.
CoerceToTempNode
):
# works for CoerceToLockedTempNode as well
while
isinstance
(
node
,
ExprNodes
.
CoerceToTempNode
):
node
=
node
.
arg
if
node
.
is_name
:
return
node
.
entry
...
...
@@ -531,13 +531,13 @@ class CypclassLockTransform(Visitor.EnvTransform):
)
%
self
.
id_to_name
(
ref_id
)
)
elif
lock_mode
==
"autolock"
:
# for now, lock a temporary for each expression
return
ExprNodes
.
CoerceToLocked
Temp
Node
(
read_node
,
self
.
current_env
(),
rlock_only
=
True
)
return
ExprNodes
.
CoerceToLockedNode
(
read_node
,
self
.
current_env
(),
rlock_only
=
True
)
else
:
if
lock_mode
==
"checklock"
:
error
(
read_node
.
pos
,
"This expression is not correctly locked (read lock required)"
)
elif
lock_mode
==
"autolock"
:
if
not
isinstance
(
read_node
,
ExprNodes
.
CoerceToLocked
Temp
Node
):
return
ExprNodes
.
CoerceToLocked
Temp
Node
(
read_node
,
self
.
current_env
(),
rlock_only
=
True
)
if
not
isinstance
(
read_node
,
ExprNodes
.
CoerceToLockedNode
):
return
ExprNodes
.
CoerceToLockedNode
(
read_node
,
self
.
current_env
(),
rlock_only
=
True
)
return
read_node
def
lockcheck_written
(
self
,
written_node
):
...
...
@@ -553,15 +553,15 @@ class CypclassLockTransform(Visitor.EnvTransform):
)
%
self
.
id_to_name
(
ref_id
)
)
elif
lock_mode
==
"autolock"
:
# for now, lock a temporary for each expression
return
ExprNodes
.
CoerceToLocked
Temp
Node
(
written_node
,
self
.
current_env
(),
rlock_only
=
False
)
return
ExprNodes
.
CoerceToLockedNode
(
written_node
,
self
.
current_env
(),
rlock_only
=
False
)
else
:
if
lock_mode
==
"checklock"
:
error
(
written_node
.
pos
,
"This expression is not correctly locked (write lock required)"
)
elif
lock_mode
==
"autolock"
:
if
isinstance
(
written_node
,
ExprNodes
.
CoerceToLocked
Temp
Node
):
if
isinstance
(
written_node
,
ExprNodes
.
CoerceToLockedNode
):
written_node
.
rlock_only
=
False
else
:
return
ExprNodes
.
CoerceToLocked
Temp
Node
(
written_node
,
self
.
current_env
())
return
ExprNodes
.
CoerceToLockedNode
(
written_node
,
self
.
current_env
())
return
written_node
def
lockcheck_written_or_read
(
self
,
node
,
reading
=
False
):
...
...
Cython/Compiler/ExprNodes.py
View file @
03d7c50c
...
...
@@ -14158,24 +14158,29 @@ class CoerceToTempNode(CoercionNode):
code
.
put_incref_memoryviewslice
(
self
.
result
(),
self
.
type
,
have_gil
=
not
self
.
in_nogil_context
)
class
CoerceToLockedTempNode
(
CoerceToTempNode
):
class
CoerceToLockedNode
(
CoercionNode
):
# This node is used to lock a node of cypclass type around the evaluation of its subexpressions.
# rlock_only boolean
# guard_code used internally
def
__init__
(
self
,
arg
,
env
=
None
,
rlock_only
=
False
):
self
.
rlock_only
=
rlock_only
if
isinstance
(
arg
,
IndexNode
):
# reuse reference count management logic
self
.
use_managed_ref
=
arg
.
coerce_to_temp
(
env
).
use_managed_ref
elif
isinstance
(
arg
,
CoerceToTempNode
):
self
.
use_managed_ref
=
arg
.
use_managed_ref
arg
=
arg
.
arg
super
(
CoerceToLockedTempNode
,
self
).
__init__
(
arg
,
env
)
self
.
type
=
arg
.
type
arg
=
arg
.
coerce_to_temp
(
env
)
arg
.
postpone_subexpr_disposal
=
True
super
(
CoerceToLockedNode
,
self
).
__init__
(
arg
)
def
generate_result_code
(
self
,
code
):
super
(
CoerceToLockedTempNode
,
self
).
generate_result_code
(
code
)
def
result
(
self
):
return
self
.
arg
.
result
()
def
is_simple
(
self
):
return
False
def
may_be_none
(
self
):
return
self
.
arg
.
may_be_none
()
#XXX Code duplicated from Nodes.LockCypclassNode
def
generate_result_code
(
self
,
code
):
#XXX Code duplicated from Nodes.LockCypclassNode.
if
self
.
arg
.
pos
:
source_descr
,
lineno
,
colno
=
self
.
arg
.
pos
source_str
=
source_descr
.
get_description
()
...
...
@@ -14190,31 +14195,19 @@ class CoerceToLockedTempNode(CoerceToTempNode):
# Create a scope to use scope bound resource management (RAII).
code
.
putln
(
"{"
)
# Each lock guard has its onw scope, so a prefix is enough to prevent name collisions
# Since each lock guard has its onw scope,
# a prefix is enough to prevent name collisions.
guard_code
=
"%sguard"
%
Naming
.
cypclass_lock_guard_prefix
if
self
.
rlock_only
:
code
.
putln
(
"Cy_rlock_guard %s(%s, %s);"
%
(
guard_code
,
self
.
result
(),
context
))
else
:
code
.
putln
(
"Cy_wlock_guard %s(%s, %s);"
%
(
guard_code
,
self
.
result
(),
context
))
def
generate_subexpr_disposal_code
(
self
,
code
):
# Postponed until this node is disposed of.
# See ExprNode.generate_evaluation_code.
return
def
free_subexpr_temps
(
self
,
code
):
# Postponed until this node is disposed of.
# See ExprNode.generate_evaluation_code.
return
def
generate_disposal_code
(
self
,
code
):
# Close the scope to release the lock.
code
.
putln
(
"}"
)
# Dispose of and release postponed subexpressions.
ExprNode
.
generate_subexpr_disposal_code
(
self
,
code
)
ExprNode
.
free_subexpr_temps
(
self
,
code
)
# Dispose of and release this temporary.
ExprNode
.
generate_disposal_code
(
self
,
code
)
# Dispose of subexpressions.
super
(
CoerceToLockedNode
,
self
).
generate_disposal_code
(
code
)
class
ProxyNode
(
CoercionNode
):
...
...
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