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

🐛 zx: Prevent collisions between methods, signals and properties #722

Closed
wants to merge 1 commit into from

Conversation

bachp
Copy link

@bachp bachp commented Apr 17, 2024

Prevent collisons by adding an explicit suffix to properties and signals.

If a collision is detected a _ is added to the identifier until there is no more collision.

Closes:

zbus_xmlgen/src/lib.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@zeenix zeenix left a comment

Choose a reason for hiding this comment

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

Thanks so much for contributing this PR and also to follow our dev practices from the start. However, I think a good solution here would require more work than changing all generated names.

@bachp bachp force-pushed the xmlgen-avoid-collision branch from 7091871 to 1fcce02 Compare April 18, 2024 19:07
@bachp bachp requested a review from zeenix April 18, 2024 19:09
Copy link
Contributor

@zeenix zeenix left a comment

Choose a reason for hiding this comment

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

LGTM otherwise.

Comment on lines 197 to 198
let name = collision_hander
.avoid_collision(to_identifier(&to_snakecase(signal.name().as_str())));
Copy link
Contributor

@zeenix zeenix Apr 18, 2024

Choose a reason for hiding this comment

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

I think the 2 steps should be combined into one. We don't really need a separate type for name collision, just one for creating identifiers, that ensures that the identifier isn't already used.

Copy link
Author

Choose a reason for hiding this comment

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

First I also tought this, but the to_identifier is also used in other places, eg. function parameters, and they don't collide with signals and properties. but

I could move the to_identifier function inside the avoid_collision but I thought this was it is more explict

Copy link
Author

Choose a reason for hiding this comment

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

I was just wondering if there is a case where we also have collisions in arguments?

Copy link
Contributor

Choose a reason for hiding this comment

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

First I also tought this

Ah, you're ahead of me. :)

I could move the to_identifier function inside the avoid_collision but I thought this was it is more explict

Or you could have the new API use to_identifier itself so that caller doesn't need to care. I'd call the type UniqueNameGenerator and method identifier_for_name, which takes the name as arg, also taking care of to_snakecase. You can suggest a better name, just don't like collision in the name (sounds negative 😆).

I was just wondering if there is a case where we also have collisions in arguments?

Doubtful but even if there was, it won't be global (i-e args of different methods can have the same name).

Copy link
Author

Choose a reason for hiding this comment

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

I tried severl variants of combining operations. In the end I found it's best to keep the operations separate so I can combine these in the different cases:

  • Functions and signals i need to_snakecase, to_identifier and make_unique
  • For Properties I need to_snakecase, to_identifier, and I need make_unique as a separate operation depending on read or write case.
  • For arguments I only need to_identifier, optionally we could apply make_unique per function here but I don't see this needed.

So my solution now is to just rename the CollisionHandler to Idenfifier and have a make_unique method.

Copy link
Contributor

Choose a reason for hiding this comment

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

@zeenix I'm not sure what the best solution is. If you have a proposal please apply it on top of this branch.

Perhaps we can find one if you'd follow up with the discussion here? I don't see a problem mentioned here. It's more about semantics afaict and bike-shedding (sorry that's my bad but I care about code quality perhaps a bit too much) about how the functions should work/be named etc.

Copy link
Contributor

Choose a reason for hiding this comment

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

If you have a proposal

My proposal is above btw.

please apply it on top of this branch.

It'd be easier for me to start from scratch and your effort here and my review time will be wasted.

Copy link
Author

@bachp bachp Jan 8, 2025

Choose a reason for hiding this comment

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

Ok maybe we need to take a step back as I'm not sure what question you are referring too.

From my point of view this change works as it prevents collisions. It's just that there seems to be additional conflicts with hardcoded name when generating a NetworkManager interface. However I think this can be solved later.

What is now still open from your point of view?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok maybe we need to take a step back as I'm not sure what question you are referring too.

The "How so" line in the comment above where the logical flow just ended.

What is now still open from your point of view?

The changes I asked for here. If you have already addressed them, please let me know and I'll review again.


As for making everything work for NetworkManager, that indeed can wait and was not what this discussion/thread was original about.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, the branch needs a manual rebase.

@bachp bachp force-pushed the xmlgen-avoid-collision branch from 1fcce02 to 2383c24 Compare April 20, 2024 06:55
@bachp bachp requested a review from zeenix April 20, 2024 07:02
@zeenix
Copy link
Contributor

zeenix commented Jun 15, 2024

@bachp oh I'm so sorry. I never got a notification that you requested a review after updating the pr. I'll look into this very soon.

Thanks for your patience. 🙏

@bachp
Copy link
Author

bachp commented Jun 15, 2024

@zeenix As mentioned in #722 (comment) my change didn't completely solve the issue with the networkmanager dbus specification. Unfortunately I was busy with other things.

I want to add a test based on the real world example, not sure when I will get to it tough.

@zeenix
Copy link
Contributor

zeenix commented Jul 11, 2024

@bachp i hope you've not forgotten about your existing PR. 😉

@bachp
Copy link
Author

bachp commented Jul 11, 2024

@zeenix No I did not but I ran into other issues while trying to interact with network manager, mainly #312 which is more of a blocker for me.I will come back to this once I found a solution for the more blocking issues.

Copy link
Contributor

@zeenix zeenix left a comment

Choose a reason for hiding this comment

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

GH thinks this is a pending review from me so let me fix that. 😊 Also, it would be great if you could finish this soon. 🙏

@bachp bachp requested a review from zeenix August 17, 2024 17:02
If a collision is detected and additional `_` is appended to the
identifier until there is no more collision.

Signed-off-by: Pascal Bach <[email protected]>
@bachp bachp force-pushed the xmlgen-avoid-collision branch from 2383c24 to acdb5be Compare August 17, 2024 17:04
@bachp
Copy link
Author

bachp commented Aug 17, 2024

@zeenix Not sure what is still open and why GH thinks there is a change required. From my point of view this is ready, I also rebased it on main.

It doesn't fix all naming collisions I encountered with NetworkManager, but I can address the remaining issues in a sparate PR.

@zeenix
Copy link
Contributor

zeenix commented Aug 17, 2024

@zeenix Not sure what is still open

Oh? I understood from your previous two comments here that it's not ready and you've to fix something still.

why GH thinks there is a change required. From my point of view this is ready

Because there is still a conversation that's not marked as "resolved" yet.

It doesn't fix all naming collisions I encountered with NetworkManager, but I can address the remaining issues in a sparate PR.

For sure. I thought they were a blocker for you and you want to address them all here.

Copy link
Contributor

@zeenix zeenix left a comment

Choose a reason for hiding this comment

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

Based on the latest discussion here, I wanted to set the status right.

@zeenix zeenix mentioned this pull request Jan 7, 2025
@zeenix
Copy link
Contributor

zeenix commented Jan 8, 2025

@bachp Anyway, I've spent a lot of time already pointed out the obvious (if you'd care to read) again and again and each time you drop the ball. I've better things to do. I'm banning you from this project.

@zeenix zeenix closed this Jan 8, 2025
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