Skip to content

Commit bce1330

Browse files
committed
Resolve through type refs and aliases when marking type params used
In stylo bindings generation, we were hitting bugs where the analysis saw a template type parameter behind a type ref to a type alias, and this was then used as an argument to a template instantiation. Because of the indirection, the analysis got confused and ignored the template argument because it was "not" a named template type, and therefore we didn't care about its usage. This commit makes sure that we keep resolving through type references and aliases to find the inner named template type parameter to add to the current item's usage set. Fixes #638.
1 parent 7908262 commit bce1330

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

src/ir/named.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,10 @@ impl<'ctx, 'gen> MonotoneFramework for UsedTemplateParameters<'ctx, 'gen> {
481481
if used_by_def.contains(param) {
482482
debug!(" param is used by template definition");
483483

484+
let arg = arg.into_resolver()
485+
.through_type_refs()
486+
.through_type_aliases()
487+
.resolve(self.ctx);
484488
if let Some(named) = arg.as_named(self.ctx, &()) {
485489
debug!(" arg is a type parameter, marking used");
486490
used_by_this_id.insert(named);
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/* automatically generated by rust-bindgen */
2+
3+
4+
#![allow(non_snake_case)]
5+
6+
7+
#[repr(C)]
8+
#[derive(Debug, Copy, Clone)]
9+
pub struct RefPtr<T> {
10+
pub use_of_t: T,
11+
}
12+
impl <T> Default for RefPtr<T> {
13+
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
14+
}
15+
#[repr(C)]
16+
#[derive(Debug, Copy, Clone)]
17+
pub struct UsesRefPtrWithAliasedTypeParam<U> {
18+
pub member: RefPtr<UsesRefPtrWithAliasedTypeParam_V<U>>,
19+
}
20+
pub type UsesRefPtrWithAliasedTypeParam_V<U> = U;
21+
impl <U> Default for UsesRefPtrWithAliasedTypeParam<U> {
22+
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
23+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// bindgen-flags: -- -std=c++14
2+
3+
template <class T>
4+
class RefPtr {
5+
T use_of_t;
6+
};
7+
8+
template <typename U>
9+
class UsesRefPtrWithAliasedTypeParam {
10+
using V = U;
11+
RefPtr<V> member;
12+
};

0 commit comments

Comments
 (0)