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

Add --no-partialeq <regex> flag #996

Merged
merged 1 commit into from
Sep 20, 2017

Conversation

alexeyzab
Copy link
Contributor

@alexeyzab alexeyzab commented Sep 16, 2017

Related to #965.

  • Add a new RegexSet member to bindgen::Builder (similar to the whitelisted_types set).

  • A Builder method to add strings to that RegexSet.

  • Plumbing in src/options.rs to convert --no-partialeq CLI flags into invocations of the builder method.

  • Make the MonotoneFramework::constrain function in src/ir/analysis/derive_partialeq.rs check if the given item is explicitly marked not to be Partialeq, and if so, insert it into the self.cannot_derive_partialeq set via return self.insert(id).

  • Tests!

  • When the no-partialeq type is transitively referenced by a whitelisted item

  • When the no-partialeq type is explicitly whitelisted

  • When the no-partialeq type is marked opaque

This is my first pass at implementing this functionality, I haven't implemented the tests yet. I wanted to make sure I am on the right track, particularly when it comes to updating MonotoneFramework::constrain.

r? @fitzgen

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.

Yep! This looks like what I would expect it to. You're on the right path :)

@@ -144,6 +145,11 @@ impl<'ctx> MonotoneFramework for CannotDerivePartialEq<'ctx> {
};
}

let name = item.canonical_name(self.ctx);
if self.ctx.options().no_partialeq_types.matches(&name) {
Copy link
Member

Choose a reason for hiding this comment

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

Let's abstract this check into a BindgenContext::no_partialeq_by_name, similar to BindgenContext::is_opaque_by_name and BindgenContext::is_blacklisted_by_name.

@bors-servo
Copy link

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

@alexeyzab
Copy link
Contributor Author

r? @fitzgen
I've added the required tests, but I am not quite sure I did it right. I use --with-derive-partialeq for all three tests and then add the additional flags per your description. When I explicitly whitelist or make opaque a particular type PartialEq still gets derived.

@fitzgen
Copy link
Member

fitzgen commented Sep 19, 2017

It makes sense that opaque types still derive(PartialEq) because the no_partialeq_by_name check comes after the opaque check in the constrain function. We should move the no_partialeq_by_name above the opaque check.

The explicitly whitelisted types always getting derive(PartialEq) even when we request they shouldn't sounds more problematic. Let me look at the code a little more...

@fitzgen
Copy link
Member

fitzgen commented Sep 19, 2017

Hm yeah the test headers look how I'd expect them to, but the generated bindings don't. I'd try adding some debug println!s in the CanDerivePartialEq implementations and lookup_item_id_can_derive_partialeq methods. Then, I'd run with extra logging:

$ RUST_LOG=bindgen::ir::analysis RUST_LOG_LEVEL=trace ./tests/test-one.sh <one of your new tests>

If you still can't figure out what's going on after that, I can try pulling these changes down myself and investigating.


BTW, I'm not sure if you're aware that the "impl period" has just begun, but the folks hacking on bindgen during the impl period are hanging out in https://gitter.im/rust-impl-period/WG-dev-tools-bindgen if you want to join us :)

@bors-servo
Copy link

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

@alexeyzab
Copy link
Contributor Author

alexeyzab commented Sep 19, 2017

We should move the no_partialeq_by_name above the opaque check.

I've tried it just now, but the result is still the same. Makes me wonder if no_partialeq_by_name is doing the right thing at all. I'll try to figure it out.

Thanks for the invite! :)

- [x] Add a new RegexSet member to bindgen::Builder (similar to the whitelisted_types set).

- [x] A Builder method to add strings to that RegexSet.

- [x] Plumbing in src/options.rs to convert --no-partialeq <regex> CLI flags into invocations of the builder method.

- [x] Make the MonotoneFramework::constrain function in src/ir/analysis/derive_partialeq.rs check if the given item is explicitly marked not to be Partialeq, and if so, insert it into the self.cannot_derive_partialeq set via return self.insert(id).

- [x] Tests!

- [x] When the no-partialeq type is transitively referenced by a whitelisted item

- [x] When the no-partialeq type is explicitly whitelisted

- [x] When the no-partialeq type is marked opaque

Fixes rust-lang#965
@fitzgen
Copy link
Member

fitzgen commented Sep 19, 2017

@bors-servo r+

Thanks @alexeyzab !

@bors-servo
Copy link

📌 Commit ec8456b has been approved by fitzgen

@bors-servo
Copy link

⌛ Testing commit ec8456b with merge 4842973...

bors-servo pushed a commit that referenced this pull request Sep 19, 2017
Add --no-partialeq <regex> flag

Related to #965.

- [x] Add a new RegexSet member to bindgen::Builder (similar to the whitelisted_types set).

- [x] A Builder method to add strings to that RegexSet.

- [x] Plumbing in src/options.rs to convert --no-partialeq <regex> CLI flags into invocations of the builder method.

- [x] Make the MonotoneFramework::constrain function in src/ir/analysis/derive_partialeq.rs check if the given item is explicitly marked not to be Partialeq, and if so, insert it into the self.cannot_derive_partialeq set via return self.insert(id).

- [x] Tests!

- [x] When the no-partialeq type is transitively referenced by a whitelisted item

- [x] When the no-partialeq type is explicitly whitelisted

- [x] When the no-partialeq type is marked opaque

This is my first pass at implementing this functionality, I haven't implemented the tests yet. I wanted to make sure I am on the right track, particularly when it comes to updating `MonotoneFramework::constrain`.

r? @fitzgen
@bors-servo
Copy link

☀️ Test successful - status-travis
Approved by: fitzgen
Pushing 4842973 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.

None yet

4 participants