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

Commit 54881ac

Browse files
sjoelundOpenModelica-Hudson
authored andcommitted
Use Mutable in the backend
1 parent d12a035 commit 54881ac

4 files changed

Lines changed: 98 additions & 98 deletions

File tree

Compiler/BackEnd/BackendDAEOptimize.mo

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ import HpcOmTaskGraph;
8080
import List;
8181
import Matching;
8282
import MetaModelica.Dangerous;
83+
import Mutable;
8384
import RewriteRules;
8485
import SCode;
8586
import SynchronousFeatures;
@@ -3785,23 +3786,23 @@ algorithm
37853786
local
37863787
BackendDAE.Variables vars;
37873788
BackendDAE.EquationArray eqns, remeqns, inieqns;
3788-
array<BackendDAE.Shared> shared_arr;
3789+
Mutable<BackendDAE.Shared> shared_arr;
37893790

37903791
case (syst as BackendDAE.EQSYSTEM(orderedVars=vars, orderedEqs=eqns), BackendDAE.SHARED(initialEqs=inieqns))
37913792
algorithm
3792-
shared_arr := arrayCreate(1, shared);
3793+
shared_arr := Mutable.create(shared);
37933794
(_, vars) := BackendEquation.traverseEquationArray_WithUpdate(eqns, function traverserexpandDerEquation(shared=shared_arr), vars);
37943795
(_, vars) := BackendEquation.traverseEquationArray_WithUpdate(inieqns, function traverserexpandDerEquation(shared=shared_arr), vars);
37953796
syst.orderedVars := vars;
3796-
then (syst, arrayGet(shared_arr, 1));
3797+
then (syst, Mutable.access(shared_arr));
37973798
end match;
37983799
end expandDerOperatorWork;
37993800

38003801
protected function traverserexpandDerEquation "
38013802
Help function to e.g. traverserexpandDerEquation"
38023803
input output BackendDAE.Equation eq;
38033804
input output BackendDAE.Variables vars;
3804-
input array<BackendDAE.Shared> shared;
3805+
input Mutable<BackendDAE.Shared> shared;
38053806
protected
38063807
BackendDAE.Equation e, e1;
38073808
tuple<BackendDAE.Variables, DAE.FunctionTree> ext_arg, ext_art1;
@@ -3817,7 +3818,7 @@ protected function traverserexpandDerExp "
38173818
Help function to e.g. traverserexpandDerExp"
38183819
input output DAE.Exp exp;
38193820
input output tuple<BackendDAE.Variables, list<DAE.SymbolicOperation>> tpl;
3820-
input array<BackendDAE.Shared> shared;
3821+
input Mutable<BackendDAE.Shared> shared;
38213822
protected
38223823
DAE.Exp exp_1;
38233824
tuple<BackendDAE.Variables, BackendDAE.Shared, Boolean> ext_arg;
@@ -3839,7 +3840,7 @@ protected function expandDerExp "
38393840
Help function to e.g. expandDerOperatorEqn"
38403841
input output DAE.Exp exp;
38413842
input output BackendDAE.Variables vars;
3842-
input array<BackendDAE.Shared> inShared;
3843+
input Mutable<BackendDAE.Shared> inShared;
38433844
algorithm
38443845
(exp,vars) := matchcontinue exp
38453846
local
@@ -3881,8 +3882,8 @@ algorithm
38813882
then (e1, vars);
38823883
case (DAE.CALL(path=Absyn.IDENT(name = "der"), expLst={e1}))
38833884
equation
3884-
(e2, shared) = Differentiate.differentiateExpTime(e1, vars, arrayGet(inShared,1));
3885-
arrayUpdate(inShared, 1, shared);
3885+
(e2, shared) = Differentiate.differentiateExpTime(e1, vars, Mutable.access(inShared));
3886+
Mutable.update(inShared, shared);
38863887
(e2, _) = ExpressionSimplify.simplify(e2);
38873888
(_, vars) = Expression.traverseExpBottomUp(e2, derCrefsExp, vars);
38883889
then (e2, vars);

Compiler/BackEnd/BackendVariable.mo

Lines changed: 45 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -30,40 +30,40 @@
3030
*/
3131

3232
encapsulated package BackendVariable
33-
" file: mo
34-
package: BackendVariable
35-
description: BackendVariables contains the function that deals with the datytypes
36-
BackendDAE.VAR BackendDAE.Variables and BackendVariablesArray.
37-
33+
"BackendVariables contains the function that deals with the datytypes
34+
BackendDAE.VAR BackendDAE.Variables and BackendVariablesArray.
3835
"
3936

