-
-
Notifications
You must be signed in to change notification settings - Fork 95
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
Conversation
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.
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.
7091871
to
1fcce02
Compare
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.
LGTM otherwise.
zbus_xmlgen/src/lib.rs
Outdated
let name = collision_hander | ||
.avoid_collision(to_identifier(&to_snakecase(signal.name().as_str()))); |
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.
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.
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.
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
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.
I was just wondering if there is a case where we also have collisions in arguments?
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.
First I also tought this
Ah, you're ahead of me. :)
I could move the
to_identifier
function inside theavoid_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).
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.
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
andmake_unique
- For Properties I need
to_snakecase
,to_identifier
, and I needmake_unique
as a separate operation depending on read or write case. - For arguments I only need
to_identifier
, optionally we could applymake_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.
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.
@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.
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.
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.
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.
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?
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.
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.
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.
Also, the branch needs a manual rebase.
1fcce02
to
2383c24
Compare
@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. 🙏 |
@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. |
@bachp i hope you've not forgotten about your existing PR. 😉 |
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.
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. 🙏
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]>
2383c24
to
acdb5be
Compare
@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. |
Oh? I understood from your previous two comments here that it's not ready and you've to fix something still.
Because there is still a conversation that's not marked as "resolved" yet.
For sure. I thought they were a blocker for you and you want to address them all here. |
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.
Based on the latest discussion here, I wanted to set the status right.
@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. |
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: