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

Can derive hash analysis #887

Merged
merged 12 commits into from
Aug 10, 2017
Merged

Can derive hash analysis #887

merged 12 commits into from
Aug 10, 2017

Conversation

photoszzt
Copy link
Contributor

@photoszzt photoszzt commented Aug 1, 2017

r? @fitzgen Fix: #876 I haven't enable too much test yet. Enable the option for all tests changes more than 200 of them. I want some input on which test is good to enable or write a new test.

@bors-servo
Copy link

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

@bors-servo
Copy link

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

@photoszzt photoszzt changed the title WIP Can derive hash analysis Can derive hash analysis Aug 4, 2017
Copy link
Member

@fitzgen fitzgen left a comment

Choose a reason for hiding this comment

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

Overall, this looks great, thanks!

I'm impressed with your tenacity in going through all those existing tests and enabling deriving hash for them.

However, what I was expecting, and what is missing from this PR, is a handful of small, new tests targeted specifically at exercising the edge cases of when we can or cannot derive hash. The change added to the function pointer test is a good start, but I'd like to also see:

  • When the layout for an opaque type is too large to derive hash
  • When the layout for an opaque type can derive hash
  • A struct containing a struct containing a float that cannot derive hash
  • A struct containing an array of floats that cannot derive hash
  • A test with structs containing mutable and const pointers not deriving and deriving hash respectively
  • A test with a template definition containing a float, which cannot derive hash
  • A test with a template that does not contain a float, and can derive hash when instantiated with int but cannot derive hash when instantiated with float.
  • A test where a type that we cannot derive hash for is blacklisted
  • A test where a type that we could have derived hash for is blacklisted

Thanks!

src/lib.rs Outdated
@@ -242,6 +242,12 @@ impl Builder {
output_vector.push("--with-derive-default".into());
}

if !self.options.derive_hash {
output_vector.push("--no-derive-hash".into());
Copy link
Member

Choose a reason for hiding this comment

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

There is no such flag defined, and the default is not to derive hash, so this branch should be removed and we should only have the --with-derive-hash case.

let union_field_hash_impl = quote_item!(&ctx.ext_cx(),
impl<T> ::$prefix::hash::Hash for __BindgenUnionField<T> {
fn hash<H: ::$prefix::hash::Hasher>(&self, _state: &mut H) {
}
Copy link
Member

Choose a reason for hiding this comment

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

This needs a comment that the actual physical storage will be hashed, and that's why these fields don't actually do anything with the hash. That's a very surprising impl to glance at without knowing the larger context.

@photoszzt
Copy link
Contributor Author

photoszzt commented Aug 8, 2017

  • When the layout for an opaque type is too large to derive hash
    The opaque-template-inst-member.hpp, opaque-template-inst-member-2.hpp and issue-648-derive-debug-with-padding.h should handle this case. The result is expected.

@fitzgen
Copy link
Member

fitzgen commented Aug 9, 2017

I'm sorry I didn't make my feedback clearer in the original comment, and we've had to go back and forth here.

  • In order to make it clear to anyone who comes across these tests again, the new tests should be called derive-hash-<scenario>.{h,hpp}. For example derive-hash-blacklisting.hpp. Alternatively (or in addition), there should be a comment inside the header file describing what is being tested and what we should be looking for in the output.

  • Blacklisting is not the same as not whitelisting: the --blacklist-type blah flag allows you to remove portions of the whitelisted set. The edge case I was interested in testing is when something that would have otherwise been in the whitelisted set is explicitly blacklisted, and how that affects deriving hash. Something like this:

// bindgen-flags: --with-derive-hash --whitelist-type 'Whitelisted.*' --blacklist-type Blacklisted

template<class T>
struct Blacklisted {
  T t;
};

/// This would derive(Hash) if it didn't contain a blacklisted type,
/// causing us to conservatively avoid deriving hash for it.
struct WhitelistedOne {
  Blacklisted<int> a;
};

/// This can't derive(Hash) even if it didn't contain a blacklisted type.
struct WhitelistedTwo {
  Blacklisted<float> b;
};

When the layout for an opaque type is too large to derive hash The opaque-template-inst-member.hpp, opaque-template-inst-member-2.hpp and issue-648-derive-debug-with-padding.h should handle this case. The result is expected.

Then we should add comments to those test headers so that if/when their output changes in the future, the author of that change can determine whether it is valid or not, or if it is a regression. Otherwise, they would have to do lots of tedious code archaeology to determine this.

Copy link
Member

@fitzgen fitzgen left a comment

Choose a reason for hiding this comment

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

This is great, thanks for your patience with me!

👍

@fitzgen
Copy link
Member

fitzgen commented Aug 9, 2017

@bors-servo r+

@bors-servo
Copy link

📌 Commit b4895d9 has been approved by fitzgen

@bors-servo
Copy link

⌛ Testing commit b4895d9 with merge 828d468...

bors-servo pushed a commit that referenced this pull request Aug 9, 2017
Can derive hash analysis

r? @fitzgen  Fix: #876 I haven't enable too much test yet. Enable the option for all tests changes more than 200 of them. I want some input on which test is good to enable or write a new test.
@bors-servo
Copy link

☀️ Test successful - status-travis
Approved by: fitzgen
Pushing 828d468 to master...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants