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

optionally use associated constants in bitfields #1293

Merged
merged 4 commits into from
Apr 7, 2018

Conversation

strake
Copy link
Contributor

@strake strake commented Apr 2, 2018

See #1166

r? @emilio

@highfive
Copy link

highfive commented Apr 2, 2018

Thanks for the pull request, and welcome! The Servo team is excited to review your changes, and you should hear from @emilio (or someone else) soon.

@emilio
Copy link
Contributor

emilio commented Apr 2, 2018

Tests seem to already fail on master, not sure what to do.

Which tests do fail? And which OS are you on?

src/lib.rs Outdated
@@ -1235,6 +1235,12 @@ impl Builder {
self.options.no_hash_types.insert(arg.into());
self
}

/// Use associated constants for bitfields.
pub fn use_associated_consts(mut self, doIt: bool) -> Builder {
Copy link
Contributor

Choose a reason for hiding this comment

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

This probably deserves a bit more specific name. And please use snake_case for the argument name.

result.push(quote! {
impl #enum_ident {
#doc
pub const #variant_ident : #rust_ty = #rust_ty ( #expr );
Copy link
Contributor

Choose a reason for hiding this comment

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

This is probably even not worth the option, and just worth guarding it after a feature guard, wdyt? see src/features.rs.

@emilio
Copy link
Contributor

emilio commented Apr 2, 2018

Also, thanks a lot for the patch! :)

@emilio
Copy link
Contributor

emilio commented Apr 2, 2018

How do they fail? Can you post theerror? Do you happen to be in a linux32 OS or something of the sort?

@strake
Copy link
Contributor Author

strake commented Apr 4, 2018

All pass now, PTAL

@@ -68,8 +84,12 @@ impl ::std::ops::BitAndAssign for Buz {
#[repr(C)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub struct Buz(pub i8);
pub const NS_FOO: _bindgen_ty_1 = _bindgen_ty_1(1);
pub const NS_BAR: _bindgen_ty_1 = _bindgen_ty_1(2);
impl _bindgen_ty_1 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, I didn't think about unnamed enums, but this is a problem... Because the constants are no longer in the top-level namespace, and their name is not deterministic.

pub const #ident : #rust_ty = #rust_ty ( #expr );
});
EnumBuilder::Bitfield { canonical_name, .. } => {
if ctx.options().rust_features().associated_const {
Copy link
Contributor

Choose a reason for hiding this comment

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

So we need to guard this condition to prevent entering here if the enum is unnamed.

Copy link
Contributor Author

@strake strake Apr 6, 2018

Choose a reason for hiding this comment

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

How can we check? I see "_bindgen_ty_{}" in Item::base_name but am not sure how this information is propagated further. (I'm not sure whether we care about cases where the user actually defines a type called _bindgen_ty_1 or such.)

Copy link
Contributor

Choose a reason for hiding this comment

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

Unnamed enums can be detected using ir::Type::name, in which case the name would be None`.

@strake
Copy link
Contributor Author

strake commented Apr 7, 2018

PTAL

@emilio
Copy link
Contributor

emilio commented Apr 7, 2018

Looks great, thank you!

@bors-servo r+

@bors-servo
Copy link

📌 Commit 7024cf6 has been approved by emilio

@bors-servo
Copy link

⌛ Testing commit 7024cf6 with merge 0a601d6...

bors-servo pushed a commit that referenced this pull request Apr 7, 2018
optionally use associated constants in bitfields

See #1166

r? @emilio
@bors-servo
Copy link

☀️ Test successful - status-travis
Approved by: emilio
Pushing 0a601d6 to master...

@bors-servo bors-servo merged commit 7024cf6 into rust-lang:master Apr 7, 2018
@strake
Copy link
Contributor Author

strake commented Apr 8, 2018

Thanks! I think we can close #1166 now.

@strake strake deleted the use_associated_consts branch April 20, 2018 18:07
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.

4 participants