Skip to content

Commit 437ebd9

Browse files
authored
[NF] improve merging of subscripts to crefs (#14776)
- check all dimension sub configurations - [NB] improve debugging output
1 parent 58a1fdb commit 437ebd9

File tree

3 files changed

+32
-12
lines changed

3 files changed

+32
-12
lines changed

OMCompiler/Compiler/NBackEnd/Modules/1_Main/NBResolveSingularities.mo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ public
460460
else
461461
error_msg := getInstanceName()
462462
+ " failed because following non-fixable variables could not be solved:\n"
463-
+ List.toString(failed_vars, BVariable.pointerToString, "", "\t", ", ", "\n", true);
463+
+ List.toString(failed_vars, BVariable.pointerToString, "", "\t", "\n\t", "\n", true);
464464
if Flags.isSet(Flags.INITIALIZATION) then
465465
error_msg := error_msg + "\nFollowing equations were created by fixing variables:\n"
466466
+ List.toString(Pointer.access(ptr_start_eqns), function Equation.pointerToString(str = "\t"), "", "", "\n", "\n", true);

OMCompiler/Compiler/NFFrontEnd/NFComponentRef.mo

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -730,6 +730,24 @@ public
730730
input output ComponentRef cref;
731731
input UnorderedMap<list<Dimension>, list<ComponentRef>> dims_map;
732732
input UnorderedMap<ComponentRef, Subscript> iter_map;
733+
protected
734+
function checkLocalDimensions
735+
"checks if the current dimension configuration results in new subscripts for the cref"
736+
input output ComponentRef cref;
737+
input list<Dimension> dims;
738+
input UnorderedMap<list<Dimension>, list<ComponentRef>> dims_map;
739+
input UnorderedMap<ComponentRef, Subscript> iter_map;
740+
protected
741+
Option<list<ComponentRef>> iter_crefs;
742+
list<Subscript> new_subs;
743+
algorithm
744+
iter_crefs := UnorderedMap.get(dims, dims_map);
745+
if Util.isSome(iter_crefs) then
746+
// dimension configuration was found, map to subscripts and apply in reverse
747+
new_subs := list(UnorderedMap.getSafe(iter_name, iter_map, sourceInfo()) for iter_name in Util.getOption(iter_crefs));
748+
cref := mergeSubscripts(new_subs, cref, true, true, true);
749+
end if;
750+
end checkLocalDimensions;
733751
algorithm
734752
cref := match cref
735753
local
@@ -738,20 +756,22 @@ public
738756
ComponentRef new_cref;
739757
list<Subscript> new_subs, rest_subs;
740758
Type ty = getSubscriptedType(cref);
759+
Integer num_local_dims;
741760

742761
// local array type -> try to find the current dimension configuration in the map and add subscripts
743762
case CREF() guard(Type.isArray(ty)) algorithm
744763
// get dimensions and check in map
745-
dims := Type.arrayDims(ty);
746-
iter_crefs := UnorderedMap.get(dims, dims_map);
747-
if Util.isSome(iter_crefs) then
748-
// dimension configuration was found, map to subscripts and apply in reverse
749-
new_subs := list(UnorderedMap.getSafe(iter_name, iter_map, sourceInfo()) for iter_name in Util.getOption(iter_crefs));
750-
new_cref := mergeSubscripts(new_subs, cref, true, true, true);
751-
else
752-
// not found, just keep current cref
753-
new_cref := cref;
754-
end if;
764+
dims := Type.arrayDims(ty);
765+
num_local_dims := listLength(Type.arrayDims(cref.ty));
766+
767+
// check if the dimension configuration exists in the map
768+
// and iteratively remove one dimension to check all local configurations
769+
new_cref := cref;
770+
while num_local_dims > 0 loop
771+
new_cref := checkLocalDimensions(new_cref, dims, dims_map, iter_map);
772+
dims := List.stripLast(dims);
773+
num_local_dims := num_local_dims - 1;
774+
end while;
755775

756776
// apply to restCref afterwards such that the outermost dimensions are handled first
757777
// this is important because the full dimension list is considered when checking in the map

OMCompiler/Compiler/NFFrontEnd/NFExpression.mo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4650,7 +4650,7 @@ public
46504650
case STRING() then true;
46514651
case BOOLEAN() then true;
46524652
case ENUM_LITERAL() then true;
4653-
case ARRAY() then exp.literal or Array.all(exp.elements, isLiteralXML);
4653+
case ARRAY() then Array.all(exp.elements, isLiteralXML);
46544654
case RECORD() then List.all(exp.elements, isLiteralXML);
46554655
case RANGE() then isLiteralXML(exp.start) and isLiteralXML(exp.stop) and
46564656
Util.applyOptionOrDefault(exp.step, isLiteralXML, true);

0 commit comments

Comments
 (0)