You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
engine: RANK builtin not supported in VM or interpreter #359
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
Implement RANK directly in both VM and interpreter using array sorting/ranking logic
Use VM "extern calls" to invoke interpreter logic from within the VM (similar pattern to other complex builtins)
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