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

Commit

Permalink
Improve check for failed function inlining
Browse files Browse the repository at this point in the history
Expressions like `v[i]` would fail to inline before, and be silently
ignored. Now inlining fails, which does not corrupt the model.

Belonging to [master]:
  - #1773
  - OpenModelica/OpenModelica-testsuite#678
  • Loading branch information
sjoelund authored and OpenModelica-Hudson committed Oct 13, 2017
1 parent 0406ea2 commit 37e75ad
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions Compiler/FrontEnd/Inline.mo
Original file line number Diff line number Diff line change
Expand Up @@ -1415,12 +1415,18 @@ algorithm
equation
e = getExpFromArgMap(argmap,cref);
(e,_) = ExpressionSimplify.simplify(e);
then (e,(argmap,checkcr,true));
then (e,inTuple);

case (e as DAE.CREF(componentRef = cref),(argmap,checkcr,true))
case (DAE.CREF(componentRef = cref),(argmap,checkcr,true))
guard
BaseHashTable.hasKey(cref,checkcr)
then (e,(argmap,checkcr,false));
BaseHashTable.hasKey(ComponentReference.crefFirstCref(cref),checkcr)
then (inExp,(argmap,checkcr,false));

case (DAE.CREF(componentRef = cref),(argmap,checkcr,true))
equation
getExpFromArgMap(argmap,ComponentReference.crefStripSubs(ComponentReference.crefFirstCref(cref)));
// We have something like v[i].re and v is in the inputs... So we fail to inline.
then (inExp,(argmap,checkcr,false));

case (DAE.UNBOX(DAE.CALL(path,expLst,DAE.CALL_ATTR(_,tuple_,false,isImpure,_,inlineType,tc)),ty),(argmap,checkcr,true))
equation
Expand All @@ -1432,7 +1438,7 @@ algorithm
isFunctionPointerCall = Types.isFunctionReferenceVar(ty2);
e = DAE.CALL(path,expLst,DAE.CALL_ATTR(ty,tuple_,b,isImpure,isFunctionPointerCall,inlineType,tc));
(e,_) = ExpressionSimplify.simplify(e);
then (e,(argmap,checkcr,true));
then (e,inTuple);

case (e as DAE.UNBOX(DAE.CALL(path,_,DAE.CALL_ATTR(builtin=false)),_),(argmap,checkcr,true))
equation
Expand All @@ -1453,15 +1459,15 @@ algorithm
e = DAE.CALL(path,expLst,DAE.CALL_ATTR(ty2,tuple_,b,isImpure,isFunctionPointerCall,inlineType,tc));
e = boxIfUnboxedFunRef(e,ty);
(e,_) = ExpressionSimplify.simplify(e);
then (e,(argmap,checkcr,true));
then (e,inTuple);

case (e as DAE.CALL(path,_,DAE.CALL_ATTR(ty=DAE.T_METATYPE(),builtin=false)),(argmap,checkcr,true))
equation
cref = ComponentReference.pathToCref(path);
true = BaseHashTable.hasKey(cref,checkcr);
then (e,(argmap,checkcr,false));

case (e,(argmap,checkcr,replacedfailed)) then (e,(argmap,checkcr,replacedfailed));
else (inExp,inTuple);
end matchcontinue;
end replaceArgs;

Expand Down

0 comments on commit 37e75ad

Please sign in to comment.