From 65207b6f637275165bbfa0c51b7c198423e4a0dc Mon Sep 17 00:00:00 2001 From: phannebohm Date: Tue, 20 Feb 2024 16:46:14 +0100 Subject: [PATCH] [NB] Use simplifyDump everywhere (#12012) --- OMCompiler/Compiler/NBackEnd/Classes/NBEquation.mo | 6 +++--- .../NBackEnd/Modules/2_Pre/NBDetectStates.mo | 2 +- .../Compiler/NBackEnd/Modules/3_Post/NBSolve.mo | 2 +- OMCompiler/Compiler/NBackEnd/Util/NBDifferentiate.mo | 4 ++-- OMCompiler/Compiler/NBackEnd/Util/NBReplacements.mo | 2 +- OMCompiler/Compiler/NBackEnd/Util/NBSlice.mo | 2 +- OMCompiler/Compiler/NFFrontEnd/NFSimplifyExp.mo | 12 ++++++------ OMCompiler/Compiler/NFFrontEnd/NFSimplifyModel.mo | 2 +- 8 files changed, 16 insertions(+), 16 deletions(-) diff --git a/OMCompiler/Compiler/NBackEnd/Classes/NBEquation.mo b/OMCompiler/Compiler/NBackEnd/Classes/NBEquation.mo index 4217d750338..cd620510197 100644 --- a/OMCompiler/Compiler/NBackEnd/Classes/NBEquation.mo +++ b/OMCompiler/Compiler/NBackEnd/Classes/NBEquation.mo @@ -548,7 +548,7 @@ public Expression.INTEGER(1)}, inv_arguments = {}, operator = Operator.makeAdd(ty)); - sub_exp := SimplifyExp.simplify(sub_exp, true); + sub_exp := SimplifyExp.simplifyDump(sub_exp, true, getInstanceName()); sub_exp := Expression.CALL(Call.makeTypedCall(NFBuiltinFuncs.INTEGER_REAL, {sub_exp}, Variability.DISCRETE, Purity.PURE)); end if; then Subscript.INDEX(sub_exp); @@ -1518,7 +1518,7 @@ public Error.addMessage(Error.INTERNAL_ERROR,{getInstanceName() + " failed for:\n" + toString(eqn)}); then fail(); end match; - exp := SimplifyExp.simplify(exp, true); + exp := SimplifyExp.simplifyDump(exp, true, getInstanceName()); end getResidualExp; function getType @@ -2054,7 +2054,7 @@ public equality_exp := Expression.RELATION( exp1 = Expression.fromCref(cref), operator = Operator.OPERATOR(ComponentRef.nodeType(cref), NFOperator.Op.NEQUAL), - exp2 = SimplifyExp.simplify(exp, true) + exp2 = SimplifyExp.simplifyDump(exp, true, getInstanceName()) ); end makeInequality; diff --git a/OMCompiler/Compiler/NBackEnd/Modules/2_Pre/NBDetectStates.mo b/OMCompiler/Compiler/NBackEnd/Modules/2_Pre/NBDetectStates.mo index f9243e6c222..89ebad82bd1 100644 --- a/OMCompiler/Compiler/NBackEnd/Modules/2_Pre/NBDetectStates.mo +++ b/OMCompiler/Compiler/NBackEnd/Modules/2_Pre/NBDetectStates.mo @@ -274,7 +274,7 @@ protected else // one or less algebraic variables > differentiate the expression (returnExp, oDiffArgs) := Differentiate.differentiateExpression(arg, diffArgs); - returnExp := SimplifyExp.simplify(returnExp, true); + returnExp := SimplifyExp.simplifyDump(returnExp, true, getInstanceName()); if listLength(oDiffArgs.new_vars) == 1 then der_var := List.first(oDiffArgs.new_vars); Pointer.update(acc_derivatives, der_var :: Pointer.access(acc_derivatives)); diff --git a/OMCompiler/Compiler/NBackEnd/Modules/3_Post/NBSolve.mo b/OMCompiler/Compiler/NBackEnd/Modules/3_Post/NBSolve.mo index 43b70593d91..271ce2b648e 100644 --- a/OMCompiler/Compiler/NBackEnd/Modules/3_Post/NBSolve.mo +++ b/OMCompiler/Compiler/NBackEnd/Modules/3_Post/NBSolve.mo @@ -527,7 +527,7 @@ public scalarized = false ); (derivative, diffArgs) := Differentiate.differentiateExpressionDump(residual, diffArgs, getInstanceName()); - derivative := SimplifyExp.simplify(derivative, true); + derivative := SimplifyExp.simplifyDump(derivative, true, getInstanceName()); if Expression.isZero(derivative) then invertRelation := false; diff --git a/OMCompiler/Compiler/NBackEnd/Util/NBDifferentiate.mo b/OMCompiler/Compiler/NBackEnd/Util/NBDifferentiate.mo index 12a1b551cb0..302c51ff32d 100644 --- a/OMCompiler/Compiler/NBackEnd/Util/NBDifferentiate.mo +++ b/OMCompiler/Compiler/NBackEnd/Util/NBDifferentiate.mo @@ -858,7 +858,7 @@ public // d delta/dz (ret2, diffArguments) := differentiateExpression(arg2, diffArguments); // dt/dz - d delta/dz - ret2 := SimplifyExp.simplify(Expression.MULTARY({ret1}, {ret2}, addOp)); + ret2 := SimplifyExp.simplifyDump(Expression.MULTARY({ret1}, {ret2}, addOp), true, getInstanceName()); if Expression.isZero(ret2) then ret := Expression.makeZero(Expression.typeOf(arg1)); else @@ -1376,7 +1376,7 @@ public (lhs, diffArguments) := differentiateExpression(diff_stmt.lhs, diffArguments); (rhs, diffArguments) := differentiateExpression(diff_stmt.rhs, diffArguments); diff_stmt.lhs := lhs; - diff_stmt.rhs := SimplifyExp.simplify(rhs, true); + diff_stmt.rhs := SimplifyExp.simplifyDump(rhs, true, getInstanceName()); then {diff_stmt, stmt}; // II. delegate differentiation to body and only return differentiated statement diff --git a/OMCompiler/Compiler/NBackEnd/Util/NBReplacements.mo b/OMCompiler/Compiler/NBackEnd/Util/NBReplacements.mo index e49b5db320d..019e2089186 100644 --- a/OMCompiler/Compiler/NBackEnd/Util/NBReplacements.mo +++ b/OMCompiler/Compiler/NBackEnd/Util/NBReplacements.mo @@ -124,7 +124,7 @@ public replace_exp := Equation.getRHS(solvedEq); replace_exp := Expression.map(replace_exp, function applySimpleExp(replacements = replacements)); // add the new replacement rule - UnorderedMap.add(varName, SimplifyExp.simplify(replace_exp, true), replacements); + UnorderedMap.add(varName, SimplifyExp.simplifyDump(replace_exp, true, getInstanceName()), replacements); else Error.addMessage(Error.INTERNAL_ERROR,{getInstanceName() + " failed because strong component cannot be solved explicitely: " + StrongComponent.toString(comp)}); fail(); diff --git a/OMCompiler/Compiler/NBackEnd/Util/NBSlice.mo b/OMCompiler/Compiler/NBackEnd/Util/NBSlice.mo index 0b68ad7bcc3..298538e2b47 100644 --- a/OMCompiler/Compiler/NBackEnd/Util/NBSlice.mo +++ b/OMCompiler/Compiler/NBackEnd/Util/NBSlice.mo @@ -1097,7 +1097,7 @@ protected list values; algorithm replaced := list(Expression.map(sub, function Replacements.applySimpleExp(replacements = replacements)) for sub in subs); - values := list(Expression.integerValue(SimplifyExp.simplify(rep, true)) for rep in replaced); + values := list(Expression.integerValue(SimplifyExp.simplifyDump(rep, true, getInstanceName())) for rep in replaced); ranges := List.zip(sizes, values); end resolveDimensionsSubscripts; diff --git a/OMCompiler/Compiler/NFFrontEnd/NFSimplifyExp.mo b/OMCompiler/Compiler/NFFrontEnd/NFSimplifyExp.mo index a2ecb8af4cd..5dd16a0873d 100644 --- a/OMCompiler/Compiler/NFFrontEnd/NFSimplifyExp.mo +++ b/OMCompiler/Compiler/NFFrontEnd/NFSimplifyExp.mo @@ -62,12 +62,12 @@ public function simplifyDump "wrapper function for simplification to allow dumping before and afterwards" input Expression exp; - input Boolean backend; + input Boolean includeScope; output Expression res; input String name = ""; input String indent = ""; algorithm - res := simplify(exp, backend); + res := simplify(exp, includeScope); if Flags.isSet(Flags.DUMP_SIMPLIFY) and not Expression.isEqual(exp, res) then print(indent + "### dumpSimplify | " + name + " ###\n"); print(indent + "[BEFORE] " + Expression.toString(exp) + "\n"); @@ -77,20 +77,20 @@ end simplifyDump; function simplify input output Expression exp; - input Boolean backend = false; + input Boolean includeScope = false; algorithm exp := match exp case Expression.CREF() algorithm exp.cref := ComponentRef.simplifySubscripts(exp.cref); - exp.ty := ComponentRef.getSubscriptedType(exp.cref, backend); + exp.ty := ComponentRef.getSubscriptedType(exp.cref, includeScope); then exp; case Expression.ARRAY() guard not exp.literal algorithm - exp.elements := Array.map(exp.elements, function simplify(backend = false)); + exp.elements := Array.map(exp.elements, function simplify(includeScope = false)); then exp; @@ -636,7 +636,7 @@ algorithm end for; outExp := Expression.foldReduction(simplify(exp), listReverseInPlace(iters), - default_exp, function simplify(backend = false), function simplifyBinaryOp(op = op)); + default_exp, function simplify(includeScope = false), function simplifyBinaryOp(op = op)); end simplifyReduction2; function simplifySize diff --git a/OMCompiler/Compiler/NFFrontEnd/NFSimplifyModel.mo b/OMCompiler/Compiler/NFFrontEnd/NFSimplifyModel.mo index 2254922b168..46de8e0c57d 100644 --- a/OMCompiler/Compiler/NFFrontEnd/NFSimplifyModel.mo +++ b/OMCompiler/Compiler/NFFrontEnd/NFSimplifyModel.mo @@ -603,7 +603,7 @@ protected algorithm if not Function.isSimplified(func) then Function.markSimplified(func); - Function.mapExp(func, function SimplifyExp.simplify(backend = false), mapBody = false); + Function.mapExp(func, function SimplifyExp.simplify(includeScope = false), mapBody = false); cls := InstNode.getClass(func.node); () := match cls