#!/usr/bin/env python3 # growing frames keep pointers into older segments alive through collection. import subprocess import sys command = sys.argv[1:] source = '''include rt; unchecked int descend(int depth, int* root) { int[2000] padding; padding[0] = depth; if (depth == 0) { rt.gc(); return *root; } return descend(depth - 1, root) + padding[0]; } unchecked int oversized(int* root) { int[300000] values; values[0] = *root; values[299999] = 9; rt.gc(); return values[0] + values[299999]; } unchecked fn main() { int value = 7; rt.put_n(descend(300, &value)); rt.put_c(32); rt.put_n(oversized(&value)); rt.put_c(32); rt.gc(); rt.put_n(rt.frame_node == 0); rt.put_c(10); return 0; } ''' result = subprocess.run(command, input=source, text=True, capture_output=True, timeout=40) assert result.returncode == 0 and result.stdout == '45157 16 1\n', (command, result.returncode, result.stdout, result.stderr) print('ok deep and oversized frames preserve borrowed locals through collection: ' + command[0]) optimized = source.replace('unchecked int descend', 'unchecked o3 int descend').replace('unchecked int oversized', 'unchecked o3 int oversized') result = subprocess.run(command, input=optimized, text=True, capture_output=True, timeout=40) assert result.returncode == 0 and result.stdout == '45157 16 1\n', (command, result.returncode, result.stdout, result.stderr) print('ok optimized recursive calls wait for the matching return depth: ' + command[0])