-
-
Notifications
You must be signed in to change notification settings - Fork 87
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
base: main
Are you sure you want to change the base?
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.
The way I understand your proposal is to put the rules how to combine these into separate functions/methods and just call them, e.g.
to_method
,to_signal
,to_property
andto_argument
At the very least, it should have been clear, which names I proposed. :)
While I can do that I'm not convinced it is a good idea as it basically splits the rules into two locations.
How so? They'll do pretty much the same thing as you're doing right now, just in one place/type. They will all use to_snakecase
and to_identifier
, for example.
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.
Let me know, if you'd want me to make the proposed changes in a separate commit on top.
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 did a test with these changes and the NetworkManager dbus xml, and it doesn't solve all the conflicts. I need to dig a bit deeper. I think I will add a test case using the NetworkManager interface description to make the issue more reproducible.
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.
@bachp this is the part that is still not resolved. You never answered my last question here. I know it's been many months since so I don't blame you for not remembering but let's try to conclude this only remaining issue,
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.
hello??
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 <pascal.bach@nextrem.ch>
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.
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: