#!/usr/bin/env python3 # focused growth checks for compiler columns, stable names, types, and scratch stacks. import argparse import subprocess import sys parser = argparse.ArgumentParser() parser.add_argument('server') parser.add_argument('--names', type=int, default=18000) options = parser.parse_args() server = options.server assert options.names > 0 def run(source, expected): result = subprocess.run([server], input=source, text=True, capture_output=True, timeout=30) assert result.returncode == 0, result.stderr assert result.stdout == expected, result.stdout[:1000] locals_source = 'fn main() {\n' locals_source += ''.join(f'int local_{i} = {i};\n' for i in range(900)) locals_source += 'put_n(local_899); put_c(10); return 0; }\n' run(locals_source, '899\n') types_source = ''.join(f'type array_{i} = [{i + 1}]int;\n' for i in range(1500)) types_source += 'fn main() { put_n(ntl > 1500); put_c(10); gc(); put_n(tsz(tarr(tint, 1500))); put_c(10); return 0; }\n' run(types_source, '1\n1500\n') names_source = ''.join(f'const int repeated_long_identifier_for_pool_and_hash_growth_{i} = {i};\n' for i in range(options.names)) names_source += f'''fn main() {{ word saved = intern("a name that must survive growth"); reserve_names(hashcap * 4); reserve_symbols(symcap * 2); reserve_locals(loccap * 2); reserve_fixes(fixcap * 2); reserve_R_SRC(4096); reserve_R_CTX(4096); reserve_R_LOOP(4096); reserve_R_SNAP(32768); reserve_R_QBUF(32768); reserve_R_EXIT(8192); gc(); put_n(saved == intern("a name that must survive growth")); put_c(10); put_n(repeated_long_identifier_for_pool_and_hash_growth_{options.names - 1}); put_c(10); put_n(poolblocks != 0 && symcap > NS && hashcap > IHN); put_c(10); return 0; }} ''' run(names_source, f'1\n{options.names - 1}\n1\n') long_name = 'identifier_' + 'x' * 1500 run(f'const int {long_name} = 7; fn main() {{ put_n({long_name}); put_c(10); return 0; }}\n', '7\n') mark_source = '''let roots[60000]; unchecked fn main() { int i = 0; while (i < 60000) { roots[i] = new(1); i++; } gc(); put_n(markcap > MARKN); put_c(32); put_n(live_objects() == 60000); put_c(32); fill_w(roots, 0, 60000); scrub(); gc(); // conservative roots can retain incidental addresses in code or untyped words. put_n(live_objects() < 1000); put_c(10); return 0; } ''' run(mark_source, '1 1 1\n') generics_source = ''.join(f'int generic_{i}() {{ return sizeof(T); }}\n' for i in range(90)) generics_source += 'int size_of() { return sizeof(T); }\n' generics_source += 'fn main() { int total = 0;\n' generics_source += ''.join(f'total += generic_{i}();\n' for i in range(90)) generics_source += ''.join(f'total += size_of<[{i + 1}]int>();\n' for i in range(150)) generics_source += 'gc(); put_n(total); put_c(10); return 0; }\n' run(generics_source, '11415\n') captures_source = 'fn main() {\n' + ''.join(f'int captured_{i} = {i};\n' for i in range(70)) captures_source += 'let f = fn() { return ' + ' + '.join(f'captured_{i}' for i in range(70)) + '; };\n' captures_source += 'gc(); put_n(f()); put_c(10); return 0; }\n' run(captures_source, '2415\n') nested_source = 'fn main() { int captured = 7;\n' nested_source += ''.join(f'let nested_{i} = fn() {{\n' for i in range(12)) nested_source += 'return captured;\n' nested_source += ''.join(f'}}; return nested_{i}();\n' for i in reversed(range(1, 12))) nested_source += '}; gc(); put_n(nested_0()); put_c(10); return 0; }\n' run(nested_source, '7\n') assembly_source = 'fn main() { int value = asm { ' + 'future _ ' * 300 assembly_source += ''.join(f':label_{i} ' for i in range(200)) + ':future 7 }; gc(); put_n(value); put_c(10); return 0; }\n' run(assembly_source, '7\n') print('ok compiler tables, long identifiers, and mark work grow without losing references')