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

Return Vec on TemplateParameters #1245

Closed
wants to merge 1 commit into from

Conversation

ericho
Copy link

@ericho ericho commented Feb 4, 2018

The Option returned in this trait was removed to return Vec.

Fixes #960.

// num_template_params,
// )
// },
// )
Copy link
Author

Choose a reason for hiding this comment

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

I will remove this!

@ericho
Copy link
Author

ericho commented Feb 4, 2018

Ha! I noticed two things..

  1. There are several failures in Travis. It seems that running the tests twice hides some errors and everything seems ok. The errors I see are not the same as Travis shows. Need to investigate more.
  2. I didn't see the PR Change return type of TemplateParameters' methods from Option to just… #1064 that fixes the same issue as this one..

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.

Hi, thanks a lot for doing this, it's great! Just some nits and questions :)

@@ -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)
Copy link
Contributor

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| {
Copy link
Contributor

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.

Copy link
Contributor

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 :)

Copy link
Author

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| {
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 .flat_map(|id| id.self_template_params(ctx)).collect() would do here I suspect.

Copy link
Author

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.

)
},
)
Some((
Copy link
Contributor

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.

Copy link
Author

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

)
},
)
Some((
Copy link
Contributor

Choose a reason for hiding this comment

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

Same issue as above

@@ -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
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: !is_empty.

Copy link
Contributor

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).

Copy link
Contributor

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 :)

Copy link
Author

Choose a reason for hiding this comment

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

:O That's nice!

Copy link
Author

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 ?

Copy link
Contributor

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)
Copy link
Contributor

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)
Copy link
Contributor

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 :)

} else {
Some(ps)
});
let mut outer_params = match item.used_template_params(ctx).len() {
Copy link
Contributor

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.

Copy link
Author

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! 😄

@ericho ericho force-pushed the ericho-fixoption branch 2 times, most recently from 2d9f48c to 6fbb0be Compare February 4, 2018 18:49
#[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);
Copy link
Author

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.

Copy link
Contributor

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.

Copy link
Author

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.

Copy link
Contributor

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:

https://github.com/rust-lang-nursery/rust-bindgen/pull/1245/files#diff-567e947a8cc5ad306d3eff99dfb66cc9R1735

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.

Copy link
Author

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);
}

Copy link
Contributor

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.

@bors-servo
Copy link

☔ 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.
@bors-servo
Copy link

☔ The latest upstream changes (presumably #1271) made this pull request unmergeable. Please resolve the merge conflicts.

bors-servo pushed a commit that referenced this pull request Apr 8, 2018
TemplateParameters do not return Option

Fixes #960.
Closes #1245.

I found it useful to do this incrementally, changing each method in a separate commit and ensuring the tests continue to pass unchanged.

r? @emilio
/cc @ericho
bors-servo pushed a commit that referenced this pull request Apr 10, 2018
TemplateParameters do not return Option

Fixes #960.
Closes #1245.

I found it useful to do this incrementally, changing each method in a separate commit and ensuring the tests continue to pass unchanged.

r? @emilio
/cc @ericho
@emilio emilio closed this in #1305 Apr 10, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants