From 9724f6a49f397ff74f0b09fffb6c862bb8860123 Mon Sep 17 00:00:00 2001 From: HOS Date: Tue, 30 Sep 2025 17:50:53 +0200 Subject: [PATCH 1/7] Proposal for improving pure situation, to ensure that current MSL is valid and that users can update. Closes #3719 Note that in addition to the changes in the issue reordered the items and changed "must" to "should" for the deprecated semantic, and clearly indicated that the exception is the deprecated case. (Having a "must"-requirement and then have exceptions for it just seems wrong.) --- chapters/functions.tex | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/chapters/functions.tex b/chapters/functions.tex index a557cfe06..300bef8ae 100644 --- a/chapters/functions.tex +++ b/chapters/functions.tex @@ -225,16 +225,13 @@ \section{Pure Modelica Functions}\label{pure-modelica-functions} \item Functions defined in Modelica (non-external) are \emph{normally} assumed to be pure (the exception is the deprecated case below), if they are impure they shall be marked with the \lstinline!impure! keyword. They can be explicitly marked as \lstinline!pure!\indexinline{pure}. - \begin{nonnormative} - However, since functions as default are pure it is not recommended to explicitly declare them as \lstinline!pure!. - \end{nonnormative} -\item - External functions must be explicitly declared with \lstinline!pure! or \lstinline!impure!. \item If a function is declared as \lstinline!impure! any function extending from it shall be declared as \lstinline!impure!. \item - A deprecated semantics is that external functions (and functions defined in Modelica directly or indirectly calling them) without \lstinline!pure! or \lstinline!impure! keyword are assumed to be impure, but without any restriction on calling them. - Except for the function \lstinline!Modelica.Utilities.Streams.print!, a diagnostic must be given if called in a simulation model. + External functions should be explicitly declared with \lstinline!pure! or \lstinline!impure!. + The case without the keyword is deprecated semantics described in the next item. +\item + A deprecated semantics for functions without \lstinline!pure! or \lstinline!impure! keyword is that they assumed to be impure, but without any restriction on calling them for the following cases: external functions and functions defined in Modelica directly or indirectly (through functions without the \lstinline!pure! keyword) calling external functions without \lstinline!pure! keyword. \end{itemize} Calls of pure functions used inside expression may be skipped if the resulting expression will not depend on the possible returned value; ignoring the possibility of the function generating an error. From c9e5041cd3ffd7331733b2a040ca3f4725126fb1 Mon Sep 17 00:00:00 2001 From: Hans Olsson Date: Thu, 16 Oct 2025 18:27:17 +0200 Subject: [PATCH 2/7] Update chapters/functions.tex Co-authored-by: Henrik Tidefelt --- chapters/functions.tex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chapters/functions.tex b/chapters/functions.tex index 300bef8ae..0e6671131 100644 --- a/chapters/functions.tex +++ b/chapters/functions.tex @@ -231,7 +231,7 @@ \section{Pure Modelica Functions}\label{pure-modelica-functions} External functions should be explicitly declared with \lstinline!pure! or \lstinline!impure!. The case without the keyword is deprecated semantics described in the next item. \item - A deprecated semantics for functions without \lstinline!pure! or \lstinline!impure! keyword is that they assumed to be impure, but without any restriction on calling them for the following cases: external functions and functions defined in Modelica directly or indirectly (through functions without the \lstinline!pure! keyword) calling external functions without \lstinline!pure! keyword. + A deprecated semantics for functions without \lstinline!pure! or \lstinline!impure! keyword is that they are assumed to be impure, but without any restriction on calling them for the following cases: external functions and functions defined in Modelica directly or indirectly (through functions without the \lstinline!pure! keyword) calling external functions without \lstinline!pure! keyword. \end{itemize} Calls of pure functions used inside expression may be skipped if the resulting expression will not depend on the possible returned value; ignoring the possibility of the function generating an error. From 7aedbf104f60d55a878902245869e34e76a70998 Mon Sep 17 00:00:00 2001 From: Hans Olsson Date: Thu, 30 Oct 2025 14:55:10 +0100 Subject: [PATCH 3/7] Update chapters/functions.tex --- chapters/functions.tex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chapters/functions.tex b/chapters/functions.tex index 0e6671131..497189483 100644 --- a/chapters/functions.tex +++ b/chapters/functions.tex @@ -231,7 +231,7 @@ \section{Pure Modelica Functions}\label{pure-modelica-functions} External functions should be explicitly declared with \lstinline!pure! or \lstinline!impure!. The case without the keyword is deprecated semantics described in the next item. \item - A deprecated semantics for functions without \lstinline!pure! or \lstinline!impure! keyword is that they are assumed to be impure, but without any restriction on calling them for the following cases: external functions and functions defined in Modelica directly or indirectly (through functions without the \lstinline!pure! keyword) calling external functions without \lstinline!pure! keyword. + A deprecated semantics for functions without \lstinline!pure! or \lstinline!impure! keyword is that in the following cases: external functions and functions defined in Modelica directly or indirectly (through functions without the \lstinline!pure! keyword) calling external functions without \lstinline!pure! keyword, they are assumed to be impure, but without any restriction on calling them. \end{itemize} Calls of pure functions used inside expression may be skipped if the resulting expression will not depend on the possible returned value; ignoring the possibility of the function generating an error. From 7db252a1c0f9925d089e2cc7a55a5fbe64717964 Mon Sep 17 00:00:00 2001 From: Hans Olsson Date: Thu, 30 Oct 2025 14:59:39 +0100 Subject: [PATCH 4/7] Update chapters/functions.tex --- chapters/functions.tex | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/chapters/functions.tex b/chapters/functions.tex index 497189483..70976f54c 100644 --- a/chapters/functions.tex +++ b/chapters/functions.tex @@ -231,7 +231,8 @@ \section{Pure Modelica Functions}\label{pure-modelica-functions} External functions should be explicitly declared with \lstinline!pure! or \lstinline!impure!. The case without the keyword is deprecated semantics described in the next item. \item - A deprecated semantics for functions without \lstinline!pure! or \lstinline!impure! keyword is that in the following cases: external functions and functions defined in Modelica directly or indirectly (through functions without the \lstinline!pure! keyword) calling external functions without \lstinline!pure! keyword, they are assumed to be impure, but without any restriction on calling them. + A deprecated semantics for functions without \lstinline!pure! or \lstinline!impure! keyword only applies in the following cases: external functions and functions defined in Modelica directly or indirectly (through functions without the \lstinline!pure! keyword) calling external functions without \lstinline!pure! keyword. + In these cases they are assumed to be impure, but without any restriction on calling them. \end{itemize} Calls of pure functions used inside expression may be skipped if the resulting expression will not depend on the possible returned value; ignoring the possibility of the function generating an error. From ab2c2fec2a622927acbe31ab35ab7e012527f09b Mon Sep 17 00:00:00 2001 From: Hans Olsson Date: Wed, 5 Nov 2025 18:09:09 +0100 Subject: [PATCH 5/7] Update chapters/functions.tex Co-authored-by: Henrik Tidefelt --- chapters/functions.tex | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/chapters/functions.tex b/chapters/functions.tex index 70976f54c..ef4dd8ad1 100644 --- a/chapters/functions.tex +++ b/chapters/functions.tex @@ -228,8 +228,7 @@ \section{Pure Modelica Functions}\label{pure-modelica-functions} \item If a function is declared as \lstinline!impure! any function extending from it shall be declared as \lstinline!impure!. \item - External functions should be explicitly declared with \lstinline!pure! or \lstinline!impure!. - The case without the keyword is deprecated semantics described in the next item. + External functions not explicitly declared with \lstinline!pure! or \lstinline!impure! is deprecated. \item A deprecated semantics for functions without \lstinline!pure! or \lstinline!impure! keyword only applies in the following cases: external functions and functions defined in Modelica directly or indirectly (through functions without the \lstinline!pure! keyword) calling external functions without \lstinline!pure! keyword. In these cases they are assumed to be impure, but without any restriction on calling them. From 2da64b39b1fc9bea0be19219dd0838e543584ab2 Mon Sep 17 00:00:00 2001 From: Hans Olsson Date: Tue, 11 Nov 2025 15:25:06 +0100 Subject: [PATCH 6/7] Update chapters/functions.tex Co-authored-by: Henrik Tidefelt --- chapters/functions.tex | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/chapters/functions.tex b/chapters/functions.tex index ef4dd8ad1..498126c88 100644 --- a/chapters/functions.tex +++ b/chapters/functions.tex @@ -230,8 +230,9 @@ \section{Pure Modelica Functions}\label{pure-modelica-functions} \item External functions not explicitly declared with \lstinline!pure! or \lstinline!impure! is deprecated. \item - A deprecated semantics for functions without \lstinline!pure! or \lstinline!impure! keyword only applies in the following cases: external functions and functions defined in Modelica directly or indirectly (through functions without the \lstinline!pure! keyword) calling external functions without \lstinline!pure! keyword. - In these cases they are assumed to be impure, but without any restriction on calling them. + For a function without explicit purity, it is deprecated to call any function declared \lstinline!impure!, except when wrapped in \lstinline!pure($\ldots$)!. +\item + For a function not declared \lstinline!impure!, it is deprecated to call an external function not declared \lstinline!pure!, except when wrapped in \lstinline!pure($\ldots$)!. \end{itemize} Calls of pure functions used inside expression may be skipped if the resulting expression will not depend on the possible returned value; ignoring the possibility of the function generating an error. From e404d5c6c5cb212e2a233c1f3703619338703c48 Mon Sep 17 00:00:00 2001 From: HOS Date: Tue, 11 Nov 2025 15:25:17 +0100 Subject: [PATCH 7/7] AddText --- chapters/functions.tex | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/chapters/functions.tex b/chapters/functions.tex index ef4dd8ad1..bb835c558 100644 --- a/chapters/functions.tex +++ b/chapters/functions.tex @@ -234,6 +234,17 @@ \section{Pure Modelica Functions}\label{pure-modelica-functions} In these cases they are assumed to be impure, but without any restriction on calling them. \end{itemize} +For purposes of symbolic transformations and optimizations, the deprecated semantics above imply that not only the functions explicitly declared \lstinline!impure! are the ones which cannot be treated as pure. +Instead, a function shall be treated as impure in the following cases (applied recursively): +\begin{itemize} +\item + It is declared \lstinline!impure!. +\item + It is an external function without explicit purity. +\item + It calls another function treated as impure, except when wrapped in \lstinline!pure($\ldots$)!. +\end{itemize} + Calls of pure functions used inside expression may be skipped if the resulting expression will not depend on the possible returned value; ignoring the possibility of the function generating an error. A call to a function with no declared outputs is assumed to have desired side-effects or assertion checks.