Skip to content

Commit f85785c

Browse files
committed
Relax error checking when checking partial model
- Skip checking when-requirements when checking a partial model. - Don't fail when checking partial models with out of bounds subscripts.
1 parent d55fe79 commit f85785c

File tree

7 files changed

+88
-19
lines changed

7 files changed

+88
-19
lines changed

OMCompiler/Compiler/NFFrontEnd/NFInst.mo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ algorithm
254254
execStat("replaceArrayConstructors");
255255
end if;
256256

257-
VerifyModel.verify(flatModel);
257+
VerifyModel.verify(flatModel, InstNode.isPartial(inst_cls));
258258

259259
(flatModel, functions) := InstUtil.expandSlicedCrefs(flatModel, functions);
260260

OMCompiler/Compiler/NFFrontEnd/NFVerifyModel.mo

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -58,61 +58,68 @@ protected
5858
public
5959
function verify
6060
input FlatModel flatModel;
61+
input Boolean isPartial;
6162
algorithm
6263
for var in flatModel.variables loop
63-
verifyVariable(var);
64+
verifyVariable(var, isPartial);
6465
end for;
6566

6667
for eq in flatModel.equations loop
67-
verifyEquation(eq);
68+
verifyEquation(eq, isPartial);
6869
end for;
6970

7071
for ieq in flatModel.initialEquations loop
71-
verifyEquation(ieq);
72+
verifyEquation(ieq, isPartial);
7273
end for;
7374

7475
for alg in flatModel.algorithms loop
75-
verifyAlgorithm(alg);
76+
verifyAlgorithm(alg, isPartial);
7677
end for;
7778

7879
for ialg in flatModel.initialAlgorithms loop
79-
verifyAlgorithm(ialg);
80+
verifyAlgorithm(ialg, isPartial);
8081
end for;
8182

8283
// check for discrete real variables not assigned in when equations (#5836)
83-
checkDiscreteReal(flatModel);
84+
if not isPartial then
85+
checkDiscreteReal(flatModel);
86+
end if;
8487

8588
execStat(getInstanceName());
8689
end verify;
8790

8891
protected
8992
function verifyVariable
9093
input Variable var;
94+
input Boolean isPartial;
9195
algorithm
92-
verifyBinding(var.binding);
96+
verifyBinding(var.binding, isPartial);
9397

9498
for attr in var.typeAttributes loop
95-
verifyBinding(Util.tuple22(attr));
99+
verifyBinding(Util.tuple22(attr), isPartial);
96100
end for;
97101

98102
for v in var.children loop
99-
verifyVariable(v);
103+
verifyVariable(v, isPartial);
100104
end for;
101105
end verifyVariable;
102106

103107
function verifyBinding
104108
input Binding binding;
109+
input Boolean isPartial;
105110
algorithm
106111
if Binding.isBound(binding) then
107-
checkSubscriptBounds(Binding.getTypedExp(binding), Binding.getInfo(binding));
112+
checkSubscriptBounds(Binding.getTypedExp(binding), isPartial, Binding.getInfo(binding));
108113
end if;
109114
end verifyBinding;
110115

111116
function verifyEquation
112117
input Equation eq;
118+
input Boolean isPartial;
113119
algorithm
114120
() := match eq
115121
case Equation.WHEN()
122+
guard not isPartial
116123
algorithm
117124
verifyWhenEquation(eq.branches, eq.source);
118125
then
@@ -121,7 +128,7 @@ protected
121128
else ();
122129
end match;
123130

124-
Equation.applyExpShallow(eq, function checkSubscriptBounds(info = Equation.info(eq)));
131+
Equation.applyExpShallow(eq, function checkSubscriptBounds(isPartial = isPartial, info = Equation.info(eq)));
125132
end verifyEquation;
126133

127134
function verifyWhenEquation
@@ -251,31 +258,35 @@ protected
251258

252259
function verifyAlgorithm
253260
input Algorithm alg;
261+
input Boolean isPartial;
254262
algorithm
255-
Algorithm.apply(alg, verifyStatement);
263+
Algorithm.apply(alg, function verifyStatement(isPartial = isPartial));
256264
end verifyAlgorithm;
257265

258266
function verifyStatement
259267
input Statement stmt;
268+
input Boolean isPartial;
260269
algorithm
261-
Statement.applyExp(stmt, function checkSubscriptBounds(info = Statement.info(stmt)));
270+
Statement.applyExp(stmt, function checkSubscriptBounds(isPartial = isPartial, info = Statement.info(stmt)));
262271
end verifyStatement;
263272

264273
function checkSubscriptBounds
265274
input Expression exp;
275+
input Boolean isPartial;
266276
input SourceInfo info;
267277
algorithm
268-
Expression.apply(exp, function checkSubscriptBounds_traverser(info = info));
278+
Expression.apply(exp, function checkSubscriptBounds_traverser(isPartial = isPartial, info = info));
269279
end checkSubscriptBounds;
270280

271281
function checkSubscriptBounds_traverser
272282
input Expression exp;
283+
input Boolean isPartial;
273284
input SourceInfo info;
274285
algorithm
275286
() := match exp
276287
case Expression.CREF()
277288
algorithm
278-
checkSubscriptBoundsCref(exp.cref, info);
289+
checkSubscriptBoundsCref(exp.cref, isPartial, info);
279290
then
280291
();
281292

@@ -285,6 +296,7 @@ protected
285296

286297
function checkSubscriptBoundsCref
287298
input ComponentRef cref;
299+
input Boolean isPartial;
288300
input SourceInfo info;
289301
algorithm
290302
() := match cref
@@ -308,14 +320,17 @@ protected
308320
Error.addSourceMessage(Error.ARRAY_INDEX_OUT_OF_BOUNDS,
309321
{Subscript.toString(s), String(index),
310322
Dimension.toString(d), ComponentRef.firstName(cref)}, info);
311-
fail();
323+
324+
if not isPartial then
325+
fail();
326+
end if;
312327
end if;
313328
end if;
314329

315330
index := index + 1;
316331
end for;
317332

318-
checkSubscriptBoundsCref(cref.restCref, info);
333+
checkSubscriptBoundsCref(cref.restCref, isPartial, info);
319334
then
320335
();
321336

OMCompiler/Compiler/Script/NFApi.mo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ algorithm
637637
flat_model.variables := List.filterOnFalse(flat_model.variables, Variable.isEmptyArray);
638638
end if;
639639

640-
VerifyModel.verify(flat_model);
640+
VerifyModel.verify(flat_model, InstNode.isPartial(inst_cls));
641641

642642
// Convert the flat model to a DAE.
643643
(dae, daeFuncs) := ConvertDAE.convert(flat_model, funcs);

testsuite/flattening/modelica/arrays/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ MatrixRowIndexing.mo \
133133
MatrixSubtraction.mo \
134134
modelica_1_1_Array9.mo \
135135
NestedSubscriptFor.mo \
136+
OutOfBoundsPartial1.mos \
136137
PolynomialEvaluator1.mo \
137138
PolynomialEvaluator2.mo \
138139
PolynomialEvaluator3.mo \
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// name: OutOfBoundsCheck1
2+
// keywords: array subscript
3+
// status: correct
4+
//
5+
// A partial model with out of bounds subscripts should not make checkModel fail.
6+
//
7+
8+
loadString("
9+
partial model M
10+
Real x[1];
11+
equation
12+
x[2] = 1;
13+
end M;
14+
");
15+
16+
checkModel(M);
17+
getErrorString();
18+
19+
// Result:
20+
// true
21+
// "Check of M completed successfully.
22+
// Class M has 1 equation(s) and 1 variable(s).
23+
// 1 of these are trivial equation(s)."
24+
// "[<interactive>:5:5-5:13:writable] Error: Subscript '2' for dimension 1 (size = 1) of x is out of bounds.
25+
// "
26+
// endResult

testsuite/flattening/modelica/equations/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ WhenEquation.mo \
5454
WhenNestedEquation.mo \
5555
WhenNotInitial.mo \
5656
WhenNotValid.mo \
57+
WhenPartial1.mos \
5758
WhenValidResult.mo \
5859
WhenSemantics1.mo \
5960
WhenVectorPredicateEquation.mo \
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// name: WhenPartial1
2+
// keywords: when
3+
// status: correct
4+
//
5+
// Discrete variables in a partial model does not need to be assigned in a when-equation.
6+
//
7+
8+
loadString("
9+
partial model M
10+
Real x;
11+
discrete Real xd;
12+
equation
13+
x = xd;
14+
end M;
15+
");
16+
17+
checkModel(M);
18+
getErrorString();
19+
20+
// Result:
21+
// true
22+
// "Check of M completed successfully.
23+
// Class M has 1 equation(s) and 2 variable(s).
24+
// 1 of these are trivial equation(s)."
25+
// ""
26+
// endResult

0 commit comments

Comments
 (0)