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

Ipv6Addr <-> u128 #39324

Merged
merged 1 commit into from
Feb 8, 2017
Merged

Ipv6Addr <-> u128 #39324

merged 1 commit into from
Feb 8, 2017

Conversation

clarfonthey
Copy link
Contributor

@clarfonthey clarfonthey commented Jan 26, 2017

Because we have u128 now, it makes sense to add a conversion between Ipv6Addr and u128 in addition to the existing one between Ipv4Addr and u32.

This shouldn't violate the existing feature gate on u128 because you can't use the type without the feature gate, but if i have to add something, I can.

@rust-highfive
Copy link
Collaborator

r? @alexcrichton

(rust_highfive has picked a reviewer for you, use r? to override)

@alexcrichton
Copy link
Member

Sounds reasonable to me!

@alexcrichton alexcrichton added the T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. label Jan 26, 2017
@alexcrichton
Copy link
Member

I think to fix the errors on Travis we'll want to tag these with #[cfg(not(stage0))] perhaps?

@rfcbot fcp merge

@rfcbot
Copy link

rfcbot commented Jan 26, 2017

Team member @alexcrichton has proposed to merge this. The next step is review by the rest of the tagged teams:

No concerns currently listed.

Once these reviewers reach consensus, this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

See this document for info about what commands tagged team members can give me.

@brson
Copy link
Contributor

brson commented Jan 27, 2017

Aren't 128-bit ints cfg'd in some target-specific way? These are defined unconditionally.

@clarfonthey
Copy link
Contributor Author

clarfonthey commented Jan 27, 2017

@brson are there any tier 1 platforms where this happens? Because if that's the case, bors will catch that

EDIT: I tried rg 'cfg.*128' and couldn't find anything that would indicate that this is compiled per-platform, but if that's wrong please let me know.

@clarfonthey clarfonthey force-pushed the ipv6_u128 branch 3 times, most recently from 1e954f3 to c978631 Compare January 27, 2017 03:55
@alexcrichton
Copy link
Member

@brson that's a good point, actually. I'm not sure what we should consider the status of u128/i128 in terms of portability. I believe that all current platforms Rust targets supports the types but that doesn't necessarily mean that all future platforms will.

@clarfonthey
Copy link
Contributor Author

clarfonthey commented Jan 27, 2017

@alexcrichton I personally think that a catch-all cfg(has_i128) or something along those lines would be a better fix than the current cfg(not(stage0))

@sfackler
Copy link
Member

I'm not sure I understand the portability issues with u/i128. How are those different than e.g. u/i64?

@clarfonthey
Copy link
Contributor Author

@brson I'd check @nagisa's comment on the tracking issue for 128-bit issue regarding that. @sfackler is right

@@ -1153,6 +1153,28 @@ impl FromInner<c::in6_addr> for Ipv6Addr {
}
}

#[cfg(not(stage0))]
#[stable(feature = "ipv6_u128", since = "1.17.0")]
Copy link
Member

Choose a reason for hiding this comment

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

These are still unstable so should be #[unstable(feature = "i128", issue="35118")].

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Impls can't be unstable so I made it stable.

Copy link
Member

Choose a reason for hiding this comment

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

You're correct but rustdoc will display the version number on impls that are marked stable and 1.17.0 is clearly wrong for these.

