Skip to content

Commit b64b470

Browse files
committed
Remove List.first/rest
1 parent dc242e4 commit b64b470

File tree

18 files changed

+81
-103
lines changed

18 files changed

+81
-103
lines changed

OMCompiler/Compiler/BackEnd/BackendDAEOptimize.mo

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2800,7 +2800,7 @@ algorithm
28002800

28012801
case (conds,tbs,fb::fbs)
28022802
equation
2803-
tbsRest = List.map(tbs,List.rest);
2803+
tbsRest = List.map(tbs, listRest);
28042804
rest_res = makeResidualIfExpLst(conds, tbsRest, fbs);
28052805

28062806
tbsFirst = List.map(tbs,listHead);
@@ -2908,7 +2908,7 @@ algorithm
29082908
case (_, _, fb::fbs, _, _)
29092909
equation
29102910
size = Expression.sizeOf(Expression.typeof(fb));
2911-
tbsRest = List.map(inExpLst2, List.rest);
2911+
tbsRest = List.map(inExpLst2, listRest);
29122912
rest_res = makeEquationsFromResiduals(inExp1, tbsRest, fbs, inSource, inEqAttr);
29132913
tbsFirst = List.map(inExpLst2, listHead);
29142914
ifexp = Expression.makeNestedIf(inExp1,tbsFirst,fb);

OMCompiler/Compiler/FrontEnd/Ceval.mo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2703,7 +2703,7 @@ algorithm
27032703
case (lst,dim)
27042704
equation
27052705
first_lst = List.map(lst, listHead);
2706-
rest = List.map(lst, List.rest);
2706+
rest = List.map(lst, listRest);
27072707
first_lst_1 = catDimension(first_lst, dim);
27082708
rest_1 = catDimension2(rest, dim);
27092709
res = List.threadMap(rest_1, first_lst_1, List.consr);

OMCompiler/Compiler/FrontEnd/OperatorOverloading.mo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2110,7 +2110,7 @@ algorithm
21102110
// Step 3: Call constructor functions to try matching inputs
21112111
args = List.map(types, Types.getFuncArg);
21122112
tys1 = List.mapMap(args, listHead, Types.funcArgType);
2113-
args = List.map(args, List.rest);
2113+
args = List.map(args, listRest);
21142114
tys2 = List.mapMap(args, listHead, Types.funcArgType);
21152115
// We only look for constructors that are not of the initial type. Filter duplicates.
21162116
tys1 = List.setDifference(List.union(tys1,{}),{inType1});

OMCompiler/Compiler/NBackEnd/Classes/NBEquation.mo

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ public
200200
list<Option<Iterator>> tmp_maps, maps = {};
201201
algorithm
202202
if List.hasOneElement(iterators) then
203-
result := List.first(iterators);
203+
result := listHead(iterators);
204204
else
205205
for iter in listReverse(iterators) loop
206206
(tmp_names, tmp_ranges, tmp_maps) := getFrames(iter);
@@ -709,7 +709,7 @@ public
709709

710710
if listLength(occs) == 1 then
711711
// get the only occuring iterator cref and solve the body for it
712-
cref := List.first(occs);
712+
cref := listHead(occs);
713713
(tmpEqn, _, status, invert) := Solve.solveBody(tmpEqn, cref, FunctionTree.EMPTY());
714714
operator := if invert == NBSolve.RelationInversion.TRUE then Operator.invert(condition.operator) else condition.operator;
715715

