Skip to content

Commit

Permalink
Workaround for bugs with hash tables
Browse files Browse the repository at this point in the history
  • Loading branch information
sjoelund authored and OpenModelica-Hudson committed Apr 4, 2016
1 parent f49dbc4 commit 7100384
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 19 deletions.
33 changes: 17 additions & 16 deletions Compiler/FrontEnd/Inline.mo
Expand Up @@ -691,7 +691,7 @@ algorithm
then (e_1,source,true);
case (e,fns,source)
equation
(e_1,_) = Expression.Expression.traverseExpBottomUp(e,function forceInlineCall(fns=fns),{});
(e_1,_) = Expression.traverseExpBottomUp(e,function forceInlineCall(fns=fns),{});
false = referenceEq(e, e_1);
source = DAEUtil.addSymbolicTransformation(source,DAE.OP_INLINE(DAE.PARTIAL_EQUATION(e),DAE.PARTIAL_EQUATION(e_1)));
(DAE.PARTIAL_EQUATION(e_2),source) = ExpressionSimplify.simplifyAddSymbolicOperation(DAE.PARTIAL_EQUATION(e_1), source);
Expand Down Expand Up @@ -821,9 +821,9 @@ algorithm
// add noEvent to avoid events as usually for functions
// MSL 3.2.1 need GenerateEvents to disable this
newExp = Expression.addNoEventToRelationsAndConds(newExp);
(newExp,(_,_,true)) = Expression.Expression.traverseExpBottomUp(newExp,replaceArgs,(argmap,checkcr,true));
(newExp,(_,_,true)) = Expression.traverseExpBottomUp(newExp,replaceArgs,(argmap,checkcr,true));
// for inlinecalls in functions
(newExp1,assrtLst) = Expression.Expression.traverseExpBottomUp(newExp,function inlineCall(fns=fns),assrtLst);
(newExp1,assrtLst) = Expression.traverseExpBottomUp(newExp,function inlineCall(fns=fns),assrtLst);
else // normal Modelica
// get inputs, body and output
(crefs,lst_cr,stmts,repl) = getFunctionInputsOutputBody(fn,{},{},{},repl);
Expand All @@ -842,9 +842,9 @@ algorithm
// MSL 3.2.1 need GenerateEvents to disable this
generateEvents = hasGenerateEventsAnnotation(comment);
newExp = if not generateEvents then Expression.addNoEventToRelationsAndConds(newExp) else newExp;
(newExp,(_,_,true)) = Expression.Expression.traverseExpBottomUp(newExp,replaceArgs,(argmap,checkcr,true));
(newExp,(_,_,true)) = Expression.traverseExpBottomUp(newExp,replaceArgs,(argmap,checkcr,true));
// for inlinecalls in functions
(newExp1,assrtLst) = Expression.Expression.traverseExpBottomUp(newExp,function inlineCall(fns=fns),assrtLst);
(newExp1,assrtLst) = Expression.traverseExpBottomUp(newExp,function inlineCall(fns=fns),assrtLst);
else // assert detected
true = listLength(assrtStmts) == 1;
assrt = listHead(assrtStmts);
Expand All @@ -859,10 +859,10 @@ algorithm
// MSL 3.2.1 need GenerateEvents to disable this
generateEvents = hasGenerateEventsAnnotation(comment);
newExp = if not generateEvents then Expression.addNoEventToRelationsAndConds(newExp) else newExp;
(newExp,(_,_,true)) = Expression.Expression.traverseExpBottomUp(newExp,replaceArgs,(argmap,checkcr,true));
(newExp,(_,_,true)) = Expression.traverseExpBottomUp(newExp,replaceArgs,(argmap,checkcr,true));
assrt = inlineAssert(assrt,fns,argmap,checkcr);
// for inlinecalls in functions
(newExp1,assrtLst) = Expression.Expression.traverseExpBottomUp(newExp,function inlineCall(fns=fns),assrt::assrtLst);
(newExp1,assrtLst) = Expression.traverseExpBottomUp(newExp,function inlineCall(fns=fns),assrt::assrtLst);
end if;
end if;
then
Expand All @@ -886,11 +886,12 @@ protected
DAE.Exp cond, msg, level;
algorithm
DAE.STMT_ASSERT(cond=cond, msg=msg, level=level, source=source) := assrtIn;
(cond,_,_,_) := inlineExp(cond,fns,source);
(cond,(_,_,true)) := Expression.Expression.traverseExpBottomUp(cond,replaceArgs,(argmap,checkcr,true));
(cond,(_,_,true)) := Expression.traverseExpBottomUp(cond,replaceArgs,(argmap,checkcr,true));
//print("ASSERT inlined: "+ExpressionDump.printExpStr(cond)+"\n");
(msg,_,_,_) := inlineExp(msg,fns,source);
(msg,(_,_,true)) := Expression.Expression.traverseExpBottomUp(msg,replaceArgs,(argmap,checkcr,true));
(msg,(_,_,true)) := Expression.traverseExpBottomUp(msg,replaceArgs,(argmap,checkcr,true));
// These clear checkcr/repl and need to be performed last
// (cond,_,_,_) := inlineExp(cond,fns,source);
// (msg,_,_,_) := inlineExp(msg,fns,source);
assrtOut := DAE.STMT_ASSERT(cond, msg, level, source);
end inlineAssert;

Expand Down Expand Up @@ -965,7 +966,7 @@ algorithm
// MSL 3.2.1 need GenerateEvents to disable this
generateEvents = hasGenerateEventsAnnotation(comment);
newExp = if not generateEvents then Expression.addNoEventToRelationsAndConds(newExp) else newExp;
(newExp,(_,_,true)) = Expression.Expression.traverseExpBottomUp(newExp,replaceArgs,(argmap,checkcr,true));
(newExp,(_,_,true)) = Expression.traverseExpBottomUp(newExp,replaceArgs,(argmap,checkcr,true));
// for inlinecalls in functions
(newExp1,assrtLst) = Expression.traverseExpBottomUp(newExp,function forceInlineCall(fns=fns),assrtLst);
then (newExp1,assrtLst);
Expand Down Expand Up @@ -1599,24 +1600,24 @@ algorithm
list<DAE.Statement> assrtLst;
case DAE.PARTIAL_EQUATION(e)
equation
(e_1,_) = Expression.Expression.traverseExpBottomUp(e,fn,{});
(e_1,_) = Expression.traverseExpBottomUp(e,fn,{});
changed = not referenceEq(e, e_1);
eq2 = DAE.PARTIAL_EQUATION(e_1);
source = DAEUtil.condAddSymbolicTransformation(changed,inSource,DAE.OP_INLINE(inExp,eq2));
(eq2,source) = ExpressionSimplify.condSimplifyAddSymbolicOperation(changed, eq2, source);
then (eq2,source);
case DAE.RESIDUAL_EXP(e)
equation
(e_1,_) = Expression.Expression.traverseExpBottomUp(e,fn,{});
(e_1,_) = Expression.traverseExpBottomUp(e,fn,{});
changed = not referenceEq(e, e_1);
eq2 = DAE.RESIDUAL_EXP(e_1);
source = DAEUtil.condAddSymbolicTransformation(changed,inSource,DAE.OP_INLINE(inExp,eq2));
(eq2,source) = ExpressionSimplify.condSimplifyAddSymbolicOperation(changed, eq2, source);
then (eq2,source);
case DAE.EQUALITY_EXPS(e1,e2)
equation
(e1_1,_) = Expression.Expression.traverseExpBottomUp(e1,fn,{});
(e2_1,_) = Expression.Expression.traverseExpBottomUp(e2,fn,{});
(e1_1,_) = Expression.traverseExpBottomUp(e1,fn,{});
(e2_1,_) = Expression.traverseExpBottomUp(e2,fn,{});
changed = not (referenceEq(e1, e1_1) and referenceEq(e2, e2_1));
eq2 = DAE.EQUALITY_EXPS(e1_1,e2_1);
source = DAEUtil.condAddSymbolicTransformation(changed,inSource,DAE.OP_INLINE(inExp,eq2));
Expand Down
26 changes: 23 additions & 3 deletions Compiler/Util/BaseHashTable.mo
Expand Up @@ -648,22 +648,42 @@ protected
FuncHash hashFunc;
Key key;
array<Option<HashEntry>> vae;
constant Boolean workaroundForBug=true "TODO: Make it impossible to update a value by not updating n (fully mutable HT instead of this hybrid)";
constant Boolean debug=false;
algorithm
(hv, (vs, ve, vae), bs, ft as (hashFunc,_,_,_)) := ht;
for i in 1:ve loop
_ := match arrayGet(vae, i)
case SOME((key,_))
algorithm
hash_idx := hashFunc(key, bs) + 1;
arrayUpdate(hv, hash_idx, {});
if not workaroundForBug then
hash_idx := hashFunc(key, bs) + 1;
arrayUpdate(hv, hash_idx, {});
end if;
arrayUpdate(vae, i, NONE());
then ();
else
algorithm
return;
if not workaroundForBug then return; end if;
then ();
end match;
end for;
if debug then
for i in vae loop
if isSome(i) then
print("vae not empty\n");
break;
end if;
end for;
end if;
if workaroundForBug then
for i in 1:arrayLength(hv) loop
if not listEmpty(arrayGet(hv,i)) then
if debug then print("hv not empty\n"); end if;
arrayUpdate(hv,i,{});
end if;
end for;
end if;
end clearAssumeNoDelete;

annotation(__OpenModelica_Interface="util");
Expand Down

0 comments on commit 7100384

Please sign in to comment.