diff options
Diffstat (limited to 'tests/drivers/compiler_growth_test.py')
| -rw-r--r-- | tests/drivers/compiler_growth_test.py | 61 |
1 files changed, 32 insertions, 29 deletions
diff --git a/tests/drivers/compiler_growth_test.py b/tests/drivers/compiler_growth_test.py index 982611c..e56bf43 100644 --- a/tests/drivers/compiler_growth_test.py +++ b/tests/drivers/compiler_growth_test.py @@ -18,65 +18,68 @@ def run(source, expected): assert result.stdout == expected, result.stdout[:1000] -locals_source = 'fn main() {\n' +locals_source = 'include rt; 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' +locals_source += 'rt.put_n(local_899); rt.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' +types_source = ''.join(f'type array_{i} = int[{i + 1}];\n' for i in range(1500)) +types_source = 'include rt, run;\n' + types_source +types_source += 'fn main() { rt.put_n(run.ntl > 1500); rt.put_c(10); rt.gc(); rt.put_n(run.tsz(run.tarr(run.tint, 1500))); rt.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 = 'include rt, run;\n' + ''.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); + word saved = run.intern("a name that must survive growth"); + run.reserve_names(run.hashcap * 4); run.reserve_symbols(run.symcap * 2); run.reserve_locals(run.loccap * 2); + run.reserve_fixes(run.fixcap * 2); run.reserve_R_SRC(4096); run.reserve_R_CTX(4096); + run.reserve_R_LOOP(4096); run.reserve_R_SNAP(32768); run.reserve_R_QBUF(32768); run.reserve_R_EXIT(8192); + rt.gc(); + rt.put_n(saved == run.intern("a name that must survive growth")); rt.put_c(10); + rt.put_n(repeated_long_identifier_for_pool_and_hash_growth_{options.names - 1}); rt.put_c(10); + rt.put_n(run.poolblocks != 0 && run.symcap > run.NS && run.hashcap > run.IHN); rt.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') +run(f'include rt; const int {long_name} = 7; fn main() {{ rt.put_n({long_name}); rt.put_c(10); return 0; }}\n', '7\n') -mark_source = '''let roots[60000]; +mark_source = '''include rt; 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; + int i = 0, before = rt.live_objects(); + while (i < 60000) { roots[i] = rt.new(1); i++; } + rt.gc(); rt.put_n(rt.markcap > rt.MARKN); rt.put_c(32); rt.put_n(rt.live_objects() - before == 60000); rt.put_c(32); + // explicitly release survivors: conservative instruction roots may resemble heap addresses. + i = 0; while (i < 60000) { rt.free(roots[i]); i++; } + rt.fill_w(roots, 0, 60000); rt.scrub(); rt.gc(); + rt.put_n(rt.live_objects() == before); rt.put_c(10); return 0; } ''' run(mark_source, '1 1 1\n') generics_source = ''.join(f'int generic_{i}<T>() {{ return sizeof(T); }}\n' for i in range(90)) generics_source += 'int size_of<T>() { return sizeof(T); }\n' +generics_source = 'include rt;\n' + generics_source generics_source += 'fn main() { int total = 0;\n' generics_source += ''.join(f'total += generic_{i}<int>();\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' +generics_source += ''.join(f'total += size_of<int[{i + 1}]>();\n' for i in range(150)) +generics_source += 'rt.gc(); rt.put_n(total); rt.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 = 'include rt; 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' +captures_source += 'rt.gc(); rt.put_n(f()); rt.put_c(10); return 0; }\n' run(captures_source, '2415\n') -nested_source = 'fn main() { int captured = 7;\n' +nested_source = 'include rt; 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' +nested_source += '}; rt.gc(); rt.put_n(nested_0()); rt.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' +assembly_source = 'include rt; fn main() { int value = asm { ' + 'future _ ' * 300 +assembly_source += ''.join(f':label_{i} ' for i in range(200)) + ':future 7 }; rt.gc(); rt.put_n(value); rt.put_c(10); return 0; }\n' run(assembly_source, '7\n') print('ok compiler tables, long identifiers, and mark work grow without losing references') |
