Repository navigation
perf(sv-analyzer): borrow constant function environments - #1175
Merged
Merged
Conversation
tignear
marked this pull request as ready for review
October 10, 2026 13:24
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Constant-function evaluation cloned all visible values and scanned their type markers on every call. The literal evaluator also executed unsupported user functions with an empty environment before falling back to numeric evaluation, multiplying repeated work in recursive expressions.
Borrow the caller's values, keep writes in a local frame, and query width/signedness markers only for referenced names. Nested calls borrow the previous frame. Reject unsupported literal function evaluation before executing it, so a 12-level recursion now executes 13 calls and exceeding the depth limit executes 64 calls. Public map-based evaluator APIs stay unchanged.
This draft builds on #1174. It includes the current master (
ef37b2c6c); only the new branch was pushed.Validation:
cargo fmt --all -- --checkcargo clippy --locked -p celox-sv-analyzer -p celox-frontend-sv --all-targets --all-features -- -D warningscargo test --locked -p celox-sv-analyzer -p celox-frontend-sv --all-features --quiet: 235 passed; two manual timing probes ignored by the normal suite.cargo test --locked -p celox --features sv-dpi --test systemverilog --test sv_unpacked_array --test sv_dpi --test sv_packages --test interface --test advanced_interface --quiet: SystemVerilog 1,617; DPI 52; arrays 7; packages 37; interfaces 216 passed, with 39 existing interface exclusions.cargo test --locked -p celox-test-suite --features verilator,icarus --quiet: 52 tests plus two doctests passed; nine existing external-oracle tests remain ignored. Shared executable cases and adapters are unchanged, so external results are reused under CONTRIBUTING.md.cargo doc --locked -p celox-sv-analyzer -p celox-frontend-sv --no-depsandpnpm docs:buildpassed.Internal regressions compare results with the former copied initialization, check caller isolation, local/argument/return-variable shadowing, signed shifts, symbolic argument widths, selected writes, unresolved values, nested calls, and depth restoration. A counted environment performs the same lookups with 16, 256, and 4,096 unrelated bindings.
The manual optimized paired probe (
compare_borrowed_and_copied_function_environments -- --ignored --nocapture) passed. For 512 unrelated parameters and 512 leaf calls, the median was 53.946 ms with copied initialization versus 0.305 ms with borrowing. This isolates frame initialization/evaluation and checks every result; it excludes parsing, declaration discovery, and backend compilation.The new
type_queries --constant-functions 32 128 512mode passed with IR value assertions. At 512 parameters, separate three-sample medians comparing21eb07cf3with this change were 2,652.147 → 1,170.084 ms for AST lowering (parse 56.719 → 51.676 ms). Full measurements and reproduction commands are in the performance document. Shared-machine timing varies, and overall AST lowering remains nonlinear because other collectors repeatedly resolve parameter prefixes. The baseline also overflows a default Rust test thread stack for the 256-element function-call chain; that owning-crate regression uses an 8 MiB stack. Recursive parameter substitution's existing stack use remains.