Skip to content

Commit

Permalink
[NF] Propagate structuralness via modifications.
Browse files Browse the repository at this point in the history
- Mark parameters that have a structural cref as binding as also
  structural.

Belonging to [master]:
  - OpenModelica/OMCompiler#2887
  - OpenModelica/OpenModelica-testsuite#1108
  • Loading branch information
perost authored and OpenModelica-Hudson committed Jan 21, 2019
1 parent 25cfbd5 commit 8a20ce0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
10 changes: 10 additions & 0 deletions Compiler/NFFrontEnd/NFBinding.mo
Expand Up @@ -259,6 +259,16 @@ public
end match;
end isRecordExp;

function isCrefExp
input Binding binding;
output Boolean isCref;
algorithm
isCref := match binding
case TYPED_BINDING(bindingExp = Expression.CREF()) then true;
else false;
end match;
end isCrefExp;

function recordFieldBinding
input InstNode fieldNode;
input Binding recordBinding;
Expand Down
22 changes: 17 additions & 5 deletions Compiler/NFFrontEnd/NFTyping.mo
Expand Up @@ -761,7 +761,8 @@ protected
InstNode cls;
MatchKind matchKind;
String name;
Variability comp_var, comp_eff_var, bind_var;
Variability comp_var, comp_eff_var, bind_var, bind_eff_var;
Component.Attributes attrs;
algorithm
if InstNode.isEmpty(component) then
return;
Expand All @@ -770,7 +771,7 @@ algorithm
c := InstNode.component(node);

() := match c
case Component.TYPED_COMPONENT(binding = Binding.UNTYPED_BINDING())
case Component.TYPED_COMPONENT(binding = Binding.UNTYPED_BINDING(), attributes = attrs)
algorithm
name := InstNode.name(component);
binding := c.binding;
Expand All @@ -783,15 +784,26 @@ algorithm
binding := TypeCheck.matchBinding(binding, c.ty, name, node);
comp_var := Component.variability(c);
comp_eff_var := Prefixes.effectiveVariability(comp_var);
bind_var := Prefixes.effectiveVariability(Binding.variability(binding));
bind_var := Binding.variability(binding);
bind_eff_var := Prefixes.effectiveVariability(bind_var);

if bind_var > comp_eff_var and ExpOrigin.flagNotSet(origin, ExpOrigin.FUNCTION) then
if bind_eff_var > comp_eff_var and ExpOrigin.flagNotSet(origin, ExpOrigin.FUNCTION) then
Error.addSourceMessage(Error.HIGHER_VARIABILITY_BINDING, {
name, Prefixes.variabilityString(comp_eff_var),
"'" + Binding.toString(c.binding) + "'", Prefixes.variabilityString(bind_var)},
"'" + Binding.toString(c.binding) + "'", Prefixes.variabilityString(bind_eff_var)},
Binding.getInfo(binding));
fail();
end if;

// Mark parameters that have a structural cref as binding as also
// structural. This is perhaps not optimal, but is required right now
// to avoid structural singularity and other issues.
if bind_var == Variability.STRUCTURAL_PARAMETER and
comp_var == Variability.PARAMETER and
Binding.isCrefExp(binding) then
attrs.variability := bind_var;
c.attributes := attrs;
end if;
else
if Binding.isBound(c.condition) then
binding := Binding.INVALID_BINDING(binding, ErrorExt.getMessages());
Expand Down

0 comments on commit 8a20ce0

Please sign in to comment.