Skip to content

fix(instantiate): preserve nested array modifier element scope#324

Merged
jgoppert merged 1 commit into
CogniPilot:mainfrom
climamind:fix/cli-37-array-modifier-element-scope
Jul 18, 2026
Merged

fix(instantiate): preserve nested array modifier element scope#324
jgoppert merged 1 commit into
CogniPilot:mainfrom
climamind:fix/cli-37-array-modifier-element-scope

Conversation

@hechuan9

@hechuan9 hechuan9 commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Preserve the current array element's scope when distributing nested, non-each modifiers during component-array expansion.
  • For Pump pumps[2](per(curve(eta=motorEta))), the two scalar instances now retain motorEta[1] and motorEta[2] respectively instead of both retaining the unsliced matrix.
  • This addresses only the array-modifier element-scope subproblem tracked in ClimaMind CLI-37. It does not include end lowering or downstream FMI compensation.

Spec / MLS Alignment

  • Relevant active spec(s) checked: SPEC_0007, SPEC_0021, SPEC_0022, SPEC_0025, SPEC_0029, SPEC_0032.
  • Relevant MLS section(s), if semantics changed: MLS §7.2 (modifier value context) and §7.2.5 (each and array-modifier distribution).
  • Crate/phase owner: rumoca-phase-instantiate, array expansion.

Risk and Design Notes

  • Main correctness risk: indexing scalar or shape-unproven nested expressions. The implementation reuses the existing conservative index_array_expression_for_element path and leaves values unchanged when array projection cannot be proven.
  • Main maintenance risk: one additional private recursive helper in the existing array-expansion owner.
  • Why the change belongs in these crate(s): the first divergence occurs while an array component is expanded into scalar instances; later Flat/DAE/FMI layers should receive already-correct modifier bindings.
  • Any new abstraction, public API, or migration path: one private helper; no public API or migration.

Testing

  • Focused regression: cargo test -p rumoca --test mod_propagation_test test_nested_modifier_on_array_component_selects_element_row -- --exact
  • The regression proves elements 1 and 2 select rows 1 and 2, while nested each preserves the complete shared array for both elements.
  • CI on exact head 0d9d172 passes formatting, lint, documentation, coverage, Linux/macOS/Windows tests, all four MSL quality shards and the final MSL merge gate.

Code Size Budget (required)

  • production_lines_added: 45
  • production_lines_deleted: 0
  • test_lines_added: 65
  • test_lines_deleted: 0
  • public_items_added: 0
  • public_items_removed: 0
  • files_touched: 2
  • net_added_lines: 110

The net growth is the private recursive traversal needed to reach nested modification leaves plus one end-to-end regression. The first compression pass reduced the prior downstream candidate from 249 added lines across three files to 110 lines across two files by removing unrelated modifier-environment behavior and consolidating recursion around the existing conservative array-projection helper. No follow-up cleanup is planned because no parallel path or public abstraction remains.

Reviewer Checklist

  • Relevant active specs were checked.
  • MLS-sensitive changes cite the right MLS section.
  • Crate boundaries and phase ownership preserved (SPEC_0029).
  • Tests prove behavior or explain the remaining gap.
  • Standard CI gates pass (fmt, clippy -D warnings, cargo test, cargo doc).
  • MSL gate run for compiler/simulator changes; no regression vs baseline.
  • Size-budget section completed.
  • Positive net diff has explicit compression justification.
  • New APIs are required and minimal.
  • Old/new parallel paths removed unless explicitly migrating.
  • No #[allow(clippy::...)] added outside generated code.
  • Every commit signed off (git commit -s); no Co-Authored-By for AI.
  • External material (if any) attributed and Apache-2.0 compatible.

Signed-off-by: Chuan He <hechuan@climamind.ai>
@hechuan9
hechuan9 marked this pull request as ready for review July 18, 2026 14:22
@jgoppert
jgoppert merged commit 8cdc741 into CogniPilot:main Jul 18, 2026
41 checks passed
@hechuan9
hechuan9 deleted the fix/cli-37-array-modifier-element-scope branch July 18, 2026 15:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants