ModelicaSpecification icon indicating copy to clipboard operation
ModelicaSpecification copied to clipboard

Semantics of function call equations and statements

Open henrikt-ma opened this issue 1 year ago • 6 comments

Isn't the specification missing some sections giving semantics of equations and statements in the following form?

f(args);

For example, I can find the type rule for a simple equality equation in 8.3.1, but where is the type rule for the equation above?

I suppose a record constructor can never be used in this form, since the record constructor should be seen as a function with a single output for purposes of these rules (they are sometimes not seen as just a function with a single output, but is see no reason to make such an exception here).

Speaking of record constructors, is this a valid way to ignore a constructed record value (which is syntactically in the correct form for ignoring all outputs of a function call)?

() := R(1.0);

henrikt-ma avatar Dec 20 '24 22:12 henrikt-ma

Isn't the specification missing some sections giving semantics of equations and statements in the following form?

f(args);

It could be made clearer, but https://specification.modelica.org/master/functions.html#function-call specify how function call works, before considering the outputs, so it should still apply.

It is included as the last item in https://specification.modelica.org/master/equations.html#equations-in-equation-sections

For specific semantics, https://specification.modelica.org/master/functions.html#pure-modelica-functions state that the function is assumed to have side-effects and/or asserts, so that it cannot just be ignored. The possibility of asserts (which are allowed even for a pure function) mean that we cannot totally remove such a call, but can reduce the number of calls (if it is pure).

For example, I can find the type rule for a simple equality equation in 8.3.1, but where is the type rule for the equation above?

Since there is no equality I don't see why we need a type rule in this case (or specifically what the type should should say). However, for overview it could be that we should have a subsection for them including https://specification.modelica.org/master/equations.html#reinit etc

Speaking of record constructors, is this a valid way to ignore a constructed record value (which is syntactically in the correct form for ignoring all outputs of a function call)?

() := R(1.0);

I don't see a problem with that, but I don't see much use either, since a record constructor is pure. So the only reason would be to trigger an automatically generated assertion based on some potential mismatch of sizes for the inputs.

HansOlsson avatar Jan 03 '25 11:01 HansOlsson

I don't see that any additional text is needed based on the above.

HansOlsson avatar Jan 08 '25 16:01 HansOlsson

However, for overview it could be that we should have a subsection for them including https://specification.modelica.org/master/equations.html#reinit etc

Sounds like a good plan to me (with symmetric treatment of statements, of course).

henrikt-ma avatar Jan 08 '25 16:01 henrikt-ma

Speaking of record constructors, is this a valid way to ignore a constructed record value (which is syntactically in the correct form for ignoring all outputs of a function call)?

() := R(1.0);

I don't see a problem with that, but I don't see much use either, since a record constructor is pure. So the only reason would be to trigger an automatically generated assertion based on some potential mismatch of sizes for the inputs.

Agreed. Admittedly, this part deviated a bit from the central topic here. The main point was to conclude that a record constructor cannot be used in the component-reference function-call-args since it is a function returning one value, and that there should be a rule in the (still missing) section for the component-reference function-call-args form saying that the function called shall have no outputs.

henrikt-ma avatar Jan 08 '25 16:01 henrikt-ma

However, for overview it could be that we should have a subsection for them including https://specification.modelica.org/master/equations.html#reinit etc

Sounds like a good plan to me (with symmetric treatment of statements, of course).

I always found it odd that the semantics of stand-alone functions is not explicitly explain, so I wholeheartedly support this plan.

BTW, it is definitely not clear to me what the semantics is in case there are side effects and the function is not placed inside a when statement. It reasonable to assume that the function can only be called after its arguments (if any) have been computed for the current step. But it's not clear, for example, how many times it's going to be called for each step (I'd say once, but it's not stated anywhere), if it's also going to be called during event iterations, etc.

This should be clarified, I guess.

casella avatar Jun 10 '25 20:06 casella

This should be clarified, I guess.

Are you aware of https://specification.modelica.org/master/functions.html#S3.p9?

henrikt-ma avatar Jun 10 '25 20:06 henrikt-ma