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

feat: init policy defaults to true #459

Open
wants to merge 10 commits into
base: transition-to-runkit
Choose a base branch
from

Conversation

eduardacoppo
Copy link

The :init policy flag requests that the connection sends the last value written to it.
This PR applies the :init policy using the recommend_init flag

Depends on:

@doudou doudou requested review from jhonasiv and doudou February 6, 2025 18:02
Copy link
Member

@doudou doudou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good first step.

However, I believe this won't work for ports that are exported on a composition (since they are not using this codepath). I don't think it would work in many cases related to compositions (such as e.g. a composition that has a service as child and gets its real component as an injection in profiles).

The more generic place to resolve this would be where we compute the final connection policy. https://github.com//rock-core/tools-syskit/blob/b674ba903538d229ded38c5980cfd5549535e4eb/lib/syskit/network_generation/dataflow_dynamics.rb#L525

And it will definitely not work for data readers. For data readers, you would need to work here: https://github.com//rock-core/tools-syskit/blob/6b0d92aa0c8bc62a79ce6d58dffb330abdfcceb9/lib/syskit/dynamic_port_binding.rb#L205

lib/syskit/models/port.rb Outdated Show resolved Hide resolved
test/models/test_port.rb Outdated Show resolved Hide resolved
raise WrongPortConnectionTypes.new(self, in_port), "cannot connect #{out_port} to #{in_port}: types mismatch"
end

validate_connection!(out_port, in_port)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the ! here ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is subjective, but while reading about ! methods in ruby, I learned that this is a convention in rails for methods that might raise exceptions (example: https://api.rubyonrails.org/classes/ActiveRecord/Persistence.html#method-i-save-21). Seemed like a practical way to indicate that the method might interrupt the normal flow of code.
But now that you mention it, maybe it doesn't make sense here, since it's not being called by the user. It does draw attention to the method, though, and that was the main idea.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a ... long discussion in the Ruby circles. The ! is generally meant to represent "unexpectedly dangerous methods".... Not a very easy criteria to apply. For instance, in containers, it's used to mark self-modifying versions of modification methods (e.g. Hash#merge! vs. Hash#merge)

Regardless of the overall discussion, it's best to always follow the conventions of the codebase you're modifying. Within Syskit, the validate_* methods all raise and none has a !.

lib/syskit/models/port.rb Outdated Show resolved Hide resolved
@eduardacoppo eduardacoppo requested a review from doudou February 12, 2025 20:02
lib/syskit/dynamic_port_binding.rb Outdated Show resolved Hide resolved
lib/syskit/dynamic_port_binding.rb Outdated Show resolved Hide resolved
lib/syskit/dynamic_port_binding.rb Outdated Show resolved Hide resolved
lib/syskit/models/port.rb Outdated Show resolved Hide resolved
@eduardacoppo eduardacoppo force-pushed the init_policy_defaults_to_true branch from 78b2475 to 4132b18 Compare February 13, 2025 14:32
fix Metrics/CyclomaticComplexity offense by moving the connection validation code to a separate function
Use init_policy from the port as a default for the policy
Do not override the existing init flag in the policy
`policy.fetch(:init, port.model.init_policy)` to set the init value if not already provided in the policy
@eduardacoppo eduardacoppo force-pushed the init_policy_defaults_to_true branch from 4132b18 to 7ab7ee8 Compare February 13, 2025 14:35
@eduardacoppo eduardacoppo requested a review from doudou February 13, 2025 15:27
Copy link
Member

@doudou doudou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right ... so turns out that the syskit dataflow comptuation code itself is binary. Either the policy is empty and it gets computed automatically, or it's not and policy_for gets called.

Let's merge this PR following that behaviour and fix it later.

lib/syskit/network_generation/dataflow_dynamics.rb Outdated Show resolved Hide resolved
@eduardacoppo eduardacoppo force-pushed the init_policy_defaults_to_true branch from a54ec92 to 945bf58 Compare February 14, 2025 14:15
@eduardacoppo eduardacoppo requested a review from doudou February 14, 2025 15:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants