-
Notifications
You must be signed in to change notification settings - Fork 338
Use C++ templates to represent Rust generics #88
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
Conversation
2499623
to
6a066cd
Compare
@eqrion What do you think in general? I'll be happy to do C part too, but would love to hear any concerns before I got too far just in case this turns out unacceptable. |
(also, complexity of generic part of #78 in other branch depends on whether this will be accepted approach or not, as it simplifies implementing new generics) |
This looks great to me. Thanks for doing this! I will need to do some investigation tomorrow to ensure this doesn't cause any unreasonable breakage for webrender, but after a first pass this looks good. |
Sure, thank you for reviews! I would be curious to see the diff of webrender output with this change. |
ec7ee81
to
897f375
Compare
It had custom method with same name, while semantically it makes more sense to implement instantiate_monomorph from Item.
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 looks great! There is some bustage from this for webrender
but with easy fixes. They were all caused by places that were using the mangled names.
If you're interested the diff is here. I'm happy to see mangled names disappear.
@@ -123,6 +120,12 @@ impl Bindings { | |||
out.new_line(); | |||
} | |||
|
|||
if self.config.language == Language::Cxx { | |||
out.new_line_if_not_start(); | |||
out.write("extern \"C\" {"); |
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.
Could you also update the end of block comments to indicate that extern "C"
is nested within namespaces, instead of the other way around?
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.
Oh yeah, sure.
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.
It would be nice to have tests covering these nuances :) Done.
That went surprisingly smoothly :) |
Thanks! |
This implements native representation of Rust generics as templates when generating C++ code.
Parameter for generic template specialisation which generated template groups on top of monomorphised structs was removed as it's now covered by just regular generic templates.
Didn't touch C part yet as it's somewhat more involved, TODO later.
Fixes #85
UPD: Also added generic typedef support instead of manual specialization, which makes aliased types compatible with their unaliased counterparts in C++ (as they resolve to the same type) and significantly simplifies implementation.