diff options
| author | 2026-10-12 08:46:23 +0330 | |
|---|---|---|
| committer | 2026-10-12 08:46:23 +0330 | |
| commit | ecc350ca5c2eb50be8309c5f14f8bf0d87db9a02 (patch) | |
| tree | 70e0af76a1b13affff7c6cc8aac7b3e6ef960478 /tests/drivers/inference_growth_test.py | |
a
Diffstat (limited to 'tests/drivers/inference_growth_test.py')
| -rw-r--r-- | tests/drivers/inference_growth_test.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/tests/drivers/inference_growth_test.py b/tests/drivers/inference_growth_test.py new file mode 100644 index 0000000..d747f70 --- /dev/null +++ b/tests/drivers/inference_growth_test.py @@ -0,0 +1,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') |