impl From<Ipv6Addr> for u128 {
fn from(ip: Ipv6Addr) -> u128 {
let ip = ip.segments();
((ip[0] as u128) << 104) + ((ip[1] as u128) << 96) + ((ip[2] as u128) << 80) +
Copy link
Member

Choose a reason for hiding this comment

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

104 -> 112.

Personally I would use u128::from() for these rather than as u128.

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 mostly copy-pasted the one from IPv4; is the difference worthwhile?

Copy link
Member

Choose a reason for hiding this comment

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

Not really, either way works fine.

impl From<u128> for Ipv6Addr {
fn from(ip: u128) -> Ipv6Addr {
Ipv6Addr::new(
(ip >> 104) as u16, (ip >> 96) as u16, (ip >> 80) as u16,
Copy link
Member

Choose a reason for hiding this comment

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

104 ->112.

@@ -1515,6 +1537,18 @@ mod tests {
}

#[test]
fn test_ipv6_to_int() {
let a = Ipv4Addr::new(0xffff, 0xffff, 0xffff, 0xffff, 127, 0, 0, 1);
Copy link
Member

Choose a reason for hiding this comment

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

Ipv4Addr -> Ipv6Addr for here and the two below.

@@ -1515,6 +1537,18 @@ mod tests {
}

#[test]
fn test_ipv6_to_int() {
let a = Ipv4Addr::new(0xffff, 0xffff, 0xffff, 0xffff, 127, 0, 0, 1);
assert_eq!(u128::from(a), 0xffffffffffffffff0080000000000001u128);
Copy link
Member

Choose a reason for hiding this comment

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

0xffffffffffffffff0080000000000001u128 -> 0xffffffffffffffff007f000000000001u128 for here and below.

Although it might be better to use examples like the ipv6_from_segments test where getting a shift wrong (like using 104 instead of 112) will definitely cause these tests to fail.

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 agree with you there. I'll update the IPv4 test too.

@clarfonthey
Copy link
Contributor Author

The latest travis errors seem to be an error in parsing the integer literals.

@nagisa
Copy link
Member

nagisa commented Jan 27, 2017

The latest travis errors seem to be an error in parsing the integer literals.

Most likely a staging issue of some sort; these literals work just fine on a proper nightly compiler.

@brson
Copy link
Contributor

brson commented Jan 27, 2017

Further comments here.

@alexcrichton
Copy link
Member

ping @brson @BurntSushi (checkboxes)

@alexcrichton
Copy link
Member

Also @clarcharr it looks like there's still failing tests on travis?

@nagisa
Copy link
Member

nagisa commented Jan 31, 2017

The test should get fixed automatically when we release the new beta, so I do not see any point in trying to fix it now only to undo it a few days later.

@clarfonthey
Copy link
Contributor Author

Yeah, I'm not particularly sure how to fix it myself. It seems to be accepting u128 as a type but not the integer literal, which indicates that it's probably not a staging issue.

@alexcrichton
Copy link
Member

This was discussed at the libs triage a little while ago, and the conclusion was that we'll merge this for now but consider the portability of i128/u128 in the tracking issue (and before stabilizing).

@clarcharr want to rebase and remove the stage0 annotations? With a new stage0 I think they may not be necessary any more.

@clarfonthey clarfonthey force-pushed the ipv6_u128 branch 2 times, most recently from c186a4f to 3ef7428 Compare February 5, 2017 23:28
@clarfonthey
Copy link
Contributor Author

@alexcrichton I removed the stage0 cfgs and Travis is passing now.

@alexcrichton
Copy link
Member

Thanks!

ping @brson (checkbox)

@alexcrichton
Copy link
Member

@bors: r+

@bors
Copy link
Contributor

bors commented Feb 7, 2017

📌 Commit 8b2e334 has been approved by alexcrichton

@bors
Copy link
Contributor

bors commented Feb 7, 2017

⌛ Testing commit 8b2e334 with merge 1807904...

@bors
Copy link
Contributor

bors commented Feb 7, 2017

💔 Test failed - status-travis

@alexcrichton
Copy link
Member

alexcrichton commented Feb 7, 2017 via email

@bors
Copy link
Contributor

bors commented Feb 7, 2017

⌛ Testing commit 8b2e334 with merge afe9881...

bors added a commit that referenced this pull request Feb 7, 2017
Ipv6Addr <-> u128

Because we have `u128` now, it makes sense to add a conversion between `Ipv6Addr` and `u128` in addition to the existing one between `Ipv4Addr` and `u32`.

This shouldn't violate the existing feature gate on `u128` because you can't use the type without the feature gate, but if i have to add something, I can.
@bors
Copy link
Contributor

bors commented Feb 7, 2017

💔 Test failed - status-travis

@alexcrichton
Copy link
Member

alexcrichton commented Feb 8, 2017 via email

@bors
Copy link
Contributor

bors commented Feb 8, 2017

⌛ Testing commit 8b2e334 with merge c14f87e...

bors added a commit that referenced this pull request Feb 8, 2017
Ipv6Addr <-> u128

Because we have `u128` now, it makes sense to add a conversion between `Ipv6Addr` and `u128` in addition to the existing one between `Ipv4Addr` and `u32`.

This shouldn't violate the existing feature gate on `u128` because you can't use the type without the feature gate, but if i have to add something, I can.
@bors
Copy link
Contributor

bors commented Feb 8, 2017

☀️ Test successful - status-appveyor, status-travis
Approved by: alexcrichton
Pushing c14f87e to master...

@bors bors merged commit 8b2e334 into rust-lang:master Feb 8, 2017
@clarfonthey clarfonthey deleted the ipv6_u128 branch February 12, 2017 22:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants