-
Notifications
You must be signed in to change notification settings - Fork 707
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
Unify derive #1540
Unify derive #1540
Conversation
This looks really great overall, thanks @jethrogb! It would've been much nicer to try to put the behavior change in its own commit, but no big deal. I can try to take a look at the failing test. You also need to add docs for a couple things: https://travis-ci.com/rust-lang/rust-bindgen/jobs/186600231#L641 |
You also need to update the libclang5+ tests:
|
So the test fails because bindgen thinks now that the inner union cannot derive |
So you need to figure out why the |
@emilio thanks for the pointers.
They are not considered copy because they're not whitelisted: (trace with my PR)
I don't think this is the source of the issue. The inner union is ItemId 2, which was already not considered copy: (trace with ab5d31a)
Note that it looks like the old analysis is just completely missing some types in its analysis: it never looks at types 4, 6 and 7. This results in the following difference later in the trace: (trace with my PR)
(trace with ab5d31a)
Again, the only thing that's missing here are non-analyzed types. Is code later on incorrectly looking at these types that weren't analyzed? |
I managed to split the |
Sure, sorry, I meant the field types. To be clear, the difference between the output of your test-case and the current output is that this function: Returns a different result. Which means that the field types were considered copy, but are not anymore. I find it weird because they're trivials, even if blacklisted. |
That being said I'm having a hard time figuring out where the decision that made those types copiable happens, looks like it's an accident right now that those types are being skipped, let me check. |
Ok, yeah, the old code was bogus. It indeed doesn't visit any of the fields, and mistakenly conveys that it can be a rust union. I'd just check-in the new expectation for that test. |
It does bring up an interesting question: how is whitelisting supposed to interact with anonymous types? This example is compiled with |
Yeah, we should probably propagate the whitelisting from the parent for inner types. |
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.
Thanks so much again for this @jethrogb!
The logic for deriving traits is mostly the same, but it was implemented 5 times. This resulted in bugs only being fixed in one place but not the other, and in general just diverging implementations. This PR unifies the logic into a single implementation, while aiming to maintain bug-for-bug compatibility with the old implementations. Fixing the bugs found as a result of this PR may be done in the future. This PR is also a step in the right direction for fixing #1454, splitting PartialEq/PartialOrd, and many other possible improvements to deriving.
I've made one material change: deriving
Default
for a function pointer is now allowed. It was previously already allowed for function types, but those rarely appear in C source. This now follows the general flow that deriving for a function pointer and a function type should be treated the same. This change is the only change that affects the expected test outputs.One thing of note is that there is no longer any special code for checking bitfields in compound types. This code was added in 95879dd, however, I verified with 843eb1c that none of the unit tests actually trigger that logic. I'm assuming this is already handled elsewhere (I think by the opaque type or union handling), since bitfields are part of the test suite.
There is one test failing, header_issue_1285_h. Bindgen suddenly decided to add a type in the middle that didn't exist before. I didn't really touch codegen, so I don't really understand what's going on here.