Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
privileges_available = cx.privileges
if request.region.kind.ispace is not None:
request = request.as_ispace()
privileges_available = set(
privilege.as_ispace()
for privilege in cx.privileges
if cx.region_forest.find(privilege.region) == cx.region_forest.find(original_request.region))
if not search_constraints_for_privilege(request, privileges_available, cx.constraints):
if request.privilege != Privilege.REDUCE:
return (False, original_request)
# If the initial search fails on a reduce request, search
# again for read-write.
read_request = Privilege(request.node, Privilege.READ, None, request.region, request.field_path, True)
write_request = Privilege(request.node, Privilege.WRITE, None, request.region, request.field_path, True)
if not (search_constraints_for_privilege(read_request, privileges_available, cx.constraints) and
search_constraints_for_privilege(write_request, privileges_available, cx.constraints)):
return (False, original_request)
return (True, None)
def substitute_regions(self, region_map):
if self.region in region_map:
return Privilege(self.node, self.privilege, self.op, region_map[self.region], self.field_path)
return self
def as_ispace(self):
nested_field_privileges = {}
for field_path, privileges in field_privileges.iteritems():
for nested_field_path in field_types.iterkeys():
if is_prefix(nested_field_path, field_path):
if nested_field_path not in nested_field_privileges:
nested_field_privileges[nested_field_path] = set()
nested_field_privileges[nested_field_path].update(privileges)
ll_nested_field_privileges = {}
for nested_field_path, privileges in nested_field_privileges.iteritems():
reads = False
writes = False
reduce_op = None
element_type = None
for privilege in privileges:
if types.Privilege.READ == privilege.privilege:
reads = True
elif types.Privilege.WRITE == privilege.privilege:
writes = True
elif types.Privilege.REDUCE == privilege.privilege:
assert reduce_op is None and element_type is None
reduce_op = privilege.op
field_types = trans_fields(privilege.region.kind.contains_type, cx)
element_type = field_types[nested_field_path]
else:
assert False
if reduce_op is not None:
assert not reads and not writes
ll_privilege = None
if reads and writes:
request = request
privileges_available = cx.privileges
if request.region.kind.ispace is not None:
request = request.as_ispace()
privileges_available = set(
privilege.as_ispace()
for privilege in cx.privileges
if cx.region_forest.find(privilege.region) == cx.region_forest.find(original_request.region))
if not search_constraints_for_privilege(request, privileges_available, cx.constraints):
if request.privilege != Privilege.REDUCE:
return (False, original_request)
# If the initial search fails on a reduce request, search
# again for read-write.
read_request = Privilege(request.node, Privilege.READ, None, request.region, request.field_path, True)
write_request = Privilege(request.node, Privilege.WRITE, None, request.region, request.field_path, True)
if not (search_constraints_for_privilege(read_request, privileges_available, cx.constraints) and
search_constraints_for_privilege(write_request, privileges_available, cx.constraints)):
return (False, original_request)
return (True, None)
if nested_field_path not in nested_field_privileges:
nested_field_privileges[nested_field_path] = set()
nested_field_privileges[nested_field_path].update(privileges)
ll_nested_field_privileges = {}
for nested_field_path, privileges in nested_field_privileges.iteritems():
reads = False
writes = False
reduce_op = None
element_type = None
for privilege in privileges:
if types.Privilege.READ == privilege.privilege:
reads = True
elif types.Privilege.WRITE == privilege.privilege:
writes = True
elif types.Privilege.REDUCE == privilege.privilege:
assert reduce_op is None and element_type is None
reduce_op = privilege.op
field_types = trans_fields(privilege.region.kind.contains_type, cx)
element_type = field_types[nested_field_path]
else:
assert False
if reduce_op is not None:
assert not reads and not writes
ll_privilege = None
if reads and writes:
ll_privilege = 'READ_WRITE'
elif reads:
ll_privilege = 'READ_ONLY'
elif writes:
for nested_field_path in field_types.iterkeys():
if is_prefix(nested_field_path, field_path):
if nested_field_path not in nested_field_privileges:
nested_field_privileges[nested_field_path] = set()
nested_field_privileges[nested_field_path].update(privileges)
ll_nested_field_privileges = {}
for nested_field_path, privileges in nested_field_privileges.iteritems():
reads = False
writes = False
reduce_op = None
element_type = None
for privilege in privileges:
if types.Privilege.READ == privilege.privilege:
reads = True
elif types.Privilege.WRITE == privilege.privilege:
writes = True
elif types.Privilege.REDUCE == privilege.privilege:
assert reduce_op is None and element_type is None
reduce_op = privilege.op
field_types = trans_fields(privilege.region.kind.contains_type, cx)
element_type = field_types[nested_field_path]
else:
assert False
if reduce_op is not None:
assert not reads and not writes
ll_privilege = None
if reads and writes:
ll_privilege = 'READ_WRITE'
elif reads:
def is_privilege(p):
return isinstance(p, Privilege)
def check_reduce(self, node, op, cx):
privileges_requested = [
Privilege(node, Privilege.REDUCE, op, region, self.field_path)
for region in self.regions]
success, failed_request = check_privileges(privileges_requested, cx)
if not success:
raise TypeError(node, 'Invalid privilege %s requested in pointer dereference' % failed_request)
return self.as_write()
def substitute_regions(self, region_map):