Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subscripted variables are sometimes overlooked during unused variable elimination #64

Closed
chrispcampbell opened this issue Feb 2, 2021 · 0 comments · Fixed by #65 or #190
Closed
Assignees
Milestone

Comments

@chrispcampbell
Copy link
Contributor

We ran into a subtle issue with the En-ROADS model and the latest SDE where sde would fail in the case where a subscripted variable is only partially defined in the mdl file. For example:

Constant Partial 1 = 1
	~~|

Constant Partial 2 = 2
	~~|

Initial Partial[C1] =
  INITIAL( Constant Partial 1 )
	~~|

Initial Partial[C2] =
  INITIAL( Constant Partial 2 )
	~~|

Partial[C2] =
  Initial Partial[C2]
	~~|

In this case, technically Initial Partial[C1] is unused and doesn't need to be included in the compiled code, but the removeUnusedVariables function is currently conservative and doesn't eliminate unused subscript cases.

As currently written, one part of that function would skip over Initial Partial[C1] because it appears to be unreferenced, but then another part of the code would try to include all subscript variants of Initial Partial when emitting the code, and there would be a broken dependency, leading to this sort of error message:

ERROR: no var found for refId : '_constant_partial_1'
no var with refId for _constant_partial_1, referenced by _initial_partial[_c1]
ERROR: no var found for refId : '_constant_partial_1'
TypeError: Cannot read property 'varType' of undefined

The fix is to make both parts of the code equally conservative for now. Eventually we might be able to try a different approach that eliminates the unused subscripted variable, but for now, better to be safe.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment