Skip to content

Commit

Permalink
Mark externally used records
Browse files Browse the repository at this point in the history
- Implement marking of externally used records as needed by OpenModelica#9399.
  • Loading branch information
perost committed Sep 21, 2022
1 parent c96d24e commit 7a5f78c
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 6 deletions.
30 changes: 30 additions & 0 deletions OMCompiler/Compiler/NFFrontEnd/NFCall.mo
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ import NFFunction.TypedArg;
import NFInstNode.CachedData;
import Operator = NFOperator;
import Prefixes = NFPrefixes;
import Restriction = NFRestriction;
import SCodeUtil;
import SimplifyExp = NFSimplifyExp;
import Subscript = NFSubscript;
Expand Down Expand Up @@ -393,6 +394,11 @@ public
if MatchedFunction.isVectorized(matchedFunc) then
call := vectorizeCall(call, matchedFunc.mk, scope, info);
end if;

if Function.isExternal(func) then
updateExternalRecordArgs(args);
updateExternalRecordArgsInType(ty);
end if;
end matchTypedNormalCall;

function typeOf
Expand Down Expand Up @@ -1995,6 +2001,30 @@ public
end match;
end getNameAndArgs;

function updateExternalRecordArgs
input list<Expression> args;
algorithm
for arg in args loop
updateExternalRecordArgsInType(Expression.typeOf(arg));
end for;
end updateExternalRecordArgs;

function updateExternalRecordArgsInType
input Type ty;
protected
InstNode node;
Class cls;
Restriction res;
algorithm
if Type.isRecord(ty) then
node := Type.complexNode(ty);
cls := InstNode.getClass(node);
res := Restriction.setExternalRecord(Class.restriction(cls));
cls := Class.setRestriction(res, cls);
InstNode.updateClass(cls, node);
end if;
end updateExternalRecordArgsInType;

protected
function instNormalCall
input Absyn.ComponentRef functionName;
Expand Down
20 changes: 19 additions & 1 deletion OMCompiler/Compiler/NFFrontEnd/NFExpression.mo
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,16 @@ public
end match;
end isImpureCall;

function isExternalCall
input Expression exp;
output Boolean res;
algorithm
res := match exp
case CALL() then Call.isExternal(exp.call);
else false;
end match;
end isExternalCall;

function isCallNamed
input Expression exp;
input String name;
Expand Down Expand Up @@ -6053,7 +6063,15 @@ public
end match;
end toJSON;


function tupleElements
input Expression exp;
output list<Expression> expl;
algorithm
expl := match exp
case TUPLE() then exp.elements;
else {exp};
end match;
end tupleElements;

annotation(__OpenModelica_Interface="frontend");
end NFExpression;
12 changes: 8 additions & 4 deletions OMCompiler/Compiler/NFFrontEnd/NFInstNode.mo
Original file line number Diff line number Diff line change
Expand Up @@ -1658,6 +1658,7 @@ uniontype InstNode
local
Class cls;
ClassInf.State state;
Restriction res;

case CLASS_NODE()
algorithm
Expand All @@ -1668,9 +1669,10 @@ uniontype InstNode

else
algorithm
state := Restriction.toDAE(Class.restriction(cls), fullPath(clsNode));
res := Class.restriction(cls);
state := Restriction.toDAE(res, fullPath(clsNode));
then
DAE.Type.T_COMPLEX(state, {}, NONE(), false);
DAE.Type.T_COMPLEX(state, {}, NONE(), Restriction.isExternalRecord(res));

end match;
end match;
Expand Down Expand Up @@ -1700,6 +1702,7 @@ uniontype InstNode
Class cls;
list<DAE.Var> vars;
ClassInf.State state;
Restriction res;

case CLASS_NODE()
algorithm
Expand All @@ -1710,9 +1713,10 @@ uniontype InstNode

else
algorithm
state := Restriction.toDAE(Class.restriction(cls), fullPath(clsNode));
res := Class.restriction(cls);
state := Restriction.toDAE(res, fullPath(clsNode));
vars := ConvertDAE.makeTypeVars(clsNode);
outType := DAE.Type.T_COMPLEX(state, vars, NONE(), false);
outType := DAE.Type.T_COMPLEX(state, vars, NONE(), Restriction.isExternalRecord(res));
Pointer.update(clsNode.cls, Class.DAE_TYPE(outType));
then
outType;
Expand Down
27 changes: 26 additions & 1 deletion OMCompiler/Compiler/NFFrontEnd/NFRestriction.mo
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public

record RECORD
Boolean isOperator;
Boolean usedExternally;
end RECORD;

record RECORD_CONSTRUCTOR end RECORD_CONSTRUCTOR;
Expand All @@ -77,7 +78,7 @@ public
case SCode.Restriction.R_MODEL() then MODEL();
case SCode.Restriction.R_OPERATOR() then OPERATOR();
case SCode.Restriction.R_PACKAGE() then PACKAGE();
case SCode.Restriction.R_RECORD() then RECORD(sres.isOperator);
case SCode.Restriction.R_RECORD() then RECORD(sres.isOperator, false);
case SCode.Restriction.R_TYPE() then TYPE();
else MODEL();
end match;
Expand Down Expand Up @@ -175,6 +176,30 @@ public
end match;
end isRecord;

function isExternalRecord
input Restriction res;
output Boolean isExtRecord;
algorithm
isExtRecord := match res
case RECORD() then res.usedExternally;
else false;
end match;
end isExternalRecord;

function setExternalRecord
input output Restriction res;
algorithm
() := match res
case RECORD(usedExternally = false)
algorithm
res.usedExternally := true;
then
();

else ();
end match;
end setExternalRecord;

function isOperatorRecord
input Restriction res;
output Boolean isOpRecord;
Expand Down
7 changes: 7 additions & 0 deletions OMCompiler/Compiler/NFFrontEnd/NFType.mo
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,13 @@ public
end match;
end isComplex;

function complexNode
input Type ty;
output InstNode node;
algorithm
COMPLEX(cls = node) := ty;
end complexNode;

function isConnector
input Type ty;
output Boolean isConnector;
Expand Down
8 changes: 8 additions & 0 deletions OMCompiler/Compiler/NFFrontEnd/NFTyping.mo
Original file line number Diff line number Diff line change
Expand Up @@ -3142,6 +3142,10 @@ algorithm
end if;

checkAssignment(e1, e2, var, context, info);

if Expression.isExternalCall(e2) then
Call.updateExternalRecordArgs(Expression.tupleElements(e1));
end if;
then
Statement.ASSIGNMENT(e1, e2, ty1, st.source);

Expand Down Expand Up @@ -3322,6 +3326,10 @@ algorithm
end if;

eq := Equation.EQUALITY(e1, e2, ty, source);

if Expression.isExternalCall(e2) then
Call.updateExternalRecordArgs(Expression.tupleElements(e1));
end if;
end typeEqualityEquation;

function typeCondition
Expand Down

0 comments on commit 7a5f78c

Please sign in to comment.