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

Commit 89eacbb

Browse files
perostOpenModelica-Hudson
authored andcommitted
[NF] Minor fixes.
- Flatten the class tree of functions before creating the actual Function, so that duplicate elements are handled correctly. - Use Ceval when evaluating 'fill' instead of deprecated SimplifyExp. Belonging to [master]: - #2410 - OpenModelica/OpenModelica-testsuite#937
1 parent ace473c commit 89eacbb

File tree

8 files changed

+66
-22
lines changed

8 files changed

+66
-22
lines changed

Compiler/NFFrontEnd/NFCall.mo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1911,7 +1911,7 @@ protected
19111911
(arg, arg_ty, arg_var) := Typing.typeExp(arg, origin, info);
19121912

19131913
if arg_var <= Variability.STRUCTURAL_PARAMETER then
1914-
arg := SimplifyExp.simplifyExp(arg);
1914+
arg := Ceval.evalExp(arg);
19151915
arg_ty := Expression.typeOf(arg);
19161916
end if;
19171917

Compiler/NFFrontEnd/NFClass.mo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ uniontype Class
163163
ClassTree tree;
164164
algorithm
165165
tree := ClassTree.fromRecordConstructor(inputs, locals, out);
166-
cls := EXPANDED_CLASS(tree, Modifier.NOMOD(), DEFAULT_PREFIXES, Restriction.FUNCTION());
166+
cls := INSTANCED_CLASS(Type.UNKNOWN(), tree, Sections.EMPTY(), Restriction.FUNCTION());
167167
end makeRecordConstructor;
168168

169169
function initExpandedClass

Compiler/NFFrontEnd/NFClassTree.mo

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -660,28 +660,26 @@ public
660660
protected
661661
LookupTree.Tree ltree = LookupTree.new();
662662
Integer i = 1;
663-
array<Mutable<InstNode>> comps;
663+
array<InstNode> comps;
664664
algorithm
665-
comps := arrayCreateNoInit(listLength(inputs) + listLength(locals) + 1,
666-
Mutable.create(InstNode.EMPTY_NODE()));
665+
comps := arrayCreateNoInit(listLength(inputs) + listLength(locals) + 1, InstNode.EMPTY_NODE());
667666

668667
for ci in inputs loop
669-
comps[i] := Mutable.create(ci);
668+
comps[i] := ci;
670669
ltree := addLocalElement(InstNode.name(ci), LookupTree.Entry.COMPONENT(i), tree, ltree);
671670
i := i + 1;
672671
end for;
673672

674673
for cl in locals loop
675-
comps[i] := Mutable.create(cl);
674+
comps[i] := cl;
676675
ltree := addLocalElement(InstNode.name(cl), LookupTree.Entry.COMPONENT(i), tree, ltree);
677676
i := i + 1;
678677
end for;
679678

680-
comps[i] := Mutable.create(out);
679+
comps[i] := out;
681680
ltree := addLocalElement(InstNode.name(out), LookupTree.Entry.COMPONENT(i), tree, ltree);
682681

683-
tree := INSTANTIATED_TREE(ltree, listArray({}), comps, List.intRange(i),
684-
listArray({}), listArray({}), DuplicateTree.new());
682+
tree := FLAT_TREE(ltree, listArray({}), comps, listArray({}), DuplicateTree.new());
685683
end fromRecordConstructor;
686684

687685
function mapRedeclareChains

Compiler/NFFrontEnd/NFFlatten.mo

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,6 +1069,10 @@ algorithm
10691069
case Class.INSTANCED_CLASS(elements = cls_tree as ClassTree.FLAT_TREE(), sections = sections)
10701070
algorithm
10711071
for c in cls_tree.components loop
1072+
if InstNode.isEmpty(c) then
1073+
continue;
1074+
end if;
1075+
10721076
comp := InstNode.component(c);
10731077
funcs := collectTypeFuncs(Component.getType(comp), funcs);
10741078
binding := Component.getBinding(comp);

Compiler/NFFrontEnd/NFFunction.mo

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ uniontype Function
300300
case CachedData.FUNCTION() then (fn_node, cache.specialBuiltin);
301301
else algorithm
302302
(fn_node, specialBuiltin) := instFunc2(ComponentRef.toPath(fn_ref), fn_node, info);
303-
instFuncExpressions(fn_node);
303+
//instFuncExpressions(fn_node);
304304
then (fn_node, specialBuiltin);
305305
end match;
306306
end instFuncRef;
@@ -357,6 +357,8 @@ uniontype Function
357357
algorithm
358358
// fnNode := InstNode.setNodeType(NFInstNode.InstNodeType.ROOT_CLASS(), fnNode);
359359
fnNode := Inst.instantiate(fnNode);
360+
InstNode.cacheInitFunc(fnNode);
361+
Inst.instExpressions(fnNode);
360362
fnNode := Record.instConstructors(fnPath, fnNode, info);
361363
then
362364
(fnNode, false);
@@ -365,6 +367,8 @@ uniontype Function
365367
algorithm
366368
// fnNode := InstNode.setNodeType(NFInstNode.InstNodeType.ROOT_CLASS(), fnNode);
367369
fnNode := Inst.instantiate(fnNode);
370+
InstNode.cacheInitFunc(fnNode);
371+
Inst.instExpressions(fnNode);
368372
fnNode := Record.instOperatorFunctions(fnNode, info);
369373
then
370374
(fnNode, false);
@@ -385,6 +389,10 @@ uniontype Function
385389
algorithm
386390
fnNode := InstNode.setNodeType(NFInstNode.InstNodeType.ROOT_CLASS(), fnNode);
387391
fnNode := Inst.instantiate(fnNode);
392+
// Set up an empty function cache to signal that this function is
393+
// currently being instantiated, so recursive functions can be handled.
394+
InstNode.cacheInitFunc(fnNode);
395+
Inst.instExpressions(fnNode);
388396
fn := Function.new(fnPath, fnNode);
389397
specialBuiltin := isSpecialBuiltin(fn);
390398
fnNode := InstNode.cacheAddFunc(fnNode, fn, specialBuiltin);
@@ -1151,17 +1159,21 @@ protected
11511159
input output list<InstNode> locals = {};
11521160
protected
11531161
Class cls;
1154-
array<Mutable<InstNode>> comps;
1162+
array<InstNode> comps;
11551163
InstNode n;
11561164
algorithm
11571165
Error.assertion(InstNode.isClass(node), getInstanceName() + " got non-class node", sourceInfo());
11581166
cls := InstNode.getClass(node);
11591167

