summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2017-05-19 22:50:51 -0500
committerGitHub <noreply@github.com>2017-05-19 22:50:51 -0500
commitea9a9322053b4bfef91206e33a67cf96e2831930 (patch)
tree63e3fa2d52fedcdeb7bc4c99859af2b9866c52fa
parent25150ca64f8009ac53829a2daa031c8723684523 (diff)
parent44f68587e4635df5661e64f03dd2dd4d9a3ebd30 (diff)
Auto merge of #708 - emilio:template-inst-noise, r=fitzgen
codegen: Reuse the next_child_local_id hack for template instantiations. This should be good enough, following the pattern of anonymous items, and should prevent most of the current noise in stylo updates. Closes #620 Fixes #619
-rw-r--r--src/codegen/mod.rs4
-rw-r--r--src/ir/item.rs25
-rw-r--r--tests/expectations/tests/anon_union.rs2
-rw-r--r--tests/expectations/tests/class_nested.rs2
-rw-r--r--tests/expectations/tests/class_with_dtor.rs2
-rw-r--r--tests/expectations/tests/crtp.rs4
-rw-r--r--tests/expectations/tests/default-template-parameter.rs2
-rw-r--r--tests/expectations/tests/issue-569-non-type-template-params-causing-layout-test-failures.rs2
-rw-r--r--tests/expectations/tests/issue-691-template-parameter-virtual.rs2
-rw-r--r--tests/expectations/tests/non-type-params.rs2
-rw-r--r--tests/expectations/tests/partial-specialization-and-inheritance.rs2
-rw-r--r--tests/expectations/tests/template.rs8
12 files changed, 35 insertions, 22 deletions
diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs
index 06e3a4f6..2f8ad805 100644
--- a/src/codegen/mod.rs
+++ b/src/codegen/mod.rs
@@ -760,8 +760,8 @@ impl CodeGenerator for TemplateInstantiation {
let name = item.canonical_name(ctx);
let fn_name = format!("__bindgen_test_layout_{}_instantiation_{}",
- name,
- item.id().as_usize());
+ name, item.exposed_id(ctx));
+
let fn_name = ctx.rust_ident_raw(&fn_name);
let prefix = ctx.trait_prefix();
diff --git a/src/ir/item.rs b/src/ir/item.rs
index fdf2507d..6c118f54 100644
--- a/src/ir/item.rs
+++ b/src/ir/item.rs
@@ -370,7 +370,7 @@ pub struct Item {
/// This item's id.
id: ItemId,
- /// The item's local id, unique only amongst its siblings. Only used for
+ /// The item's local id, unique only amongst its siblings. Only used for
/// anonymous items.
///
/// Lazily initialized in local_id().
@@ -379,7 +379,7 @@ pub struct Item {
/// case this is an implementation detail.
local_id: Cell<Option<usize>>,
- /// The next local id to use for a child..
+ /// The next local id to use for a child or template instantiation.
next_child_local_id: Cell<usize>,
/// A cached copy of the canonical name, as returned by `canonical_name`.
@@ -490,13 +490,23 @@ impl Item {
pub fn local_id(&self, ctx: &BindgenContext) -> usize {
if self.local_id.get().is_none() {
let parent = ctx.resolve_item(self.parent_id);
- let local_id = parent.next_child_local_id.get();
- parent.next_child_local_id.set(local_id + 1);
- self.local_id.set(Some(local_id));
+ self.local_id.set(Some(parent.next_child_local_id()));
}
self.local_id.get().unwrap()
}
+ /// Get an identifier that differentiates a child of this item of other
+ /// related items.
+ ///
+ /// This is currently used for anonymous items, and template instantiation
+ /// tests, in both cases in order to reduce noise when system headers are at
+ /// place.
+ pub fn next_child_local_id(&self) -> usize {
+ let local_id = self.next_child_local_id.get();
+ self.next_child_local_id.set(local_id + 1);
+ local_id
+ }
+
/// Returns whether this item is a top-level item, from the point of view of
/// bindgen.
///
@@ -777,13 +787,16 @@ impl Item {
ctx.rust_mangle(&name).into_owned()
}
- fn exposed_id(&self, ctx: &BindgenContext) -> String {
+ /// The exposed id that represents an unique id among the siblings of a
+ /// given item.
+ pub fn exposed_id(&self, ctx: &BindgenContext) -> String {
// Only use local ids for enums, classes, structs and union types. All
// other items use their global id.
let ty_kind = self.kind().as_type().map(|t| t.kind());
if let Some(ty_kind) = ty_kind {
match *ty_kind {
TypeKind::Comp(..) |
+ TypeKind::TemplateInstantiation(..) |
TypeKind::Enum(..) => return self.local_id(ctx).to_string(),
_ => {}
}
diff --git a/tests/expectations/tests/anon_union.rs b/tests/expectations/tests/anon_union.rs
index eb600cc7..fde9b307 100644
--- a/tests/expectations/tests/anon_union.rs
+++ b/tests/expectations/tests/anon_union.rs
@@ -80,7 +80,7 @@ impl Default for ErrorResult {
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
}
#[test]
-fn __bindgen_test_layout_TErrorResult_instantiation_21() {
+fn __bindgen_test_layout_TErrorResult_instantiation_1() {
assert_eq!(::std::mem::size_of::<TErrorResult>() , 24usize , concat ! (
"Size of template specialization: " , stringify ! (
TErrorResult ) ));
diff --git a/tests/expectations/tests/class_nested.rs b/tests/expectations/tests/class_nested.rs
index 77072354..ba1d274c 100644
--- a/tests/expectations/tests/class_nested.rs
+++ b/tests/expectations/tests/class_nested.rs
@@ -78,7 +78,7 @@ extern "C" {
pub static mut var: A_B;
}
#[test]
-fn __bindgen_test_layout_A_D_instantiation_16() {
+fn __bindgen_test_layout_A_D_instantiation_1() {
assert_eq!(::std::mem::size_of::<A_D<::std::os::raw::c_int>>() , 4usize ,
concat ! (
"Size of template specialization: " , stringify ! (
diff --git a/tests/expectations/tests/class_with_dtor.rs b/tests/expectations/tests/class_with_dtor.rs
index a3210247..f7f8e20b 100644
--- a/tests/expectations/tests/class_with_dtor.rs
+++ b/tests/expectations/tests/class_with_dtor.rs
@@ -35,7 +35,7 @@ impl Default for WithoutDtor {
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
}
#[test]
-fn __bindgen_test_layout_HandleWithDtor_instantiation_10() {
+fn __bindgen_test_layout_HandleWithDtor_instantiation_1() {
assert_eq!(::std::mem::size_of::<HandleWithDtor<::std::os::raw::c_int>>()
, 8usize , concat ! (
"Size of template specialization: " , stringify ! (
diff --git a/tests/expectations/tests/crtp.rs b/tests/expectations/tests/crtp.rs
index 8a83e198..8df5716e 100644
--- a/tests/expectations/tests/crtp.rs
+++ b/tests/expectations/tests/crtp.rs
@@ -51,7 +51,7 @@ impl Default for DerivedFromBaseWithDestructor {
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
}
#[test]
-fn __bindgen_test_layout_Base_instantiation_9() {
+fn __bindgen_test_layout_Base_instantiation_1() {
assert_eq!(::std::mem::size_of::<Base>() , 1usize , concat ! (
"Size of template specialization: " , stringify ! ( Base ) ));
assert_eq!(::std::mem::align_of::<Base>() , 1usize , concat ! (
@@ -59,7 +59,7 @@ fn __bindgen_test_layout_Base_instantiation_9() {
));
}
#[test]
-fn __bindgen_test_layout_BaseWithDestructor_instantiation_12() {
+fn __bindgen_test_layout_BaseWithDestructor_instantiation_2() {
assert_eq!(::std::mem::size_of::<BaseWithDestructor>() , 1usize , concat !
(
"Size of template specialization: " , stringify ! (
diff --git a/tests/expectations/tests/default-template-parameter.rs b/tests/expectations/tests/default-template-parameter.rs
index 3b65075c..a180dcf9 100644
--- a/tests/expectations/tests/default-template-parameter.rs
+++ b/tests/expectations/tests/default-template-parameter.rs
@@ -16,7 +16,7 @@ impl <T, U> Default for Foo<T, U> {
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
}
#[test]
-fn __bindgen_test_layout_Foo_instantiation_6() {
+fn __bindgen_test_layout_Foo_instantiation_1() {
assert_eq!(::std::mem::size_of::<Foo<bool, ::std::os::raw::c_int>>() ,
8usize , concat ! (
"Size of template specialization: " , stringify ! (
diff --git a/tests/expectations/tests/issue-569-non-type-template-params-causing-layout-test-failures.rs b/tests/expectations/tests/issue-569-non-type-template-params-causing-layout-test-failures.rs
index c4ce5139..48e86596 100644
--- a/tests/expectations/tests/issue-569-non-type-template-params-causing-layout-test-failures.rs
+++ b/tests/expectations/tests/issue-569-non-type-template-params-causing-layout-test-failures.rs
@@ -32,7 +32,7 @@ impl Default for JS_AutoIdVector {
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
}
#[test]
-fn __bindgen_test_layout_JS_Base_instantiation_20() {
+fn __bindgen_test_layout_JS_Base_instantiation_2() {
assert_eq!(::std::mem::size_of::<JS_Base>() , 1usize , concat ! (
"Size of template specialization: " , stringify ! ( JS_Base )
));
diff --git a/tests/expectations/tests/issue-691-template-parameter-virtual.rs b/tests/expectations/tests/issue-691-template-parameter-virtual.rs
index 8333f1f7..4903fbfd 100644
--- a/tests/expectations/tests/issue-691-template-parameter-virtual.rs
+++ b/tests/expectations/tests/issue-691-template-parameter-virtual.rs
@@ -51,7 +51,7 @@ impl Default for ServoElementSnapshotTable {
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
}
#[test]
-fn __bindgen_test_layout_Set_instantiation_13() {
+fn __bindgen_test_layout_Set_instantiation_1() {
assert_eq!(::std::mem::size_of::<Set>() , 4usize , concat ! (
"Size of template specialization: " , stringify ! ( Set ) ));
assert_eq!(::std::mem::align_of::<Set>() , 4usize , concat ! (
diff --git a/tests/expectations/tests/non-type-params.rs b/tests/expectations/tests/non-type-params.rs
index 039aa711..7470d28f 100644
--- a/tests/expectations/tests/non-type-params.rs
+++ b/tests/expectations/tests/non-type-params.rs
@@ -38,7 +38,7 @@ impl Default for UsesArray {
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
}
#[test]
-fn __bindgen_test_layout_Array_instantiation_18() {
+fn __bindgen_test_layout_Array_instantiation_1() {
assert_eq!(::std::mem::size_of::<[u32; 4usize]>() , 16usize , concat ! (
"Size of template specialization: " , stringify ! (
[u32; 4usize] ) ));
diff --git a/tests/expectations/tests/partial-specialization-and-inheritance.rs b/tests/expectations/tests/partial-specialization-and-inheritance.rs
index 24225934..5e09ed4d 100644
--- a/tests/expectations/tests/partial-specialization-and-inheritance.rs
+++ b/tests/expectations/tests/partial-specialization-and-inheritance.rs
@@ -15,7 +15,7 @@ pub struct Derived {
pub b: bool,
}
#[test]
-fn __bindgen_test_layout__bindgen_ty_id_20_instantiation_14() {
+fn __bindgen_test_layout__bindgen_ty_id_20_instantiation_1() {
assert_eq!(::std::mem::size_of::<[u32; 2usize]>() , 8usize , concat ! (
"Size of template specialization: " , stringify ! (
[u32; 2usize] ) ));
diff --git a/tests/expectations/tests/template.rs b/tests/expectations/tests/template.rs
index 00061ecd..c5eb2a27 100644
--- a/tests/expectations/tests/template.rs
+++ b/tests/expectations/tests/template.rs
@@ -245,7 +245,7 @@ pub struct TemplateWithVar {
pub _address: u8,
}
#[test]
-fn __bindgen_test_layout_Foo_instantiation_95() {
+fn __bindgen_test_layout_Foo_instantiation_1() {
assert_eq!(::std::mem::size_of::<Foo<::std::os::raw::c_int>>() , 24usize ,
concat ! (
"Size of template specialization: " , stringify ! (
@@ -256,7 +256,7 @@ fn __bindgen_test_layout_Foo_instantiation_95() {
Foo<::std::os::raw::c_int> ) ));
}
#[test]
-fn __bindgen_test_layout_Foo_instantiation_101() {
+fn __bindgen_test_layout_Foo_instantiation_2() {
assert_eq!(::std::mem::size_of::<Foo<::std::os::raw::c_int>>() , 24usize ,
concat ! (
"Size of template specialization: " , stringify ! (
@@ -267,7 +267,7 @@ fn __bindgen_test_layout_Foo_instantiation_101() {
Foo<::std::os::raw::c_int> ) ));
}
#[test]
-fn __bindgen_test_layout_Rooted_instantiation_111() {
+fn __bindgen_test_layout_Rooted_instantiation_3() {
assert_eq!(::std::mem::size_of::<Rooted<*mut ::std::os::raw::c_void>>() ,
24usize , concat ! (
"Size of template specialization: " , stringify ! (
@@ -278,7 +278,7 @@ fn __bindgen_test_layout_Rooted_instantiation_111() {
Rooted<*mut ::std::os::raw::c_void> ) ));
}
#[test]
-fn __bindgen_test_layout_WithDtor_instantiation_123() {
+fn __bindgen_test_layout_WithDtor_instantiation_4() {
assert_eq!(::std::mem::size_of::<WithDtor<::std::os::raw::c_int>>() ,
4usize , concat ! (
"Size of template specialization: " , stringify ! (