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

Commit 20606a9

Browse files
perostOpenModelica-Hudson
authored andcommitted
[NF] Improve performance of DAE conversion.
- Cache the conversion of complex types by replacing a converted INSTANCED_CLASS with a new DAE_TYPE class. Belonging to [master]: - #2296
1 parent 77407e8 commit 20606a9

File tree

4 files changed

+40
-11
lines changed

4 files changed

+40
-11
lines changed

Compiler/NFFrontEnd/NFClass.mo

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@ uniontype Class
118118
Restriction restriction;
119119
end INSTANCED_BUILTIN;
120120

121+
record DAE_TYPE
122+
DAE.Type ty;
123+
end DAE_TYPE;
124+
121125
function fromSCode
122126
input list<SCode.Element> elements;
123127
input Boolean isClassExtends;

Compiler/NFFrontEnd/NFConvertDAE.mo

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,17 +1045,15 @@ end convertExternalDeclOutput;
10451045

10461046
public
10471047
function makeTypesVars
1048-
input Type complex_ty;
1049-
output list<DAE.Var> type_vars;
1048+
input InstNode complexCls;
1049+
output list<DAE.Var> typeVars;
10501050
protected
1051-
InstNode cls_node;
10521051
Component comp;
10531052
DAE.Var type_var;
10541053
algorithm
1055-
Type.COMPLEX(cls = cls_node) := complex_ty;
1056-
type_vars := {};
1054+
typeVars := {};
10571055

1058-
() := match cls as InstNode.getClass(cls_node)
1056+
() := match cls as InstNode.getClass(complexCls)
10591057
case Class.INSTANCED_CLASS(elements = ClassTree.FLAT_TREE()) algorithm
10601058

10611059
for c in ClassTree.getComponents(cls.elements) loop
@@ -1072,10 +1070,10 @@ algorithm
10721070
, DAE.UNBOUND()
10731071
, NONE()
10741072
);
1075-
type_vars := type_var::type_vars;
1073+
typeVars := type_var::typeVars;
10761074
end for;
10771075

1078-
type_vars := listReverse(type_vars);
1076+
typeVars := listReverse(typeVars);
10791077
then ();
10801078

10811079
else ();

Compiler/NFFrontEnd/NFInstNode.mo

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,11 @@ import Prefixes = NFPrefixes;
4343
import Visibility = NFPrefixes.Visibility;
4444
import NFModifier.Modifier;
4545
import SCodeDump;
46+
import DAE;
4647

4748
protected
4849
import List;
50+
import ConvertDAE = NFConvertDAE;
4951

5052
public
5153
uniontype InstNodeType
@@ -1201,6 +1203,33 @@ uniontype InstNode
12011203
end match;
12021204
end setModifier;
12031205

1206+
function toDAEType
1207+
input InstNode clsNode;
1208+
output DAE.Type outType;
1209+
algorithm
1210+
outType := match clsNode
1211+
local
1212+
Class cls;
1213+
1214+
case CLASS_NODE()
1215+
algorithm
1216+
cls := Pointer.access(clsNode.cls);
1217+
then
1218+
match cls
1219+
case Class.DAE_TYPE() then cls.ty;
1220+
else
1221+
algorithm
1222+
// TODO: Use proper ClassInf.State here.
1223+
outType := DAE.Type.T_COMPLEX(ClassInf.MODEL(scopePath(clsNode)),
1224+
ConvertDAE.makeTypesVars(clsNode),
1225+
NONE());
1226+
Pointer.update(clsNode.cls, Class.DAE_TYPE(outType));
1227+
then
1228+
outType;
1229+
end match;
1230+
end match;
1231+
end toDAEType;
1232+
12041233
end InstNode;
12051234

12061235
annotation(__OpenModelica_Interface="frontend");

Compiler/NFFrontEnd/NFType.mo

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -514,9 +514,7 @@ public
514514
then DAE.T_FUNCTION({} /*TODO:FIXME*/, toDAE(ty.resultType), ty.attributes, Absyn.IDENT("TODO:FIXME"));
515515
case Type.NORETCALL() then DAE.T_NORETCALL_DEFAULT;
516516
case Type.UNKNOWN() then DAE.T_UNKNOWN_DEFAULT;
517-
case Type.COMPLEX()
518-
// TODO: Use proper ClassInf.State here.
519-
then DAE.Type.T_COMPLEX(ClassInf.MODEL(InstNode.scopePath(ty.cls)), ConvertDAE.makeTypesVars(ty), NONE());
517+
case Type.COMPLEX() then InstNode.toDAEType(ty.cls);
520518
case Type.POLYMORPHIC() then DAE.T_METAPOLYMORPHIC(ty.name);
521519
case Type.ANY() then DAE.T_ANYTYPE(NONE());
522520
else

0 commit comments

Comments
 (0)