Skip to content

Commit ea9a932

Browse files
author
bors-servo
authored
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
2 parents 25150ca + 44f6858 commit ea9a932

12 files changed

+35
-22
lines changed

src/codegen/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -760,8 +760,8 @@ impl CodeGenerator for TemplateInstantiation {
760760

761761
let name = item.canonical_name(ctx);
762762
let fn_name = format!("__bindgen_test_layout_{}_instantiation_{}",
763-
name,
764-
item.id().as_usize());
763+
name, item.exposed_id(ctx));
764+
765765
let fn_name = ctx.rust_ident_raw(&fn_name);
766766

767767
let prefix = ctx.trait_prefix();

src/ir/item.rs

+19-6
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ pub struct Item {
370370
/// This item's id.
371371
id: ItemId,
372372

373-
/// The item's local id, unique only amongst its siblings. Only used for
373+
/// The item's local id, unique only amongst its siblings. Only used for
374374
/// anonymous items.
375375
///
376376
/// Lazily initialized in local_id().
@@ -379,7 +379,7 @@ pub struct Item {
379379
/// case this is an implementation detail.
380380
local_id: Cell<Option<usize>>,
381381

382-
/// The next local id to use for a child..
382+
/// The next local id to use for a child or template instantiation.
383383
next_child_local_id: Cell<usize>,
384384

385385
/// A cached copy of the canonical name, as returned by `canonical_name`.
@@ -490,13 +490,23 @@ impl Item {
490490
pub fn local_id(&self, ctx: &BindgenContext) -> usize {
491491
if self.local_id.get().is_none() {
492492
let parent = ctx.resolve_item(self.parent_id);
493-
let local_id = parent.next_child_local_id.get();
494-
parent.next_child_local_id.set(local_id + 1);
495-
self.local_id.set(Some(local_id));
493+
self.local_id.set(Some(parent.next_child_local_id()));
496494
}
497495
self.local_id.get().unwrap()
498496
}
499497

498+
/// Get an identifier that differentiates a child of this item of other
499+
/// related items.
500+
///
501+
/// This is currently used for anonymous items, and template instantiation
502+
/// tests, in both cases in order to reduce noise when system headers are at
503+
/// place.
504+
pub fn next_child_local_id(&self) -> usize {
505+
let local_id = self.next_child_local_id.get();
506+
self.next_child_local_id.set(local_id + 1);
507+
local_id
508+
}
509+
500510
/// Returns whether this item is a top-level item, from the point of view of
501511
/// bindgen.
502512
///
@@ -777,13 +787,16 @@ impl Item {
777787
ctx.rust_mangle(&name).into_owned()
778788
}
779789

780-
fn exposed_id(&self, ctx: &BindgenContext) -> String {
790+
/// The exposed id that represents an unique id among the siblings of a
791+
/// given item.
792+
pub fn exposed_id(&self, ctx: &BindgenContext) -> String {
781793
// Only use local ids for enums, classes, structs and union types. All
782794
// other items use their global id.
783795
let ty_kind = self.kind().as_type().map(|t| t.kind());
784796
if let Some(ty_kind) = ty_kind {
785797
match *ty_kind {
786798
TypeKind::Comp(..) |
799+
TypeKind::TemplateInstantiation(..) |
787800
TypeKind::Enum(..) => return self.local_id(ctx).to_string(),
788801
_ => {}
789802
}

tests/expectations/tests/anon_union.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ impl Default for ErrorResult {
8080
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
8181
}
8282
#[test]
83-
fn __bindgen_test_layout_TErrorResult_instantiation_21() {
83+
fn __bindgen_test_layout_TErrorResult_instantiation_1() {
8484
assert_eq!(::std::mem::size_of::<TErrorResult>() , 24usize , concat ! (
8585
"Size of template specialization: " , stringify ! (
8686
TErrorResult ) ));

tests/expectations/tests/class_nested.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ extern "C" {
7878
pub static mut var: A_B;
7979
}
8080
#[test]
81-
fn __bindgen_test_layout_A_D_instantiation_16() {
81+
fn __bindgen_test_layout_A_D_instantiation_1() {
8282
assert_eq!(::std::mem::size_of::<A_D<::std::os::raw::c_int>>() , 4usize ,
8383
concat ! (
8484
"Size of template specialization: " , stringify ! (

tests/expectations/tests/class_with_dtor.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ impl Default for WithoutDtor {
3535
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
3636
}
3737
#[test]
38-
fn __bindgen_test_layout_HandleWithDtor_instantiation_10() {
38+
fn __bindgen_test_layout_HandleWithDtor_instantiation_1() {
3939
assert_eq!(::std::mem::size_of::<HandleWithDtor<::std::os::raw::c_int>>()
4040
, 8usize , concat ! (
4141
"Size of template specialization: " , stringify ! (

tests/expectations/tests/crtp.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,15 @@ impl Default for DerivedFromBaseWithDestructor {
5151
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
5252
}
5353
#[test]
54-
fn __bindgen_test_layout_Base_instantiation_9() {
54+
fn __bindgen_test_layout_Base_instantiation_1() {
5555
assert_eq!(::std::mem::size_of::<Base>() , 1usize , concat ! (
5656
"Size of template specialization: " , stringify ! ( Base ) ));
5757
assert_eq!(::std::mem::align_of::<Base>() , 1usize , concat ! (
5858
"Alignment of template specialization: " , stringify ! ( Base )
5959
));
6060
}
6161
#[test]
62-
fn __bindgen_test_layout_BaseWithDestructor_instantiation_12() {
62+
fn __bindgen_test_layout_BaseWithDestructor_instantiation_2() {
6363
assert_eq!(::std::mem::size_of::<BaseWithDestructor>() , 1usize , concat !
6464
(
6565
"Size of template specialization: " , stringify ! (

tests/expectations/tests/default-template-parameter.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ impl <T, U> Default for Foo<T, U> {
1616
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
1717
}
1818
#[test]
19-
fn __bindgen_test_layout_Foo_instantiation_6() {
19+
fn __bindgen_test_layout_Foo_instantiation_1() {
2020
assert_eq!(::std::mem::size_of::<Foo<bool, ::std::os::raw::c_int>>() ,
2121
8usize , concat ! (
2222
"Size of template specialization: " , stringify ! (

tests/expectations/tests/issue-569-non-type-template-params-causing-layout-test-failures.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ impl Default for JS_AutoIdVector {
3232
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
3333
}
3434
#[test]
35-
fn __bindgen_test_layout_JS_Base_instantiation_20() {
35+
fn __bindgen_test_layout_JS_Base_instantiation_2() {
3636
assert_eq!(::std::mem::size_of::<JS_Base>() , 1usize , concat ! (
3737
"Size of template specialization: " , stringify ! ( JS_Base )
3838
));

tests/expectations/tests/issue-691-template-parameter-virtual.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ impl Default for ServoElementSnapshotTable {
5151
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
5252
}
5353
#[test]
54-
fn __bindgen_test_layout_Set_instantiation_13() {
54+
fn __bindgen_test_layout_Set_instantiation_1() {
5555
assert_eq!(::std::mem::size_of::<Set>() , 4usize , concat ! (
5656
"Size of template specialization: " , stringify ! ( Set ) ));
5757
assert_eq!(::std::mem::align_of::<Set>() , 4usize , concat ! (

tests/expectations/tests/non-type-params.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ impl Default for UsesArray {
3838
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
3939
}
4040
#[test]
41-
fn __bindgen_test_layout_Array_instantiation_18() {
41+
fn __bindgen_test_layout_Array_instantiation_1() {
4242
assert_eq!(::std::mem::size_of::<[u32; 4usize]>() , 16usize , concat ! (
4343
"Size of template specialization: " , stringify ! (
4444
[u32; 4usize] ) ));

tests/expectations/tests/partial-specialization-and-inheritance.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub struct Derived {
1515
pub b: bool,
1616
}
1717
#[test]
18-
fn __bindgen_test_layout__bindgen_ty_id_20_instantiation_14() {
18+
fn __bindgen_test_layout__bindgen_ty_id_20_instantiation_1() {
1919
assert_eq!(::std::mem::size_of::<[u32; 2usize]>() , 8usize , concat ! (
2020
"Size of template specialization: " , stringify ! (
2121
[u32; 2usize] ) ));

tests/expectations/tests/template.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ pub struct TemplateWithVar {
245245
pub _address: u8,
246246
}
247247
#[test]
248-
fn __bindgen_test_layout_Foo_instantiation_95() {
248+
fn __bindgen_test_layout_Foo_instantiation_1() {
249249
assert_eq!(::std::mem::size_of::<Foo<::std::os::raw::c_int>>() , 24usize ,
250250
concat ! (
251251
"Size of template specialization: " , stringify ! (
@@ -256,7 +256,7 @@ fn __bindgen_test_layout_Foo_instantiation_95() {
256256
Foo<::std::os::raw::c_int> ) ));
257257
}
258258
#[test]
259-
fn __bindgen_test_layout_Foo_instantiation_101() {
259+
fn __bindgen_test_layout_Foo_instantiation_2() {
260260
assert_eq!(::std::mem::size_of::<Foo<::std::os::raw::c_int>>() , 24usize ,
261261
concat ! (
262262
"Size of template specialization: " , stringify ! (
@@ -267,7 +267,7 @@ fn __bindgen_test_layout_Foo_instantiation_101() {
267267
Foo<::std::os::raw::c_int> ) ));
268268
}
269269
#[test]
270-
fn __bindgen_test_layout_Rooted_instantiation_111() {
270+
fn __bindgen_test_layout_Rooted_instantiation_3() {
271271
assert_eq!(::std::mem::size_of::<Rooted<*mut ::std::os::raw::c_void>>() ,
272272
24usize , concat ! (
273273
"Size of template specialization: " , stringify ! (
@@ -278,7 +278,7 @@ fn __bindgen_test_layout_Rooted_instantiation_111() {
278278
Rooted<*mut ::std::os::raw::c_void> ) ));
279279
}
280280
#[test]
281-
fn __bindgen_test_layout_WithDtor_instantiation_123() {
281+
fn __bindgen_test_layout_WithDtor_instantiation_4() {
282282
assert_eq!(::std::mem::size_of::<WithDtor<::std::os::raw::c_int>>() ,
283283
4usize , concat ! (
284284
"Size of template specialization: " , stringify ! (

0 commit comments

Comments
 (0)