Skip to content

Commit 2f58570

Browse files
bbyalcinkayaclaude
andcommitted
scope the recursion limit to run_module and clean up dead code
sys.setrecursionlimit(1500000000) was an import-time side effect inherited from the 2020 py-wasm-era script, and the value effectively disabled Python's recursion guard. The limit is only needed because pyk serializes kore terms recursively (pyk.kore.syntax.Pattern.write) and the depth grows with module size: basic-features.wat needs about 4000, while the default 1000 is enough for everything else. Set 20000 inside run_module, never lowering an externally raised limit. Also remove an assert made dead by check=True and a try/except that re-raised as a bare Exception, hiding the original exception type. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent 5f16b3a commit 2f58570

1 file changed

Lines changed: 14 additions & 17 deletions

File tree

‎pykwasm/src/tests/integration/test_binary_parser.py‎

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
BINARY_DIR = Path(__file__).parent / 'binary'
2222
BINARY_WAT_FILES = list(BINARY_DIR.glob('*.wat'))
2323

24-
sys.setrecursionlimit(1500000000)
25-
2624

2725
@pytest.mark.parametrize('wat_path', BINARY_WAT_FILES, ids=str)
2826
def test_wasm2kast(krun_llvm: KRun, wat_path: Path) -> None:
@@ -31,8 +29,6 @@ def test_wasm2kast(krun_llvm: KRun, wat_path: Path) -> None:
3129
proc_res = run(wat2wasm_cmd, check=True, capture_output=True)
3230
wasm_file = BytesIO(proc_res.stdout)
3331

34-
assert not proc_res.returncode
35-
3632
# When
3733
module = wasm2kast(wasm_file)
3834

@@ -41,20 +37,21 @@ def test_wasm2kast(krun_llvm: KRun, wat_path: Path) -> None:
4137

4238

4339
def run_module(krun: KRun, parsed_module: KInner) -> Pattern:
44-
try:
45-
# Create an initial config
46-
config_kast = krun.definition.init_config(KSort('GeneratedTopCell'))
40+
# pyk serializes kore terms recursively (pyk.kore.syntax.Pattern.write) and the term
41+
# nesting depth grows with module size, so the default limit of 1000 is not enough:
42+
# basic-features.wat needs about 4000. Set 20000 for headroom.
43+
sys.setrecursionlimit(max(sys.getrecursionlimit(), 20_000))
4744

48-
# Embed parsed_module to <k>
49-
symbolic_config, init_subst = split_config_from(config_kast)
50-
init_subst['K_CELL'] = KSequence(parsed_module)
51-
config_with_module = Subst(init_subst)(symbolic_config)
45+
# Create an initial config
46+
config_kast = krun.definition.init_config(KSort('GeneratedTopCell'))
5247

53-
# Convert the config to kore
54-
config_kore = krun.kast_to_kore(config_with_module, KSort('GeneratedTopCell'))
48+
# Embed parsed_module into the <k> cell
49+
symbolic_config, init_subst = split_config_from(config_kast)
50+
init_subst['K_CELL'] = KSequence(parsed_module)
51+
config_with_module = Subst(init_subst)(symbolic_config)
5552

56-
# Run the config
57-
return krun.run_pattern(config_kore)
53+
# Convert the config to kore
54+
config_kore = krun.kast_to_kore(config_with_module, KSort('GeneratedTopCell'))
5855

59-
except Exception as e:
60-
raise Exception('Received error while running') from e
56+
# Run the config
57+
return krun.run_pattern(config_kore)

0 commit comments

Comments
 (0)