Skip to content

Pure functions calling impure functions  #4182

Open

Description

@abuntrock

Description

There are some pure MSL 4.0.0 functions, which call other (impure) MSL functions, which is not allowed according to Modelica specification section 12.3.
I found the issues #3857, #3856, #3855 , and #3655, which are all still open.
Since from our perspective more tools are checking this now, the number of warnings thrown during simulation increased. Is there something planned regarding those issues?

Expected behaviour

Impure functions are only called in the circumstances allowed by the Modelica specification section 12.3.

Tested version

MSL 4.0.0

Thanks for looking into this
Aaron Buntrock

Activity

  1. changed the title [-]Pure function calling impure functions [/-] [+]Pure functions calling impure functions [/+] on Aug 16, 2023
  2. abuntrock commented on Aug 20, 2025

    @abuntrock
    Author

    Is there something planned regarding this problem here.
    It still exists with MSL 4.1.0. For example the pure function Modelica.Utilities.Files.loadResource calls the impure function Modelica.Utilities.Files.fullPathName.

    It seems that the Modelica specification will be reworked regarding impure and pure as well (see modelica/ModelicaSpecification#3719).
    But is there something planned for the MSL independent from eventual changes in the specification. @HansOlsson do you maybe have something to add here?

    To explain our pain with this problem. We are automatically checking (check function of the tools) all of our models within our CI pipelines. If there is a warning within the MSL, all of our models using that Modelica function will fail their CI test and we have to program an exception for the specific warning message.

  3. HansOlsson commented on Aug 20, 2025

    @HansOlsson
    Contributor

    Is there something planned regarding this problem here. It still exists with MSL 4.1.0. For example the pure function Modelica.Utilities.Files.loadResource calls the impure function Modelica.Utilities.Files.fullPathName.

    That specific example is even messier than many others:

    • The function Modelica.Utilities.Files.fullPathName is one of the special cases of impure functions that only depend on the external environment, but don't change it.
    • The call of Modelica.Utilities.Files.fullPathName is in the default implementation of Modelica.Utilities.Files.loadResource - but the implementation in many tools differ. In Dymola the called function is declared without any prefix. However, based on what loadResource is supposed to do I believe it should be impure. To enforce that it makes sense that its base-class Modelica.Utilities.Internal.PartialModelicaServices.ExternalReferences.PartialLoadResource should also be impure.

    It seems that the Modelica specification will be reworked regarding impure and pure as well (see modelica/ModelicaSpecification#3719). But is there something planned for the MSL independent from eventual changes in the specification. @HansOlsson do you maybe have something to add here?

    #4686 (and also #4685 to avoid the problems with print)

  4. HansOlsson commented on Aug 20, 2025

    @HansOlsson
    Contributor

    A minor clarification of my previous comment:

  5. abuntrock commented on Aug 21, 2025

    @abuntrock
    Author

    Thanks for the detailed explanation. I have to admit that I am not to deep into this topic and have not fully understood everything from the linked issues.
    We are happy that work is being spent on improving the whole impure/pure situation since our main objective with this is that no warnings from within the MSL are thrown when we simulate our models.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions