Skip to content

Commit 3548b47

Browse files
perostOpenModelica-Hudson
authored andcommitted
NFInst fix.
- Fix NFClassTree.flatten so that the lookup tree isn't invalidated when there are duplicate elements. Belonging to [master]: - OpenModelica/OMCompiler#2036 - OpenModelica/OpenModelica-testsuite#786
1 parent add36ff commit 3548b47

File tree

3 files changed

+56
-50
lines changed

3 files changed

+56
-50
lines changed

Compiler/NFFrontEnd/NFClassTree.mo

Lines changed: 15 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -640,8 +640,8 @@ public
640640
algorithm
641641
(dup_cls, dup_comp) := enumerateDuplicates(tree.duplicates);
642642

643-
clsc := arrayLength(tree.classes) - listLength(dup_cls);
644-
compc := arrayLength(tree.components) - listLength(dup_comp);
643+
clsc := arrayLength(tree.classes);
644+
compc := arrayLength(tree.components);
645645
clss := arrayCreateNoInit(clsc, InstNode.EMPTY_NODE());
646646
comps := arrayCreateNoInit(compc, InstNode.EMPTY_NODE());
647647

@@ -655,48 +655,18 @@ public
655655
end flatten;
656656

657657
function flatten2
658-
input array<Mutable<InstNode>> elements "The array to take elements from";
659-
input array<InstNode> flatElements "The array to add elements to";
660-
input list<Integer> duplicates "Sorted list of duplicate element indices";
661-
protected
662-
list<Integer> dups;
663-
Integer pos = 1, begin, dup;
664-
algorithm
665-
// If we have any duplicates, filter them out while adding them to the flat array.
666-
if not listEmpty(duplicates) then
667-
dup :: dups := duplicates;
668-
669-
// Loop through the elements using 'i', while 'pos' keeps track of where
670-
// in the flat array we are.
671-
for i in 1:arrayLength(elements) loop
672-
if i == dup then
673-
if listEmpty(dups) then
674-
// When we run out of duplicates, switch to the faster mode.
675-
begin := i + 1;
676-
break;
677-
else
678-
dup :: dups := dups;
679-
end if;
680-
else
681-
arrayUpdateNoBoundsChecking(flatElements, pos,
682-
Mutable.access(arrayGetNoBoundsChecking(elements, i)));
683-
pos := pos + 1;
684-
end if;
685-
end for;
658+
input array<Mutable<InstNode>> elements;
659+
input array<InstNode> flatElements;
660+
input list<Integer> duplicates;
661+
algorithm
662+
for i in 1:arrayLength(elements) loop
663+
arrayUpdateNoBoundsChecking(flatElements, i,
664+
Mutable.access(arrayGetNoBoundsChecking(elements, i)));
665+
end for;
686666

687-
// Add the remaining elements.
688-
for i in begin:arrayLength(elements) loop
689-
arrayUpdateNoBoundsChecking(flatElements, pos,
690-
Mutable.access(arrayGetNoBoundsChecking(elements, i)));
691-
pos := pos + 1;
692-
end for;
693-
else
694-
// If we don't have any duplicates we can just copy from one array to the other.
695-
for i in pos:arrayLength(elements) loop
696-
arrayUpdateNoBoundsChecking(flatElements, i,
697-
Mutable.access(arrayGetNoBoundsChecking(elements, i)));
698-
end for;
699-
end if;
667+
for i in duplicates loop
668+
arrayUpdateNoBoundsChecking(flatElements, i, InstNode.EMPTY_NODE());
669+
end for;
700670
end flatten2;
701671

702672
function lookupElement
@@ -1518,8 +1488,8 @@ public
15181488
components := {};
15191489
else
15201490
(classes, components) := DuplicateTree.fold_2(duplicates, enumerateDuplicates2, {}, {});
1521-
classes := List.sort(classes, intGt);
1522-
components := List.sort(components, intGt);
1491+
//classes := List.sort(classes, intGt);
1492+
//components := List.sort(components, intGt);
15231493
end if;
15241494
end enumerateDuplicates;
15251495

Compiler/NFFrontEnd/NFFlatten.mo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ protected
197197
Visibility vis;
198198
algorithm
199199
// Remove components that are only outer.
200-
if InstNode.isOnlyOuter(component) then
200+
if InstNode.isOnlyOuter(component) or InstNode.isEmpty(component) then
201201
return;
202202
end if;
203203

Compiler/NFFrontEnd/NFTyping.mo

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,9 @@ algorithm
135135
case Class.INSTANCED_CLASS(elements = cls_tree as ClassTree.FLAT_TREE())
136136
algorithm
137137
for c in cls_tree.components loop
138-
typeComponent(c, clsScope);
138+
if not InstNode.isEmpty(c) then
139+
typeComponent(c, clsScope);
140+
end if;
139141
end for;
140142
then
141143
();
@@ -519,8 +521,14 @@ function typeComponentBinding
519521
input InstNode component;
520522
protected
521523
InstNode node = InstNode.resolveOuter(component);
522-
Component c = InstNode.component(node);
524+
Component c;
523525
algorithm
526+
if InstNode.isEmpty(component) then
527+
return;
528+
end if;
529+
530+
c := InstNode.component(node);
531+
524532
() := match c
525533
local
526534
Binding binding;
@@ -1573,8 +1581,8 @@ algorithm
15731581
function typeEquation(scope = EquationScope.NORMAL), typeAlgorithm);
15741582
typed_cls := Class.setSections(sections, cls);
15751583

1576-
for i in 1:arrayLength(components) loop
1577-
typeSections(InstNode.classScope(InstNode.resolveOuter(components[i])));
1584+
for c in components loop
1585+
typeComponentSections(InstNode.resolveOuter(c));
15781586
end for;
15791587

15801588
InstNode.updateClass(typed_cls, classNode);
@@ -1592,6 +1600,34 @@ algorithm
15921600
end match;
15931601
end typeSections;
15941602

1603+
function typeComponentSections
1604+
input InstNode component;
1605+
protected
1606+
Component comp;
1607+
algorithm
1608+
if InstNode.isEmpty(component) then
1609+
return;
1610+
end if;
1611+
1612+
comp := InstNode.component(component);
1613+
1614+
() := match comp
1615+
case Component.TYPED_COMPONENT()
1616+
algorithm
1617+
typeSections(comp.classInst);
1618+
then
1619+
();
1620+
1621+
else
1622+
algorithm
1623+
assert(false, getInstanceName() + " got uninstantiated component " +
1624+
InstNode.name(component));
1625+
then
1626+
fail();
1627+
1628+
end match;
1629+
end typeComponentSections;
1630+
15951631
function typeEquation
15961632
input output Equation eq;
15971633
input EquationScope scope = EquationScope.NORMAL;

0 commit comments

Comments
 (0)