cli: lower array initializers iteratively
This commit is contained in:
1 parent
6d2c4d40a8
commit
8c34a4d64d
5 files changed
+440
-29
No files matched your search
@@ -450,6 +450,85 @@ with tempfile.TemporaryDirectory(prefix='aji-expression-depth-') as directory:
|
||||
assert cli(command, path, code=1) == expected
|
||||
print(f'struct field invalid depth: {depth}', flush=True)
|
||||
|
||||
# Lists and repetitions suspend in the same driver as calls/scalars/fields.
|
||||
for depth in (0, 1, 16, 1024, 16384, 32768, 65536):
|
||||
for kind in ('list-call', 'repeat-call', 'mixed-array'):
|
||||
if depth == 32768 and kind != 'mixed-array':
|
||||
continue
|
||||
prefix, suffix = ('one([', '; 1])' if kind == 'repeat-call' else '])')
|
||||
if kind == 'mixed-array':
|
||||
prefix, suffix = 'Box { n: one([- id(', ')]) }.n'
|
||||
helper = 'fn one(a: [i64; 1]) -> i64 effects [] { let (x) = array.unpack(a); return x; }\n'
|
||||
mixed = kind == 'mixed-array'
|
||||
if mixed:
|
||||
helper += 'struct Box { n: i64 }\nfn id(x: i64) -> i64 effects [] { return x; }\n'
|
||||
path = root / f'array-{kind}-{depth}.aji'
|
||||
path.write_text('module depth\n' + helper + 'fn main() -> i64 effects [] { return ' +
|
||||
prefix * depth + '1i64' + suffix * depth + '; }\n')
|
||||
main_instructions = (7 if mixed else 2) * depth + 2
|
||||
limited = main_instructions > 262144
|
||||
check = cli('check', path, code=1 if limited else 0)
|
||||
if limited:
|
||||
diagnostic = json.loads(check)
|
||||
assert (diagnostic['code'], diagnostic['limit'], diagnostic['max'], diagnostic['found']) == (
|
||||
'E5101', 'instructions per function', 262144, main_instructions), diagnostic
|
||||
for command in ('run', 'report', 'explore'):
|
||||
assert cli(command, path, code=1) == check
|
||||
else:
|
||||
assert check == b''
|
||||
lowered = cli('lower', path)
|
||||
instructions = sum((line.lstrip().startswith(b'%') and b' = ' in line) or
|
||||
line.strip().startswith((b'ret ', b'array.unpack ')) for line in lowered.splitlines())
|
||||
assert instructions == main_instructions + 2 + int(mixed), (kind, depth, instructions)
|
||||
if depth <= 1024:
|
||||
fuel = main_instructions + (3 if mixed else 2) * depth
|
||||
value = -1 if mixed and depth % 2 else 1
|
||||
assert json.loads(cli('run', path, '--fuel', fuel)) == {'status': 'returned', 'value': value, 'stdout': '', 'stderr': '', 'files': {}}
|
||||
assert json.loads(cli('run', path, '--fuel', fuel - 1, code=5)) == {
|
||||
'status': 'limit_exceeded', 'kind': 'fuel', 'limit': fuel - 1, 'steps': fuel - 1, 'stdout': '', 'stderr': '', 'files': {}}
|
||||
air = path.with_suffix('.air')
|
||||
air.write_bytes(lowered)
|
||||
assert cli('run', air, '--fuel', fuel) == cli('run', path, '--fuel', fuel)
|
||||
output = cli('fmt', path)
|
||||
formatted = path.with_suffix('.formatted.aji')
|
||||
formatted.write_bytes(output)
|
||||
assert cli('fmt', formatted) == output
|
||||
assert json.loads(cli('fmt', formatted, '--check')) == {
|
||||
'file': str(formatted), 'status': 'formatted', 'changed': False}
|
||||
formatted_check = cli('check', formatted, code=1 if limited else 0)
|
||||
if limited:
|
||||
diagnostic = json.loads(formatted_check)
|
||||
assert (diagnostic['code'], diagnostic['limit'], diagnostic['max'], diagnostic['found']) == (
|
||||
'E5101', 'instructions per function', 262144, main_instructions), diagnostic
|
||||
else:
|
||||
assert formatted_check == b''
|
||||
assert cli('lower', formatted) == lowered
|
||||
print(f'array expression depth: {kind} {depth}', flush=True)
|
||||
|
||||
# Pure nested arrays produce quadratic AIR type text. Keep success probes
|
||||
# at the confirmed former native-failure checkpoint instead of 65k output.
|
||||
for repeated in (False, True):
|
||||
path = root / f'pure-array-{repeated}-4096.aji'
|
||||
path.write_text('module depth\nfn main() -> i64 effects [] { let a = ' +
|
||||
'[' * 4096 + '1i64' + ('; 1]' if repeated else ']') * 4096 + '; return 0i64; }\n')
|
||||
assert cli('check', path) == b''
|
||||
print(f'pure array depth: {repeated} 4096', flush=True)
|
||||
|
||||
for depth in (1024, 16384, 65536):
|
||||
for repeated in (False, True):
|
||||
for leaf, code in (('missing()', 'E7002'), ('[missing(); 0]', 'E7005')):
|
||||
path = root / f'array-invalid-{depth}-{repeated}-{code}.aji'
|
||||
header = 'fn main() -> i64 effects [] { let a = '
|
||||
path.write_text('module depth\n' + header + '[' * depth + leaf +
|
||||
('; 1]' if repeated else ']') * depth + '; return 0i64; }\n')
|
||||
expected = cli('check', path, code=1)
|
||||
error = json.loads(expected)
|
||||
assert (error['code'], error['line'], error['col'], error['file']) == (
|
||||
code, 2, len(header) + depth + 1, str(path)), error
|
||||
for command in ('lower', 'run', 'report', 'explore'):
|
||||
assert cli(command, path, code=1) == expected
|
||||
print(f'array invalid depth: {depth}', flush=True)
|
||||
|
||||
# Builtin callbacks are still native; preserve the prior diagnostic at
|
||||
# bounded nesting while ordinary calls gain explicit continuations.
|
||||
for depth in (16, 64, 256):
|
||||
|
||||
Reference in new issue
Block a user