Commit 34924021 authored by Xavier Thompson's avatar Xavier Thompson

Rename 'locked' qualifiers

This commit introduces the following changes:
- 'locked' becomes 'lock'
- 'locked&' becomes 'locked'
- references reachable from a locked reference are noted as 'lock->'
parent cbd03841
......@@ -532,12 +532,12 @@ def inject_acthon_interfaces(self):
message_entry.is_type = 1
message_sync_attr_entry = message_scope.declare("_sync_method", "_sync_method",
PyrexTypes.cyp_class_qualified_type(sync_type, 'locked'), None, "extern")
PyrexTypes.cyp_class_qualified_type(sync_type, 'lock'), None, "extern")
message_sync_attr_entry.is_variable = 1
message_scope.var_entries.append(message_sync_attr_entry)
message_result_attr_entry = message_scope.declare("_result", "_result",
PyrexTypes.cyp_class_qualified_type(result_type, 'locked'), None, "extern")
PyrexTypes.cyp_class_qualified_type(result_type, 'lock'), None, "extern")
message_result_attr_entry.is_variable = 1
message_scope.var_entries.append(message_result_attr_entry)
......@@ -563,7 +563,7 @@ def inject_acthon_interfaces(self):
queue_entry.is_type = 1
queue_msg_arg = PyrexTypes.CFuncTypeArg("msg", message_type, None)
queue_push_type = PyrexTypes.CFuncType(PyrexTypes.c_void_type, [queue_msg_arg], nogil = 1, self_qualifier = 'locked&')
queue_push_type = PyrexTypes.CFuncType(PyrexTypes.c_void_type, [queue_msg_arg], nogil = 1, self_qualifier = 'locked')
queue_push_entry = queue_scope.declare("push", "push", queue_push_type,
None, "extern")
queue_push_entry.is_cfunction = 1
......@@ -605,7 +605,7 @@ def inject_acthon_interfaces(self):
activable_scope.var_entries.append(activable_result_attr_entry)
activable_queue_attr_entry = activable_scope.declare("_active_queue_class", "_active_queue_class",
PyrexTypes.cyp_class_qualified_type(queue_type, 'locked'), None, "extern")
PyrexTypes.cyp_class_qualified_type(queue_type, 'lock'), None, "extern")
activable_queue_attr_entry.is_variable = 1
activable_scope.var_entries.append(activable_queue_attr_entry)
......
......@@ -425,11 +425,11 @@ class CypclassLockTransform(Visitor.EnvTransform):
# that the receiver object will only be read, not that
# __all__ the reachable subobjects will only be read.
locally_writing = (field_access and node.is_target) or method_call
if objtype.is_qualified_cyp_class and objtype.qualifier == 'locked':
if objtype.is_qualified_cyp_class and objtype.qualifier == 'lock':
old_writing = self.writing
self.writing = locally_writing
self.visitchildren(node)
if field_access or (method_call and not nodetype.self_qualifier == 'locked'):
if field_access or (method_call and not nodetype.self_qualifier == 'lock'):
node.obj = ExprNodes.CoerceToLockedNode(node.obj, exclusive=self.writing)
self.writing = old_writing
elif objtype.is_cyp_class:
......
......@@ -11401,7 +11401,7 @@ class ConsumeNode(ExprNode):
return self
if operand_type.is_qualified_cyp_class:
self.generate_runtime_check = operand_type.qualifier not in ('iso', 'iso~')
self.check_refcount_only = operand_type.qualifier in ('active', 'locked')
self.check_refcount_only = operand_type.qualifier in ('active', 'lock', 'locked')
if operand_type.qualifier == 'iso~':
self.type = operand_type
else:
......
......@@ -782,8 +782,8 @@ class CFuncDeclaratorNode(CDeclaratorNode):
exc_check = self.exception_check
if return_type.is_cfunction:
error(self.pos, "Function cannot return a function")
if return_type.is_qualified_cyp_class and return_type.qualifier in ('locked&',):
error(self.pos, "Function cannot return a 'locked&' qualifier")
if return_type.is_qualified_cyp_class and return_type.qualifier in ('locked',):
error(self.pos, "Function cannot return a 'locked' cypclass instance")
func_type = PyrexTypes.CFuncType(
return_type, func_type_args, self.has_varargs,
optional_arg_count=self.optional_arg_count,
......@@ -1372,9 +1372,6 @@ class QualifiedCypclassNode(CBaseTypeNode):
if not base.is_cyp_class:
error(self.pos, "Qualifier '%s' can only apply to cypclass types" % self.qualifier)
return base
# if self.qualifier in ('locked&',) and env.return_type is None:
# error(self.pos, "Qualifier '%s' can only be used inside functions" % self.qualifier)
# return base
return PyrexTypes.cyp_class_qualified_type(base, self.qualifier)
......@@ -1507,8 +1504,8 @@ class CVarDefNode(StatNode):
else:
if self.directive_locals:
error(self.pos, "Decorators can only be followed by functions")
if base_type.is_qualified_cyp_class and base_type.qualifier in ('locked&', ) and env.return_type is None:
error(self.pos, "'locked&' variables are only allowed inside a function")
if base_type.is_qualified_cyp_class and base_type.qualifier in ('locked', ) and env.return_type is None:
error(self.pos, "'locked' variables are only allowed inside a function")
return error_type
self.entry = dest_scope.declare_var(
name, type, declarator.pos,
......
......@@ -2545,12 +2545,9 @@ def p_c_simple_base_type(s, self_flag, nonempty, templates = None):
base_type=base_type, is_const=is_const, is_volatile=is_volatile)
# Handle cypclass qualifiers
if s.sy == 'IDENT' and s.systring in ('active', 'iso', 'locked'):
if s.sy == 'IDENT' and s.systring in ('active', 'iso', 'lock', 'locked'):
qualifier = s.systring
s.next()
if s.sy == '&' and qualifier in ('locked',):
qualifier = "%s&" % qualifier
s.next()
base_type = p_c_base_type(s, self_flag=self_flag, nonempty=nonempty, templates=templates)
return Nodes.QualifiedCypclassNode(pos, base_type=base_type, qualifier=qualifier)
......
......@@ -4850,8 +4850,9 @@ class QualifiedCypclassType(BaseType):
'iso': ('iso~',),
'iso~': (),
'iso->': ('iso~',),
'locked': ('locked', 'locked&', 'iso~'),
'locked&': ('locked&', 'iso~'),
'lock': ('lock', 'locked', 'iso~'),
'locked': ('locked', 'iso~'),
'lock->': ('iso~',),
}
def __new__(cls, base_type, qualifier):
......@@ -5902,6 +5903,10 @@ def viewpoint_adaptation(base_type, qualifier = 'iso->'):
if base_type.is_qualified_cyp_class:
return base_type
if base_type.is_cyp_class:
if qualifier.startswith('iso'):
qualifier = 'iso->'
elif qualifier.startswith('lock'):
qualifier = 'lock->'
return QualifiedCypclassType(base_type, qualifier)
return base_type
......
......@@ -2853,7 +2853,7 @@ class CppClassScope(Scope):
# create the sync argument type
activated_method_sync_attr_type = PyrexTypes.CFuncTypeArg(
EncodedString("sync_method"),
PyrexTypes.cyp_class_qualified_type(sync_type, 'locked'),
PyrexTypes.cyp_class_qualified_type(sync_type, 'lock'),
entry.pos,
"sync_method",
)
......@@ -2997,9 +2997,9 @@ class CppClassScope(Scope):
if (self.parent_type.is_cyp_class and type.is_static_method and name not in ("<alloc>", "__new__")):
entry.static_cname = "%s__static__%s" % (Naming.func_prefix, cname or name)
if type.self_qualifier in ('locked&',):
if type.self_qualifier in ('locked',):
reify = False
if any(arg.type.is_qualified_cyp_class and arg.type.qualifier in ('locked&',) for arg in type.args):
if any(arg.type.is_qualified_cyp_class and arg.type.qualifier in ('locked',) for arg in type.args):
reify = False
if reify:
......@@ -3330,7 +3330,7 @@ def qualified_cypclass_scope(base_type_scope, qualifier):
return ActiveCypclassScope(base_type_scope)
elif qualifier.startswith('iso'):
return IsoCypclassScope(base_type_scope, qualifier)
elif qualifier.startswith('locked'):
elif qualifier.startswith('lock'):
return IsoCypclassScope(base_type_scope, qualifier)
else:
return QualifiedCypclassScope(base_type_scope, qualifier)
......@@ -3350,7 +3350,7 @@ class IsoCypclassScope(QualifiedCypclassScope):
def adapt_arg_type(self, arg):
arg = copy.copy(arg)
arg.type = viewpoint_adaptation(arg.type)
arg.type = viewpoint_adaptation(arg.type, self.qualifier)
return arg
def adapt_method_entry(self, base_entry):
......@@ -3358,12 +3358,12 @@ class IsoCypclassScope(QualifiedCypclassScope):
if base_type.self_qualifier:
if self.qualifier in PyrexTypes.QualifiedCypclassType.assignable_to[base_type.self_qualifier]:
return base_entry
elif base_type.self_qualifier == 'locked&' and self.qualifier == 'locked':
elif base_type.self_qualifier == 'locked' and self.qualifier == 'lock':
return base_entry
else:
return None
iso_method_type = copy.copy(base_type)
return_type = viewpoint_adaptation(base_type.return_type)
return_type = viewpoint_adaptation(base_type.return_type, self.qualifier)
iso_method_type.return_type = return_type
iso_method_type.args = [self.adapt_arg_type(arg) for arg in base_type.args]
entry = copy.copy(base_entry)
......@@ -3377,7 +3377,7 @@ class IsoCypclassScope(QualifiedCypclassScope):
return self.adapt_method_entry(base_entry)
else:
base_entry_type = base_entry.type
adapted_type = viewpoint_adaptation(base_entry_type)
adapted_type = viewpoint_adaptation(base_entry_type, self.qualifier)
if adapted_type is base_entry_type:
return base_entry
else:
......
......@@ -9,7 +9,7 @@ cdef cypclass A activable:
void f_iso(self, iso A other):
pass
void f_locked(self, locked A other):
void f_lock(self, lock A other):
pass
void f_active(self, active A other):
......@@ -23,8 +23,8 @@ def test_aliasing():
cdef iso A iso_a
iso_a = active_a
cdef locked A locked_a
locked_a = active_a
cdef lock A lock_a
lock_a = active_a
cdef A ref_a
ref_a = active_a
......@@ -37,7 +37,7 @@ def test_aliasing():
active_c = consume A()
cdef active A active_d
active_d = <locked A> consume A()
active_d = <lock A> consume A()
def test_calling():
......@@ -50,8 +50,8 @@ def test_calling():
cdef iso A iso_a
a.f_iso(NULL, consume iso_a)
cdef locked A locked_a
a.f_locked(NULL, locked_a)
cdef lock A lock_a
a.f_lock(NULL, lock_a)
cdef active A active_a
a.f_active(NULL, active_a)
......@@ -64,8 +64,8 @@ def test_typecast():
cdef iso A iso_a
iso_a = consume <iso A> active_a
cdef locked A locked_a
locked_a = <locked A> active_a
cdef lock A lock_a
lock_a = <lock A> active_a
cdef A ref_a
ref_a = <A> active_a
......@@ -78,20 +78,20 @@ def test_typecast():
active_c = <active A> <iso A> consume A()
cdef active A active_d
active_d = <active A> <locked A> consume A()
active_d = <active A> <lock A> consume A()
_ERRORS = u'''
24:12: Cannot assign type 'active A' to 'iso A'
27:15: Cannot assign type 'active A' to 'locked A'
27:13: Cannot assign type 'active A' to 'lock A'
30:12: Cannot assign type 'active A' to 'A'
34:16: Cannot assign type 'A' to 'active A'
40:15: Cannot assign type 'locked A' to 'active A'
40:15: Cannot assign type 'lock A' to 'active A'
46:15: Cannot assign type 'A' to 'iso-> A'
65:20: Cannot cast 'active A' to 'iso A'
68:15: Cannot cast 'active A' to 'locked A'
68:13: Cannot cast 'active A' to 'lock A'
71:12: Cannot cast 'active A' to 'A'
75:15: Cannot cast 'A' to 'active A'
78:15: Cannot cast 'iso A' to 'active A'
81:15: Cannot cast 'locked A' to 'active A'
81:15: Cannot cast 'lock A' to 'active A'
'''
......@@ -26,7 +26,7 @@ cdef cypclass BasicQueue(ActhonQueueInterface):
bint is_empty(const self):
return self._queue.empty()
void push(locked& self, ActhonMessageInterface message):
void push(locked self, ActhonMessageInterface message):
self._queue.push_back(message)
if message._sync_method is not NULL:
message._sync_method.insertActivity()
......@@ -106,9 +106,9 @@ cdef cypclass WaitResult(ActhonResultInterface):
cdef cypclass ActivityCounterSync(ActhonSyncInterface):
int count
locked ActivityCounterSync previous_sync
lock ActivityCounterSync previous_sync
__init__(self, locked ActivityCounterSync prev = NULL):
__init__(self, lock ActivityCounterSync prev = NULL):
self.count = 0
self.previous_sync = prev
......@@ -146,9 +146,9 @@ def test_acthon_chain(n):
42
"""
cdef ActhonResultInterface res
cdef locked ActhonQueueInterface queue
sync1 = <locked ActivityCounterSync> consume ActivityCounterSync()
after_sync1 = <locked ActivityCounterSync> consume ActivityCounterSync(sync1)
cdef lock ActhonQueueInterface queue
sync1 = <lock ActivityCounterSync> consume ActivityCounterSync()
after_sync1 = <lock ActivityCounterSync> consume ActivityCounterSync(sync1)
obj = A()
queue = obj._active_queue_class
......
......@@ -514,13 +514,13 @@ def test_consume_template_with_aliased_field():
print(e)
return 0
def test_consume_template_with_aliased_locked_field():
def test_consume_template_with_aliased_lock_field():
"""
>>> test_consume_template_with_aliased_locked_field()
>>> test_consume_template_with_aliased_lock_field()
0
"""
template = <Template[locked Leaf]> new Template[locked Leaf]()
leaf = <locked Leaf> consume Leaf()
template = <Template[lock Leaf]> new Template[lock Leaf]()
leaf = <lock Leaf> consume Leaf()
template.field = leaf
try:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment