Changeset 5a6cea7 in OpenModelica


Ignore:
Timestamp:
2021-11-24T17:22:50+01:00 (2 years ago)
Author:
Per Östlund <perost86@…>
Parents:
f6468ae
git-author:
Per Östlund <perost86@…> (11/24/21 17:11:27)
git-committer:
Per Östlund <perost86@…> (11/24/21 17:22:50)
Message:

Improve sorting of local function variables

  • Take the modifiers on local record instances into account too when computing the dependencies between local function variables.

Fixes thorade/HelmholtzMedia#48

Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • OMCompiler/Compiler/NFFrontEnd/NFFunction.mo

    r89b043ca r5a6cea7  
    24762476    output list<InstNode> dependencies;
    24772477  protected
     2478    UnorderedSet<InstNode> deps;
     2479  algorithm
     2480    // Use a set to store the dependencies to avoid duplicates.
     2481    deps := UnorderedSet.new(InstNode.hash, InstNode.refEqual, 1);
     2482    deps := getLocalDependencies2(node, locals, deps);
     2483
     2484    // If we have a record instance with fields that have bindings that refer to
     2485    // other fields we'll get a dependency on the record instance itself here.
     2486    // But that's actually fine, so remove it to avoid a false cycle being detected.
     2487    UnorderedSet.remove(node, deps);
     2488
     2489    deps := Type.foldDims(InstNode.getType(node),
     2490      function getLocalDependenciesDim(locals = locals), deps);
     2491
     2492    dependencies := UnorderedSet.toList(deps);
     2493  end getLocalDependencies;
     2494
     2495  function getLocalDependencies2
     2496    input InstNode node;
     2497    input UnorderedSet<InstNode> locals;
     2498    input output UnorderedSet<InstNode> dependencies;
     2499  protected
    24782500    Component comp;
    24792501    Binding binding;
    2480     UnorderedSet<InstNode> deps;
    2481   algorithm
    2482     // Use a set to store the dependencies to avoid duplicates.
    2483     deps := UnorderedSet.new(InstNode.hash, InstNode.refEqual, 1);
    2484 
     2502  algorithm
    24852503    comp := InstNode.component(node);
    24862504    binding := Component.getBinding(comp);
    24872505
    24882506    if Binding.hasExp(binding) then
    2489       deps := getLocalDependenciesExp(Binding.getExp(binding), locals, deps);
    2490     end if;
    2491 
    2492     deps := Type.foldDims(Component.getType(comp),
    2493       function getLocalDependenciesDim(locals = locals), deps);
    2494 
    2495     dependencies := UnorderedSet.toList(deps);
    2496   end getLocalDependencies;
     2507      dependencies := getLocalDependenciesExp(Binding.getExp(binding), locals, dependencies);
     2508    elseif Type.isRecord(Component.getType(comp)) then
     2509      // If the component is a record instance without a binding, check the
     2510      // bindings on the record fields instead.
     2511      dependencies := ClassTree.foldComponents(
     2512        Class.classTree(InstNode.getClass(node)),
     2513        function getLocalDependencies2(locals = locals), dependencies);
     2514    end if;
     2515  end getLocalDependencies2;
    24972516
    24982517  function getLocalDependenciesExp
  • testsuite/flattening/modelica/scodeinst/Makefile

    r9f0cb452 r5a6cea7  
    585585FunctionCompOrder2.mo \
    586586FunctionCompOrder3.mo \
     587FunctionCompOrder4.mo \
    587588FunctionDerivative1.mo \
    588589FunctionDerivativeInvalidInput1.mo \
Note: See TracChangeset for help on using the changeset viewer.