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

[NF] Fix function variability. #6733

Merged
merged 1 commit into from Sep 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 2 additions & 5 deletions OMCompiler/Compiler/NFFrontEnd/NFCall.mo
Expand Up @@ -315,11 +315,8 @@ public
typed_args := matchedFunc.args;

args := {};
// if is impure, make it a parameter expression
// see https://trac.openmodelica.org/OpenModelica/ticket/5133
var := if Function.isImpure(func) or Function.isOMImpure(func)
then Variability.PARAMETER
else Variability.CONSTANT;
var := Variability.CONSTANT;

for a in typed_args loop
(arg_exp, _, arg_var) := a;
args := arg_exp :: args;
Expand Down
16 changes: 16 additions & 0 deletions OMCompiler/Compiler/NFFrontEnd/NFExpression.mo
Expand Up @@ -4787,5 +4787,21 @@ public
end if;
end foldReduction2;

function isPure
input Expression exp;
output Boolean isPure;
algorithm
isPure := match exp
case Expression.CREF() then not ComponentRef.isIterator(exp.cref);
case Expression.CALL()
then match AbsynUtil.pathFirstIdent(Call.functionName(exp.call))
case "Connections" then false;
case "cardinality" then false;
else not Call.isImpure(exp.call);
end match;
else true;
end match;
end isPure;

annotation(__OpenModelica_Interface="frontend");
end NFExpression;
4 changes: 3 additions & 1 deletion OMCompiler/Compiler/NFFrontEnd/NFFlatten.mo
Expand Up @@ -1141,7 +1141,9 @@ algorithm

// Evaluate structural conditions.
if var <= Variability.STRUCTURAL_PARAMETER then
cond := Ceval.evalExp(cond, target);
if Expression.isPure(cond) then
cond := Ceval.evalExp(cond, target);
end if;

// Conditions in an if-equation that contains connects must be possible to evaluate.
if not Expression.isBoolean(cond) and has_connect then
Expand Down