tests: audit buffer and error-value rejection twins
This commit is contained in:
1 parent
2742867ef7
commit
5371eb7a2f
14 files changed
+273
-17
No files matched your search
@@ -87,7 +87,8 @@ def inventory():
|
||||
row = {'air': name, 'codes': expected, 'kind': 'pending', 'sources': []}
|
||||
else:
|
||||
allowed = {'kind', 'rule', 'spec', 'site', 'lowering', 'analogues',
|
||||
'required_ops', 'match_type_declarations', 'early_context'}
|
||||
'required_ops', 'exact_ops', 'required_identity_uses',
|
||||
'match_type_declarations', 'early_context'}
|
||||
if set(review) - allowed:
|
||||
raise ValueError(f'{name}: unknown/reserved review keys: {sorted(set(review) - allowed)}')
|
||||
witnesses = review.get('required_ops', {})
|
||||
@@ -96,13 +97,21 @@ def inventory():
|
||||
not isinstance(n, int) or isinstance(n, bool) or n < 1
|
||||
for op, n in witnesses.items()):
|
||||
raise ValueError(f'{name}: operation witness counts must be positive integers')
|
||||
if 'exact_ops' in review and (review['exact_ops'] is not True or not witnesses):
|
||||
raise ValueError(f'{name}: exact operation witness needs nonempty required_ops')
|
||||
uses = review.get('required_identity_uses', {})
|
||||
if not isinstance(uses, dict) or any(
|
||||
field not in IDENTITIES - {'function', 'block', 'inst', 'callee', 'task_function'} or
|
||||
not isinstance(op, str) or not re.fullmatch(r'[A-Za-z][A-Za-z0-9_.]*', op)
|
||||
for field, op in uses.items()):
|
||||
raise ValueError(f'{name}: invalid diagnostic-identity use witness')
|
||||
if review.get('lowering') not in {None, 'rejected'}:
|
||||
raise ValueError(f'{name}: invalid lowering mode')
|
||||
if 'match_type_declarations' in review and review['match_type_declarations'] is not True:
|
||||
raise ValueError(f'{name}: type-declaration witness must be true')
|
||||
if review['kind'] not in {'same_code', 'source_error', 'air_only'}:
|
||||
raise ValueError(f'{name}: invalid classification')
|
||||
if ('required_ops' in review or 'match_type_declarations' in review) and (
|
||||
if ({'required_ops', 'exact_ops', 'required_identity_uses', 'match_type_declarations'} & review.keys()) and (
|
||||
review['kind'] != 'same_code' or review.get('lowering') == 'rejected'):
|
||||
raise ValueError(f'{name}: AIR witnesses require a lowered same-code pair')
|
||||
if not review.get('rule') or not review.get('spec'):
|
||||
@@ -304,18 +313,27 @@ def annotation_map(annotated):
|
||||
return '\n'.join(lines) + '\n', mapping
|
||||
|
||||
|
||||
def operation_witnesses(air, diagnostics, required):
|
||||
def operation_witnesses(air, diagnostics, required, exact=False, identity_uses=None):
|
||||
for d in diagnostics:
|
||||
function = re.search(r'^fn @' + re.escape(d['function']) + r'\(.*?(?=^fn @|\Z)', air, re.MULTILINE | re.DOTALL)
|
||||
if not function:
|
||||
raise ValueError('operation witness has no diagnostic function')
|
||||
counts = Counter()
|
||||
operands = {}
|
||||
for line in function[0].splitlines():
|
||||
line = line.split(';', 1)[0].strip()
|
||||
if line and not line.startswith(('fn ', 'effects ')) and not line.endswith(':'):
|
||||
counts[operation(line)] += 1
|
||||
op = operation(line)
|
||||
counts[op] += 1
|
||||
rhs = line.split('=', 1)[1] if line.startswith('%') and '=' in line else line
|
||||
operands.setdefault(op, set()).update(re.findall(r'%[A-Za-z_][\w.]*', rhs))
|
||||
if any(counts[op] < minimum for op, minimum in required.items()):
|
||||
raise ValueError('missing required operation witness in diagnostic function')
|
||||
if exact and counts != Counter(required):
|
||||
raise ValueError('different exact operation witness in diagnostic function')
|
||||
if any(d.get(field) not in operands.get(op, set())
|
||||
for field, op in (identity_uses or {}).items()):
|
||||
raise ValueError('missing diagnostic-identity use witness')
|
||||
|
||||
|
||||
def header_origin(air_line, source, path, site):
|
||||
@@ -437,9 +455,10 @@ def verify_pair(aji, root, row, source):
|
||||
raise ValueError(f'{source}: incorrect related source position')
|
||||
if (related['air_line'], related['air_col']) != (rr['line'], rr['col']):
|
||||
raise ValueError(f'{source}: incorrect related AIR position')
|
||||
if row.get('required_ops'):
|
||||
operation_witnesses(original, air_ds, row['required_ops'])
|
||||
operation_witnesses(canonical, projected, row['required_ops'])
|
||||
if row.get('required_ops') or row.get('required_identity_uses'):
|
||||
for air, diagnostics in ((original, air_ds), (canonical, projected)):
|
||||
operation_witnesses(air, diagnostics, row.get('required_ops', {}),
|
||||
row.get('exact_ops', False), row.get('required_identity_uses'))
|
||||
if Counter(signature(original, d, row['site']) for d in air_ds) != Counter(signature(canonical, d, row['site']) for d in projected):
|
||||
raise ValueError(f'{source}: same codes but different offending operation/rule facts')
|
||||
if any(d['code'] == 'E5101' and ('limit' not in d or 'max' not in d) for d in ds):
|
||||
|
||||
Reference in new issue
Block a user