Skip to content

engine: RANK builtin not supported in VM or interpreter #359

Closed

Description

@bpowers

Problem

The RANK builtin function is not implemented in either execution path:

  • VM bytecode compiler (src/simlin-engine/src/compiler/codegen.rs): Returns TodoArrayBuiltin error when RANK is encountered
  • Interpreter (src/simlin-engine/src/interpreter.rs): Contains unreachable!() for RANK

This means models using RANK cannot execute in either the VM or interpreter backends.

Current State

  • RANK is fully parsed and type-checked (src/simlin-engine/src/builtins.rs, src/simlin-engine/src/units_infer.rs)
  • Unit inference correctly handles RANK semantics: RANK(A, SIZE) returns the index of the maximum value in array A; RANK(A, N, B) returns the index of the Nth smallest value in A, with ties broken by array B
  • The AST and expression types support RANK in all three compilation stages (expr1, expr2, expr3)
  • No test models currently use RANK, so the absence is not caught

Why it matters

  • Completeness: RANK is a standard array function in Vensim and Stella; builtin parity requires full support
  • User models: Any user model with RANK equations will fail to compile
  • Test coverage: The ignored test count (36 in simlin-engine) may grow if RANK-using models are added

Component(s) affected

  • src/simlin-engine/src/interpreter.rs (would need implementation)
  • src/simlin-engine/src/compiler/codegen.rs (would need bytecode emission)
  • src/simlin-engine/src/bytecode.rs (may need new opcodes if bytecode approach is taken)
  • src/simlin-engine/src/vm.rs (may need dispatch handlers)

Possible approaches

  1. Implement RANK directly in both VM and interpreter using array sorting/ranking logic
  2. Use VM "extern calls" to invoke interpreter logic from within the VM (similar pattern to other complex builtins)
  3. Add a test model that uses RANK to catch future regressions

Context

Identified during design work for issue #355 (vector operations and ALLOCATE AVAILABLE VM support). Related to overall builtin parity work in MDL full compatibility.

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