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

Re-add --rust-target option to replace --unstable-rust #892

Merged
merged 1 commit into from Aug 14, 2017

Conversation

tmfink
Copy link
Contributor

@tmfink tmfink commented Aug 5, 2017

Re-apply commit. Addresses #832

Instead of specifying whether or not to use stable, specify the Rust
release to support (one of several stable/beta releases or nightly).
The --unstable-rust option is still accepted and implies nightly.

The definitions of RustTarget and RustFeatures are created with
macros.

For each test that uses unions, there is a version that uses the latest stable
and 1.0.

@tmfink
Copy link
Contributor Author

tmfink commented Aug 5, 2017

Since the last pull request, I removed unnecessary lint suppressions and warn when using the --unstable--rust option.

@photoszzt
Copy link
Contributor

The failure is related to rust-lang/rust#32836.

@tmfink
Copy link
Contributor Author

tmfink commented Aug 5, 2017

It looks like this bug is not from my code, but exists in master. I modified tests/headers/issue-493.hpp to use "untagged_unions" rust by adding // bindgen-flags: --unstable-rust.

When running cargo test from tests/expectations with rust 1.19 or nightly (rustc 1.21.0-nightly (ed16b0a1d 2017-08-05)), I get:

error: unions with non-`Copy` fields are unstable (see issue #32836)
  --> tests/issue-493.rs:47:1
   |
47 | / pub union basic_string___ulx {
48 | |     pub __lx: basic_string___long,
49 | |     pub __lxx: basic_string___short,
50 | | }
   | |_^

error: unions with non-`Copy` fields are unstable (see issue #32836)
  --> tests/issue-493.rs:72:1
   |
72 | / pub union basic_string___rep__bindgen_ty_1 {
73 | |     pub __l: basic_string___long,
74 | |     pub __s: basic_string___short,
75 | |     pub __r: basic_string___raw,
76 | | }
   | |_^

@tmfink
Copy link
Contributor Author

tmfink commented Aug 6, 2017

I commented out parts of the headers that are causing the failures. These tests failed when using the Rust union instead of bindgen unions.

@photoszzt
Copy link
Contributor

I think the problem is for the field cannot derive Copy the behavior is not standardized. You would need to add the feature gate in the header. @fitzgen maybe fall back to generate the BingenUnion when the field cannot be Copy?

@tmfink
Copy link
Contributor Author

tmfink commented Aug 7, 2017

I filed issue #895 for the pre-existing error

@@ -27,7 +26,10 @@ struct rte_ipv6_tuple {
};
};

// TODO(tmfink) uncomment once test passes
#if 0
Copy link
Member

Choose a reason for hiding this comment

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

Thanks for leaving them uncommented in the non-union cases so we don't lose test coverage. That is essential to landing this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I left these lines disabled because of issue #908, which exist in master.

@fitzgen
Copy link
Member

fitzgen commented Aug 8, 2017

I'm hesitant to land this without fixing #895 at the same time (or at least before the next release), as it will expose that bug to many more people than were exposed to it before.

@fitzgen
Copy link
Member

fitzgen commented Aug 8, 2017

@tmfink do you think you could take a crack at #895? I expect it shouldn't be too difficult. Essentially, we need a new method on ir::Comp that checks if all of its fields can_derive_copy (and bases? I think unions can only inherit from int types in C++ but I'd need to go double check in the standard) and then check this method in codegen where we check the rust target features for unions.

Something like this:

fn can_be_rust_union(&self, ctx: &BindgenContext) {
    self.fields().all(|f| f.ty().can_derive_copy(ctx))
}

@photoszzt
Copy link
Contributor

@fitzgen What about adding a checking of the result of item.can_derive_copy(ctx) at https://github.com/rust-lang-nursery/rust-bindgen/blob/master/src/codegen/mod.rs#L1448 It should already do this check in the analysis.

@photoszzt
Copy link
Contributor

The check I mean checking all the fields can derive copy

@fitzgen
Copy link
Member

fitzgen commented Aug 8, 2017

(and bases? I think unions can only inherit from int types in C++ but I'd need to go double check in the standard)

I was actually thinking of enums here. I'm even less sure about what goes on with inheritance in unions.

@fitzgen
Copy link
Member

fitzgen commented Aug 8, 2017

@fitzgen What about adding a checking of the result of item.can_derive_copy(ctx) at https://github.com/rust-lang-nursery/rust-bindgen/blob/master/src/codegen/mod.rs#L1448 It should already do this check in the analysis.

Yes, this is where I was imagining the can_be_rust_union method would be queried.

@tmfink
Copy link
Contributor Author

tmfink commented Aug 9, 2017

@fitzgen I'll try to fix #895 with this PR as well

@fitzgen
Copy link
Member

fitzgen commented Aug 9, 2017

@tmfink great, thanks! Let me know when you have something for me to look at :)

@bors-servo
Copy link

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

@emilio
Copy link
Contributor

emilio commented Aug 13, 2017

Can you squash the commits, please? This looks fine to me.

Thanks!

src/ir/comp.rs Outdated
pub fn can_be_rust_union(&self, ctx: &BindgenContext) -> bool {
ctx.options().rust_features().untagged_union() &&
self.fields().iter().all(|f|
match f {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Maybe match *f for consistency with the rest of the codebase.

Instead of specifying whether or not to use stable, specify the Rust
release to support (one of several stable/beta releases or nightly).
The `--unstable-rust` option is still accepted and implies nightly.

The definitions of `RustTarget` and `RustFeatures` are created with
macros.

For each test that uses unions, there is a version that uses the latest
stable and 1.0.

This also fixes the bug where unions were generated with non-Copy
fields.
@tmfink tmfink force-pushed the feature-832-custom-rust-target branch from ab3ae47 to e7fa289 Compare August 13, 2017 20:17
@tmfink
Copy link
Contributor Author

tmfink commented Aug 14, 2017

@emilio I squashed the commits, but it looks like the CI job failed because of an error with the setup or possibly network:
https://travis-ci.org/rust-lang-nursery/rust-bindgen/jobs/264155826

We may want to consider not spawning so many "sub-jobs". If any sub-job fails, then the main job fails.

@emilio
Copy link
Contributor

emilio commented Aug 14, 2017

@bors-servo r+

Let's see, if we see many jobs intermittently failing, we'd need to reduce the number of them I agree (they were just bumped in #901).

@bors-servo
Copy link

📌 Commit e7fa289 has been approved by emilio

@bors-servo
Copy link

⌛ Testing commit e7fa289 with merge 8c71eed...

bors-servo pushed a commit that referenced this pull request Aug 14, 2017
Re-add --rust-target option to replace --unstable-rust

Re-apply commit. Addresses #832

Instead of specifying whether or not to use stable, specify the Rust
release to support (one of several stable/beta releases or nightly).
The `--unstable-rust` option is still accepted and implies nightly.

The definitions of `RustTarget` and `RustFeatures` are created with
macros.

For each test that uses unions, there is a version that uses the latest stable
and 1.0.
@bors-servo
Copy link

☀️ Test successful - status-travis
Approved by: emilio
Pushing 8c71eed to master...

@fitzgen
Copy link
Member

fitzgen commented Aug 14, 2017

Note that we can restart individual jobs that fail, but I agree that isn't ideal. Still, breaking up our CI into multiple jobs shaved off more than half of our wall clock time, so I'd like to do our best to preserve it.

The intermittent there didn't look like something fundamental to having multiple jobs, just that when we have multiple jobs, we have more chances to hit an extant intermittent. If my intuition is incorrect, and this failure is caused by having multiple jobs, then we should fix that (of course) and investigate if regrouping jobs helps any. "Just" a matter of time, effort, and priorities :)

@bradfier bradfier mentioned this pull request Aug 26, 2017
bors-servo pushed a commit that referenced this pull request Aug 28, 2017
Bump version to 0.30.0

Version bump, primarily to get #832 and #892 in now that 1.19 is out and untagged unions are usable in stable!

r? @emilio
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

5 participants