Skip to content

Include namespaces in mangled symbols #281

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 2 commits into from
Nov 18, 2016

Conversation

fitzgen
Copy link
Member

@fitzgen fitzgen commented Nov 18, 2016

When we aren't using --enable-cxx-namespaces, we can end up with
conflicting struct symbol names that we need to disambiguate. The
solution is to mangle the namespaced C++ symbol "foo::bar::Baz" into the
Rust "foo_bar_Baz" symbol.

This did change the way anonymous types and modules get named a little,
but I think our approach is much more sane now than it was before.

Fixes #267.

r? @emilio

@emilio
Copy link
Contributor

emilio commented Nov 18, 2016

\o/ awesome! Will review this properly tomorrow, and probably run it through stylo since the change is likely breaking, but awesome! :)

Thanks for doing this :)

Copy link
Contributor

@emilio emilio left a comment

Choose a reason for hiding this comment

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

Looks great, though this means that the stylo script probably should change some of its whitelisting and blacklisting. cc @Manishearth and @upsuper.

// Template aliases use their inner alias type's name if we
// are checking names for whitelisting/replacement/etc.
TypeKind::TemplateAlias(inner, _) if for_name_checking => {
item = ctx.resolve_item(inner);
Copy link
Contributor

Choose a reason for hiding this comment

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

probably should be able to just return inner in this case.

Copy link
Member Author

Choose a reason for hiding this comment

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

Again, will try with a debug_assert!.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

// If we're a template specialization, our name is our
// parent's name.
TypeKind::Comp(ref ci) if ci.is_template_specialization() => {
item = ctx.resolve_item(ci.specialized_template().unwrap());
Copy link
Contributor

Choose a reason for hiding this comment

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

and here we may be able to just do return ci.specialized_template(), this can't be recursive if I'm not wrong.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll do this, but also add a debug_assert! that the specialized template's name target is itself.

Copy link
Member Author

Choose a reason for hiding this comment

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

This assertion is failing in our tests, I'm going to leave the code as it was.

Copy link
Contributor

Choose a reason for hiding this comment

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

Just curious, which tests are failing?


/// Get this function item's name, or `None` if this item is not a function.
fn func_name(&self) -> Option<&str> {
if let ItemKind::Function(ref func) = *self.kind() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Using match you can save a line, but at your choice :)

Copy link
Member Author

Choose a reason for hiding this comment

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

Good call ;)

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.


/// Get the overload index for this method. If this is not a method, return
/// `None`.
fn method_overload_index(&self, ctx: &BindgenContext) -> Option<usize> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Ahh, I understand why this can't be completely moved to codegen, we generate calls for it... Well looks fine :)

When we aren't using `--enable-cxx-namespaces`, we can end up with
conflicting struct symbol names that we need to disambiguate. The
solution is to mangle the namespaced C++ symbol "foo::bar::Baz" into the
Rust "foo_bar_Baz" symbol.
@fitzgen fitzgen force-pushed the namespace-mangle-rust-symbols branch from cfbb7d4 to 2a93411 Compare November 18, 2016 18:19
@fitzgen
Copy link
Member Author

fitzgen commented Nov 18, 2016

r? @emilio, I addressed the previous review's comments.

@emilio
Copy link
Contributor

emilio commented Nov 18, 2016

@bors-servo r+

@bors-servo
Copy link

📌 Commit 2a93411 has been approved by emilio

@bors-servo
Copy link

⚡ Test exempted - status

@bors-servo bors-servo merged commit 2a93411 into rust-lang:master Nov 18, 2016
bors-servo pushed a commit that referenced this pull request Nov 18, 2016
Include namespaces in mangled symbols

When we aren't using `--enable-cxx-namespaces`, we can end up with
conflicting struct symbol names that we need to disambiguate. The
solution is to mangle the namespaced C++ symbol "foo::bar::Baz" into the
Rust "foo_bar_Baz" symbol.

This did change the way anonymous types and modules get named a little,
but I think our approach is much more sane now than it was before.

Fixes #267.

r? @emilio
@fitzgen fitzgen deleted the namespace-mangle-rust-symbols branch November 18, 2016 18:40
@fitzgen
Copy link
Member Author

fitzgen commented Nov 18, 2016

THanks @emilio! :)

@bholley
Copy link

bholley commented Nov 21, 2016

This busts stylo bindings, causing us to generate erroneous code like:

-pub type mozilla_UniquePtr_Pointer =
-    typename detail::PointerType<T, DeleterType>::Type;

Is this related to the whitelisting/blacklisting @emilio was mentioning above?

In general, it would be nice if large changes like this were tested against stylo before landing.

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.

5 participants