Skip to content

Commit

Permalink
Only print we remove variables actually removed
Browse files Browse the repository at this point in the history
The problem is loops have 1 extra call to find dead stores, and
notifications from this step should not be visible.
  • Loading branch information
sjoelund authored and OpenModelica-Hudson committed Jan 26, 2017
1 parent 86c3226 commit ef1458e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
11 changes: 7 additions & 4 deletions Compiler/FrontEnd/Patternm.mo
Expand Up @@ -65,6 +65,7 @@ import ElementSource;
import Expression;
import ExpressionDump;
import Error;
import ErrorExt;
import Flags;
import FGraph;
import Inst;
Expand Down Expand Up @@ -1284,7 +1285,7 @@ protected function checkDefUsePattern
output DAE.Pattern outPat;
output tuple<AvlSetString.Tree,AvlSetString.Tree,SourceInfo> outTpl=inTpl;
algorithm
outPat := matchcontinue (inPat,inTpl)
outPat := match (inPat,inTpl)
local
AvlSetString.Tree localsTree,useTree;
String name;
Expand All @@ -1294,7 +1295,6 @@ algorithm
tuple<AvlSetString.Tree,AvlSetString.Tree,SourceInfo> extra;
case ((DAE.PAT_AS(id=name,pat=pat),extra as (localsTree,useTree,info)))
equation
// TODO: Can skip matchcontinue and failure if there was an AvlTree.exists(key)
if AvlSetString.hasKey(localsTree,name) and not AvlSetString.hasKey(useTree,name) then
Error.assertionOrAddSourceMessage(not Flags.isSet(Flags.PATTERNM_ALL_INFO),Error.META_UNUSED_AS_BINDING,{name},info);
else
Expand All @@ -1303,7 +1303,6 @@ algorithm
then pat;
case ((DAE.PAT_AS_FUNC_PTR(id=name,pat=pat),extra as (localsTree,useTree,info)))
equation
// TODO: Can skip matchcontinue and failure if there was an AvlTree.exists(key)
if AvlSetString.hasKey(localsTree,name) and not AvlSetString.hasKey(useTree,name) then
Error.assertionOrAddSourceMessage(not Flags.isSet(Flags.PATTERNM_ALL_INFO),Error.META_UNUSED_AS_BINDING,{name},info);
else
Expand All @@ -1314,7 +1313,7 @@ algorithm
algorithm
(pat,_) := simplifyPattern(inPat,1);
then pat;
end matchcontinue;
end match;
end checkDefUsePattern;

protected function useLocalCref
Expand Down Expand Up @@ -2959,7 +2958,9 @@ algorithm
case DAE.STMT_FOR(ty,b,id,index,exp,body,source)
equation
// Loops repeat, so check for usage in the whole loop before removing any dead stores.
ErrorExt.setCheckpoint(getInstanceName());
(_, useTree) = List.map1Fold(body, statementFindDeadStore, localsTree, inUseTree);
ErrorExt.rollBack(getInstanceName());
(body,useTree) = statementListFindDeadStoreRemoveEmptyStatements(body,localsTree, useTree);
(_,useTree) = Expression.traverseExpBottomUp(exp, useLocalCref, useTree);
// TODO: We should remove ident from the use-tree in case of shadowing... But our avlTree cannot delete
Expand All @@ -2969,7 +2970,9 @@ algorithm
case DAE.STMT_WHILE(exp=exp,statementLst=body,source=source)
equation
// Loops repeat, so check for usage in the whole loop before removing any dead stores.
ErrorExt.setCheckpoint(getInstanceName());
(_, useTree) = List.map1Fold(body, statementFindDeadStore, localsTree, inUseTree);
ErrorExt.rollBack(getInstanceName());
(body,useTree) = statementListFindDeadStoreRemoveEmptyStatements(body, localsTree, useTree);
(_,useTree) = Expression.traverseExpBottomUp(exp, useLocalCref, useTree);
// The loop might not be entered just like if. The following should not remove all previous uses:
Expand Down
7 changes: 5 additions & 2 deletions Compiler/Util/BaseAvlSet.mo
Expand Up @@ -222,10 +222,13 @@ function printTreeStr
protected
Tree left, right;
algorithm
NODE(left = left, right = right) := inTree;
outString := printTreeStr2(left, true, "") +
outString := match inTree
case EMPTY() then "EMPTY()";
case LEAF() then printNodeStr(inTree);
case NODE(left = left, right = right) then printTreeStr2(left, true, "") +
printNodeStr(inTree) + "\n" +
printTreeStr2(right, false, "");
end match;
end printTreeStr;

replaceable function setTreeLeftRight
Expand Down

0 comments on commit ef1458e

Please sign in to comment.