-
Notifications
You must be signed in to change notification settings - Fork 41
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
Make 'constant expression' more restricted compared to full Modelica #2473
Conversation
…of variability Excluding impure function calls from parameter expressions is a similar simplification as requiring functions in constant expressions to be pure constant. To me, the two changes belong together and are therefore made part of the same PR.
…expressions According to poll in today's web meeting.
|
||
### Reason for change | ||
By excluding `external` functions, translation time evaluation of constant expressions is greatly simplified. By excluding `impure` functions and `pure(…)` expressions, it is ensured that it doesn't matter whether evaluation happens at translation time or at simulation (initialization) time. | ||
|
||
Forbidding translation time evaluation of function calls in non-constant expressions generalizes the current Modelica rule for `impure` functions and makes it clear that this is not allowed regardless whether this is seen as an optimization or not. (The current Modelica specification only has a non-normative paragraph saying that performing optimizations is not allowd.) | ||
|
||
The change regarding parameter expressions could be extended to discrete-time expressions as well without loss of expressiveness due to the existing restrictions on where an impure function may be called. This could also be expressed more generally by saying that a function call expression where the callee is impure is a non-discrete-time expression. However, it was decided to not include this in the formal description of differences between Modelica and Flat Modelica in order to avoid describing changes that only clarify things without actually making a difference to semantics. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see how this is true for discrete-time expressions. You are allowed to call impure functions in when-clauses, and the result is a discrete-time expressions. That is sort of the intended way to communicate with external systems.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is true because the rule of capping the variability inside when-clauses to discrete-time still applies.
The goal of this change is to ensure that a constant expression can be evaluated at translation time.
The proposed way of achieving this is to identify a special kind of pure functions that are the ones that can be called in a constant expression.