11601168
() := match cls
1161-
case Class.EXPANDED_CLASS(elements = ClassTree.INSTANTIATED_TREE(components = comps))
1169+
case Class.INSTANCED_CLASS(elements = ClassTree.FLAT_TREE(components = comps))
11621170
algorithm
11631171
for i in arrayLength(comps):-1:1 loop
1164-
n := Mutable.access(comps[i]);
1172+
n := comps[i];
1173+
1174+
if InstNode.isEmpty(n) then
1175+
continue;
1176+
end if;
11651177

11661178
// Sort the components based on their direction.
11671179
() := match paramDirection(n)

Compiler/NFFrontEnd/NFInstNode.mo

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,20 @@ uniontype CachedData
129129
output array<CachedData> cache = arrayCreate(NUMBER_OF_CACHES, NO_CACHE());
130130
end empty;
131131

132+
function initFunc
133+
input array<CachedData> caches;
134+
protected
135+
CachedData func_cache;
136+
algorithm
137+
func_cache := getFuncCache(caches);
138+
func_cache := match func_cache
139+
case NO_CACHE() then FUNCTION({}, false, false);
140+
case FUNCTION() then func_cache;
141+
end match;
142+
143+
setFuncCache(caches, func_cache);
144+
end initFunc;
145+
132146
function addFunc
133147
input Function fn;
134148
input Boolean specialBuiltin;
@@ -913,6 +927,15 @@ uniontype InstNode
913927
end match;
914928
end resolveOuter;
915929

930+
function cacheInitFunc
931+
input output InstNode node;
932+
algorithm
933+
() := match node
934+
case CLASS_NODE() algorithm CachedData.initFunc(node.caches); then ();
935+
else algorithm Error.assertion(false, getInstanceName() + " got node without cache", sourceInfo()); then fail();
936+
end match;
937+
end cacheInitFunc;
938+
916939
function cacheAddFunc
917940
input output InstNode node;
918941
input Function fn;

Compiler/NFFrontEnd/NFPackage.mo

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,10 @@ public
178178
sections = sections)
179179
algorithm
180180
for c in comps loop
181-
constants := collectBindingConstants(
182-
Component.getBinding(InstNode.component(c)), constants);
181+
if not InstNode.isEmpty(c) then
182+
constants := collectBindingConstants(
183+
Component.getBinding(InstNode.component(c)), constants);
184+
end if;
183185
end for;
184186

185187
() := match sections

Compiler/NFFrontEnd/NFRecord.mo

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ function collectRecordParams
148148
protected
149149

150150
Class cls;
151-
array<Mutable<InstNode>> components;
151+
array<InstNode> components;
152152
InstNode n;
153153
Component comp;
154154
algorithm
@@ -157,10 +157,15 @@ algorithm
157157
cls := InstNode.getClass(recNode);
158158

159159
() := match cls
160-
case Class.EXPANDED_CLASS(elements = ClassTree.INSTANTIATED_TREE(components = components))
160+
case Class.INSTANCED_CLASS(elements = ClassTree.FLAT_TREE(components = components))
161161
algorithm
162162
for i in arrayLength(components):-1:1 loop
163-
n := Mutable.access(components[i]);
163+
n := components[i];
164+
165+
if InstNode.isEmpty(n) then
166+
continue;
167+
end if;
168+
164169
comp := InstNode.component(n);
165170

166171
if InstNode.isProtected(n) or
@@ -187,7 +192,7 @@ function instOperatorFunctions
187192
input SourceInfo info;
188193
protected
189194
Class cls;
190-
array<Mutable<InstNode>> mclss;
195+
array<InstNode> mclss;
191196
InstNode op;
192197
Absyn.Path path;
193198
list<Function> allfuncs = {}, funcs;
@@ -196,9 +201,9 @@ algorithm
196201
cls := InstNode.getClass(node);
197202

198203
() := match cls
199-
case Class.EXPANDED_CLASS(elements = ClassTree.INSTANTIATED_TREE(classes = mclss)) algorithm
204+
case Class.INSTANCED_CLASS(elements = ClassTree.FLAT_TREE(classes = mclss)) algorithm
200205
for i in arrayLength(mclss):-1:1 loop
201-
op := Mutable.access(mclss[i]);
206+
op := mclss[i];
202207
path := InstNode.scopePath(op);
203208
Function.instFunc2(path, op, info);
204209
funcs := Function.getCachedFuncs(op);

0 commit comments

Comments
 (0)