Skip to content

feat(interpreter): compile mixed control flow inside functions - #2983

Open
chaliy wants to merge 4 commits into
mainfrom
feat/mixed-execution-plan
Open

chaliy wants to merge 4 commits into
mainfrom
feat/mixed-execution-plan

Conversation

@chaliy

@chaliy chaliy commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

What changed

The opt-in execution-plan compiler now prepares function bodies and mixed loop/branch control flow. Supported child regions and arithmetic-for clauses execute compiled instructions around ordinary tool calls, pipelines, substitutions, regex captures and array access. Bash syntax and execution APIs stay unchanged.

Plans belong to the invocation and borrow its active definition. Shared orchestration preserves output, conditions, traps, loop flow and frame cleanup. No interpreter fields or persistent compiler cache are added. jq uses its existing lazy jaq compilation and bounded execution-local LRU, with current bindings, filter files and function shadowing.

The optional browser compiler build retains the ordinary optimization pipeline with a separate 3.12 MB gzip cap. The normal package keeps 3.1 MB; raw/Brotli caps and runtime limits are unchanged. Tests enforce profile selection and every cap.

Why

Tool-containing function loops previously fell back as a whole. The compiler can now prepare their control flow and supported arithmetic while preserving normal Bash tool protocols.

Performance

Fresh-shell same-binary comparisons include parsing, lowering and execution, with four alternating rounds and 30 samples per mode per round. On a fixed Linux CPU, arithmetic inside a function took 19.397 → 9.073 ms (53% less). Substitution and jq differences were smaller and variable; fan-out took about 4% more, and short scripts about 1% more.

The unchanged original event-JSON tool workload showed no clear gain: +3% elapsed time pinned, −3% unpinned, with variation between rounds. These results do not justify enabling the feature by default. Raw samples, build identities and reproduction.

Risk

  • Medium: interpreter orchestration, resource accounting and cancellation.
  • experimental_execution_plan remains disabled by default. Unsupported dynamic contexts and redirected compound boundaries use interpreter fallback.
  • Wholly opaque loops retain ordinary execution and synchronous limit reporting.
  • Plans reserve storage before lowering and release it on return, errors and future cancellation.

Validation

  • just pre-pr and just test pass: 7,503 workspace/unit/integration/doc tests, 277 Python script tests and serialized security failpoints.
  • Compiler-enabled serialized run: 3,549 unit tests and all 19 security failpoint tests pass. All-target/all-feature Clippy passes.
  • Actual backend selection, locals/redefinition, control flow, inherited stdin, output/status/counters, jq dynamic behavior, admission/refunds and suspended-tool cancellation have regression coverage.
  • Local ASan differential campaign: 256 cases. The Rust revision finished all 104 CI checks (103 successes, one skip), including feature-on/off native suites, discovered fuzz targets, runtime bindings, strict oracles and security properties.
  • Final browser packaging: 86 Node tests, 24 GNU Bash comparisons and transfer limits pass locally. An extra Binaryen pass was rejected after jq runtime probes; browser measurements explain the size/speed choice.
  • Exploratory broad benchmark: all 96 cases match Bash output with zero errors; parallel-execution Criterion comparison completed. Timing clusters in both builds required fixed-CPU rechecks.
  • Final packaging/report commit is in CI. Validation record also records pre-existing chrono unmaintained advisories; root dependencies and audit policy are unchanged.

Checklist

  • Tests added or updated
  • Backward compatibility considered

See it in action
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

@chaliy
chaliy marked this pull request as ready for review November 23, 2026 20:48
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
bashkit 30411ff Commit Preview URL

Branch Preview URL
Nov 23 2026, 11:03 PM

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant