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

Commit 70ef32b

Browse files
perostOpenModelica-Hudson
authored andcommitted
[NF] Better handling of constants.
- Take the subscripts into account when determining the variability of a cref, so we don't try to e.g. evaluate a constant with non-constant subscripts. - Turn on collection of package constants again, since they might be used in the flat model due to the above change. Belonging to [master]: - #2175
1 parent 5cc04d9 commit 70ef32b

File tree

3 files changed

+26
-23
lines changed

3 files changed

+26
-23
lines changed

Compiler/NFFrontEnd/NFInst.mo

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -141,15 +141,10 @@ algorithm
141141
// Flatten and convert the class into a DAE.
142142
(flat_model, funcs) := Flatten.flatten(inst_cls, name);
143143

144-
// The backend doesn't handle constants well, so for now we just replace all
145-
// constants in Typing.typeExp.
146-
//// Replace or collect package constants depending on the
147-
//// replacePackageConstants debug flag.
148-
//if Flags.isSet(Flags.REPLACE_PACKAGE_CONSTS) then
149-
// (flat_model, funcs) := Package.replaceConstants(flat_model, funcs);
150-
//else
151-
// flat_model := Package.collectConstants(flat_model, funcs);
152-
//end if;
144+
// Collect package constants that couldn't be substituted with their values
145+
// (e.g. because they where used with non-constants subscripts), and add them
146+
// to the model.
147+
flat_model := Package.collectConstants(flat_model, funcs);
153148

154149
flat_model := Scalarize.scalarize(flat_model, name);
155150
(dae, daeFuncs) := ConvertDAE.convert(flat_model, funcs, name, InstNode.info(inst_cls));

Compiler/NFFrontEnd/NFTyping.mo

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1316,6 +1316,8 @@ function typeCref
13161316
input SourceInfo info;
13171317
output Type ty;
13181318
output Variability variability;
1319+
protected
1320+
Variability subs_var;
13191321
algorithm
13201322
// Check that time isn't used in a function context.
13211323
// TODO: Fix NFBuiltin.TIME_CREF so that the compiler treats it like an actual
@@ -1326,36 +1328,39 @@ algorithm
13261328
fail();
13271329
end if;
13281330

1329-
cref := typeCref2(cref, origin, info);
1331+
(cref, subs_var) := typeCref2(cref, origin, info);
13301332
ty := ComponentRef.getSubscriptedType(cref);
1331-
variability := ComponentRef.getVariability(cref);
1333+
variability := Prefixes.variabilityMax(ComponentRef.getVariability(cref), subs_var);
13321334
end typeCref;
13331335

13341336
function typeCref2
13351337
input output ComponentRef cref;
13361338
input ExpOrigin.Type origin;
13371339
input SourceInfo info;
1340+
output Variability subsVariability;
13381341

13391342
import NFComponentRef.Origin;
13401343
algorithm
1341-
cref := match cref
1344+
(cref, subsVariability) := match cref
13421345
local
13431346
ComponentRef rest_cr;
13441347
Type node_ty;
13451348
list<Subscript> subs;
1349+
Variability subs_var, rest_var;
13461350

13471351
case ComponentRef.CREF(origin = Origin.SCOPE)
1348-
then cref;
1352+
then (cref, Variability.CONSTANT);
13491353

13501354
case ComponentRef.CREF(node = InstNode.COMPONENT_NODE())
13511355
algorithm
13521356
node_ty := typeComponent(cref.node, origin);
1353-
subs := typeSubscripts(cref.subscripts, node_ty, cref, origin, info);
1354-
rest_cr := typeCref2(cref.restCref, origin, info);
1357+
(subs, subs_var) := typeSubscripts(cref.subscripts, node_ty, cref, origin, info);
1358+
(rest_cr, rest_var) := typeCref2(cref.restCref, origin, info);
1359+
subsVariability := Prefixes.variabilityMax(subs_var, rest_var);
13551360
then
1356-
ComponentRef.CREF(cref.node, subs, node_ty, cref.origin, rest_cr);
1361+
(ComponentRef.CREF(cref.node, subs, node_ty, cref.origin, rest_cr), subsVariability);
13571362

1358-
else cref;
1363+
else (cref, Variability.CONSTANT);
13591364
end match;
13601365
end typeCref2;
13611366

@@ -1366,10 +1371,13 @@ function typeSubscripts
13661371
input ExpOrigin.Type origin;
13671372
input SourceInfo info;
13681373
output list<Subscript> typedSubs;
1374+
output Variability variability = Variability.CONSTANT;
13691375
protected
13701376
list<Dimension> dims;
13711377
Dimension dim;
13721378
Integer next_origin, i;
1379+
Subscript sub;
1380+
Variability var;
13731381
algorithm
13741382
dims := Type.arrayDims(crefType);
13751383

@@ -1386,7 +1394,9 @@ algorithm
13861394

13871395
for s in subscripts loop
13881396
dim :: dims := dims;
1389-
typedSubs := typeSubscript(s, dim, cref, i, origin, info) :: typedSubs;
1397+
(sub, var) := typeSubscript(s, dim, cref, i, origin, info);
1398+
typedSubs := sub :: typedSubs;
1399+
variability := Prefixes.variabilityMax(variability, var);
13901400
i := i + 1;
13911401
end for;
13921402

@@ -1401,6 +1411,7 @@ function typeSubscript
14011411
input ExpOrigin.Type origin;
14021412
input SourceInfo info;
14031413
output Subscript outSubscript = subscript;
1414+
output Variability variability = Variability.CONSTANT;
14041415
protected
14051416
Expression e;
14061417
Type ty, ety;
@@ -1411,7 +1422,7 @@ algorithm
14111422
case Subscript.UNTYPED()
14121423
algorithm
14131424
e := evaluateEnd(subscript.exp, dimension, cref, index, origin, info);
1414-
(e, ty, _) := typeExp(e, origin, info);
1425+
(e, ty, variability) := typeExp(e, origin, info);
14151426

14161427
if Type.isArray(ty) then
14171428
outSubscript := Subscript.SLICE(e);

Compiler/Util/Flags.mo

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -526,8 +526,6 @@ constant DebugFlag SUSAN_MATCHCONTINUE_DEBUG = DEBUG_FLAG(175, "susanDebug", fal
526526
Util.gettext("Makes Susan generate code using try/else to better debug which function broke the expected match semantics."));
527527
constant DebugFlag OLD_FE_UNITCHECK = DEBUG_FLAG(176, "oldFrontEndUnitCheck", false,
528528
Util.gettext("Checks the consistency of units in equation (for the old front-end)."));
529-
constant DebugFlag REPLACE_PACKAGE_CONSTS = DEBUG_FLAG(177, "replacePackageConstants", true,
530-
Util.gettext("Replaces package constants with their evaluated values if set."));
531529

532530
// This is a list of all debug flags, to keep track of which flags are used. A
533531
// flag can not be used unless it's in this list, and the list is checked at
@@ -710,8 +708,7 @@ constant list<DebugFlag> allDebugFlags = {
710708
IGNORE_CYCLES,
711709
ALIAS_CONFLICTS,
712710
SUSAN_MATCHCONTINUE_DEBUG,
713-
OLD_FE_UNITCHECK,
714-
REPLACE_PACKAGE_CONSTS
711+
OLD_FE_UNITCHECK
715712
};
716713

717714
public

0 commit comments

Comments
 (0)