Skip to content

Commit a51a08b

Browse files
authored
Mark externally used records (#9408)
- Implement marking of externally used records as needed by #9399.
1 parent c96d24e commit a51a08b

File tree

6 files changed

+98
-6
lines changed

6 files changed

+98
-6
lines changed

OMCompiler/Compiler/NFFrontEnd/NFCall.mo

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ import NFFunction.TypedArg;
6565
import NFInstNode.CachedData;
6666
import Operator = NFOperator;
6767
import Prefixes = NFPrefixes;
68+
import Restriction = NFRestriction;
6869
import SCodeUtil;
6970
import SimplifyExp = NFSimplifyExp;
7071
import Subscript = NFSubscript;
@@ -393,6 +394,11 @@ public
393394
if MatchedFunction.isVectorized(matchedFunc) then
394395
call := vectorizeCall(call, matchedFunc.mk, scope, info);
395396
end if;
397+
398+
if Function.isExternal(func) then
399+
updateExternalRecordArgs(args);
400+
updateExternalRecordArgsInType(ty);
401+
end if;
396402
end matchTypedNormalCall;
397403

398404
function typeOf
@@ -1995,6 +2001,30 @@ public
19952001
end match;
19962002
end getNameAndArgs;
19972003

2004+
function updateExternalRecordArgs
2005+
input list<Expression> args;
2006+
algorithm
2007+
for arg in args loop
2008+
updateExternalRecordArgsInType(Expression.typeOf(arg));
2009+
end for;
2010+
end updateExternalRecordArgs;
2011+
2012+
function updateExternalRecordArgsInType
2013+
input Type ty;
2014+
protected
2015+
InstNode node;
2016+
Class cls;
2017+
Restriction res;
2018+
algorithm
2019+
if Type.isRecord(ty) then
2020+
node := Type.complexNode(ty);
2021+
cls := InstNode.getClass(node);
2022+
res := Restriction.setExternalRecord(Class.restriction(cls));
2023+
cls := Class.setRestriction(res, cls);
2024+
InstNode.updateClass(cls, node);
2025+
end if;
2026+
end updateExternalRecordArgsInType;
2027+
19982028
protected
19992029
function instNormalCall
20002030
input Absyn.ComponentRef functionName;

OMCompiler/Compiler/NFFrontEnd/NFExpression.mo

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,16 @@ public
323323
end match;
324324
end isImpureCall;
325325

326+
function isExternalCall
327+
input Expression exp;
328+
output Boolean res;
329+
algorithm
330+
res := match exp
331+
case CALL() then Call.isExternal(exp.call);
332+
else false;
333+
end match;
334+
end isExternalCall;
335+
326336
function isCallNamed
327337
input Expression exp;
328338
input String name;
@@ -6053,7 +6063,15 @@ public
60536063
end match;
60546064
end toJSON;
60556065

6056-
6066+
function tupleElements
6067+
input Expression exp;
6068+
output list<Expression> expl;
6069+
algorithm
6070+
expl := match exp
6071+
case TUPLE() then exp.elements;
6072+
else {exp};
6073+
end match;
6074+
end tupleElements;
60576075

60586076
annotation(__OpenModelica_Interface="frontend");
60596077
end NFExpression;

OMCompiler/Compiler/NFFrontEnd/NFInstNode.mo

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1658,6 +1658,7 @@ uniontype InstNode
16581658
local
16591659
Class cls;
16601660
ClassInf.State state;
1661+
Restriction res;
16611662

16621663
case CLASS_NODE()
16631664
algorithm
@@ -1668,9 +1669,10 @@ uniontype InstNode
16681669

16691670
else
16701671
algorithm
1671-
state := Restriction.toDAE(Class.restriction(cls), fullPath(clsNode));
1672+
res := Class.restriction(cls);
1673+
state := Restriction.toDAE(res, fullPath(clsNode));
16721674
then
1673-
DAE.Type.T_COMPLEX(state, {}, NONE(), false);
1675+
DAE.Type.T_COMPLEX(state, {}, NONE(), Restriction.isExternalRecord(res));
16741676

16751677
end match;
16761678
end match;
@@ -1700,6 +1702,7 @@ uniontype InstNode
17001702
Class cls;
17011703
list<DAE.Var> vars;
17021704
ClassInf.State state;
1705+
Restriction res;
17031706

17041707
case CLASS_NODE()
17051708
algorithm
@@ -1710,9 +1713,10 @@ uniontype InstNode
17101713

17111714
else
17121715
algorithm
1713-
state := Restriction.toDAE(Class.restriction(cls), fullPath(clsNode));
1716+
res := Class.restriction(cls);
1717+
state := Restriction.toDAE(res, fullPath(clsNode));
17141718
vars := ConvertDAE.makeTypeVars(clsNode);
1715-
outType := DAE.Type.T_COMPLEX(state, vars, NONE(), false);
1719+
outType := DAE.Type.T_COMPLEX(state, vars, NONE(), Restriction.isExternalRecord(res));
17161720
Pointer.update(clsNode.cls, Class.DAE_TYPE(outType));
17171721
then
17181722
outType;

OMCompiler/Compiler/NFFrontEnd/NFRestriction.mo

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ public
5757

5858
record RECORD
5959
Boolean isOperator;
60+
Boolean usedExternally;
6061
end RECORD;
6162

6263
record RECORD_CONSTRUCTOR end RECORD_CONSTRUCTOR;
@@ -77,7 +78,7 @@ public
7778
case SCode.Restriction.R_MODEL() then MODEL();
7879
case SCode.Restriction.R_OPERATOR() then OPERATOR();
7980
case SCode.Restriction.R_PACKAGE() then PACKAGE();
80-
case SCode.Restriction.R_RECORD() then RECORD(sres.isOperator);
81+
case SCode.Restriction.R_RECORD() then RECORD(sres.isOperator, false);
8182
case SCode.Restriction.R_TYPE() then TYPE();
8283
else MODEL();
8384
end match;
@@ -175,6 +176,30 @@ public
175176
end match;
176177
end isRecord;
177178

179+
function isExternalRecord
180+
input Restriction res;
181+
output Boolean isExtRecord;
182+
algorithm
183+
isExtRecord := match res
184+
case RECORD() then res.usedExternally;
185+
else false;
186+
end match;
187+
end isExternalRecord;
188+
189+
function setExternalRecord
190+
input output Restriction res;
191+
algorithm
192+
() := match res
193+
case RECORD(usedExternally = false)
194+
algorithm
195+
res.usedExternally := true;
196+
then
197+
();
198+
199+
else ();
200+
end match;
201+
end setExternalRecord;
202+
178203
function isOperatorRecord
179204
input Restriction res;
180205
output Boolean isOpRecord;

OMCompiler/Compiler/NFFrontEnd/NFType.mo

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,13 @@ public
455455
end match;
456456
end isComplex;
457457

458+
function complexNode
459+
input Type ty;
460+
output InstNode node;
461+
algorithm
462+
COMPLEX(cls = node) := ty;
463+
end complexNode;
464+
458465
function isConnector
459466
input Type ty;
460467
output Boolean isConnector;

OMCompiler/Compiler/NFFrontEnd/NFTyping.mo

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3142,6 +3142,10 @@ algorithm
31423142
end if;
31433143

31443144
checkAssignment(e1, e2, var, context, info);
3145+
3146+
if Expression.isExternalCall(e2) then
3147+
Call.updateExternalRecordArgs(Expression.tupleElements(e1));
3148+
end if;
31453149
then
31463150
Statement.ASSIGNMENT(e1, e2, ty1, st.source);
31473151

@@ -3322,6 +3326,10 @@ algorithm
33223326
end if;
33233327

33243328
eq := Equation.EQUALITY(e1, e2, ty, source);
3329+
3330+
if Expression.isExternalCall(e2) then
3331+
Call.updateExternalRecordArgs(Expression.tupleElements(e1));
3332+
end if;
33253333
end typeEqualityEquation;
33263334

33273335
function typeCondition

0 commit comments

Comments
 (0)