Skip to content

engine: element-level cycle check misses edges between arrayed variables #575

Closed

Description

@bpowers

When two or more arrayed variables depend on each other element by element, the engine must decide whether the per-element dependencies form a real cycle or just an ordering problem.
The check that builds the per-element graph compared each variable's slot numbers as if they shared one layout, but each variable was compiled in its own private layout.
So for a group of two or more variables it found no edges between them.

Example

ce[t1] = 1
ce[tNext] = ecc[tPrev] + 1
ecc[t1] = ce[t1] + 1
ecc[tNext] = ce[tNext] + 1

This (test/sdeverywhere/models/ref/ref.mdl) needs an interleaved order, giving ce = 1,3,5 and ecc = 2,4,6.
The check returned all of ce then all of ecc.
Worse, for a real cycle, a[i] = b[i] and b[i] = a[i], it reported no cycle at all.

The bug was hidden because only single-variable recurrences were sent to the check; groups of two or more were always reported as circular.

Why it matters

Allowing multi-variable groups (needed for C-LEARN) would have turned a correct circular-dependency error into a silently wrong simulation.

Fix

Build the per-element graph from the compiled code's symbolic variable references (name plus element), which are the same across variables, so the one-variable and many-variable cases share one builder.

Pointers

  • src/simlin-engine/src/db/dep_graph.rs: refine_scc_to_element_verdict, symbolic_phase_element_order

Activity

  1. added
    engine
    on Jun 8, 2026
  2. changed the title [-]engine: phase_element_order builds the SCC element graph from per-variable mini-slots -- zero cross-member edges + unsound resolution of genuine multi-variable element cycles (masked by members.len()!=1; Phase 2 Subcomponent B must remove mask)[/-] [+]engine: element-level cycle check misses edges between arrayed variables[/+] on Oct 12, 2026
  3. added
    bug
    on Oct 12, 2026
  4. bpowers commented on Oct 12, 2026

    @bpowers
    OwnerAuthor

    Closing: already fixed on main.

    The per-element graph is built from symbolic name+element references by symbolic_phase_element_order (src/simlin-engine/src/db/dep_graph.rs:896), shared by one- and many-variable groups in refine_scc_to_element_verdict (:1190). Pinned by ref_mdl_multi_variable_recurrence_simulates (tests/integration/simulate.rs:4649, ce=1,3,5 / ecc=2,4,6 against ref.dat), resolve_dt_two_member_ref_shaped_scc_resolves_interleaved (db/dep_graph_tests.rs:1856) and model_dep_graph_genuine_element_two_cycle_stays_circular (:2828, a[d]=b[d]; b[d]=a[d] still reports a cycle).

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

    bugengine

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions