Skip to content

Commit

Permalink
[NF] Various fixes.
Browse files Browse the repository at this point in the history
- Don't cache bindings created in NFCeval.makeComponentBinding if the cref
  has subscripts, it might not be safe.
- Don't ignore subscripts in connections when building the connection
  graph.
- Don't expand record in Expression.extendArrExp. Doing so causes record
  crefs to be expanded into arrays of record fields, which causes
  BackendVarTransform to make invalid replacements.

Belonging to [master]:
  - OpenModelica/OMCompiler#2852
  • Loading branch information
perost authored and OpenModelica-Hudson committed Jan 9, 2019
1 parent 43bdde4 commit 0695240
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 20 deletions.
15 changes: 8 additions & 7 deletions Compiler/FrontEnd/Expression.mo
Expand Up @@ -12051,6 +12051,7 @@ public function expandExpression
"

input DAE.Exp inExp;
input Boolean expandRecord;
output list<DAE.Exp> outExps;
algorithm
(outExps) := match (inExp)
Expand All @@ -12064,22 +12065,22 @@ algorithm

case (DAE.CREF(cr,_))
algorithm
crlst := ComponentReference.expandCref(cr,true);
crlst := ComponentReference.expandCref(cr, expandRecord);
outExps := List.map(crlst, crefToExp);
then outExps;

case (DAE.UNARY(operator=DAE.UMINUS()))
algorithm
expl := list(DAE.UNARY(inExp.operator, exp) for exp in expandExpression(inExp.exp));
expl := list(DAE.UNARY(inExp.operator, exp) for exp in expandExpression(inExp.exp, expandRecord));
then expl;

case (DAE.BINARY())
algorithm
// TODO! FIXME! we should change the type in the operator,
// i.e. use Types.unliftArray on the type inside the operator
op := inExp.operator;
expl1 := expandExpression(inExp.exp1);
expl2 := expandExpression(inExp.exp2);
expl1 := expandExpression(inExp.exp1, expandRecord);
expl2 := expandExpression(inExp.exp2, expandRecord);
// TODO! FIXME! maybe we should also support (array op scalar)
// make sure the lists have the same length
if listLength(expl1) <> listLength(expl2) then
Expand All @@ -12097,7 +12098,7 @@ algorithm

case DAE.ARRAY(_,_,expl)
algorithm
expl := List.mapFlat(expl,expandExpression);
expl := List.mapFlat(expl, function expandExpression(expandRecord = expandRecord));
then expl;

else
Expand Down Expand Up @@ -12159,7 +12160,7 @@ algorithm
equation
i = dimensionSize(id);
j = dimensionSize(jd);
expl = expandExpression(inExp);
expl = expandExpression(inExp, expandRecord = false);
mat = makeMatrix(expl, j);
e = DAE.MATRIX(ty, i, mat);
then
Expand All @@ -12168,7 +12169,7 @@ algorithm
// CASE for Array
case DAE.CREF(ty=ty as DAE.T_ARRAY())
equation
expl = expandExpression(inExp);
expl = expandExpression(inExp, expandRecord = false);
e = DAE.ARRAY(ty, true, expl);
then
(e, true);
Expand Down
10 changes: 8 additions & 2 deletions Compiler/NFFrontEnd/NFCeval.mo
Expand Up @@ -519,7 +519,10 @@ algorithm
algorithm
exp := makeRecordBindingExp(component.classInst, rec_node, component.ty, cref);
binding := Binding.CEVAL_BINDING(exp, {node});
InstNode.updateComponent(Component.setBinding(binding, component), node);

if not ComponentRef.hasSubscripts(cref) then
InstNode.updateComponent(Component.setBinding(binding, component), node);
end if;
then
binding;

Expand All @@ -530,7 +533,10 @@ algorithm
exp := makeRecordBindingExp(component.classInst, rec_node, component.ty, cref);
exp := splitRecordArrayExp(exp);
binding := Binding.CEVAL_BINDING(exp, {node});
InstNode.updateComponent(Component.setBinding(binding, component), node);

if not ComponentRef.hasSubscripts(cref) then
InstNode.updateComponent(Component.setBinding(binding, component), node);
end if;
then
binding;

Expand Down
9 changes: 0 additions & 9 deletions Compiler/NFFrontEnd/NFOCConnectionGraph.mo
Expand Up @@ -164,7 +164,6 @@ protected
list<Connector> cl1, cl2, lhsl, rhsl;
Equation replaceEq;
Expression exp;
Boolean added = false;
algorithm
// go over all equations, connect, Connection.branch
for eq in flatModel.equations loop
Expand All @@ -173,7 +172,6 @@ algorithm
rhs = Expression.CREF(ty = ty2, cref = rhs),
source = source)
algorithm
added := false;
if not (ComponentRef.isDeleted(lhs) or ComponentRef.isDeleted(rhs))
then
cl1 := NFConnections.makeConnectors(lhs, ty1, source);
Expand All @@ -193,19 +191,12 @@ algorithm
lhs := getOverconstrainedCref(lhs);
rhs := getOverconstrainedCref(rhs);

lhs := ComponentRef.stripSubscripts(lhs);
rhs := ComponentRef.stripSubscripts(rhs);

eq.broken := generateEqualityConstraintEquation(eq.lhs, ty1, eq.rhs, ty2, ExpOrigin.EQUATION, source);
graph := addConnection(graph, lhs, rhs, eq.broken);
added := true;
break;
end if;
end if;
end for;
if added then
break;
end if;
end for;
end if;
then
Expand Down
4 changes: 2 additions & 2 deletions Compiler/SimCode/SimCodeUtil.mo
Expand Up @@ -2424,9 +2424,9 @@ algorithm

// Record()-tmp = 0
/* Expand the tmp record and any arrays */
e1lst = Expression.expandExpression(e1_1);
e1lst = Expression.expandExpression(e1_1, expandRecord = true);
/* Expand the varLst. Each var might be an array or record. */
e2lst = List.mapFlat(e2lst, Expression.expandExpression);
e2lst = List.mapFlat(e2lst, function Expression.expandExpression(expandRecord = true));
/* pair each of the expanded expressions to coressponding one*/
exptl = List.threadTuple(e1lst, e2lst);
/* Create residual equations for each pair*/
Expand Down

0 comments on commit 0695240

Please sign in to comment.