Opened 4 years ago

Closed 4 years ago

#6109 closed defect (fixed)

[NF] Function pure/impure checking affects result variability

Reported by: Adrian Pop Owned by: Per Östlund
Priority: high Milestone: 1.16.0
Component: New Instantiation Version:
Keywords: Cc:

Description

  // pure function f calling impure function
  // Modelica.Utilities.Streams.print
  constant String x = "blah";
  // NF complains f(x) has parameter variability
  constant String y = f(x); 

If you comment out the calls to Modelica.Utilities.Streams.print in f all works fine.

Change History (6)

comment:1 by Per Östlund, 4 years ago

That's because you added the rule that impure function calls are at least parameter expressions, see PR 2671. I have a vague memory that I tried to revert that a while ago when I improved the pure/impure handling, but that it still caused some issues.

We could check again though, the issues might've been fixed by now. I guess we still don't have any way to run the library coverage on a branch?

comment:2 by Adrian Pop, 4 years ago

Ouch :)
Yeah, we should check it again.
I tried a model from from ThermoCycle library that uses ExternalMedia that calls function:
https://github.com/modelica-3rdparty/ExternalMedia/blob/master/Modelica/ExternalMedia%203.2.1/Common/CheckCoolPropOptions.mo#L2
Basically:
CheckCoolPropOptions(someConstant, debug=false);

In this case, the call to the impure function contributes no output so it should not
affect the variability.

comment:3 by Per Östlund, 4 years ago

Ok, I made PR 6733 that reverts it back to always starting as constant. I guess we'll just merge it and see what the damage is.

comment:4 by Per Östlund, 4 years ago

The PR uncovered one issue, the NF tries to evaluate operators such as firstTick. It's defined in ModelicaBuiltin as:

function firstTick = $overload(OMC_NO_ARGS.firstTick, OMC_ARGS.firstTick)

The individual functions are marked as impure, but this is for some reason lost due to the overload. Marking the overloaded function as impure also doesn't do anything. I'll see if I can figure out what's going on.

comment:5 by Per Östlund, 4 years ago

The issue turned out to be that we simply didn't check whether an if-condition was pure or impure before trying to evaluate it. As I pointed out in #6047 we really should calculate the purity of expressions when typing them in the same was that we now calculate their variability, that would solve a lot of similar issues. For now I just added a check that an if-condition doesn't contain any impure calls though.

comment:6 by Adrian Pop, 4 years ago

Milestone: 1.17.01.16.0
Resolution: fixed
Status: newclosed

Calling CheckCoolPropOptions works fine now.

Note: See TracTickets for help on using tickets.