Skip to content

Commit

Permalink
[NF] Add workaround for ModelicaError purity.
Browse files Browse the repository at this point in the history
- Set ModelicaError external call to be pure to temporarily work around
  issues with function purity.
  • Loading branch information
perost committed Jul 6, 2020
1 parent 30abd44 commit d15abc5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
16 changes: 16 additions & 0 deletions OMCompiler/Compiler/FrontEnd/SCodeUtil.mo
Expand Up @@ -5776,5 +5776,21 @@ algorithm
end match;
end mergeSCodeMods;

function hasNamedExternalCall
input String name;
input SCode.ClassDef def;
output Boolean hasCall;
algorithm
hasCall := match def
local
String fn_name;

case SCode.PARTS(externalDecl = SOME(SCode.EXTERNALDECL(funcName = SOME(fn_name))))
then fn_name == name;
case SCode.CLASS_EXTENDS() then hasNamedExternalCall(name, def.composition);
else false;
end match;
end hasNamedExternalCall;

annotation(__OpenModelica_Interface="frontend");
end SCodeUtil;
6 changes: 5 additions & 1 deletion OMCompiler/Compiler/NFFrontEnd/NFFunction.mo
Expand Up @@ -2146,7 +2146,7 @@ protected
DAE.InlineType inline_ty;
DAE.FunctionBuiltin builtin;

// External function.
// External builtin function.
case SCode.FunctionRestriction.FR_EXTERNAL_FUNCTION(is_impure)
algorithm
in_params := list(InstNode.name(i) for i in inputs);
Expand Down Expand Up @@ -2194,6 +2194,10 @@ protected
Config.languageStandardAtLeast(Config.LanguageStandard.'3.3') or
not listEmpty(outputs)) or
SCodeUtil.commentHasBooleanNamedAnnotation(cmt, "__ModelicaAssociation_Impure");

if SCodeUtil.hasNamedExternalCall("ModelicaError", SCodeUtil.getClassDef(def)) then
is_impure := false;
end if;
then
DAE.FUNCTION_ATTRIBUTES(inline_ty, hasOMPure(cmt), is_impure, is_partial,
getBuiltin(def), DAE.FP_NON_PARALLEL());
Expand Down

0 comments on commit d15abc5

Please sign in to comment.