Skip to content

Commit

Permalink
Fix for bug #1040:
Browse files Browse the repository at this point in the history
- Added new record to DAE.Const, DAE.C_UNKNOWN, which is used for component
  binding with unknown variability.
- Rewrote Static.elabBuiltinFill to use DAE.C_UNKNOWN when checkModel is used
  and fill couldn't be expanded.
- Added test case mosfiles-nosim/ModifierVariabilityError.


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@6284 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
perost committed Oct 5, 2010
1 parent a8e9a91 commit 97cccc9
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 8 deletions.
1 change: 1 addition & 0 deletions Compiler/DAE.mo
Expand Up @@ -806,6 +806,7 @@ uniontype Const "The degree of constantness of an expression is determined by th

record C_VAR "\'parameter\'s, evaluated if structural not constants, never evaluated" end C_VAR;

record C_UNKNOWN end C_UNKNOWN;
end Const;

public
Expand Down
2 changes: 1 addition & 1 deletion Compiler/Inst.mo
Expand Up @@ -7450,7 +7450,7 @@ algorithm
// When doing checkModel we might have parameters with variable bindings,
// for example when the binding depends on the dimensions on an array with
// unknown dimensions.
case (DAE.C_PARAM,DAE.C_VAR,_,_,_)
case (DAE.C_PARAM,DAE.C_UNKNOWN,_,_,_)
equation
true = OptManager.getOption("checkModel");
then ();
Expand Down
8 changes: 5 additions & 3 deletions Compiler/Mod.mo
Expand Up @@ -333,11 +333,13 @@ algorithm
Values.Value v;
Ceval.Msg msg;
Env.Cache cache;
DAE.Const c;
equation
c = Types.propAllConst(inProp);
// Don't ceval variables.
failure(DAE.C_VAR() = Types.propAllConst(inProp));
// Show error messages from ceval only if the expression is not a parameter.
msg = Util.if_(Util.equal(DAE.C_PARAM(), Types.propAllConst(inProp)), Ceval.NO_MSG(), Ceval.MSG());
false = Types.constIsVariable(c);
// Show error messages from ceval only if the expression is a constant.
msg = Util.if_(Types.constIsConst(c), Ceval.MSG, Ceval.NO_MSG);
(cache,v,_) = Ceval.ceval(inCache, inEnv, inExp, false, NONE, NONE, msg);
then
(cache,SOME(v));
Expand Down
36 changes: 32 additions & 4 deletions Compiler/Static.mo
Expand Up @@ -1297,6 +1297,11 @@ algorithm
case(DAE.C_VAR()) then SCode.VAR();
case(DAE.C_PARAM()) then SCode.PARAM();
case(DAE.C_CONST()) then SCode.CONST();
case(DAE.C_UNKNOWN())
equation
Debug.fprintln("failtrace", "- Static.constToVariability failed on DAE.C_UNKNOWN");
then
fail();
end matchcontinue;
end constToVariability;

Expand Down Expand Up @@ -3206,20 +3211,21 @@ algorithm
list<Env.Frame> env;
Absyn.Exp s;
list<Absyn.Exp> dims;
Boolean impl;
Boolean impl, show_msg;
Ident implstr,expstr,str,sp;
list<Ident> expstrs;
Env.Cache cache;
DAE.Const c1;
DAE.DAElist dae,dae1,dae2;
Prefix pre;
Ceval.Msg msg;