40-
public import BackendDAE;
41-
public import DAE;
42-
public import SCode;
43-
public import Values;
44-
45-
protected import Absyn;
46-
protected import Array;
47-
protected import BackendDAEUtil;
48-
protected import BaseHashSet;
49-
protected import BaseHashTable;
50-
protected import ComponentReference;
51-
protected import DAEUtil;
52-
protected import Debug;
53-
protected import ElementSource;
54-
protected import Error;
55-
protected import Expression;
56-
protected import ExpressionDump;
57-
protected import ExpressionSimplify;
58-
protected import Flags;
59-
protected import Global;
60-
protected import HashSet;
61-
protected import List;
62-
protected import MetaModelica.Dangerous;
63-
protected import StringUtil;
64-
protected import System;
65-
protected import Util;
66-
protected import Types;
37+
import BackendDAE;
38+
import DAE;
39+
import SCode;
40+
import Values;
41+
42+
protected
43+
44+
import Absyn;
45+
import Array;
46+
import BackendDAEUtil;
47+
import BaseHashSet;
48+
import BaseHashTable;
49+
import ComponentReference;
50+
import DAEUtil;
51+
import Debug;
52+
import ElementSource;
53+
import Error;
54+
import Expression;
55+
import ExpressionDump;
56+
import ExpressionSimplify;
57+
import Flags;
58+
import Global;
59+
import HashSet;
60+
import List;
61+
import MetaModelica.Dangerous;
62+
import Mutable;
63+
import StringUtil;
64+
import System;
65+
import Types;
66+
import Util;
6767

