Skip to content

Commit

Permalink
No need to match special call (#12261)
Browse files Browse the repository at this point in the history
- Try to evaluate array constructor binding
- Partially revert #12133
  • Loading branch information
phannebohm committed May 16, 2024
1 parent 26c8457 commit 0314f81
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 14 deletions.
12 changes: 6 additions & 6 deletions OMCompiler/Compiler/NBackEnd/Classes/NBVariable.mo
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public
import BackendExtension = NFBackendExtension;
import NFBackendExtension.{BackendInfo, VariableKind, VariableAttributes};
import NFBinding.Binding;
import Ceval = NFCeval;
import Class = NFClass;
import ComponentRef = NFComponentRef;
import Dimension = NFDimension;
Expand Down Expand Up @@ -1132,7 +1133,7 @@ public
end match;
end getBindingVariability;

function hasLiteralBinding extends checkVar;
function hasEvaluableBinding extends checkVar;
protected
Variable var;
Expression binding;
Expand All @@ -1141,16 +1142,15 @@ public
if isBound(var_ptr) then
var := Pointer.access(var_ptr);
binding := Binding.getExp(var.binding);
if Expression.isLiteral(binding) then
b := true;
else
b := Expression.isLiteral(binding);
if not b then
// try to extract literal from array constructor
(_, binding) := Iterator.extract(binding);
binding := SimplifyExp.simplifyDump(binding, true, getInstanceName());
b := Expression.isLiteral(binding);
b := Expression.isLiteral(Ceval.tryEvalExp(binding));
end if;
end if;
end hasLiteralBinding;
end hasEvaluableBinding;

function setFixed
input output Pointer<Variable> var_ptr;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,8 @@ public

// parse records slightly different
if BVariable.isKnownRecord(var) then
// only consider non literal parameter bindings
if not BVariable.hasLiteralBinding(var) then
// only consider non-evaluable parameter bindings
if not BVariable.hasEvaluableBinding(var) then
initial_param_vars := listAppend(BVariable.getRecordChildren(var), initial_param_vars);
parameter_eqs := Equation.generateBindingEquation(var, idx, true) :: parameter_eqs;
else
Expand All @@ -342,8 +342,8 @@ public

// all other variables that are not records and not record elements to be skipped
elseif not (BVariable.isRecord(var) or skip_record_element) then
// only consider non literal parameter bindings
if not BVariable.hasLiteralBinding(var) then
// only consider non-evaluable parameter bindings
if not BVariable.hasEvaluableBinding(var) then
// add variable to initial unknowns
initial_param_vars := var :: initial_param_vars;
// generate equation only if variable is fixed
Expand Down
4 changes: 0 additions & 4 deletions OMCompiler/Compiler/NFFrontEnd/NFExpression.mo
Original file line number Diff line number Diff line change
Expand Up @@ -4402,10 +4402,6 @@ public
case RECORD() then List.all(exp.elements, isLiteral);
case RANGE() then isLiteral(exp.start) and isLiteral(exp.stop) and
Util.applyOptionOrDefault(exp.step, isLiteral, true);
case CALL(call = Call.TYPED_ARRAY_CONSTRUCTOR()) then Call.isLiteral(exp.call);
case CAST() then isLiteral(exp.exp);
case BOX() then isLiteral(exp.exp);
case UNBOX() then isLiteral(exp.exp);
case FILENAME() then true;
else false;
end match;
Expand Down

0 comments on commit 0314f81

Please sign in to comment.