cli: lower mutex value operands iteratively
This commit is contained in:
1 parent
c5d0d09a81
commit
7ccded2b59
5 files changed
+348
-21
No files matched your search
@@ -1095,4 +1095,85 @@ with tempfile.TemporaryDirectory(prefix='aji-expression-depth-') as directory:
|
||||
assert (trapped['status'], trapped['code'], trapped['kind'], trapped['inst']) == (
|
||||
'trapped', 'T0003', 'trap.overflow', 2), trapped
|
||||
|
||||
# Mutex operands share consuming continuations; element/loan rules stay unchanged.
|
||||
for mixed in (False, True):
|
||||
for depth in (0, 1, 16, 256, 1024, 16384, 32768, 65536):
|
||||
if depth == 32768 and not mixed:
|
||||
continue
|
||||
opening = 'mutex.take(mutex.make(id(- ' if mixed else 'mutex.take(mutex.make('
|
||||
expression = opening * depth + ('id(42i64)' if mixed else '42i64') + (')))' if mixed else '))') * depth
|
||||
worker = 'fn id(x: i64) -> i64 effects [] { x }\n' if mixed else ''
|
||||
path = root / f'mutex-operand-{mixed}-{depth}.aji'
|
||||
path.write_text('module depth\n' + worker + 'fn main() -> i64 effects [] { return ' + expression + '; }\n')
|
||||
instructions, fuel = (5 * depth + 4, 6 * depth + 4) if mixed else (2 * depth + 2, 2 * depth + 2)
|
||||
limited = mixed and depth == 65536
|
||||
checked = cli('check', path, code=1 if limited else 0)
|
||||
if limited:
|
||||
error = json.loads(checked)
|
||||
assert (error['code'], error['limit'], error['max'], error['found']) == ('E5101', 'instructions per function', 262144, 327683), error
|
||||
for command in ('run', 'report', 'explore'):
|
||||
assert cli(command, path, code=1) == checked
|
||||
else:
|
||||
assert checked == b''
|
||||
lowered = cli('lower', path)
|
||||
actual = sum((line.lstrip().startswith(b'%') and b' = ' in line) or line.strip().startswith(b'ret') for line in lowered.splitlines())
|
||||
assert actual == instructions, (mixed, depth, actual, instructions)
|
||||
if depth <= 1024:
|
||||
record = {'status': 'returned', 'value': 42 if depth % 2 == 0 or not mixed else -42}
|
||||
options = ('--quantum', 1, '--schedule-seed', 7, '--fuel', fuel)
|
||||
result = cli('run', path, *options)
|
||||
assert json.loads(result) == record, result
|
||||
assert json.loads(cli('run', path, '--fuel', fuel - 1, code=5)) == {'status': 'limit_exceeded', 'kind': 'fuel', 'limit': fuel - 1, 'steps': fuel - 1}
|
||||
air = path.with_suffix('.air')
|
||||
air.write_bytes(lowered)
|
||||
assert cli('run', air, *options) == result
|
||||
formatted = path.with_suffix('.formatted.aji')
|
||||
output = cli('fmt', path)
|
||||
formatted.write_bytes(output)
|
||||
assert cli('fmt', formatted) == output
|
||||
assert cli('lower', formatted) == lowered
|
||||
if depth <= 1024:
|
||||
assert cli('check', formatted) == b''
|
||||
print(f'mutex operand accepted depth: mixed={mixed}', flush=True)
|
||||
|
||||
for leaf, code, extra in (
|
||||
('unknown', 'E7002', {}),
|
||||
('p', 'E7005', {'found': 'ref<i64>'}),
|
||||
('m', 'E7003', {'suggestion': 'move m'}),
|
||||
('empty()', 'E7005', {'position': 'member', 'type_constructor': 'void'}),
|
||||
('stop()', 'E7005', {'position': 'member', 'type_constructor': 'never'}),
|
||||
('mutex.take(true)', 'E7005', {'found': 'bool'}),
|
||||
('mutex.take(unknown, ref n)', 'E7005', {}),
|
||||
('mutex.make(unknown, ref n)', 'E7005', {}),
|
||||
):
|
||||
for depth in (16, 1024, 65536):
|
||||
prefix = 'module depth\nfn empty() -> void effects [] {}\nfn stop() -> never effects [] { trap; }\nfn main() -> i64 effects [] { var n: i64 = 1i64; let m = mutex.make(1i64); ref p = n; return '
|
||||
opening = 'mutex.take(mutex.make('
|
||||
leaf_name = re.sub(r'[^A-Za-z0-9]+', '-', leaf).strip('-')
|
||||
path = root / f'mutex-reject-{code}-{leaf_name}-{depth}.aji'
|
||||
path.write_text(prefix + opening * depth + leaf + '))' * depth + '; }\n')
|
||||
expected = cli('check', path, code=1)
|
||||
error = json.loads(expected)
|
||||
offset = len('mutex.take(') if leaf == 'mutex.take(true)' else 0
|
||||
assert (error['code'], error['file'], error['line'], error['col']) == (code, str(path), 4, len(prefix.split('\n')[-1]) + len(opening) * depth + offset + 1), error
|
||||
for key, value in extra.items():
|
||||
assert error[key] == value, error
|
||||
for command in ('lower', 'run', 'report', 'explore'):
|
||||
assert cli(command, path, code=1) == expected
|
||||
formatted = path.with_suffix('.formatted.aji')
|
||||
output = cli('fmt', path)
|
||||
formatted.write_bytes(output)
|
||||
assert cli('fmt', formatted) == output
|
||||
formatted_error = json.loads(cli('check', formatted, code=1))
|
||||
text = output.decode()
|
||||
if leaf in ('m', 'p'):
|
||||
pos = list(re.finditer(r'(?<![A-Za-z0-9_])' + leaf + r'(?![A-Za-z0-9_])', text))[-1].start()
|
||||
else:
|
||||
pos = text.rfind(leaf) + offset
|
||||
assert (formatted_error['code'], formatted_error['file'], formatted_error['line'], formatted_error['col']) == (code, str(formatted), text[:pos].count('\n') + 1, pos - text.rfind('\n', 0, pos)), formatted_error
|
||||
for key, value in extra.items():
|
||||
assert formatted_error[key] == value, formatted_error
|
||||
print(f'mutex operand rejection depth: {leaf}', flush=True)
|
||||
|
||||
|
||||
print(f'source expression depth: {checks} checks passed')
|
||||
Reference in new issue
Block a user