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

Commit 0695240

Browse files
perostOpenModelica-Hudson
authored andcommitted
[NF] Various fixes.
- 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]: - #2852
1 parent 43bdde4 commit 0695240

File tree

4 files changed

+18
-20
lines changed

4 files changed

+18
-20
lines changed

Compiler/FrontEnd/Expression.mo

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12051,6 +12051,7 @@ public function expandExpression
1205112051
"
1205212052

1205312053
input DAE.Exp inExp;
12054+
input Boolean expandRecord;
1205412055
output list<DAE.Exp> outExps;
1205512056
algorithm
1205612057
(outExps) := match (inExp)
@@ -12064,22 +12065,22 @@ algorithm
1206412065

1206512066
case (DAE.CREF(cr,_))
1206612067
algorithm
12067-
crlst := ComponentReference.expandCref(cr,true);
12068+
crlst := ComponentReference.expandCref(cr, expandRecord);
1206812069
outExps := List.map(crlst, crefToExp);
1206912070
then outExps;
1207012071

1207112072
case (DAE.UNARY(operator=DAE.UMINUS()))
1207212073
algorithm
12073-
expl := list(DAE.UNARY(inExp.operator, exp) for exp in expandExpression(inExp.exp));
12074+
expl := list(DAE.UNARY(inExp.operator, exp) for exp in expandExpression(inExp.exp, expandRecord));
1207412075
then expl;
1207512076

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

1209812099
case DAE.ARRAY(_,_,expl)
1209912100
algorithm
12100-
expl := List.mapFlat(expl,expandExpression);
12101+
expl := List.mapFlat(expl, function expandExpression(expandRecord = expandRecord));
1210112102
then expl;
1210212103

1210312104
else
@@ -12159,7 +12160,7 @@ algorithm
1215912160
equation
1216012161
i = dimensionSize(id);
1216112162
j = dimensionSize(jd);
12162-
expl = expandExpression(inExp);
12163+
expl = expandExpression(inExp, expandRecord = false);
1216312164
mat = makeMatrix(expl, j);
1216412165
e = DAE.MATRIX(ty, i, mat);
1216512166
then
@@ -12168,7 +12169,7 @@ algorithm
1216812169
// CASE for Array
1216912170
case DAE.CREF(ty=ty as DAE.T_ARRAY())
1217012171
equation
12171-
expl = expandExpression(inExp);
12172+
expl = expandExpression(inExp, expandRecord = false);
1217212173
e = DAE.ARRAY(ty, true, expl);
1217312174
then
1217412175
(e, true);

Compiler/NFFrontEnd/NFCeval.mo

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,10 @@ algorithm
519519
algorithm
520520
exp := makeRecordBindingExp(component.classInst, rec_node, component.ty, cref);
521521
binding := Binding.CEVAL_BINDING(exp, {node});
522-
InstNode.updateComponent(Component.setBinding(binding, component), node);
522+
523+
if not ComponentRef.hasSubscripts(cref) then
524+
InstNode.updateComponent(Component.setBinding(binding, component), node);
525+
end if;
523526
then
524527
binding;
525528

@@ -530,7 +533,10 @@ algorithm
530533
exp := makeRecordBindingExp(component.classInst, rec_node, component.ty, cref);
531534
exp := splitRecordArrayExp(exp);
532535
binding := Binding.CEVAL_BINDING(exp, {node});
533-
InstNode.updateComponent(Component.setBinding(binding, component), node);
536+
537+
if not ComponentRef.hasSubscripts(cref) then
538+
InstNode.updateComponent(Component.setBinding(binding, component), node);
539+
end if;
534540
then
535541
binding;
536542

Compiler/NFFrontEnd/NFOCConnectionGraph.mo

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,6 @@ protected
164164
list<Connector> cl1, cl2, lhsl, rhsl;
165165
Equation replaceEq;
166166
Expression exp;
167-
Boolean added = false;
168167
algorithm
169168
// go over all equations, connect, Connection.branch
170169
for eq in flatModel.equations loop
@@ -173,7 +172,6 @@ algorithm
173172
rhs = Expression.CREF(ty = ty2, cref = rhs),
174173
source = source)
175174
algorithm
176-
added := false;
177175
if not (ComponentRef.isDeleted(lhs) or ComponentRef.isDeleted(rhs))
178176
then
179177
cl1 := NFConnections.makeConnectors(lhs, ty1, source);
@@ -193,19 +191,12 @@ algorithm
193191
lhs := getOverconstrainedCref(lhs);
194192
rhs := getOverconstrainedCref(rhs);
195193

196-
lhs := ComponentRef.stripSubscripts(lhs);
197-
rhs := ComponentRef.stripSubscripts(rhs);
198-
199194
eq.broken := generateEqualityConstraintEquation(eq.lhs, ty1, eq.rhs, ty2, ExpOrigin.EQUATION, source);
200195
graph := addConnection(graph, lhs, rhs, eq.broken);
201-
added := true;
202196
break;
203197
end if;
204198
end if;
205199
end for;
206-
if added then
207-
break;
208-
end if;
209200
end for;
210201
end if;
211202
then

Compiler/SimCode/SimCodeUtil.mo

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2424,9 +2424,9 @@ algorithm
24242424

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

0 commit comments

Comments
 (0)