HS: sieve test compile-once + string-var expansion in generator
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 47s

Replace 11 separate eval-hs-locals compilations with a single
hs-compile call + shared run-sieve fn; reduces wall-clock from
60s+ to ~1s per call.

Generator: pre-resolve string variable concatenations before
pattern matching run() calls so multi-line HS sources translate
correctly.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-05 20:23:43 +00:00
parent 42c7a593cf
commit f6a1b53c7b
3 changed files with 202 additions and 93 deletions

View File

@@ -2590,6 +2590,27 @@ def generate_eval_only_test(test, idx):
assertions = []
# Pre-resolve string variable assignments: `var str = "..." + "..." + ...`
# so that `run(str, opts)` is treated the same as `run("expanded", opts)`.
# JS `\n` / `\t` escape sequences in the joined value are collapsed to spaces
# since HS uses keyword delimiters (if/else/end/then), not indentation.
_str_vars = {}
for _sv in re.finditer(
r'(?:var|let|const)\s+(\w+)\s*=\s*((?:"(?:[^"\\]|\\.)*"|\'(?:[^\'\\]|\\.)*\'|\s*\+\s*)+)\s*;',
body, re.DOTALL
):
_vname = _sv.group(1)
_raw = _sv.group(2)
_parts = re.findall(r'"((?:[^"\\]|\\.)*?)"|\'((?:[^\'\\]|\\.)*?)\'', _raw)
_joined = ''.join(p[0] or p[1] for p in _parts)
# Collapse JS newline/tab escapes to spaces so the HS source is flat.
_joined = _joined.replace('\\n', ' ').replace('\\t', ' ')
_str_vars[_vname] = _joined
if _str_vars:
for _vname, _val in _str_vars.items():
_escaped = _val.replace('"', '\\"')
body = re.sub(r'\brun\(' + re.escape(_vname) + r'\b', f'run("{_escaped}"', body)
# Window setups from `evaluate(() => { window.X = Y })` blocks.
# These get merged into local_pairs so the HS expression can reference them.
window_setups = extract_window_setups(body)