-
Notifications
You must be signed in to change notification settings - Fork 717
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
Return Vec on TemplateParameters #1245
Conversation
src/ir/context.rs
Outdated
// num_template_params, | ||
// ) | ||
// }, | ||
// ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will remove this!
Ha! I noticed two things..
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, thanks a lot for doing this, it's great! Just some nits and questions :)
src/codegen/mod.rs
Outdated
@@ -2972,7 +2966,7 @@ impl TryToRustTy for Type { | |||
TypeKind::Comp(ref info) => { | |||
let template_params = item.used_template_params(ctx); | |||
if info.has_non_type_template_params() || | |||
(item.is_opaque(ctx, &()) && template_params.is_some()) | |||
(item.is_opaque(ctx, &()) && template_params.len() > 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: !is_empty()
.
src/ir/item.rs
Outdated
@@ -1112,18 +1112,18 @@ where | |||
fn self_template_params( | |||
&self, | |||
ctx: &BindgenContext, | |||
) -> Option<Vec<TypeId>> { | |||
) -> Vec<TypeId> { | |||
ctx.resolve_item_fallible(*self).and_then(|item| { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: you can use .map
here, and remove the Some(
below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And actually can use map_or(vec![], |item| item.self_template_params(ctx))
, which is slightly nicer :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's done :) the usage of map_or
is nicer !
.collect(), | ||
) | ||
} | ||
.filter_map(|id| { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Just .flat_map(|id| id.self_template_params(ctx)).collect()
would do here I suspect.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried that but I got the following error:
--> src/ir/template.rs:144:58
|
144 | .flat_map(|id| id.self_template_params(ctx)).collect();
| ^^^^^^^ a collection of type `std::vec::Vec<std::vec::Vec<_>>` cannot be built from an iterator over elements of type `ir::context::TypeId`
|
= help: the trait `std::iter::FromIterator<ir::context::TypeId>` is not implemented for `std::vec::Vec<std::vec::Vec<_>>`
So, I'm not sure how to proceed here.
src/ir/context.rs
Outdated
) | ||
}, | ||
) | ||
Some(( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this I think changes behavior in a non-obvious way: before we'd only return Some
here only if there was any template parameter, now we don't... Have you checked the callers are ok with that?
If they are, you can remove the Some(
and just use map
instead of and_then
in the line above.
If they're not, then you can save template_decl_id.num_self_template_params(self)
in a local, and return None
if num_template_params == 0
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe I fixed this, I added the num_template_params == 0
check
src/ir/context.rs
Outdated
) | ||
}, | ||
) | ||
Some(( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same issue as above
src/codegen/mod.rs
Outdated
@@ -1657,7 +1652,7 @@ impl CodeGenerator for CompInfo { | |||
derives.push("Copy"); | |||
|
|||
if ctx.options().rust_features().builtin_clone_impls() || | |||
used_template_params.is_some() | |||
used_template_params.len() > 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: !is_empty
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also the travis failures are on rust stable, and look a lot like they're related to this line (they're generating a bunch of unnecessary clone
impls).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That being said, I think this is actually fixing a bug... So let's just update the test expectations :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:O That's nice!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to confirm, does that means that I should include all the modifications under tests/expectations/tests
folder ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes! :)
.collect() | ||
}, | ||
) | ||
ctx.resolve_item(id).all_template_params(ctx) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, in particular, used_template_params
used to mean a different thing with the Option<..>
...
It used to return Some
if there was any (used or unused) template parameter. then the Vec
inside contained only the ones that were actually used...
.collect() | ||
}, | ||
) | ||
ctx.resolve_item(id).all_template_params(ctx) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, so, used_template_params
used to mean a different thing with the Option<..>
...
It used to return Some
if there was any (used or unused) template parameter. then the Vec
inside contained only the ones that were actually used...
But per the above the only use that changed behavior in our test-suite I think was actually buggy, so yeah, this is fine :)
src/codegen/mod.rs
Outdated
} else { | ||
Some(ps) | ||
}); | ||
let mut outer_params = match item.used_template_params(ctx).len() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably be just:
let used_params = item.used_template_params(ctx);
let outer_params = if used_params.is_empty() { None } else { Some(used_params) };
Or something of the sort.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes!, that's cleaner, thanks! 😄
2d9f48c
to
6fbb0be
Compare
#[inline] | ||
pub unsafe fn new(arg1: *mut nsBaseHashtable_EntryType, arg2: *mut nsBaseHashtable) -> Self { | ||
let mut __bindgen_tmp = ::std::mem::uninitialized(); | ||
nsBaseHashtable_LookupResult_LookupResult(&mut __bindgen_tmp, arg1, arg2); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test building is failing due to this line, it looks weird the repeated LookupResult_LookupResult
string here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I see what's going on... We're now generating constructors and such for structs that don't use any template parameter. That's bogus actually, since LookupResult
is parameterized by a bunch of stuff, so that condition needs to use all_template_parameters
or something of the sort.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you have any advice on where to start looking to solve this problem? I'm kind of completely lost right now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, sorry :)
So this is probably related to this check:
Your patch somehow made that condition change. Those are nested template structs, so it's kind of tricky, but I'd double-check with and without your changes running some of the reduced tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added manually the extern definitions and now the code compiles. Is this something that should be generated automatically?
extern "C" {
pub fn nsBaseHashtable_EntryPtr_EntryPtr_destructor(this: *mut nsBaseHashtable_EntryPtr);
pub fn nsBaseHashtable_EntryPtr_EntryPtr(this: *mut nsBaseHashtable_EntryPtr,
arg1: *mut nsBaseHashtable,
arg2: *mut nsBaseHashtable_EntryType,
arg3: bool);
pub fn nsBaseHashtable_LookupResult_LookupResult(this: *mut nsBaseHashtable_LookupResult,
arg1: *mut nsBaseHashtable_EntryType,
arg2: *mut nsBaseHashtable);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really, that will compile, but will not link. We can't generate them because they have no symbols, being them in a templated struct.
☔ The latest upstream changes (presumably #1256) made this pull request unmergeable. Please resolve the merge conflicts. |
The Option<T> returned in this trait was removed to return Vec. Fixes rust-lang#960.
6fbb0be
to
b03316a
Compare
☔ The latest upstream changes (presumably #1271) made this pull request unmergeable. Please resolve the merge conflicts. |
The Option returned in this trait was removed to return Vec.
Fixes #960.