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

Commit 03101bd

Browse files
perostOpenModelica-Hudson
authored andcommitted
[NF] Variability fixes.
- Change the variability of size to be constant, except for size of : in functions where it's discrete. - Disable variability checks for bindings in functions. It's not well specified how it should work, and the variability doesn't really need to match when initializing local variables in a function anyway. Belonging to [master]: - #2661
1 parent 0bcaee0 commit 03101bd

File tree

1 file changed

+12
-22
lines changed

1 file changed

+12
-22
lines changed

Compiler/NFFrontEnd/NFTyping.mo

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -727,19 +727,12 @@ algorithm
727727
comp_eff_var := Prefixes.effectiveVariability(comp_var);
728728
bind_var := Prefixes.effectiveVariability(Binding.variability(binding));
729729

730-
if bind_var > comp_eff_var then
731-
if comp_var == Variability.PARAMETER and intBitAnd(origin, ExpOrigin.FUNCTION) > 0 then
732-
Error.addSourceMessage(Error.FUNCTION_HIGHER_VARIABILITY_BINDING, {
733-
name, Prefixes.variabilityString(comp_eff_var),
734-
Binding.toString(c.binding), Prefixes.variabilityString(bind_var)},
735-
Binding.getInfo(binding));
736-
else
737-
Error.addSourceMessage(Error.HIGHER_VARIABILITY_BINDING, {
738-
name, Prefixes.variabilityString(comp_eff_var),
739-
"'" + Binding.toString(c.binding) + "'", Prefixes.variabilityString(bind_var)},
740-
Binding.getInfo(binding));
741-
fail();
742-
end if;
730+
if bind_var > comp_eff_var and intBitAnd(origin, ExpOrigin.FUNCTION) == 0 then
731+
Error.addSourceMessage(Error.HIGHER_VARIABILITY_BINDING, {
732+
name, Prefixes.variabilityString(comp_eff_var),
733+
"'" + Binding.toString(c.binding) + "'", Prefixes.variabilityString(bind_var)},
734+
Binding.getInfo(binding));
735+
fail();
743736
end if;
744737

745738
// Evaluate the binding if the component is a constant or has annotation(Evaluate=true)
@@ -1783,15 +1776,12 @@ algorithm
17831776
exp := Expression.SIZE(exp, SOME(index));
17841777
end if;
17851778

1786-
// Use the most variable of the index and the dimension as the variability
1787-
// of the size expression.
1788-
variability := Prefixes.variabilityMax(variability, Dimension.variability(dim));
1789-
1790-
// Hack to make size work properly in functions. The size of an input
1791-
// parameter should really be based on the variability of the input
1792-
// argument, but we don't have that information while typing functions.
1793-
if variability > Variability.PARAMETER and intBitAnd(origin, ExpOrigin.FUNCTION) > 0 then
1794-
variability := Variability.PARAMETER;
1779+
if intBitAnd(origin, ExpOrigin.FUNCTION) == 0 or Dimension.isKnown(dim) then
1780+
// size is constant outside functions, or for known dimensions inside functions.
1781+
variability := Variability.CONSTANT;
1782+
else
1783+
// size is discrete for : in functions.
1784+
variability := Variability.DISCRETE;
17951785
end if;
17961786
else
17971787
// If the index is not a constant, type the whole expression.

0 commit comments

Comments
 (0)