@@ -875,7 +875,7 @@ public
875875
algorithm
876876
if Util.isSome(map) then
877877
(names, _) := getFrames(Util.getOption(map));
878-
str := str + " (" + ComponentRef.toString(List.first(names)) + ")";
878+
str := str + " (" + ComponentRef.toString(listHead(names)) + ")";
879879
end if;
880880
end singleStr;
881881
algorithm
@@ -1559,7 +1559,7 @@ public
15591559
case SCALAR_EQUATION() then eq.lhs;
15601560
case ARRAY_EQUATION() then eq.lhs;
15611561
case RECORD_EQUATION() then eq.lhs;
1562-
case FOR_EQUATION(body = {_}) then getLHS(List.first(eq.body));
1562+
case FOR_EQUATION(body = {_}) then getLHS(listHead(eq.body));
15631563
case IF_EQUATION() algorithm
15641564
(lhs, success) := IfEquationBody.getLHS(eq.body);
15651565
if not success then
@@ -1582,7 +1582,7 @@ public
15821582
case SCALAR_EQUATION() then eq.rhs;
15831583
case ARRAY_EQUATION() then eq.rhs;
15841584
case RECORD_EQUATION() then eq.rhs;
1585-
case FOR_EQUATION(body = {_}) then getRHS(List.first(eq.body));
1585+
case FOR_EQUATION(body = {_}) then getRHS(listHead(eq.body));
15861586
case IF_EQUATION() then IfEquationBody.getRHS(eq.body);
15871587
else algorithm
15881588
Error.addMessage(Error.INTERNAL_ERROR,{getInstanceName() + " failed because RHS was ambiguous for: " + toString(eq)});
@@ -1600,7 +1600,7 @@ public
16001600
case ARRAY_EQUATION() algorithm eq.lhs := lhs; then eq;
16011601
case RECORD_EQUATION() algorithm eq.lhs := lhs; then eq;
16021602
case FOR_EQUATION(body = {_}) algorithm
1603-
eq.body := {setLHS(List.first(eq.body), lhs)};
1603+
eq.body := {setLHS(listHead(eq.body), lhs)};
16041604
then eq;
16051605
else algorithm
16061606
Error.addMessage(Error.INTERNAL_ERROR,{getInstanceName() + " failed because LHS " + Expression.toString(lhs) + " could not be set for:\n " + toString(eq)});
@@ -1618,7 +1618,7 @@ public
16181618
case ARRAY_EQUATION() algorithm eq.rhs := rhs; then eq;
16191619
case RECORD_EQUATION() algorithm eq.rhs := rhs; then eq;
16201620
case FOR_EQUATION(body = {_}) algorithm
1621-
eq.body := {setRHS(List.first(eq.body), rhs)};
1621+
eq.body := {setRHS(listHead(eq.body), rhs)};
16221622
then eq;
16231623
else algorithm
16241624
Error.addMessage(Error.INTERNAL_ERROR,{getInstanceName() + " failed because RHS could not be set for: " + toString(eq)});
@@ -1756,7 +1756,7 @@ public
17561756
if isNone(if_body.else_if) and not List.hasSeveralElements(if_body.then_eqns) then
17571757
// first if-branch is true and has only one equation
17581758
// just replace if-equation with body
1759-
new_eq := Pointer.access(List.first(if_body.then_eqns));
1759+
new_eq := Pointer.access(listHead(if_body.then_eqns));
17601760
else
17611761
eq.body := if_body;
17621762
try
@@ -1997,7 +1997,7 @@ public
19971997

19981998
// returns innermost residual!
19991999
// Ambiguous for entwined for loops!
2000-
case FOR_EQUATION(body = {_}) then getResidualExp(List.first(eqn.body));
2000+
case FOR_EQUATION(body = {_}) then getResidualExp(listHead(eqn.body));
20012001

20022002
else algorithm
20032003
Error.addMessage(Error.INTERNAL_ERROR,{getInstanceName() + " failed for:\n" + toString(eqn)});
@@ -2016,7 +2016,7 @@ public
20162016
case ARRAY_EQUATION() then eq.ty;
20172017
case RECORD_EQUATION() then eq.ty;
20182018
case FOR_EQUATION() algorithm
2019-
ty := getType(List.first(eq.body));
2019+
ty := getType(listHead(eq.body));
20202020
if not skipIterator then
20212021
ty := Type.liftArrayRightList(ty, Iterator.dimensions(eq.iter));
20222022
end if;
@@ -2278,7 +2278,7 @@ public
22782278
local
22792279
Equation body;
22802280
case FOR_EQUATION() algorithm
2281-
(body, acc) := mergeIterators(List.first(eq.body), false);
2281+
(body, acc) := mergeIterators(listHead(eq.body), false);
22822282
acc := eq.iter :: acc;
22832283
then (if top_level then FOR_EQUATION(eq.size, Iterator.merge(acc), {body}, eq.source, eq.attr) else body, acc);
22842284
else (eq, {});
@@ -2296,7 +2296,7 @@ public
22962296
case FOR_EQUATION() algorithm
22972297
// split returns innermost first
22982298
iterators := Iterator.split(eqn.iter);
2299-
body := List.first(eqn.body);
2299+
body := listHead(eqn.body);
23002300
for iter in iterators loop
23012301
body := FOR_EQUATION(eqn.size, iter, {body}, eqn.source, eqn.attr);
23022302
end for;
@@ -2475,7 +2475,7 @@ public
24752475
ComponentRef cref;
24762476
case SOME(cref) algorithm
24772477
// first solve then replace iterators
2478-
(body, funcTree, solve_status, _) := Solve.solveBody(List.first(eqn.body), cref, funcTree);
2478+
(body, funcTree, solve_status, _) := Solve.solveBody(listHead(eqn.body), cref, funcTree);
24792479
body := map(body, function Replacements.applySimpleExp(replacements = replacements));
24802480

24812481
// if there is a diagonal to remove, get the necessary linear maps
@@ -2543,7 +2543,7 @@ public
25432543
// create the replacement rules for this location
25442544
Iterator.createLocationReplacements(eqn.iter, listArray(location), replacements);
25452545
// replace iterators
2546-
sliced_eqn := map(List.first(eqn.body), function Replacements.applySimpleExp(replacements = replacements));
2546+
sliced_eqn := map(listHead(eqn.body), function Replacements.applySimpleExp(replacements = replacements));
25472547
// solve the body if necessary
25482548
if not ComponentRef.isEmpty(cref_to_solve) then
25492549
(sliced_eqn, funcTree, _, _) := Solve.solveBody(sliced_eqn, cref_to_solve, funcTree);

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ public
145145
mode := Util.getOption(mode_opt);
146146
if Equation.isRecordOrTupleEquation(EquationPointers.getEqnAt(eqns, mapping.eqn_StA[eqn_scal_idx])) then
147147
// add the cref to the result, but remove it from the modes so all modes of a tuple equations are equal
148-
cref := List.first(mode.crefs);
148+
cref := listHead(mode.crefs);
149149
mode.crefs := {};
150150
addMulti(cref, eqn_scal_idx, mode, buckets);
151151
else
@@ -172,7 +172,7 @@ public
172172
val := Value.addEquation(val, eqn_scal_idx);
173173
UnorderedMap.add(mode, val, buckets);
174174
else
175-
val := Value.SINGLE_VAL(List.first(mode.crefs), {eqn_scal_idx});
175+
val := Value.SINGLE_VAL(listHead(mode.crefs), {eqn_scal_idx});
176176
UnorderedMap.addNew(mode, val, buckets);
177177
end if;
178178
end add;
@@ -555,8 +555,8 @@ public
555555
for i in node.eqn_indices loop
556556
indep := indep and List.hasOneElement(m_local[i]);
557557
end for;
558-
eqn_arr_idx := mapping.eqn_StA[List.first(node.eqn_indices)];
559-
var_arr_idx := mapping.var_StA[matching.eqn_to_var[List.first(node.eqn_indices)]];
558+
eqn_arr_idx := mapping.eqn_StA[listHead(node.eqn_indices)];
559+
var_arr_idx := mapping.var_StA[matching.eqn_to_var[listHead(node.eqn_indices)]];
560560
then StrongComponent.createPseudoSlice(var_arr_idx, eqn_arr_idx, node.cref_to_solve, sorted_body_indices, matching.eqn_to_var, eqns, mapping, indep);
561561

562562
// entwined array equations

OMCompiler/Compiler/NBackEnd/Modules/2_Pre/NBAlias.mo

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -861,7 +861,7 @@ protected
861861
end if;
862862
fixed_start_map := setStartFixed(attrcollector.start_map, attrcollector.fixed_map, set);
863863
if UnorderedMap.size(fixed_start_map) == 1 then
864-
new_start := SOME(List.first(UnorderedMap.valueList(fixed_start_map)));
864+
new_start := SOME(listHead(UnorderedMap.valueList(fixed_start_map)));
865865
fixed_var := BVariable.getVarPointer(UnorderedMap.firstKey(fixed_start_map));
866866
BVariable.setFixed(fixed_var, false, true); // avoid having two fixed variables
867867
UnorderedMap.add(BVariable.getVarName(fixed_var), Expression.BOOLEAN(false), attrcollector.fixed_map); // update attribute collector
@@ -942,7 +942,7 @@ protected
942942
if listEmpty(rest) then // constants and rest are empty
943943
max_exp := NONE();
944944
elseif List.hasOneElement(rest) then // one constant or one rest
945-
max_exp := SOME(List.first(rest));
945+
max_exp := SOME(listHead(rest));
946946
else
947947
max_exp_val := Expression.CALL(Call.makeTypedCall(
948948
fn = NFBuiltinFuncs.MAX_REAL,
@@ -971,7 +971,7 @@ protected
971971
if listEmpty(rest) then // constants and rest are empty
972972
min_exp := NONE();
973973
elseif List.hasOneElement(rest) then // one constant or one rest
974-
min_exp := SOME(List.first(rest));
974+
min_exp := SOME(listHead(rest));
975975
else
976976
min_exp_val := Expression.CALL(Call.makeTypedCall(
977977
fn = NFBuiltinFuncs.MAX_REAL,
@@ -1198,7 +1198,7 @@ protected
11981198
chosen_val := NONE();
11991199
chosen_cref := NONE();
12001200
elseif List.hasOneElement(lst_values) then
1201-
(compref, sval) := List.first(lst_values);
1201+
(compref, sval) := listHead(lst_values);
12021202
chosen_val := SOME(sval);
12031203
chosen_cref := SOME(compref);
12041204
else
@@ -1225,7 +1225,7 @@ protected
12251225
if listEmpty(lst_values) then
12261226
chosen_val := NONE();
12271227
elseif List.hasOneElement(lst_values) then
1228-
chosen_val := SOME(List.first(lst_values));
1228+
chosen_val := SOME(listHead(lst_values));
12291229
else
12301230
tearing_select := TearingSelect.NEVER;
12311231
for val in lst_values loop

OMCompiler/Compiler/NBackEnd/Modules/2_Pre/NBDetectStates.mo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ protected
297297
(returnExp, oDiffArgs) := Differentiate.differentiateExpression(arg, diffArgs);
298298
returnExp := SimplifyExp.simplifyDump(returnExp, true, getInstanceName());
299299
if List.hasOneElement(oDiffArgs.new_vars) then
300-
der_var := List.first(oDiffArgs.new_vars);
300+
der_var := listHead(oDiffArgs.new_vars);
301301
Pointer.update(acc_derivatives, der_var :: Pointer.access(acc_derivatives));
302302
Pointer.update(acc_states, Util.getOption(BVariable.getVarState(der_var)) :: Pointer.access(acc_states));
303303
elseif List.hasSeveralElements(oDiffArgs.new_vars) then

OMCompiler/Compiler/NBackEnd/Modules/2_Pre/NBInline.mo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ public
209209
else (eqn, false);
210210
end match;
211211
// unpack the equation
212-
eqn := if Equation.isDummy(eqn) then Pointer.access(List.first(Pointer.access(new_eqns))) else eqn;
212+
eqn := if Equation.isDummy(eqn) then Pointer.access(listHead(Pointer.access(new_eqns))) else eqn;
213213
else
214214
changed := false;
215215
if Flags.isSet(Flags.FAILTRACE) then

OMCompiler/Compiler/NBackEnd/Modules/3_Post/NBJacobian.mo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ public
197197
algorithm
198198

199199
if List.hasOneElement(jacobians) then
200-
jacobian := List.first(jacobians);
200+
jacobian := listHead(jacobians);
201201
jacobian := match jacobian case BackendDAE.JACOBIAN() algorithm jacobian.name := name; then jacobian; end match;
202202
else
203203
for jac in jacobians loop

OMCompiler/Compiler/NBackEnd/Modules/3_Post/NBSolve.mo

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public
118118
if Flags.isSet(Flags.DUMP_SLICE) then
119119
for tpl in UnorderedMap.toList(duplicate_map) loop
120120
(unsolved, solved) := tpl;
121-
if not referenceEq(List.first(solved), unsolved) then
121+
if not referenceEq(listHead(solved), unsolved) then
122122
print("[dumpSlice] The block:\n" + StrongComponent.toString(unsolved) + "\n"
123123
+ "[dumpSlice] got sliced to:\n" + List.toString(solved, function StrongComponent.toString(index = -1), "", "", "\n", "") + "\n\n");
124124
end if;
@@ -365,7 +365,7 @@ public
365365
// solve implicit equation (algebraic loop is always implicit)
366366
if solve_status == Status.IMPLICIT and List.hasOneElement(solved_comps) then
367367
(implicit_comp, funcTree, implicit_index) := Tearing.implicit(
368-
comp = List.first(solved_comps),
368+
comp = listHead(solved_comps),
369369
funcTree = funcTree,
370370
index = implicit_index,
371371
kind = kind
@@ -424,7 +424,7 @@ public
424424
algorithm
425425
if listLength(eqn_slice.indices) == 1 then
426426
replacements := UnorderedMap.new<Expression>(ComponentRef.hash, ComponentRef.isEqual);
427-
(eqn, funcTree) := Equation.singleSlice(eqn_ptr, List.first(eqn_slice.indices), Equation.sizes(eqn_ptr), cref, replacements, funcTree);
427+
(eqn, funcTree) := Equation.singleSlice(eqn_ptr, listHead(eqn_slice.indices), Equation.sizes(eqn_ptr), cref, replacements, funcTree);
428428
else
429429
(eqn, funcTree, solve_status, implicit_index, _) := solveEquation(Pointer.access(eqn_ptr), cref, funcTree, kind, implicit_index, slicing_map);
430430
end if;
@@ -1438,7 +1438,7 @@ protected
14381438
slices_lst := Equation.collectCrefs(eqn, function Slice.getSliceCandidates(name = var_cref));
14391439

14401440
if List.hasOneElement(slices_lst) then
1441-
var_cref := List.first(slices_lst);
1441+
var_cref := listHead(slices_lst);
14421442
solve_status := Status.UNPROCESSED;
14431443
else
14441444
// check if the record parents occur (todo: vice versa?)

0 commit comments

Comments
 (0)