Skip to content

compile_implicit_var_fragment drops composite module·output deps #301

Closed

Description

@bpowers

Problem

In src/simlin-engine/src/db.rs, the compile_implicit_var_fragment function (around lines 4041-4092) only resolves dependency names that exactly match entries in source_vars or implicit_info. Composite deps like module·output (using the middle-dot separator U+00B7) are silently dropped because they don't match either lookup.

In contrast, compile_var_fragment (lines 3344-3418) has explicit handling for composite module-output deps:

  1. Strips the leading · prefix (parent model reference in XMILE)
  2. Recognizes deps containing · as module references
  3. Looks up the module source variable
  4. Builds a Variable::Module with resolved inputs
  5. Adds extra_module_refs and extra_submodels entries for proper metadata resolution

The implicit var function skips all of this -- any dep name containing · falls through both source_vars.get() and implicit_info.contains_key() without matching, and is silently ignored.

Impact

If an implicit variable generated by SMOOTH/DELAY/TREND builtin expansion depends on a module output (e.g., SMTH1(some_module.output, delay_time)), the required module metadata will be missing from the mini-Module context used for compilation. This could cause:

  • Offset resolution failures during bytecode compilation
  • Incorrect compilation producing wrong simulation results
  • Silent data corruption where the dep resolves to the wrong offset

This is a correctness bug in the monolithic compilation path, not an incremental pipeline gap. It affects the existing, production compilation pipeline.

Current State

No existing test models exercise this path -- all SMOOTH/DELAY test models use plain scalar deps. This is a valid pattern in real-world SD models that needs to work correctly.

Affected Component

  • src/simlin-engine/src/db.rs, function compile_implicit_var_fragment

Suggested Fix

Add composite dep handling to compile_implicit_var_fragment matching the pattern in compile_var_fragment (lines 3344-3418):

  1. Strip leading · prefix from dep names
  2. Check for · in the effective name to identify module references
  3. Look up the referenced module variable in source_vars
  4. Build a Variable::Module stub with resolved inputs
  5. Add extra_module_refs and extra_submodels entries
  6. Add a test model with SMOOTH(module.output, dt) to cover this path

Related

Context

Identified during code review of the incremental compilation path (incremental-compilation-followup branch).

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