Repository navigation
engine: fix nested array-producing builtin reductions in A2A - #368
Conversation
Nested array-producing builtins in A2A expressions were always rewritten to TempArrayElement. That collapsed full-array arguments for reduction builtins like SUM into element-local reads, yielding incorrect interpreter results. This change makes nested builtin rewriting argument-aware so array-consuming argument positions keep TempArray semantics while scalar positions still use TempArrayElement. Added regression coverage for nested VECTOR ELM MAP, VECTOR SORT ORDER, and ALLOCATE AVAILABLE reductions in array context.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 386b966826
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| BuiltinFn::Max(arg, None) => BuiltinFn::Max( | ||
| Box::new(replace_nested_builtins_for_element( |
There was a problem hiding this comment.
Treat two-arg MAX/MIN children as scalar
replace_nested_builtins_for_element now marks array-reduction arguments as ArrayValue, but only Max(_, None)/Min(_, None) are explicitly handled; Max(_, Some(_)) and Min(_, Some(_)) fall through other.map(..., arg_mode). In expressions like sum(max(vector_elm_map(...), 15)), that rewrites the nested vector_elm_map to TempArray inside scalar MAX/MIN, and the interpreter later evaluates two-arg MAX/MIN in scalar mode, which cannot consume TempArray and panics (TempArray ... cannot be evaluated as scalar). This regression is introduced by this change and breaks nested reduction formulas that combine SUM with scalar MAX/MIN wrappers.
Useful? React with 👍 / 👎.
Code ReviewFindings[P3] Unreachable match arms for
The explicit match arms for Overall Correctness VerdictCorrect. The core fix — making |
|
This change set fixes the root cause behind issue #364 by preserving full-array semantics when nested array-producing builtins are hoisted in A2A lowering. Previously, nested replacements always became element reads, which caused reductions like I also added focused regression coverage in |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #368 +/- ##
========================================
Coverage 79.03% 79.03%
========================================
Files 142 142
Lines 37264 37396 +132
========================================
+ Hits 29451 29556 +105
- Misses 7813 7840 +27 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Summary
This PR fixes incorrect interpreter behavior when array-producing builtins are nested inside other builtins in A2A contexts.
The root cause was nested hoisting always rewriting array-producing builtins to
TempArrayElement, even when the parent builtin expected an array argument (for exampleSUM(...)). That collapsed full-array semantics into element-local reads.Changes
ScalarElementvsArrayValue).TempArrayfor array-consuming argument positions andTempArrayElementfor scalar-consuming positions.SUM(VECTOR ELM MAP(...))in array contextSUM(VECTOR SORT ORDER(...))in array contextSUM(ALLOCATE AVAILABLE(...))in array contextValidation
cargo test -p simlin-engine --test compiler_vector