Skip to content

Commit

Permalink
Use the indexed prefix when replacing split indices (#11349)
Browse files Browse the repository at this point in the history
Fixes #11329
  • Loading branch information
perost committed Oct 6, 2023
1 parent 355f775 commit 5bc3308
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion OMCompiler/Compiler/NFFrontEnd/NFFlatten.mo
Original file line number Diff line number Diff line change
Expand Up @@ -1034,6 +1034,21 @@ algorithm
exp := Binding.getExp(binding);
binding_ty := Binding.getType(binding);

// When replacing split indices we often get expressions such as
// {"m" for $i1 in 1:3}[$x1]. If the subscripts are the same as the subscripts
// in the prefix we can just remove all the subscripts and be done.
() := match exp
case Expression.SUBSCRIPTED_EXP()
guard Subscript.isEqualList(exp.subscripts, subs)
algorithm
binding := Binding.makeFlat(exp.exp, Binding.variability(binding), Binding.source(binding));
return;
then
();

else ();
end match;

nodes := ComponentRef.nodes(prefix_cr);
dims := List.flatten(list(Type.arrayDims(InstNode.getType(n)) for n in nodes));
dims := List.lastN(dims, listLength(subs));
Expand Down Expand Up @@ -1394,7 +1409,7 @@ protected
Integer index;
InstNode cr_node;
algorithm
for cr in ComponentRef.toListReverse(Prefix.prefix(prefix)) loop
for cr in ComponentRef.toListReverse(Prefix.indexedPrefix(prefix)) loop
cr_subs := ComponentRef.getSubscripts(cr);

if not listEmpty(cr_subs) then
Expand Down

0 comments on commit 5bc3308

Please sign in to comment.