-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Simplify value modification #2747
Conversation
There has only been minor work done on value modifications so far. The following is extracted and cleaned up from #2558 (comment). Examples for Modifications of valuesShould references in declaration equations of types be avoided?
In Flat Modelica the scope of the short class declaration (see Use cases of having declaration equations in records:
Constant value modifications of a type allowed?
For constants we require to have a declaration equation. Record constructors rely on the declaration equations for building the constructor function. |
I think we should revisit the questions and examples above with inspiration from what we did regarding the so-called variability-constrained types: https://github.com/modelica/ModelicaSpecification/blob/MCP/0031/RationaleMCP/0031/variability-constrained-types.md. To me, a record with non-constant declaration equations (which is only possible by referencing other members of the same record) seems like something that one would at most need for use in model component declarations. Even there, however, I wonder why we – as a first simple approach – don't require equations to be given separately in the model rather than through the record type definitions. |
Here are some full Modelica examples relying on record members being in scope inside the record itself. They would complicate the Flat Modelica type concept considerably, so it would be great if we could convince ourselves that such access could be forbidden in Flat Modelica.
A more advanced variant (which Modelica tools can handle this?):
Use in a built-in attribute modification, with array size depending on record member:
Similar to the above, but with only values depending on record member:
Constant value modification:
Non-constant value modification:
|
@henrikt-ma, for my information, are those examples meant to be (possibly) valid also in Modelica (I understand they currently aren't), or only in Flat Modelica? |
The intention is not to make any extensions of full Modelica, only to put up a range of examples of possibly valid Modelica, so that we can discuss which of these we'd need to support in Flat Modelica. If we can rule out some of them as not valid full Modelica today, that is probably a good reason for not worry about how to support them in Flat Modelica. (Sometimes, though, simplifications in one end of Flat Modelica can require it to be slightly extended in another end to compensate. Let's hope this is not the case this time.) |
Web Meeting (Hans, Henrik, Gerd, Martin, Oliver) Looking at example Henrik: We could make a similar assumption as for function default arguments by automatically generating variants that avoids the record internal dependency on Hans: Lift all modifications to the use of the record:
Henrik: If look-up inside a record was disallowed in Flat Modelica and being expressed by lifting. Hans: Record members should be disallowed to modify values of members, but may be used to size other members. Gerd: Changing Henrik: In Flat Modelica this new type could be expressed explicitly. I don't expect an explosion of types as the typical usage is related to applications like the number of phases in electrics. The example
Gerd: The rule when to generate a new record type can be complicated. Henrik: No, you would keep a list of types already created. Hans: This does not compose well for records in records, e.g. using tables nested in records. Nested records example from library storing 3D visualization data
Brings us back to arrays of non-homogeneous types: Differences.md says we either have constant or flexible sizes in arrays. Applying flexible sizes to this example means in Flat Modelica:
Does this example make sense using flexible sizes? Gerd: Replacing sizes with colons means that all size variants are of the same type. Henrik: Early we stated that we do not allow flexible size in model component declarations. |
Web Meeting (Martin, Hans, Henrik, Gerd, Oliver) Gerd: Another example: reading an array of unknown size from a file. Hans: Depends on when the initialization is performed, could be before generating flat Modelica.
Consequence of allowing flexible arrays in general?
Consequence of not allowing flexible arrays in general?
Conclusion on are flexible size arrays
Poll:
in favor of Decision: |
Web Meeting (Martin, Hans, Henrik, Gerd, Oliver) Consequences of record members not being in the same scope:
flat Modelica variant 1
flat Modelica variant 2
Henrik: In flat Modelica we already know all modifications. Variant 2 looks fragile but it's as valid as variant 1. |
Web Meeting (Henrik, Hans, Gerd, Martin, Oliver)
flat Modelica variant 1 (use model component declaration modification)
flat Modelica variant 2 (use record component declaration modification)
flat Modelica variant 3: (remove record entirely)
Conclusion:
flat Modelica variant 1
flat Modelica variant 2 flat Modelica variant 3: Remove record entirely
Conclusions:
Could be handled by forcing i to be considered as evaluated parameter and turned into a constant. Poll: in favor of option 1: Henrik, Martin, Hans, Gerd, Oliver Decision: |
Web Meeting: Hans, Henrik, Gerd, Martin, Oliver Looking at Constant value modification:Example from above:
Constant value modification: flat Modelica Variant 1 (use model component declaration modification)
Constant value modification: flat Modelica Variant 2 (use record component declaration modification)
Constant value modification: flat Modelica Variant 3 (remove record entirely)
Non-constant value modification:
Non-constant value modification: flat Modelica Variant 1 (use model component declaration modification)
NonConstant value modification: flat Modelica Variant 2 (use record component declaration modification) Doesn't work because non-constant cannot be evaluated to a literal. Constant value modification: flat Modelica Variant 3 (remove record entirely)
Conclusions for constant and non-constant value modificationsOption1: Forbid access to members of a record from inside the same record class definition
Option2: Keep looking for reasons why access cannot be forbidden
Hans: Happy for what we see now at least. Poll: Decision: Next: |
The example to discuss next meeting is whether we want to support this kind of access to constant members of a record:
For comparison, it is already clear that this should be allowed in Flat Modelica:
Also note the following clearly allowed variant of the above:
|
Web Meeting (Hans, Henrik, Martin, Oliver) Discussion of the examples above:
Is there a need to treat records like package constants? Conclusion: |
RationaleMCP/0031/differences.md
Outdated
@@ -1,6 +1,44 @@ | |||
# Semantical differences between Flat Modelica and Modelica | |||
This document describes differences between Flat Modelica and Modelica that aren't clear from the differences in the grammars. | |||
|
|||
## Lexical scoping inside record definitions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should contain two subsection covering
inside records
not treating records as packages
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
Co-authored-by: Hans Olsson <HansOlsson@users.noreply.github.com>
This PR is a subtopic of #2558 concerning value modification. The first task to be addressed by this PR is to summarize the current state of value modifications considering various restrictions put into Flat Modelica, and identify any problems. After that, we might also be able to further simplify value modification.