cli: lower consuming ownership builtin operands iteratively
This commit is contained in:
1 parent
5cc69393e4
commit
062fce5cfd
5 files changed
+333
-15
No files matched your search
@@ -734,6 +734,71 @@ with tempfile.TemporaryDirectory(prefix='aji-expression-depth-') as directory:
|
||||
assert cli(command, path, code=1) == expected
|
||||
print(f'boolean builtin leaf priority: {leaf}', flush=True)
|
||||
|
||||
# Consuming ownership/region builtin arguments share the driver. Preserve
|
||||
# explicit transfers, destruction/extraction, exact AIR/fuel and failures.
|
||||
for operation in ('own.take', 'own.free', 'region.destroy'):
|
||||
is_region = operation == 'region.destroy'
|
||||
is_free = operation == 'own.free'
|
||||
ty, keep = ('region', 'keep_region') if is_region else ('own<i64>', 'keep')
|
||||
for depth in (0, 1, 16, 256, 1024, 16384, 65536):
|
||||
expression = (keep + '(') * depth + 'move x' + ')' * depth
|
||||
invocation = operation + '(' + expression + ')'
|
||||
body = 'return ' + invocation + ';' if operation == 'own.take' else invocation + '; return 42i64;'
|
||||
path = root / f'consuming-builtin-{operation}-{depth}.aji'
|
||||
path.write_text(f'module depth\nfn {keep}(x: {ty}) -> {ty} effects [] {{ return move x; }}\n'
|
||||
'fn main(heap: cap<mem.alloc>) -> i64 effects [mem.alloc] { let x = ' +
|
||||
('region.create(heap)' if is_region else 'own.new(42i64, heap)') +
|
||||
' or trap; ' + body + ' }\n')
|
||||
assert cli('check', path) == b''
|
||||
lowered = cli('lower', path)
|
||||
instructions = sum(b' = ' in line or line.strip().startswith((b'ret', b'own.new ', b'own.free ', b'region.create ', b'region.destroy ', b'trap'))
|
||||
for line in lowered.splitlines())
|
||||
assert instructions == depth + 6 + int(is_free), (operation, depth, instructions)
|
||||
assert sum(operation.encode() in line for line in lowered.splitlines()) == 1
|
||||
if depth <= 1024:
|
||||
fuel = 2 * depth + 4 + int(is_free)
|
||||
result = cli('run', path, '--fuel', fuel, '--grant', 'heap=mem.alloc:256')
|
||||
assert json.loads(result) == {'status': 'returned', 'value': 42, 'stdout': '', 'stderr': '', 'files': {}}
|
||||
limited = json.loads(cli('run', path, '--fuel', fuel - 1, '--grant', 'heap=mem.alloc:256', code=5))
|
||||
assert (limited['status'], limited['kind'], limited['limit'], limited['steps']) == ('limit_exceeded', 'fuel', fuel - 1, fuel - 1), limited
|
||||
air = path.with_suffix('.air')
|
||||
air.write_bytes(lowered)
|
||||
assert cli('run', air, '--fuel', fuel, '--grant', 'heap=mem.alloc:256') == result
|
||||
formatted = path.with_suffix('.formatted.aji')
|
||||
output = cli('fmt', path)
|
||||
formatted.write_bytes(output)
|
||||
assert cli('fmt', formatted) == output
|
||||
assert cli('check', formatted) == b''
|
||||
assert cli('lower', formatted) == lowered
|
||||
print(f'consuming builtin accepted depth: {operation}', flush=True)
|
||||
|
||||
for leaf in ('unknown', 'true', 'missing-arity'):
|
||||
for depth in (16, 1024, 16384, 65536):
|
||||
empty = leaf == 'missing-arity'
|
||||
prefix = 'module depth\nfn main() -> void effects [] { '
|
||||
expression = (operation + '(') * depth + ('' if empty else leaf) + ')' * depth
|
||||
path = root / f'consuming-builtin-reject-{operation}-{leaf}-{depth}.aji'
|
||||
path.write_text(prefix + expression + '; }\n')
|
||||
expected = cli('check', path, code=1)
|
||||
error = json.loads(expected)
|
||||
col = len(prefix.split('\n')[-1]) + len(operation + '(') * (depth - int(empty)) + 1
|
||||
assert (error['code'], error['file'], error['line'], error['col']) == (
|
||||
'E7002' if leaf == 'unknown' else 'E7005', str(path), 2, col), error
|
||||
if leaf == 'true':
|
||||
assert error['found'] == 'bool', 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()
|
||||
at = text.rfind(operation + '(') if empty else text.index(leaf)
|
||||
assert (formatted_error['code'], formatted_error['file'], formatted_error['line'], formatted_error['col']) == (
|
||||
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)
|
||||
|
||||
# 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