6868
/* =======================================================
6969
*
@@ -3115,34 +3115,30 @@ public function getVarIndexFromVariablesIndexInFirstSet
31153115
input BackendDAE.Variables inVariables2;
31163116
output list<Integer> v_lst;
31173117
protected
3118-
array<list<Integer>> a;
3118+
Mutable<list<Integer>> a;
31193119
algorithm
3120-
(a,_) := traverseBackendDAEVars(inVariables,
3121-
function traversingVarIndexInFirstSetFinder(inVars = inVariables2), (arrayCreate(1,{}),arrayCreate(1,1)));
3122-
v_lst := listReverse(a[1]);
3120+
(_,a,_) := traverseBackendDAEVars(inVariables, traversingVarIndexInFirstSetFinder, (inVariables2,Mutable.create({}),Mutable.create(1)));
3121+
v_lst := listReverse(Mutable.access(a));
31233122
end getVarIndexFromVariablesIndexInFirstSet;
31243123

31253124
protected function traversingVarIndexInFirstSetFinder
31263125
"author: Frenkel TUD 2010-11"
3127-
input BackendDAE.Var inVar;
3128-
input BackendDAE.Variables inVars;
3129-
input tuple<array<list<Integer>>,array<Integer>> inIndices;
3130-
output BackendDAE.Var outVar = inVar;
3131-
output tuple<array<list<Integer>>,array<Integer>> outIndices;
3126+
input output BackendDAE.Var var;
3127+
input output tuple<BackendDAE.Variables,Mutable<list<Integer>>,Mutable<Integer>> data;
31323128
protected
31333129
DAE.ComponentRef cr;
3134-
array<list<Integer>> l;
3135-
array<Integer> i;
3130+
BackendDAE.Variables vars;
3131+
Mutable<list<Integer>> l;
3132+
Mutable<Integer> i;
31363133
algorithm
3137-
(l,i) := inIndices;
3138-
outIndices := inIndices;
3134+
(vars,l,i) := data;
31393135
try
3140-
cr := varCref(inVar);
3141-
getVar(cr, inVars);
3142-
l[1] := i[1]::l[1];
3136+
cr := varCref(var);
3137+
getVar(cr, vars);
3138+
Mutable.update(l, Mutable.access(i)::Mutable.access(l));
31433139
else
31443140
end try;
3145-
i[1] := i[1]+1;
3141+
Mutable.update(i, Mutable.access(i)+1);
31463142
end traversingVarIndexInFirstSetFinder;
31473143

31483144
public function mergeVariables

Compiler/BackEnd/Tearing.mo

Lines changed: 43 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -38,32 +38,35 @@ encapsulated package Tearing
3838
- Cellier Tearing"
3939

4040

41-
public import BackendDAE;
42-
public import DAE;
43-
44-
protected import Array;
45-
protected import BackendDAEEXT;
46-
protected import BackendDAEOptimize;
47-
protected import BackendDAEUtil;
48-
protected import BackendDump;
49-
protected import BackendEquation;
50-
protected import BackendVariable;
51-
protected import Config;
52-
protected import DoubleEndedList;
53-
protected import DumpGraphML;
54-
protected import Error;
55-
protected import ExecStat.execStat;
56-
protected import Expression;
57-
protected import ExpressionDump;
58-
protected import ExpressionSimplify;
59-
protected import ExpressionSolve;
60-
protected import Flags;
61-
protected import Global;
62-
protected import List;
63-
protected import Matching;
64-
protected import MetaModelica.Dangerous;
65-
protected import Util;
66-
protected import Sorting;
41+
import BackendDAE;
42+
import DAE;
43+
44+
protected
45+
46+
import Array;
47+
import BackendDAEEXT;
48+
import BackendDAEOptimize;
49+
import BackendDAEUtil;
50+
import BackendDump;
51+
import BackendEquation;
52+
import BackendVariable;
53+
import Config;
54+
import DoubleEndedList;
55+
import DumpGraphML;
56+
import Error;
57+
import ExecStat.execStat;
58+
import Expression;
59+
import ExpressionDump;
60+
import ExpressionSimplify;
61+
import ExpressionSolve;
62+
import Flags;
63+
import Global;
64+
import List;
65+
import Matching;
66+
import MetaModelica.Dangerous;
67+
import Mutable;
68+
import Util;
69+
import Sorting;
6770

6871
// =============================================================================
6972
// section for type definitions
@@ -2323,7 +2326,7 @@ algorithm
23232326
// 6. determine which possible Vars causalize most equations considering impossible assignments and write them into potentials
23242327
msel2t := Array.select(mtIn,selectedcols1);
23252328
((potentials,_,_,_)) := Array.fold(msel2t,function selectCausalVars(
2326-
me=meIn,ass1In=ass1In,selEqsSetArray=selectCausalVarsPrepareSelectionSet(selectedrows, arrayLength(ass1In)),selVars=arrayCreate(1,selectedcols1)
2329+
me=meIn,ass1In=ass1In,selEqsSetArray=selectCausalVarsPrepareSelectionSet(selectedrows, arrayLength(ass1In)),selVars=Mutable.create(selectedcols1)
23272330
), ({},0,1,{}));
23282331

23292332
// 7. convert indexes from msel2t to indexes from mtIn
@@ -2368,7 +2371,7 @@ algorithm
23682371
// 3. determine which possible Vars causalize most equations considering impossible assignments and write them into potentials
23692372
msel2t := Array.select(mtIn,selectedcols1);
23702373
((potentials,_,_,_)) := Array.fold(msel2t,function selectCausalVars(
2371-
me=meIn,ass1In=ass1In,selEqsSetArray=selectCausalVarsPrepareSelectionSet(selectedrows, arrayLength(ass1In)),selVars=arrayCreate(1,selectedcols1)
2374+
me=meIn,ass1In=ass1In,selEqsSetArray=selectCausalVarsPrepareSelectionSet(selectedrows, arrayLength(ass1In)),selVars=Mutable.create(selectedcols1)
23722375
),({},0,1,{}));
23732376

23742377
// 4. convert indexes from msel2t to indexes from mtIn
@@ -2425,7 +2428,7 @@ algorithm
24252428
// 6. determine which possible Vars causalize most equations considering impossible assignments and write them into potentials
24262429
msel2t := Array.select(mtIn,selectedcols1);
24272430
((potentials,_,_,_)) := Array.fold(msel2t,function selectCausalVars(
2428-
me=meIn,ass1In=ass1In,selEqsSetArray=selectCausalVarsPrepareSelectionSet(selectedrows, arrayLength(ass1In)),selVars=arrayCreate(1,selectedcols1)
2431+
me=meIn,ass1In=ass1In,selEqsSetArray=selectCausalVarsPrepareSelectionSet(selectedrows, arrayLength(ass1In)),selVars=Mutable.create(selectedcols1)
24292432
),({},0,1,{}));
24302433

24312434
// 7. convert indexes from msel2t to indexes from mtIn
@@ -2476,7 +2479,7 @@ algorithm
24762479
// 3. determine which possible Vars causalize most equations considering impossible assignments and write them into potentials
24772480
msel2t := Array.select(mtIn,selectedcols1);
24782481
((potentials,_,_,_)) := Array.fold(msel2t,function selectCausalVars(
2479-
me=meIn,ass1In=ass1In,selEqsSetArray=selectCausalVarsPrepareSelectionSet(selectedrows, arrayLength(ass1In)),selVars=arrayCreate(1,selectedcols1)
2482+
me=meIn,ass1In=ass1In,selEqsSetArray=selectCausalVarsPrepareSelectionSet(selectedrows, arrayLength(ass1In)),selVars=Mutable.create(selectedcols1)
24802483
),({},0,1,{}));
24812484

24822485
// 4. convert indexes from msel2t to indexes from mtIn
@@ -2545,7 +2548,7 @@ algorithm
25452548
// 7. determine which possible Vars causalize most equations considering impossible assignments and write them into potentials
25462549
msel2t := Array.select(mtIn,selectedcols1);
25472550
((potentials,_,_,_)) := Array.fold(msel2t,function selectCausalVars(
2548-
me=meIn,ass1In=ass1In,selEqsSetArray=selectCausalVarsPrepareSelectionSet(selectedrows, arrayLength(ass1In)),selVars=arrayCreate(1,selectedcols1)
2551+
me=meIn,ass1In=ass1In,selEqsSetArray=selectCausalVarsPrepareSelectionSet(selectedrows, arrayLength(ass1In)),selVars=Mutable.create(selectedcols1)
25492552
),({},0,1,{}));
25502553

25512554
// 8. convert indexes from msel2t to indexes from mtIn
@@ -2596,7 +2599,7 @@ algorithm
25962599
// 4. determine which possible Vars causalize most equations considering impossible assignments and write them into potentials
25972600
msel2t := Array.select(mtIn,selectedcols1);
25982601
((potentials,_,_,_)) := Array.fold(msel2t,function selectCausalVars(
2599-
me=meIn,ass1In=ass1In,selEqsSetArray=selectCausalVarsPrepareSelectionSet(selectedrows, arrayLength(ass1In)),selVars=arrayCreate(1,selectedcols1)
2602+
me=meIn,ass1In=ass1In,selEqsSetArray=selectCausalVarsPrepareSelectionSet(selectedrows, arrayLength(ass1In)),selVars=Mutable.create(selectedcols1)
26002603
),({},0,1,{}));
26012604

26022605
// 5. convert indexes from msel2t to indexes from mtIn
@@ -2653,7 +2656,7 @@ algorithm
26532656
// 6. determine for each variable the number of equations it could causalize considering impossible assignments and save them in counts1
26542657
msel2t := Array.select(mtIn,selectedcols1);
26552658
((_,_,_,counts1)) := Array.fold(msel2t,function selectCausalVars(
2656-
me=meIn,ass1In=ass1In,selEqsSetArray=selectCausalVarsPrepareSelectionSet(selectedrows, arrayLength(ass1In)),selVars=arrayCreate(1,selectedcols1)
2659+
me=meIn,ass1In=ass1In,selEqsSetArray=selectCausalVarsPrepareSelectionSet(selectedrows, arrayLength(ass1In)),selVars=Mutable.create(selectedcols1)
26572660
),({},0,1,{}));
26582661
counts1 := listReverse(counts1);
26592662

@@ -2710,7 +2713,7 @@ algorithm
27102713
// 4. determine for each variable the number of equations it could causalize considering impossible assignments and save them in counts1
27112714
msel2t := Array.select(mtIn,selectedcols1);
27122715
((_,_,_,counts1)) := Array.fold(msel2t,function selectCausalVars(
2713-
me=meIn,ass1In=ass1In,selEqsSetArray=selectCausalVarsPrepareSelectionSet(selectedrows, arrayLength(ass1In)),selVars=arrayCreate(1,selectedcols1)
2716+
me=meIn,ass1In=ass1In,selEqsSetArray=selectCausalVarsPrepareSelectionSet(selectedrows, arrayLength(ass1In)),selVars=Mutable.create(selectedcols1)
27142717
),({},0,1,{}));
27152718
counts1 := listReverse(counts1);
27162719

@@ -2772,7 +2775,7 @@ algorithm
27722775
// 4. determine for each variable the number of equations it could causalize considering impossible assignments and save them in counts1
27732776
msel2t := Array.select(mtIn,selectedcols1);
27742777
((_,_,_,counts1)) := Array.fold(msel2t,function selectCausalVars(
2775-
me=meIn,ass1In=ass1In,selEqsSetArray=selectCausalVarsPrepareSelectionSet(selectedrows, arrayLength(ass1In)),selVars=arrayCreate(1,selectedcols1)
2778+
me=meIn,ass1In=ass1In,selEqsSetArray=selectCausalVarsPrepareSelectionSet(selectedrows, arrayLength(ass1In)),selVars=Mutable.create(selectedcols1)
27762779
),({},0,1,{}));
27772780
counts1 := listReverse(counts1);
27782781

@@ -2807,7 +2810,7 @@ algorithm
28072810
// 10. determine for each variable the number of equations it could causalize considering impossible assignments and save them in counts1
28082811
msel2t := Array.select(mtIn,selectedcols1);
28092812
((_,_,_,counts1)) := Array.fold(msel2t,function selectCausalVars(
2810-
me=meIn,ass1In=ass1In,selEqsSetArray=selectCausalVarsPrepareSelectionSet(selectedrows, arrayLength(ass1In)),selVars=arrayCreate(1,selectedcols1)
2813+
me=meIn,ass1In=ass1In,selEqsSetArray=selectCausalVarsPrepareSelectionSet(selectedrows, arrayLength(ass1In)),selVars=Mutable.create(selectedcols1)
28112814
),({},0,1,{}));
28122815
counts1 := listReverse(counts1);
28132816

@@ -2900,7 +2903,7 @@ algorithm
29002903

29012904
// 4.1 Determine for each variable the number of equations it could causalize considering impossible assignments and save them in counts1
29022905
mtsel := Array.select(mtIn,potentialTVars);
2903-
((_,_,_,counts1)) := Array.fold(mtsel,function selectCausalVars(me=meIn,ass1In=ass1In,selEqsSetArray=selectCausalVarsPrepareSelectionSet(causEq, arrayLength(ass1In)),selVars=arrayCreate(1,potentialTVars)),({},0,1,{}));
2906+
((_,_,_,counts1)) := Array.fold(mtsel,function selectCausalVars(me=meIn,ass1In=ass1In,selEqsSetArray=selectCausalVarsPrepareSelectionSet(causEq, arrayLength(ass1In)),selVars=Mutable.create(potentialTVars)),({},0,1,{}));
29042907
if debug then execStat("Tearing.ModifiedCellierHeuristic_3 - 5.1"); end if;
29052908

29062909
// 4.2 Determine for each variable the number of impossible assignments and save them in counts2
@@ -3091,7 +3094,7 @@ protected function selectCausalVars
30913094
input BackendDAE.AdjacencyMatrixEnhanced me;
30923095
input array<Integer> ass1In;
30933096
input array<Boolean> selEqsSetArray;
3094-
input array<list<Integer>> selVars;
3097+
input Mutable<list<Integer>> selVars;
30953098
output tuple<list<Integer>,Integer,Integer,list<Integer>> OutValue;
30963099
protected
30973100
list<Integer> cVars,interEqs,counts,selVarsNext;
@@ -3101,8 +3104,8 @@ algorithm
31013104
(cVars,num,indx,counts) := inValue;
31023105
// interEqs := List.intersectionOnTrue(row,selEqs,intEq);
31033106
interEqs := list(i for i guard arrayGet(selEqsSetArray,i) in row);
3104-
Var::selVarsNext := arrayGet(selVars,1);
3105-
arrayUpdate(selVars, 1, selVarsNext);
3107+
Var::selVarsNext := Mutable.access(selVars);
3108+
Mutable.update(selVars, selVarsNext);
31063109
arrayUpdate(ass1In,Var,1);
31073110
size := List.fold2(interEqs,sizeOfAssignable,me,ass1In,0);
31083111
arrayUpdate(ass1In,Var,-1);

Compiler/Util/Util.mo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1077,7 +1077,7 @@ algorithm
10771077
end match;
10781078
end mulListIntegerOpt;
10791079

1080-
public type StatefulBoolean = array<Boolean> "A single boolean value that can be updated (a destructive operation)";
1080+
public type StatefulBoolean = array<Boolean> "A single boolean value that can be updated (a destructive operation). NOTE: Use Mutable<Boolean> instead. This implementation is kept since Susan cannot use that type.";
10811081

10821082
public function makeStatefulBoolean
10831083
"Create a boolean with state (that is, it is mutable)"

0 commit comments

Comments
 (0)