-
Notifications
You must be signed in to change notification settings - Fork 234
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
Swift classes can inherit from traits #2363
Conversation
Builds on mozilla#2196, mozilla#2204 and mozilla#2297. Closes mozilla#2169.
945d38f
to
da5c636
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.
Looks great to me.
I had a comment about the protocol name, but that's not really in-scope for this issue. If you agree and wanted to make that change too, that's good with me. If you don't agree or want to do it in a separate PR that's good too.
if has_callback_interface { | ||
Ok(class_name) | ||
} else { | ||
Ok(format!("{class_name}Protocol")) |
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.
Is there a good reason why this has "Protocol" appended? IIUC, this is a Rust trait without callback interface support, so Swift can't implement it. In that case, it seems like protocol should get {class_name}
which feels like a nicer name, and the class that implements the protocol should get something like{class_name}Impl
. I think that's how the other languages handle it.
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.
This is exactly the same as kotlin which has "Interface" appended
Note that this change doesn't change the hierarchy of any existing objects, it just controls which of the 2 generated classes is used in the inheritance chain.
I'm inclined to agree that the existing hierarchy is odd in these cases, I fear that trying to change that here will accidentally introduce new regressions.
Is this also your understanding - ie, that this patch doesn't change the class hierarchy for existing types, and that doing so is something we'd need to be very careful 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.
Is this also your understanding - ie, that this patch doesn't change the class hierarchy for existing types
Yes agreed.
..and that doing so is something we'd need to be very careful about?
Maybe I have a slight difference of opinion here. I think it could be okay to make the change, since most end-users aren't going to see a difference. If they store a Foo
and only use it to call methods from the protocol, it shouldn't matter if Foo
is a concrete type that implements the protocol or the protocol itself.
I agree we should be careful, but maybe I'd remove the "very" part.
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, I think I got confused and believed that we had already made the change for other languages. If Kotlin works this way, then I think Swift should too. If we decide to change them, let's change both at the same time.
I remember looking into this when doing this for kotlin - the names smelt wrong, but I couldn't work out how to make them good. When UniFFI generates a plain-old trait, it only emits a protocol - there's no concrete implementation. So our But when we need a local impl of the trait (callback/foreign) we'd generate I don't see how to change those names? |
awesome thanks @mhammond ! |
Builds on #2196, #2204 and #2297. Closes #2169.