Skip to content

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

Merged
merged 5 commits into from
Nov 18, 2017

Conversation

RReverser
Copy link
Contributor

@RReverser RReverser commented Nov 15, 2017

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.

@RReverser
Copy link
Contributor Author

@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.

@RReverser
Copy link
Contributor Author

(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)

@eqrion
Copy link
Collaborator

eqrion commented Nov 17, 2017

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.

@RReverser
Copy link
Contributor Author

RReverser commented Nov 17, 2017

Sure, thank you for reviews! I would be curious to see the diff of webrender output with this change.

It had custom method with same name, while semantically it makes more sense to implement instantiate_monomorph from Item.
Copy link
Collaborator

@eqrion eqrion left a 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\" {");
Copy link
Collaborator

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh yeah, sure.

Copy link
Contributor Author

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.

@RReverser
Copy link
Contributor Author

If you're interested the diff is here. I'm happy to see mangled names disappear.

That went surprisingly smoothly :)

@eqrion
Copy link
Collaborator

eqrion commented Nov 18, 2017

Thanks!

@eqrion eqrion merged commit ce60054 into mozilla:master Nov 18, 2017
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.

Avoid monomorphisation for C++?
2 participants