perf: fast path array self append#137
Conversation
Greptile SummaryThis PR introduces a narrow in-place fast path for the
Confidence Score: 5/5Safe to merge. The fast path is narrow and well-guarded: it only fires when the exact assignment shape matches, all RHS elements pass an exhaustive side-effect-free check, and the binding is confirmed to be an array before any mutation. Errors during element evaluation abort before any in-place append. The fast path guards are conservative and exhaustive — all 27 Expression variants are handled in No files require special attention. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["eval_block_for_control(block)"] --> B["eval_block_inner(block, control=true)"]
B --> C["for each stmt"]
C --> D["eval_statement_for_control(stmt)"]
D --> E{Statement kind}
E -- "Located{stmt}" --> F["set line/col, recurse"]
F --> D
E -- "Expression(expr)" --> G["try_eval_array_self_append_statement(expr)"]
G --> H{Shape match?}
H -- "Not Assign / lhs≠rhs / no array binding or elements have side effects" --> I["eval_expression(expr) — generic path"]
H -- "arr = arr + literal + binding_is_array passes" --> J["eval each element"]
J --> K{Any element error?}
K -- "Err" --> L["propagate error, no mutation"]
K -- "Ok(items)" --> M["append_to_array_binding() — mutate in-place"]
M --> N["return Ok(Value::Unit)"]
E -- "other statement" --> O["eval_statement(stmt) + control_flow_or_unit"]
B --> P{stmt error?}
P -- "Err captured" --> Q["drain & run deferred stmts, restore env, propagate Err"]
P -- "Break/Continue/Return" --> R["break loop, run deferred stmts, restore env, return control value"]
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
flowchart TD
A["eval_block_for_control(block)"] --> B["eval_block_inner(block, control=true)"]
B --> C["for each stmt"]
C --> D["eval_statement_for_control(stmt)"]
D --> E{Statement kind}
E -- "Located{stmt}" --> F["set line/col, recurse"]
F --> D
E -- "Expression(expr)" --> G["try_eval_array_self_append_statement(expr)"]
G --> H{Shape match?}
H -- "Not Assign / lhs≠rhs / no array binding or elements have side effects" --> I["eval_expression(expr) — generic path"]
H -- "arr = arr + literal + binding_is_array passes" --> J["eval each element"]
J --> K{Any element error?}
K -- "Err" --> L["propagate error, no mutation"]
K -- "Ok(items)" --> M["append_to_array_binding() — mutate in-place"]
M --> N["return Ok(Value::Unit)"]
E -- "other statement" --> O["eval_statement(stmt) + control_flow_or_unit"]
B --> P{stmt error?}
P -- "Err captured" --> Q["drain & run deferred stmts, restore env, propagate Err"]
P -- "Break/Continue/Return" --> R["break loop, run deferred stmts, restore env, return control value"]
Reviews (2): Last reviewed commit: "fix: restore block scope on errors" | Re-trigger Greptile |
|
Addressed Greptile's feedback in ebedea5:
Local verification passed: cargo fmt -- --check, cargo build --profile dev-release, targeted tests, full lib tests, integration tests, docs generation, and git diff --check. |
Summary
arr = arr + [item]/[items...].+behavior for non-target shapes, including call-containing RHS arrays, assignment-expression results, RHS error behavior, and alias/copy semantics.Benchmarks
7.11s0.0122s0.0238s0.0439sVerification
cargo fmt -- --checkcargo build --profile dev-releasecargo test --lib -q— 1153 passedcargo test --test language_features_tests --test type_checker_tests --test cli_tests -q./target/dev-release/ntnt docs --generategit diff --check