Skip to content

engine: SUM(VECTOR ELM MAP(...)) in A2A context evaluates per-element rather than reducing the full array #366

Closed

Description

@bpowers

Problem

When an array-producing builtin like VECTOR ELM MAP is wrapped in a reducer like SUM() and the entire expression appears in an A2A (apply-to-all) context, the hoisting logic treats the inner array-producing builtin as the primary expression shape. This causes the outer SUM() to evaluate per-element rather than first materializing the full array and then reducing it.

For example, with result[DimA] = SUM(VECTOR ELM MAP(source[*], offsets[*])):

  • Expected: each element of result gets the same scalar value (the sum of all mapped elements)
  • Actual: the A2A hoisting detects the inner VEM and hoists it, but the outer SUM is applied per-element rather than over the full materialized array

Relationship to other issues

Context

Identified during code review of PR #361 (VM vector operations). Referenced in the PR summary as a deferred pre-existing issue but not previously filed. The issue predates the PR and affects both interpreter and VM paths.

Component(s) affected

  • src/simlin-engine/src/compiler/mod.rs (A2A hoisting detection and expansion)
  • src/simlin-engine/src/compiler/context.rs (preserve_wildcards_for_iteration semantics)

Activity

  1. bpowers commented on Mar 8, 2026

    @bpowers
    OwnerAuthor

    Fixed in commit bb3e977 (PR #368) — A2A hoisting now correctly distinguishes array-value and scalar-element arguments for reducer-wrapped array-producing builtins.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions