Skip to content
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

Get rid of 'protected' #3162

Merged
merged 12 commits into from May 25, 2022
Merged

Get rid of 'protected' #3162

merged 12 commits into from May 25, 2022

Conversation

henrikt-ma
Copy link
Collaborator

No description provided.

@HansOlsson HansOlsson changed the base branch from master to MCP/0031 May 3, 2022 09:41
@henrikt-ma henrikt-ma added the MCP0031 FlatModelica and MLS modular issues and PRs (MCP-0031) label May 3, 2022
@olivleno
Copy link
Collaborator

olivleno commented May 3, 2022

Web Meeting: Hans, Henrik, Gerd, Martin, Oliver

Uses of protected in Modelica:

  • restrict connection (does not apply in flat Modelica)
  • restrict modification (should be checked by the full Modelica tool)
  • exclude from results (vendor specific heuristic, hideResults=true)
  • prevent access via dot notation (should be checked by the full Modelica tool)
  • local variables in functions

Example:

function f
  input Real u;
  output Real y;
protected
  Real x;
algorithm
  x := u+1;
  y := x*x;
end f;

flat Modelica w/o protected

function 'f'
  input Real 'u';
  output Real 'y';
  Real 'x';
algorithm
  'x' := 'u'+1;
  'y' := 'x'*'x';
end f;

The fact that x is not part of the function interface is also clear w/o protected.

Conclusion:
There is no need for protected for functions or any other case listed above.

Open question:
Can we also remove public?

@olivleno
Copy link
Collaborator

Web Meeting: Hans, Henrik, Gerd, Martin, Oliver

Henrik: If we can handle final, then we can protected also, because restricted modifications. In terms of heuristics we will have to see.

Henrik: public is needed only to end a protected section. If we don't have protected there is no need for public.

Hans: There are heuristics using them. Adding an annotation may add so much more. Maybe we need to have an appropriate semantics for protected, then the heuristics could remain.

Henrik: To this would be cleaner to keep only what is needed.

Hans: It doesn't hurt keeping it.

Henrik: Having a keyword but a different semantics will be confusing.

Henrik: Keeping public and protected may lead to alternating sections.

What are these heuristics?

  • Determine what to store
    • storeResults=true/false is not sufficient, would have to be extended to preserve the information that it was protected.
  • Equation system tearing
    • It makes sense to give start values only to public variables.
  • Alias elimination
    • Keep the non-protected variables to make it easier to understand.

Keep the information that a start value cannot be modified would make the selection for tearing more transparent.
This is comparable to final modification of start.

Proposals:

  1. Keep keywords public and protected but remove semantic restrictions.
  2. Find annotations for storing results and alias elimination and use it also for tearing if needed.
  3. Add an annotation protected=true and don't require protected for local variables inside functions.

Poll:

Option 1: None.
Option 2: Oliver
Option 3: Henrik, Gerd, Hans
abstain: Martin

Decision:
Go with option 3.
Update the PR [Henrik]

@HansOlsson
Copy link
Collaborator

I believe we should use a longer example:

  model M
     Real x;
  protected
     Real p;
  end M;

  model N
    M m1;
  protected
    M m2;
  end N;

  // Flat
  Real 'm1.x';
  Real 'm1.p' annotation(prot=true); 
  Real 'm2.x' annotation(prot=true); 
  Real 'm2.p' annotation(prot=true); 

Co-authored-by: Oliver Lenord <oliver.lenord@de.bosch.com>
@olivleno
Copy link
Collaborator

Web Meeting (Hans, Henrik, Gerd, Martin, Oliver)

Added the "long" example from Hans to the annotations.md

Decision:
The fact that the hierarchical information about protected sections is lost is accepted.

@olivleno olivleno merged commit 6b33613 into MCP/0031 May 25, 2022
@olivleno olivleno deleted the MCP/0031-protected branch May 25, 2022 11:44
@casella
Copy link
Collaborator

casella commented Jan 24, 2024

A post-mortem comment here. I understand it is well settled in the current proposal that protected is not need in BaseModelica functions, all non-input, non-output variables are considered as local variables of the function, although this actually makes BaseModelica functions invalid in Modelica. BTW, I never fully understood why we require to put protected before non-input non-output in Modelica and complain , but that is another story. My question regards the paper presented in Aachen, where I see:
immagine
I guess the protected keyword was put there by mistake, can you please confirm?

Thanks!

@henrikt-ma
Copy link
Collaborator Author

henrikt-ma commented Jan 29, 2024

Well spotted! The text for constsize must be older than the decision to remove protected, and then we made the mistake of copying code into the paper without looking at it carefully. I'll set up a PR to at least get it fixed on the MCP branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
MCP0031 FlatModelica and MLS modular issues and PRs (MCP-0031)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants