aboutsummaryrefslogtreecommitdiff
path: root/tests/drivers/inference_growth_test.py
blob: d747f701c4f73d8b209606922715ffe8359a4301 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/env python3
# infer past the original function-record and edit-count limits.
import re
import subprocess
import sys

source = ''.join(f'fn function_{i}(x) {{ return x + 1; }}\n' for i in range(600))
source += 'fn main() {\n'
source += ''.join(f'let value_{i} = {i};\n' for i in range(5000))
source += ''.join(f'function_{i}(1);\n' for i in range(600))
source += 'return value_4999; }\n'
result = subprocess.run([sys.argv[1], '--annotate'], input=source, text=True, capture_output=True, timeout=45)
assert result.returncode == 0, result.stderr
assert re.search(r'int function_599\(int x\)', result.stdout), result.stdout[-1000:]
assert 'int value_4999 = 4999;' in result.stdout, result.stdout[-1000:]
assert 'let value_' not in result.stdout, 'later inference edits were dropped'
print('ok   inference handles 600 functions and 5000 local declarations')

# later parameters and nested functions retain the enclosing inference context.
params = ', '.join(f'arg_{i}' for i in range(20))
source = f'fn wide({params}) {{ let nested = fn(int y) {{ return y + 1; }}; return arg_19 + nested(1); }}\n'
source += 'fn main() { return wide(' + ', '.join('1' for _ in range(20)) + '); }\n'
result = subprocess.run([sys.argv[1], '--annotate'], input=source, text=True, capture_output=True, timeout=15)
assert result.returncode == 0, result.stderr
assert 'int arg_19' in result.stdout, result.stdout
assert 'int wide(' in result.stdout, result.stdout
print('ok   later arguments and nested closures preserve inferred signatures')

source = 'struct point { int x, y; };\nfn main() { let a[3]; a[1] = 7; let alias = a; point p; p.x = 9; let ref = p; return alias[1] + ref.x; }\n'
result = subprocess.run([sys.argv[1], '--annotate'], input=source, text=True, capture_output=True, timeout=15)
assert result.returncode == 0 and 'word* alias' in result.stdout and 'point* ref' in result.stdout, result.stdout
again = subprocess.run([sys.argv[1], '--annotate'], input=result.stdout, text=True, capture_output=True, timeout=15)
assert again.returncode == 0 and again.stdout == result.stdout, again.stdout
print('ok   array and struct aliases get compatible pointer annotations')