Skip to content

engine: VECTOR ELM MAP with cross-dimension sources fails in compiler #357

Closed

Description

@bpowers

Problem

VECTOR ELM MAP with cross-dimension sources (e.g., c[DimA] = VECTOR ELM MAP(b[B1], a[DimA]) where b[B1] is from DimB used in a DimA context) fails to compile with dimension mismatch errors. The compiler cannot resolve the dimension relationship between DimB (source dimension) and DimA (target dimension).

Why it matters

  • Blocking: Prevents enabling the full vector.mdl test model in the integration tests (currently only vector_simple.mdl subset works, which excludes cross-dimension indexing)
  • Design gap: Highlights a limitation in the compiler's cross-dimension indexing strategy for array operations
  • Correctness: Models using VECTOR ELM MAP with cross-dimension references are common in real SD models

Components affected

  • src/simlin-engine/src/compiler/ (dimension resolution, array subscript handling)
  • src/simlin-engine/src/compiler/dimensions.rs (dimension matching/inference)
  • src/simlin-engine/src/compiler/subscript.rs (array subscript expansion)

Possible approaches

  1. Element-level subscript flattening: Flatten b[B1] to a scalar before passing to VECTOR ELM MAP, allowing dimension mismatch resolution
  2. Cross-dimension indexing mapping: Track dimension relationships through mappings (like EXCEPT does) to allow element selection across dimension boundaries
  3. Source dimension narrowing: When a source array has a subscript that narrows it to a single element (e.g., b[B1]), treat it as dimension-agnostic for the purposes of VECTOR ELM MAP

Context

Identified during design work for issue #355 (vector operations/ALLOCATE AVAILABLE VM implementation). The specific limitation is documented in a comment in src/simlin-engine/tests/simulate.rs around line 863:

// VECTOR ELM MAP with cross-dimension source: `VECTOR ELM MAP(b[B1], a[DimA])`
// uses b[B1] (a single-element B-subscript slice) as the source array in a DimA
// context. The compiler cannot resolve the dimension mismatch because b's DimB
// dimension has no mapping to DimA. Fixing requires either element-level subscript
// flattening or a new cross-dimension indexing strategy.
// The vector_simple subset (no cross-dim indexing) passes via simulates_vector_simple_mdl.

This is a distinct sub-case of cross-dimension dimension resolution (related to #345 EXCEPT+cross-dimension mapping) but specific to vector operations.

Activity

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