Skip to content

Commit

Permalink
Remove check for each on scalars (#8409)
Browse files Browse the repository at this point in the history
- Remove the check that `each` is not applied to scalars. The check is
  not correct since it only checks the immediate parent node, and
  checking it properly is not possible right now since submodifiers do
  not keep track of their parent modifiers. Since using `each` on a
  scalar isn't actually a problem it's better to remove the warning
  message for now instead of giving false warnings.

Fixes #7777
  • Loading branch information
perost committed Jan 13, 2022
1 parent 50741cc commit f1d4754
Show file tree
Hide file tree
Showing 8 changed files with 4 additions and 48 deletions.
12 changes: 2 additions & 10 deletions OMCompiler/Compiler/NFFrontEnd/NFBinding.mo
Expand Up @@ -46,7 +46,7 @@ protected
import Error;

public
constant Binding EMPTY_BINDING = UNBOUND(false, AbsynUtil.dummyInfo);
constant Binding EMPTY_BINDING = UNBOUND();

type EachType = enumeration(
NOT_EACH,
Expand All @@ -67,12 +67,6 @@ public
);

record UNBOUND
// NOTE: Use the EMPTY_BINDING constant above when a default unbound binding
// is needed, to save memory. UNBOUND contains this information to be
// able to check that 'each' is used correctly, so info is only needed
// when isEach is true.
Boolean isEach;
SourceInfo info;
end UNBOUND;

record RAW_BINDING
Expand Down Expand Up @@ -144,7 +138,7 @@ public
then
RAW_BINDING(exp, scope, {}, each_ty, source, info);

else if eachPrefix then UNBOUND(true, info) else EMPTY_BINDING;
else EMPTY_BINDING;
end match;
end fromAbsyn;

Expand Down Expand Up @@ -381,7 +375,6 @@ public
output SourceInfo info;
algorithm
info := match binding
case UNBOUND() then binding.info;
case RAW_BINDING() then binding.info;
case UNTYPED_BINDING() then binding.info;
case TYPED_BINDING() then binding.info;
Expand Down Expand Up @@ -409,7 +402,6 @@ public
output Boolean isEach;
algorithm
isEach := match binding
case UNBOUND() then binding.isEach;
case RAW_BINDING() then binding.eachType == EachType.EACH;
case UNTYPED_BINDING() then binding.eachType == EachType.EACH;
case TYPED_BINDING() then binding.eachType == EachType.EACH;
Expand Down
25 changes: 1 addition & 24 deletions OMCompiler/Compiler/NFFrontEnd/NFTyping.mo
Expand Up @@ -881,7 +881,6 @@ algorithm

ErrorExt.setCheckpoint(getInstanceName());
try
checkBindingEach(c.binding, component);
binding := typeBinding(binding, InstContext.set(context, NFInstContext.BINDING));

if not (Config.getGraphicsExpMode() and stringEq(name, "graphics")) then
Expand Down Expand Up @@ -917,8 +916,6 @@ algorithm
// A component without a binding, or with a binding that's already been typed.
case Component.TYPED_COMPONENT()
algorithm
checkBindingEach(c.binding, component);

if Binding.isTyped(c.binding) then
c.binding := TypeCheck.matchBinding(c.binding, c.ty, InstNode.name(component), node);
checkComponentBindingVariability(InstNode.name(component), c, c.binding, context);
Expand All @@ -936,7 +933,6 @@ algorithm
case Component.UNTYPED_COMPONENT(binding = Binding.UNTYPED_BINDING(), attributes = attrs)
algorithm
name := InstNode.name(component);
checkBindingEach(c.binding, component);
binding := typeBinding(c.binding, InstContext.set(context, NFInstContext.BINDING));
comp_var := checkComponentBindingVariability(name, c, binding, context);

Expand Down Expand Up @@ -1039,22 +1035,6 @@ algorithm
end match;
end typeBinding;

function checkBindingEach
input Binding binding;
input InstNode component;
protected
InstNode parent;
algorithm
if Binding.isEach(binding) then
parent := InstNode.instanceParent(component);

if not Type.isArray(InstNode.getType(parent)) then
Error.addStrictMessage(Error.EACH_ON_NON_ARRAY,
{InstNode.name(parent)}, Binding.getInfo(binding));
end if;
end if;
end checkBindingEach;

function typeComponentCondition
input output Binding condition;
input InstContext.Type context;
Expand Down Expand Up @@ -1132,19 +1112,16 @@ algorithm
fail();

// Modifier with no binding, e.g. Real x(final start).
// Remove it so we don't have to deal with it in later.
case Modifier.MODIFIER()
guard Binding.isUnbound(attribute.binding)
algorithm
checkBindingEach(attribute.binding, component);
then
NFModifier.NOMOD();

// Normal modifier with no submodifiers.
case Modifier.MODIFIER(name = name, binding = binding)
algorithm
// Type and type check the attribute.
checkBindingEach(binding, component);

if Binding.isBound(binding) then
binding := typeBinding(binding, context);
parent := InstNode.parent(component);
Expand Down
2 changes: 0 additions & 2 deletions testsuite/flattening/modelica/scodeinst/Each1.mo
Expand Up @@ -16,6 +16,4 @@ end Each1;
// class Each1
// Real n.r = 1.0;
// end Each1;
// [flattening/modelica/scodeinst/Each1.mo:12:12-12:19:writable] Warning: 'each' used when modifying non-array element n.
//
// endResult
1 change: 0 additions & 1 deletion testsuite/flattening/modelica/scodeinst/Each3.mo
Expand Up @@ -14,7 +14,6 @@ end Each3;

// Result:
// Error processing file: Each3.mo
// [flattening/modelica/scodeinst/Each3.mo:12:12-12:25:writable] Warning: 'each' used when modifying non-array element a.
// [flattening/modelica/scodeinst/Each3.mo:12:14-12:24:writable] Notification: From here:
// [flattening/modelica/scodeinst/Each3.mo:8:3-8:12:writable] Error: Non-array modification ‘true‘ for array component ‘fixed‘, possibly due to missing ‘each‘.
//
Expand Down
2 changes: 0 additions & 2 deletions testsuite/flattening/modelica/scodeinst/Each4.mo
Expand Up @@ -16,6 +16,4 @@ end Each4;
// class Each4
// Real a.n(fixed = true);
// end Each4;
// [flattening/modelica/scodeinst/Each4.mo:12:14-12:24:writable] Warning: 'each' used when modifying non-array element n.
//
// endResult
2 changes: 0 additions & 2 deletions testsuite/flattening/modelica/scodeinst/Each5.mo
Expand Up @@ -22,6 +22,4 @@ end Each5;
// Real b[2].a.x = 1.0;
// Real b[3].a.x = 1.0;
// end Each5;
// [flattening/modelica/scodeinst/Each5.mo:16:17-16:24:writable] Warning: 'each' used when modifying non-array element a.
//
// endResult
2 changes: 0 additions & 2 deletions testsuite/flattening/modelica/scodeinst/Each6.mo
Expand Up @@ -18,6 +18,4 @@ end Each6;
// Real a[2].x(start = 1.0);
// Real a[3].x(start = 1.0);
// end Each6;
// [flattening/modelica/scodeinst/Each6.mo:12:17-12:28:writable] Warning: 'each' used when modifying non-array element x.
//
// endResult
Expand Up @@ -51,11 +51,7 @@ getErrorString();
// true
// ""
// {"Modelica.Fluid.Examples.DrumBoiler.DrumBoiler","Modelica.Fluid.Examples.DrumBoiler.DrumBoiler_init.xml"}
// "[Modelica 3.2.3+maint.om/Fluid/Sources.mo:734:36-735:54:writable] Warning: 'each' used when modifying non-array element m_flow.
// [Modelica 3.2.3+maint.om/Fluid/Sources.mo:732:36-733:54:writable] Warning: 'each' used when modifying non-array element m_flow.
// [Modelica 3.2.3+maint.om/Fluid/Sources.mo:788:36-789:54:writable] Warning: 'each' used when modifying non-array element m_flow.
// [Modelica 3.2.3+maint.om/Fluid/Sources.mo:786:36-787:54:writable] Warning: 'each' used when modifying non-array element m_flow.
// Warning: The model contains alias variables with redundant start and/or conflicting nominal values. It is recommended to resolve the conflicts, because otherwise the system could be hard to solve. To print the conflicting alias sets and the chosen candidates please use -d=aliasConflicts.
// "Warning: The model contains alias variables with redundant start and/or conflicting nominal values. It is recommended to resolve the conflicts, because otherwise the system could be hard to solve. To print the conflicting alias sets and the chosen candidates please use -d=aliasConflicts.
// "
// 0
// ""
Expand Down

0 comments on commit f1d4754

Please sign in to comment.