case (cache,env,(s :: dims),_,impl,pre) /* impl */
equation
(cache,s_1,prop,_,dae1) = elabExp(cache, env, s, impl, NONE,true,pre);
(cache,dims_1,dimprops,_,dae2) = elabExpList(cache,env, dims, impl, NONE,true,pre);
sty = Types.getPropType(prop);
(cache,dimvals) = Ceval.cevalList(cache,env, dims_1, impl, NONE, Ceval.NO_MSG());
(cache,dimvals) = Ceval.cevalList(cache,env, dims_1, impl, NONE, Ceval.NO_MSG);
c1 = Types.elabTypePropToConst(prop::dimprops);
(cache,exp,prop) = elabBuiltinFill2(cache,env, s_1, sty, dimvals,c1,pre);
dae = DAEUtil.joinDaes(dae1,dae2);
Expand All @@ -3233,13 +3239,14 @@ algorithm
local
DAE.ExpType exp_type;
equation
c1 = unevaluatedFunctionVariability(env);
(cache, s_1, prop, _, dae1) = elabExp(cache, env, s, impl, NONE, true,pre);
(cache, dims_1, dimprops, _, dae2) = elabExpList(cache, env, dims, impl, NONE, true,pre);
sty = Types.getPropType(prop);
sty = makeFillArgListType(sty, dimprops);
exp_type = Types.elabType(sty);
dae = DAEUtil.joinDaes(dae1, dae2);
prop = DAE.PROP(sty, DAE.C_VAR());
prop = DAE.PROP(sty, c1);
exp = makeBuiltinCall("fill", s_1 :: dims_1, exp_type);
then
(cache, exp, prop, dae);
Expand All @@ -3248,7 +3255,7 @@ algorithm
equation
true = RTOpts.debugFlag("failtrace");
Debug.fprint("failtrace",
"- elab_builtin_fill: Couldn't elaborate fill(): ");
"- Static.elabBuiltinFill: Couldn't elaborate fill(): ");
implstr = Util.boolString(impl);
expstrs = Util.listMap(dims, Dump.printExpStr);
expstr = Util.stringDelimitList(expstrs, ", ");
Expand Down Expand Up @@ -13742,4 +13749,25 @@ algorithm
end matchcontinue;
end addLocalDecls;

protected function unevaluatedFunctionVariability
"In a function we might have input arguments with unknown dimensions, and in
that case we can't expand calls such as fill. A function call is therefore
created with variable variability. This function checks that we're inside a
function and returns DAE.C_VAR, or fails if we're not inside a function.

The exception is if checkModel is used, in which case we don't know what the
variability would have been had all parameters received a binding. We can't
set the variability to variable or parameter because then we might get
bindings with higher variability than the component, and we can't set it to
constant because that would cause the compiler to try and constant evaluate
the call. So we set it to DAE.C_UNKNOWN instead."
input Env.Env inEnv;
output DAE.Const outConst;
algorithm
outConst := matchcontinue(inEnv)
case _ equation true = Env.inFunctionScope(inEnv); then DAE.C_VAR;
case _ equation true = OptManager.getOption("checkModel"); then DAE.C_UNKNOWN;
end matchcontinue;
end unevaluatedFunctionVariability;

end Static;
43 changes: 43 additions & 0 deletions Compiler/Types.mo
Expand Up @@ -4704,6 +4704,8 @@ algorithm
case (DAE.C_CONST(),DAE.C_PARAM()) then DAE.C_PARAM();
case (DAE.C_PARAM(),DAE.C_CONST()) then DAE.C_PARAM();
case (DAE.C_PARAM(),DAE.C_PARAM()) then DAE.C_PARAM();
case (DAE.C_UNKNOWN(), _) then DAE.C_UNKNOWN();
case (_, DAE.C_UNKNOWN()) then DAE.C_UNKNOWN();
case (_,_) then DAE.C_VAR();
end matchcontinue;
end constAnd;
Expand Down Expand Up @@ -4740,6 +4742,8 @@ algorithm
case (_,DAE.C_CONST()) then DAE.C_CONST();
case (DAE.C_PARAM(),_) then DAE.C_PARAM();
case (_,DAE.C_PARAM()) then DAE.C_PARAM();
case (DAE.C_UNKNOWN(),_) then DAE.C_UNKNOWN();
case (_, DAE.C_UNKNOWN()) then DAE.C_UNKNOWN();
case (_,_) then DAE.C_VAR();
end matchcontinue;
end constOr;
Expand Down Expand Up @@ -4776,6 +4780,45 @@ algorithm
end matchcontinue;
end boolConstSize;

public function constEqual
input Const c1;
input Const c2;
output Boolean b;
algorithm
b := matchcontinue(c1, c2)
case (_, _)
equation
equality(c1 = c2);
then
true;
case (_, _) then false;
end matchcontinue;
end constEqual;

public function constIsVariable
"Returns true if Const is C_VAR."
input Const c;
output Boolean b;
algorithm
b := constEqual(c, DAE.C_VAR);
end constIsVariable;

public function constIsParameter
"Returns true if Const is C_PARAM."
input Const c;
output Boolean b;
algorithm
b := constEqual(c, DAE.C_PARAM);
end constIsParameter;

public function constIsConst
"Returns true if Const is C_CONST."
input Const c;
output Boolean b;
algorithm
b := constEqual(c, DAE.C_CONST);
end constIsConst;

public function printPropStr "function: printPropStr
Print the properties to a string."
input Properties inProperties;
Expand Down

0 comments on commit 97cccc9

Please sign in to comment.