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

Commit

Permalink
NFInst fix.
Browse files Browse the repository at this point in the history
- Fix NFClassTree.flatten so that the lookup tree isn't invalidated
  when there are duplicate elements.

Belonging to [master]:
  - #2036
  - OpenModelica/OpenModelica-testsuite#786
  • Loading branch information
perost authored and OpenModelica-Hudson committed Nov 20, 2017
1 parent add36ff commit 3548b47
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 50 deletions.
60 changes: 15 additions & 45 deletions Compiler/NFFrontEnd/NFClassTree.mo
Expand Up @@ -640,8 +640,8 @@ public
algorithm
(dup_cls, dup_comp) := enumerateDuplicates(tree.duplicates);

clsc := arrayLength(tree.classes) - listLength(dup_cls);
compc := arrayLength(tree.components) - listLength(dup_comp);
clsc := arrayLength(tree.classes);
compc := arrayLength(tree.components);
clss := arrayCreateNoInit(clsc, InstNode.EMPTY_NODE());
comps := arrayCreateNoInit(compc, InstNode.EMPTY_NODE());

Expand All @@ -655,48 +655,18 @@ public
end flatten;

function flatten2
input array<Mutable<InstNode>> elements "The array to take elements from";
input array<InstNode> flatElements "The array to add elements to";
input list<Integer> duplicates "Sorted list of duplicate element indices";
protected
list<Integer> dups;
Integer pos = 1, begin, dup;
algorithm
// If we have any duplicates, filter them out while adding them to the flat array.
if not listEmpty(duplicates) then
dup :: dups := duplicates;

// Loop through the elements using 'i', while 'pos' keeps track of where
// in the flat array we are.
for i in 1:arrayLength(elements) loop
if i == dup then
if listEmpty(dups) then
// When we run out of duplicates, switch to the faster mode.
begin := i + 1;
break;
else
dup :: dups := dups;
end if;
else
arrayUpdateNoBoundsChecking(flatElements, pos,
Mutable.access(arrayGetNoBoundsChecking(elements, i)));
pos := pos + 1;
end if;
end for;
input array<Mutable<InstNode>> elements;
input array<InstNode> flatElements;
input list<Integer> duplicates;
algorithm
for i in 1:arrayLength(elements) loop
arrayUpdateNoBoundsChecking(flatElements, i,
Mutable.access(arrayGetNoBoundsChecking(elements, i)));
end for;

// Add the remaining elements.
for i in begin:arrayLength(elements) loop
arrayUpdateNoBoundsChecking(flatElements, pos,
Mutable.access(arrayGetNoBoundsChecking(elements, i)));
pos := pos + 1;
end for;
else
// If we don't have any duplicates we can just copy from one array to the other.
for i in pos:arrayLength(elements) loop
arrayUpdateNoBoundsChecking(flatElements, i,
Mutable.access(arrayGetNoBoundsChecking(elements, i)));
end for;
end if;
for i in duplicates loop
arrayUpdateNoBoundsChecking(flatElements, i, InstNode.EMPTY_NODE());
end for;
end flatten2;

function lookupElement
Expand Down Expand Up @@ -1518,8 +1488,8 @@ public
components := {};
else
(classes, components) := DuplicateTree.fold_2(duplicates, enumerateDuplicates2, {}, {});
classes := List.sort(classes, intGt);
components := List.sort(components, intGt);
//classes := List.sort(classes, intGt);
//components := List.sort(components, intGt);
end if;
end enumerateDuplicates;

Expand Down
2 changes: 1 addition & 1 deletion Compiler/NFFrontEnd/NFFlatten.mo
Expand Up @@ -197,7 +197,7 @@ protected
Visibility vis;
algorithm
// Remove components that are only outer.
if InstNode.isOnlyOuter(component) then
if InstNode.isOnlyOuter(component) or InstNode.isEmpty(component) then
return;
end if;

Expand Down
44 changes: 40 additions & 4 deletions Compiler/NFFrontEnd/NFTyping.mo
Expand Up @@ -135,7 +135,9 @@ algorithm
case Class.INSTANCED_CLASS(elements = cls_tree as ClassTree.FLAT_TREE())
algorithm
for c in cls_tree.components loop
typeComponent(c, clsScope);
if not InstNode.isEmpty(c) then
typeComponent(c, clsScope);
end if;
end for;
then
();
Expand Down Expand Up @@ -519,8 +521,14 @@ function typeComponentBinding
input InstNode component;
protected
InstNode node = InstNode.resolveOuter(component);
Component c = InstNode.component(node);
Component c;
algorithm
if InstNode.isEmpty(component) then
return;
end if;

c := InstNode.component(node);

() := match c
local
Binding binding;
Expand Down Expand Up @@ -1573,8 +1581,8 @@ algorithm
function typeEquation(scope = EquationScope.NORMAL), typeAlgorithm);
typed_cls := Class.setSections(sections, cls);

for i in 1:arrayLength(components) loop
typeSections(InstNode.classScope(InstNode.resolveOuter(components[i])));
for c in components loop
typeComponentSections(InstNode.resolveOuter(c));
end for;

InstNode.updateClass(typed_cls, classNode);
Expand All @@ -1592,6 +1600,34 @@ algorithm
end match;
end typeSections;

function typeComponentSections
input InstNode component;
protected
Component comp;
algorithm
if InstNode.isEmpty(component) then
return;
end if;

comp := InstNode.component(component);

() := match comp
case Component.TYPED_COMPONENT()
algorithm
typeSections(comp.classInst);
then
();

else
algorithm
assert(false, getInstanceName() + " got uninstantiated component " +
InstNode.name(component));
then
fail();

end match;
end typeComponentSections;

function typeEquation
input output Equation eq;
input EquationScope scope = EquationScope.NORMAL;
Expand Down

0 comments on commit 3548b47

Please sign in to comment.