Skip to content

MDL writer does not reconstruct GET DIRECT calls for arrayed variables #393

@bpowers

Description

@bpowers

Problem

When writing arrayed variables back to MDL format, the MDL writer (src/simlin-engine/src/mdl/writer.rs, around line 785 in the Equation::Arrayed branch) emits individual resolved element equations instead of reconstructing the original GET DIRECT CONSTANTS/GET DIRECT DATA/GET DIRECT LOOKUPS call. This breaks MDL-to-MDL round-trip fidelity for models with arrayed external data references.

For example, an arrayed variable originally defined as:

variable name[DimA] = GET DIRECT CONSTANTS('file.xlsx', 'Sheet1', 'B2*', 'A2')

gets written back as individual element equations rather than the single GET DIRECT call.

Why it matters

  • Round-trip fidelity: Models exported back to MDL lose their external data references, making the output structurally different from the input.
  • Interoperability: Other tools (Vensim, SyntheSim) expect GET DIRECT calls and would not understand the expanded element-by-element form.
  • Data locality: The GET DIRECT pattern is a deliberate design choice by modelers to keep data in external files; expanding it defeats that intent.

Components affected

  • src/simlin-engine/src/mdl/writer.rs (the Equation::Arrayed match arm)

Possible approach

The compat.data_source metadata is now preserved on arrayed variables (added in the close-array-gaps branch). The MDL writer's Equation::Arrayed branch should check whether compat.data_source is Some, and if so, reconstruct the original GET DIRECT ... expression from the DataSource fields (kind, file, tab_or_delimiter, row_or_col, cell) instead of emitting per-element equations.

Context

Identified during the close-array-gaps branch work. Related but distinct from:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions