Skip to content

Commit

Permalink
Clean up List.
Browse files Browse the repository at this point in the history
- Remove List.mapFoldTuple since using it was mostly just a sign of
  tuple misuse.
- Remove List.mapFoldListTuple for the same argument and the fact that
  it wasn't used anywhere.
- Remove List.threadTuple in favour of List.zip that does the same
  thing, and rename List.thread3Tuple => List.zip3.
- Remove List.first2FromTuple3 since it wasn't used and not a list
  function anyway.
- Move List.foldcallN to Util since it's not a list function.
  • Loading branch information
perost committed Nov 17, 2020
1 parent 2f6f01a commit aab0aff
Show file tree
Hide file tree
Showing 23 changed files with 106 additions and 317 deletions.
2 changes: 1 addition & 1 deletion OMCompiler/Compiler/BackEnd/BackendInline.mo
Expand Up @@ -1125,7 +1125,7 @@ algorithm


// replace inputs variables
argmap := List.threadTuple(listReverse(fnInputs), args);
argmap := List.zip(listReverse(fnInputs), args);
(argmap,checkcr) := Inline.extendCrefRecords(argmap, HashTableCG.emptyHashTable());
BackendDAEUtil.traverseBackendDAEExpsEqSystemWithUpdate(outEqs, replaceArgs, (argmap,checkcr,true));

Expand Down
4 changes: 2 additions & 2 deletions OMCompiler/Compiler/BackEnd/Differentiate.mo
Expand Up @@ -852,7 +852,7 @@ algorithm
(dexpLst,functions) = List.map3Fold(expLst, function differentiateExp(maxIter=maxIter), inDiffwrtCref, inInputData, inDiffType, inFunctionTree);
(derivedRHS as DAE.TUPLE(expLstRHS), functions) = differentiateExp(rhs, inDiffwrtCref, inInputData, inDiffType, functions, maxIter);
(DAE.TUPLE(expLstRHS),_) = ExpressionSimplify.simplify(derivedRHS);
exptl = List.threadTuple(dexpLst, expLstRHS);
exptl = List.zip(dexpLst, expLstRHS);
optDerivedStatements1 = List.map2(exptl, makeAssignmentfromTuple, source, inFunctionTree);
derivedStatements1 = List.flatten(List.map(optDerivedStatements1, List.fromOption));
derivedStatements2 = listAppend(derivedStatements1, {currStatement});
Expand Down Expand Up @@ -2416,7 +2416,7 @@ algorithm
end if;

// create differentiated call arguments
expBoolLst = List.threadTuple(expl, blst);
expBoolLst = List.zip(expl, blst);
expBoolLst = List.filterOnTrue(expBoolLst, Util.tuple22);
expl1 = List.map(expBoolLst, Util.tuple21);
if Flags.isSet(Flags.DEBUG_DIFFERENTIATION_VERBOSE) then
Expand Down
2 changes: 1 addition & 1 deletion OMCompiler/Compiler/BackEnd/IndexReduction.mo
Expand Up @@ -3549,7 +3549,7 @@ algorithm
equation
n = diffcount-level;
true = intGt(n,0);
cr = List.foldcallN(n, ComponentReference.crefPrefixDer, name);
cr = Util.foldcallN(n, ComponentReference.crefPrefixDer, name);
// generate replacement
e = Expression.crefExp(cr);
ht = BaseHashTable.add(((name,n),e),iHt);
Expand Down
2 changes: 1 addition & 1 deletion OMCompiler/Compiler/BackEnd/OpenTURNS.mo
Expand Up @@ -379,7 +379,7 @@ algorithm

Error.assertion(not listEmpty(varLst), "OpenTURNS.generateDistributions: No variable in the DAE has the distribution attribute! Check your model ...", AbsynUtil.dummyInfo);
dists := List.map(varLst,BackendVariable.varDistribution);
(sLst,distributionVarLst) := List.map1_2(List.threadTuple(dists,List.map(varLst,BackendVariable.varCref)),generateDistributionVariable,dae2);
(sLst,distributionVarLst) := List.map1_2(List.zip(dists,List.map(varLst,BackendVariable.varCref)),generateDistributionVariable,dae2);

