Skip to content

Commit

Permalink
Fix non-scalarized handling of stream operators (#10908)
Browse files Browse the repository at this point in the history
- Unroll equations that contain stream operators.
  • Loading branch information
perost committed Jun 30, 2023
1 parent 02127e9 commit 5ddd573
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 1 deletion.
18 changes: 18 additions & 0 deletions OMCompiler/Compiler/NFFrontEnd/NFCall.mo
Expand Up @@ -2076,6 +2076,24 @@ public
end match;
end isConnectionsOperator;

function isStreamOperator
input Call call;
output Boolean isOp;
protected
String name;
algorithm
isOp := match call
case TYPED_CALL()
guard Function.isBuiltin(call.fn)
algorithm
name := functionNameFirst(call);
then
name == "actualStream" or name == "inStream";

else false;
end match;
end isStreamOperator;

protected
function instNormalCall
input Absyn.ComponentRef functionName;
Expand Down
17 changes: 16 additions & 1 deletion OMCompiler/Compiler/NFFrontEnd/NFFlatten.mo
Expand Up @@ -1817,6 +1817,17 @@ function splitForLoop2
input list<Equation> forBody;
output list<Equation> connects = {};
output list<Equation> nonConnects = {};
protected
function is_conn_operator
input Expression exp;
output Boolean res;
algorithm
res := match exp
case Expression.CALL()
then Call.isConnectionsOperator(exp.call) or Call.isStreamOperator(exp.call);
else false;
end match;
end is_conn_operator;
protected
list<Equation> conns, nconns;
algorithm
Expand Down Expand Up @@ -1844,7 +1855,11 @@ algorithm

else
algorithm
nonConnects := eq :: nonConnects;
if Equation.containsExp(eq, function Expression.contains(func = is_conn_operator)) then
connects := eq :: connects;
else
nonConnects := eq :: nonConnects;
end if;
then
();

Expand Down
1 change: 1 addition & 0 deletions testsuite/flattening/modelica/scodeinst/Makefile
Expand Up @@ -859,6 +859,7 @@ NonexistentRedeclareModifier2.mo \
NoScalarize1.mo \
NoScalarize2.mo \
NoScalarizeConnect1.mo \
NoScalarizeConnect2.mo \
OperationAdd1.mo \
OperationAddEW1.mo \
OperationDiv1.mo \
Expand Down
36 changes: 36 additions & 0 deletions testsuite/flattening/modelica/scodeinst/NoScalarizeConnect2.mo
@@ -0,0 +1,36 @@
// name: NoScalarizeConnect2
// keywords:
// status: correct
// cflags: -d=newInst --newBackend
//

connector C
Real e;
flow Real f;
stream Real s;
end C;

model NoScalarizeConnect2
C c[3];
Real x;
equation
for i in 1:3 loop
x = actualStream(c[i].s);
end for;
end NoScalarizeConnect2;

// Result:
// class NoScalarizeConnect2
// Real[3] c.s;
// Real[3] c.f;
// Real[3] c.e;
// Real x;
// equation
// for $i1 in 1:3 loop
// c[$i1].f = 0.0;
// end for;
// x = c[1].s;
// x = c[2].s;
// x = c[3].s;
// end NoScalarizeConnect2;
// endResult

0 comments on commit 5ddd573

Please sign in to comment.