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

Make 'constant expression' more restricted compared to full Modelica #2473

Merged
merged 5 commits into from
Mar 11, 2020

Conversation

henrikt-ma
Copy link
Collaborator

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.

…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.
Copy link
Collaborator

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.

Copy link
Collaborator Author

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.

@olivleno olivleno merged commit 09f7975 into MCP/0031 Mar 11, 2020
@HansOlsson HansOlsson added the MCP0031 Base Modelica and MLS modularization (MCP-0031) label Dec 17, 2020
@henrikt-ma henrikt-ma deleted the MCP/0031+constant-expression branch January 22, 2021 11:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
MCP0031 Base Modelica and MLS modularization (MCP-0031)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants