cli: lower atomic value operands iteratively
This commit is contained in:
1 parent
062fce5cfd
commit
8d6792d4f1
5 files changed
+422
-32
No files matched your search
@@ -799,6 +799,80 @@ with tempfile.TemporaryDirectory(prefix='aji-expression-depth-') as directory:
|
||||
error['code'], str(formatted), text[:at].count('\n') + 1, at - text.rfind('\n', 0, at)), formatted_error
|
||||
print(f'consuming builtin rejection depth: {operation}', flush=True)
|
||||
|
||||
# Atomic operand continuations preserve scalar construction/extraction,
|
||||
# cell/order-before-value priority and temporary shared-loan lifetimes.
|
||||
for kind in ('atomic-pair', 'atomic-mixed', 'atomic-swap'):
|
||||
for depth in (0, 1, 16, 256, 1024, 16384, 32768, 65536):
|
||||
if depth == 32768 and kind != 'atomic-mixed':
|
||||
continue
|
||||
path = root / f'{kind}-{depth}.aji'
|
||||
if kind == 'atomic-pair':
|
||||
expression = 'atomic.take(atomic.new(' * depth + '42i64' + '))' * depth
|
||||
program = 'module depth\nfn main() -> i64 effects [] { return ' + expression + '; }\n'
|
||||
instructions, fuel, value = 2 * depth + 2, 2 * depth + 2, 42
|
||||
elif kind == 'atomic-mixed':
|
||||
expression = 'atomic.take(atomic.new(id(- ' * depth + 'id(42i64)' + ')))' * depth
|
||||
program = 'module depth\nfn id(x: i64) -> i64 effects [] { return x; }\nfn main() -> i64 effects [] { return ' + expression + '; }\n'
|
||||
instructions, fuel, value = 5 * depth + 4, 6 * depth + 4, 42 if depth % 2 == 0 else -42
|
||||
else:
|
||||
expression = 'atomic.swap(ref ac, ' * depth + '42i64' + ', seq_cst)' * depth
|
||||
program = 'module depth\nfn main() -> i64 effects [atomic] { let ac = atomic.new(0i64); let result = ' + expression + '; return atomic.take(move ac); }\n'
|
||||
instructions, fuel, value = 3 * depth + 5, 3 * depth + 5, 42 if depth % 2 else 0
|
||||
path.write_text(program)
|
||||
limited = kind == 'atomic-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(b' = ' in line or line.strip().startswith((b'ret ', b'borrow.end ')) for line in lowered.splitlines())
|
||||
assert actual == instructions, (kind, depth, actual, instructions)
|
||||
if depth <= 1024:
|
||||
result = cli('run', path, '--fuel', fuel)
|
||||
assert json.loads(result) == {'status': 'returned', 'value': value}
|
||||
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, '--fuel', fuel) == result
|
||||
formatted = path.with_suffix('.formatted.aji')
|
||||
output = cli('fmt', path)
|
||||
formatted.write_bytes(output)
|
||||
assert cli('fmt', formatted) == output
|
||||
formatted_check = cli('check', formatted, code=1 if limited else 0)
|
||||
if limited:
|
||||
assert json.loads(formatted_check)['code'] == 'E5101'
|
||||
else:
|
||||
assert formatted_check == b''
|
||||
assert cli('lower', formatted) == lowered
|
||||
print(f'atomic operand accepted depth: {kind}', flush=True)
|
||||
|
||||
for leaf, code, offset, extra in (
|
||||
('unknown', 'E7002', 0, {}),
|
||||
('atomic.new()', 'E7005', 0, {}),
|
||||
('atomic.new(1u128)', 'E7005', len('atomic.new('), {'found': 'u128'}),
|
||||
('atomic.take(true)', 'E7005', len('atomic.take('), {'found': 'bool'}),
|
||||
('atomic.store(ref ac, unknown, invalid)', 'E7006', len('atomic.store(ref ac, unknown, '), {}),
|
||||
('atomic.store(ref ac, true, seq_cst)', 'E7005', len('atomic.store(ref ac, '), {'expected': 'i64', 'found': 'bool'}),
|
||||
):
|
||||
for depth in (16, 1024, 65536):
|
||||
prefix = 'module depth\nfn main() -> i64 effects [atomic] { let ac = atomic.new(0i64); return '
|
||||
expression = 'atomic.take(atomic.new(' * depth + leaf + '))' * depth
|
||||
path = root / f'atomic-operand-reject-{code}-{offset}-{depth}-{len(leaf)}.aji'
|
||||
path.write_text(prefix + expression + '; }\n')
|
||||
expected = cli('check', path, code=1)
|
||||
error = json.loads(expected)
|
||||
col = len(prefix.split('\n')[-1]) + len('atomic.take(atomic.new(') * depth + offset + 1
|
||||
assert (error['code'], error['file'], error['line'], error['col']) == (code, str(path), 2, col), error
|
||||
for key, wanted in extra.items():
|
||||
assert error[key] == wanted, error
|
||||
for command in ('lower', 'run', 'report', 'explore'):
|
||||
assert cli(command, path, code=1) == expected
|
||||
print(f'atomic operand error priority: {leaf}', flush=True)
|
||||
|
||||
# Block/control callbacks remain native. Their existing shallow/deeper
|
||||
# syntax must retain its capacity while expression dispatch is moved out
|
||||
# of the native stack, including explicit-return callback re-entry.
|
||||
|
||||
Reference in new issue
Block a user