Skip to content
This repository was archived by the owner on May 18, 2019. It is now read-only.

Commit e8e2216

Browse files
sjoelundOpenModelica-Hudson
authored andcommitted
Remove equations like "{} = f(...)"
This should not be done, but breaks the Chemical library if we don't and this was the previous behaviour of the compiler. Should be fixed properly by patching index reduction, sorting/matching, or adding assertions for lhs/rhs that the expressions evaluate to zero-dimension (or at least that f(...) does not cause run-time errors).
1 parent 545461b commit e8e2216

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

Compiler/BackEnd/RemoveSimpleEquations.mo

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,11 +1150,33 @@ protected
11501150
list<list<DAE.Subscript>> subslst;
11511151
list<DAE.Exp> elst1, elst2;
11521152
Boolean hasInlineAfterIndexReduction, expandLhs, expandRhs;
1153+
DAE.ElementSource source;
1154+
BackendDAE.EquationAttributes attr;
1155+
BackendDAE.Equation eq;
11531156
algorithm
11541157
dims := Expression.arrayDimension(ty);
11551158
ds := Expression.dimensionsSizes(dims);
11561159
subslst := List.map(ds, Expression.dimensionSizeSubscripts);
11571160
subslst := Expression.rangesToSubscripts(subslst);
1161+
if listEmpty(subslst) then
1162+
(source,attr) := eqnAttributes;
1163+
outTpl := inTpl;
1164+
return;
1165+
/* TODO: Shouldn't we generate some sort of assertion for the lhs/rhs actually being of zero dimension or not throwing errors at run-time? */
1166+
for e in {lhs,rhs} loop
1167+
if Expression.isEvaluatedConst(e) then
1168+
continue;
1169+
end if;
1170+
eq := BackendDAE.WHEN_EQUATION(0, BackendDAE.WHEN_STMTS(
1171+
DAE.BCONST(false),
1172+
{BackendDAE.ASSERT(DAE.BCONST(false), DAE.SCONST("Failed assertion exp is 0"), DAE.ASSERTIONLEVEL_ERROR, source)},
1173+
NONE()
1174+
), source, attr);
1175+
outTpl := simpleEquationsFinder(eq, outTpl);
1176+
end for;
1177+
return;
1178+
/* End TODO. Note: The above code does not execute */
1179+
end if;
11581180
(,hasInlineAfterIndexReduction) := Expression.traverseExpTopDown(lhs, Expression.findCallIsInlineAfterIndexReduction, false);
11591181
(,hasInlineAfterIndexReduction) := Expression.traverseExpTopDown(rhs, Expression.findCallIsInlineAfterIndexReduction, hasInlineAfterIndexReduction);
11601182
(elst1,expandLhs) := List.mapFold(subslst, function Expression.applyExpSubscriptsFoldCheckSimplify(exp=lhs), false);
@@ -1163,6 +1185,9 @@ algorithm
11631185
// If inlining after index reduction or i, we need to expand equations to pass sorting+matching
11641186
// Note: We *should* be looking for the derivative annotation here, but it's not available directly
11651187
// and better would be if sorting+matching could expand/split equations when necessary
1188+
if false and not (expandLhs and expandRhs) then
1189+
print(getInstanceName() + " not expanding " + ExpressionDump.printExpStr(lhs) + " = " + ExpressionDump.printExpStr(rhs) + "\n");
1190+
end if;
11661191
true := expandLhs and expandRhs "Do not expand equation if it doesn't help with anything... Like x=f(...); => x[1]=f()[1], ..., x[n]=f()[n]";
11671192
else
11681193
end if;

0 commit comments

Comments
 (0)