Skip to content
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

Use fully disambiguated name instead of a number for layout tests (fixes #394) #829

Merged
merged 1 commit into from
Jul 21, 2017

Conversation

Manishearth
Copy link
Member

These numbers cause tons of churn in the diffs for checked in bindings.

r? @fitzgen

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.

CI is red, you need to update the platform-specific tests (you can do it using the diffs from travis).

src/ir/item.rs Outdated
/// Create a fully disambiguated name for an item, including template
/// parameters if it is a type
pub fn full_disambiguated_name(&self, ctx: &BindgenContext) -> String {
let mut s = "".into();
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: just String::new()?

src/ir/item.rs Outdated
/// Helper function for full_disambiguated_name
fn push_disambiguated_name(&self, ctx: &BindgenContext, to: &mut String, level: u8) {
to.push_str(&self.canonical_name(ctx));
match *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.

Seems like a case for either if let, or:

let ty = match *self.kind() {
    ItemKind::Type(ref ty) => ty,
    _ => return,
};

// ...

@@ -768,7 +768,7 @@ impl CodeGenerator for TemplateInstantiation {
let size = layout.size;
let align = layout.align;

let name = item.canonical_name(ctx);
let name = item.full_disambiguated_name(ctx);
let mut fn_name = format!("__bindgen_test_layout_{}_instantiation", name);
let times_seen = result.overload_number(&fn_name);
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess you can remove this overload_number stuff and so on?

Copy link
Member Author

Choose a reason for hiding this comment

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

src/ir/item.rs Outdated
TypeKind::TemplateInstantiation(ref inst) => {
to.push_str(&format!("_open{}_", level));
for arg in inst.template_arguments() {
ctx.resolve_item(*arg).push_disambiguated_name(ctx, to, level + 1);
Copy link
Contributor

Choose a reason for hiding this comment

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

This won't work for nested templates, afaict, because you don't handle ResolvedTypeRef, or anything like that.

@fitzgen
Copy link
Member

fitzgen commented Jul 20, 2017

I still think that using the C++ mangling would be best (they already solved this exact unique-ness issue), do you remember why we weren't getting the mangling for template instantiations, @emilio ? Was it just that we weren't saving the information?

Anyways, cancelling my review, since Emilio is on it.

@fitzgen fitzgen assigned emilio and unassigned fitzgen Jul 20, 2017
@Manishearth Manishearth force-pushed the disambig branch 2 times, most recently from cbbe118 to 19b69fb Compare July 20, 2017 17:15
@fitzgen
Copy link
Member

fitzgen commented Jul 20, 2017

Looks like the libclang-4 expectations need to be updated:

---- header_issue_769_bad_instantiation_test_hpp stdout ----
	/home/travis/build/servo/rust-bindgen/tests/headers/issue-769-bad-instantiation-test.hpp:9:19: warning: alias declarations are a C++11 extension [-Wc++11-extensions], err: false
/home/travis/build/servo/rust-bindgen/tests/headers/issue-769-bad-instantiation-test.hpp:10:25: warning: alias declarations are a C++11 extension [-Wc++11-extensions], err: false
diff expected generated
--- expected: "/home/travis/build/servo/rust-bindgen/tests/expectations/tests/libclang-4/issue-769-bad-instantiation-test.rs"
+++ generated from: "/home/travis/build/servo/rust-bindgen/tests/headers/issue-769-bad-instantiation-test.hpp"
 /* automatically generated by rust-bindgen */
 
 
 #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
 
 
 #[allow(non_snake_case, non_camel_case_types, non_upper_case_globals)]
 pub mod root {
     #[allow(unused_imports)]
     use self::super::root;
     #[repr(C)]
     #[derive(Debug, Copy, Clone)]
     pub struct Rooted<T> {
         pub member: T,
         pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<T>>,
     }
     impl <T> Default for Rooted<T> {
         fn default() -> Self { unsafe { ::std::mem::zeroed() } }
     }
     pub type AutoValueVector_Alias = ::std::os::raw::c_int;
     #[test]
     fn __bindgen_test_layout_Rooted_open0_int_close0_instantiation() {
         assert_eq!(::std::mem::size_of::<root::Rooted<::std::os::raw::c_int>>()
                    , 4usize , concat ! (
                    "Size of template specialization: " , stringify ! (
                    root::Rooted<::std::os::raw::c_int> ) ));
         assert_eq!(::std::mem::align_of::<root::Rooted<::std::os::raw::c_int>>()
                    , 4usize , concat ! (
                    "Alignment of template specialization: " , stringify ! (
                    root::Rooted<::std::os::raw::c_int> ) ));
     }
     #[test]
-    fn  __bindgen_test_layout_Rooted_open0_AutoValueVector_Alias_close0_instantiation() {
+    fn __bindgen_test_layout_Rooted_open0_AutoValueVector_Alias_close0_instantiation() {
         assert_eq!(::std::mem::size_of::<root::Rooted<root::AutoValueVector_Alias>>()
                    , 4usize , concat ! (
                    "Size of template specialization: " , stringify ! (
                    root::Rooted<root::AutoValueVector_Alias> ) ));
         assert_eq!(::std::mem::align_of::<root::Rooted<root::AutoValueVector_Alias>>()
                    , 4usize , concat ! (
                    "Alignment of template specialization: " , stringify ! (
                    root::Rooted<root::AutoValueVector_Alias> ) ));
     }
 }

@Manishearth
Copy link
Member Author

Passes now

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.

r=me

@emilio
Copy link
Contributor

emilio commented Jul 21, 2017

@bors-servo r+

@bors-servo
Copy link

📌 Commit 3dedc2c has been approved by emilio

@bors-servo
Copy link

⌛ Testing commit 3dedc2c with merge b51ddf3...

bors-servo pushed a commit that referenced this pull request Jul 21, 2017
Use fully disambiguated name instead of a number for layout tests (fixes #394)

These numbers cause tons of churn in the diffs for checked in bindings.

r? @fitzgen
@bors-servo
Copy link

☀️ Test successful - status-travis
Approved by: emilio
Pushing b51ddf3 to master...

@bors-servo bors-servo merged commit 3dedc2c into master Jul 21, 2017
@Manishearth Manishearth mentioned this pull request Jul 21, 2017
@emilio emilio deleted the disambig branch July 23, 2017 01:22
bors-servo pushed a commit that referenced this pull request Jul 24, 2017
Bump to 0.28

Brings in  #822 which unblocks https://bugzilla.mozilla.org/show_bug.cgi?id=1366956,
and also #829 which should greatly reduce merge conflicts in checked in bindings.
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