// reverse to get them in the proper order
distributionVarLst := listReverse(distributionVarLst);
Expand Down
12 changes: 6 additions & 6 deletions OMCompiler/Compiler/FrontEnd/Inline.mo
Expand Up @@ -827,7 +827,7 @@ algorithm
if (Config.acceptMetaModelicaGrammar()) then // MetaModelica
crefs = List.map(fn,getInputCrefs);
crefs = List.select(crefs,removeWilds);
argmap = List.threadTuple(crefs,args);
argmap = List.zip(crefs,args);
false = List.exist(fn,DAEUtil.isProtectedVar);
newExp = getRhsExp(fn);
// compare types
Expand All @@ -852,7 +852,7 @@ algorithm
// compare types
true = checkExpsTypeEquiv(e1, newExp);
// input map cref again function args
argmap = List.threadTuple(crefs,args);
argmap = List.zip(crefs,args);
(checkcr,_) = getInlineHashTableVarTransform();
(argmap,checkcr) = extendCrefRecords(argmap,checkcr);
// add noEvent to avoid events as usually for functions
Expand All @@ -870,7 +870,7 @@ algorithm
newExp = Expression.makeTuple(list( getReplacementCheckComplex(repl,cr,ty) for cr in lst_cr));
// compare types
true = checkExpsTypeEquiv(e1, newExp);
argmap = List.threadTuple(crefs,args);
argmap = List.zip(crefs,args);
(argmap,checkcr) = extendCrefRecords(argmap,checkcr);
// add noEvent to avoid events as usually for functions
// MSL 3.2.1 need GenerateEvents to disable this
Expand Down Expand Up @@ -977,7 +977,7 @@ algorithm
newExp = Expression.makeTuple(list( VarTransform.getReplacement(repl,cr) for cr in lst_cr));
// compare types
true = checkExpsTypeEquiv(e1, newExp);
argmap = List.threadTuple(crefs,args);
argmap = List.zip(crefs,args);
(argmap,checkcr) = extendCrefRecords(argmap,checkcr);
// add noEvent to avoid events as usually for functions
// MSL 3.2.1 need GenerateEvents to disable this
Expand Down Expand Up @@ -1290,15 +1290,15 @@ algorithm
equation
(res1,ht1) = extendCrefRecords(res,ht);
crlst = List.map1(varLst,extendCrefRecords2,c);
new = List.threadTuple(crlst,expl);
new = List.zip(crlst,expl);
(new1,ht2) = extendCrefRecords(new,ht1);
res2 = listAppend(new1,res1);
then ((c,e)::res2,ht2);
case((c,e as (DAE.RECORD(exps = expl,ty=DAE.T_COMPLEX(varLst=varLst))))::res,ht)
equation
(res1,ht1) = extendCrefRecords(res,ht);
crlst = List.map1(varLst,extendCrefRecords2,c);
new = List.threadTuple(crlst,expl);
new = List.zip(crlst,expl);
(new1,ht2) = extendCrefRecords(new,ht1);
res2 = listAppend(new1,res1);
then ((c,e)::res2,ht2);
Expand Down
8 changes: 3 additions & 5 deletions OMCompiler/Compiler/FrontEnd/Patternm.mo
Expand Up @@ -546,7 +546,7 @@ algorithm
funcArgs2 = listAppend(funcArgs,funcArgsNamedFixed);
Util.SUCCESS() = checkInvalidPatternNamedArgs(invalidArgs,fieldNameList,Util.SUCCESS(),info);
(cache,patterns) = elabPatternTuple(cache,env,funcArgs2,fieldTypeList,info,lhs);
namedPatterns = List.thread3Tuple(patterns, fieldNameList, List.map(fieldTypeList,Types.simplifyType));
namedPatterns = List.zip3(patterns, fieldNameList, List.map(fieldTypeList,Types.simplifyType));
namedPatterns = List.filterOnTrue(namedPatterns, filterEmptyPattern);
then (cache,DAE.PAT_CALL_NAMED(fqPath,namedPatterns));

Expand Down Expand Up @@ -1585,11 +1585,9 @@ algorithm
then (pat,extra);
case DAE.PAT_CALL_NAMED(name,namedpats)
equation
pats = List.map(namedpats,Util.tuple31);
fields = List.map(namedpats,Util.tuple32);
types = List.map(namedpats,Util.tuple33);
(pats, fields, types) = List.unzip3(namedpats);
(pats,extra) = traversePatternList(pats, func, extra);
namedpats = List.thread3Tuple(pats, fields, types);
namedpats = List.zip3(pats, fields, types);
pat = DAE.PAT_CALL_NAMED(name,namedpats);
(pat,extra) = func(pat,extra);
then (pat,extra);
Expand Down
4 changes: 2 additions & 2 deletions OMCompiler/Compiler/FrontEnd/SCodeUtil.mo
Expand Up @@ -1504,7 +1504,7 @@ algorithm
conditions = List.map(branches, Util.tuple21);
stmtsList = List.map(branches, Util.tuple22);
algsLst = List.mapList(stmtsList, statementToAlgorithmItem);
abranches = List.threadTuple(conditions,algsLst);
abranches = List.zip(conditions,algsLst);

algs2 = List.map(elseBranch,statementToAlgorithmItem);
then Absyn.ALGORITHMITEM(Absyn.ALG_IF(boolExpr,algs1,abranches,algs2),NONE(),info);
Expand All @@ -1529,7 +1529,7 @@ algorithm
(boolExpr::conditions) = List.map(branches, Util.tuple21);
stmtsList = List.map(branches, Util.tuple22);
(algs1::algsLst) = List.mapList(stmtsList, statementToAlgorithmItem);
abranches = List.threadTuple(conditions,algsLst);
abranches = List.zip(conditions,algsLst);
then Absyn.ALGORITHMITEM(Absyn.ALG_WHEN_A(boolExpr,algs1,abranches),NONE(),info);

case SCode.ALG_ASSERT()
Expand Down
4 changes: 2 additions & 2 deletions OMCompiler/Compiler/FrontEnd/StateMachineFlatten.mo
Expand Up @@ -305,7 +305,7 @@ algorithm

// We have some redundancy here (t[:].condition == c[:]) and thus need to update both
i := 0;
for tc in List.threadTuple(t,c) loop
for tc in List.zip(t,c) loop
i := i + 1;
(t2, c2) := tc;
TRANSITION(from, to, condition, immediate, reset, synchronize, priority) := t2;
Expand Down Expand Up @@ -441,7 +441,7 @@ algorithm
stateVarCrefs := List.map(stateVarLst, DAEUtil.varCref);
variableAttributesOptions := List.map(stateVarLst, DAEUtil.getVariableAttributes);
startValuesOpt := List.map(variableAttributesOptions, getStartAttrOption);
varCrefStartVal := List.threadTuple(stateVarCrefs, startValuesOpt);
varCrefStartVal := List.zip(stateVarCrefs, startValuesOpt);
crToExpOpt := HashTableCrToExpOption.emptyHashTableSized(listLength(varCrefStartVal) + 1);
// create table that maps the cref of a variable to its start value
crToExpOpt := List.fold(varCrefStartVal, BaseHashTable.add, crToExpOpt);
Expand Down
12 changes: 6 additions & 6 deletions OMCompiler/Compiler/MidCode/DAEToMid.mo
Expand Up @@ -73,7 +73,7 @@ uniontype State
end State;

function listZip<X,Y>
"List.threadTuple fails for lists of unequal length
"List.zip fails for lists of unequal length
but truncating is the more common semantics."
input list<X> xs;
input list<Y> ys;
Expand Down Expand Up @@ -1139,7 +1139,7 @@ algorithm

assert( listLength(inputsCref) == listLength(aliases), "MatchExpressionToMid: incorrect input: listLength(inputs) != listLength(aliases)" );
inputsMidVar := {};
for daeExp_aliasList in List.threadTuple(inputsCref,aliases) loop
for daeExp_aliasList in List.zip(inputsCref,aliases) loop

