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