(daeExp,aliasList) := daeExp_aliasList;
srcVar := RValueToVar(ExpToMid(daeExp, state), state);
Expand Down Expand Up @@ -1187,7 +1187,7 @@ algorithm
one := GenTmpVar(DAE.T_INTEGER_DEFAULT,state);
stateAddStmt(MidCode.ASSIGN(one, MidCode.LITERALINTEGER(1)) ,state);
stateAddStmt(MidCode.ASSIGN(muxState, MidCode.BINARYOP(MidCode.ADD(),muxState,one)),state);
stateTerminate(labelFin, MidCode.SWITCH( muxState, List.threadTuple( List.intRange(listLength(cases)+1), listAppend(caseLabels,{labelFin}) ) ), state);
stateTerminate(labelFin, MidCode.SWITCH( muxState, List.zip( List.intRange(listLength(cases)+1), listAppend(caseLabels,{labelFin}) ) ), state);
else
stateTerminate(labelFin, MidCode.GOTO(if not listEmpty(caseLabels) then listHead(caseLabels) else labelFin), state);
end if;
Expand Down Expand Up @@ -1246,9 +1246,9 @@ algorithm
// NOTE: If the guard fails we will have made pattern assignments for a failing case. This is how it was done before as far as I can tell.
if matchContinue
then
patternToMidCode(state=state, matches=List.threadTuple(inputsMidVar,patterns), labelNoMatch=labelMux);
patternToMidCode(state=state, matches=List.zip(inputsMidVar,patterns), labelNoMatch=labelMux);
else
patternToMidCode(state=state, matches=List.threadTuple(inputsMidVar,patterns)
patternToMidCode(state=state, matches=List.zip(inputsMidVar,patterns)
,labelNoMatch= if not listEmpty(caseLabelIterator) then listHead(caseLabelIterator) else labelFail);
end if;
// then guard
Expand Down Expand Up @@ -1285,7 +1285,7 @@ algorithm
Also outvars is unexpectedly removed of trailing wildcards and can be shorter than expList,
including tuples of length 1 (probably 0 too, but who knows).
So we define and use listZip instead of threadTuple.
So we define and use listZip instead of List.zip.
TODO: Document the unintuitive undocumented interface somewhere.
*/
Expand Down
18 changes: 1 addition & 17 deletions OMCompiler/Compiler/Script/Interactive.mo
Expand Up @@ -17029,7 +17029,7 @@ algorithm
list<Absyn.NamedArg> namedArgs,namedArgs1;
case( Absyn.FUNCTIONARGS(expl,namedArgs))
equation
(expl1,_) = List.mapFoldTuple(expl, transformFlatExpTrav, 0);
expl1 = list(AbsynUtil.traverseExp(e, transformFlatExp, 0) for e in expl);
namedArgs1 = List.map(namedArgs,transformFlatNamedArg);
then
Absyn.FUNCTIONARGS(expl1,namedArgs1);
Expand All @@ -17052,22 +17052,6 @@ algorithm
end match;
end transformFlatNamedArg;

protected function transformFlatExpTrav
"Transforms a flat expression by calling traverseExp"
input tuple<Absyn.Exp,Integer> inExp;
output tuple<Absyn.Exp,Integer> outExp;
algorithm
outExp := match(inExp)
local
Absyn.Exp e,e1;
Integer i;
case( (e,i))
equation
(e1,i) = AbsynUtil.traverseExp(e,transformFlatExp,0);
then ((e1,i));
end match;
end transformFlatExpTrav;

protected function transformFlatExp
input Absyn.Exp inExp;
input Integer inDummy;
Expand Down
2 changes: 1 addition & 1 deletion OMCompiler/Compiler/Script/InteractiveUtil.mo
Expand Up @@ -14731,7 +14731,7 @@ algorithm
list<Absyn.NamedArg> namedArgs,namedArgs1;
case( Absyn.FUNCTIONARGS(expl,namedArgs))
equation
(expl1,_) = List.mapFoldTuple(expl, transformFlatExpTrav, 0);
expl1 = list(AbsynUtil.traverseExp(e, transformFlatExp, 0) for e in expl);
namedArgs1 = List.map(namedArgs,transformFlatNamedArg);
then
Absyn.FUNCTIONARGS(expl1,namedArgs1);
Expand Down

0 comments on commit aab0aff

Please sign in to comment.