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

Move IpAddr, SocketAddr and V4+V6 related types to core #104265

Merged
merged 3 commits into from
Feb 27, 2023

Conversation

faern
Copy link
Contributor

@faern faern commented Nov 10, 2022

Implements RFC rust-lang/rfcs#2832. The RFC has completed FCP with disposition merge, but is not yet merged.

Moves IP types to core as specified in the RFC.

The full list of moved types is: IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6, Ipv6MulticastScope and AddrParseError.

Doing this move was one of the main driving arguments behind #78802.

@rustbot
Copy link
Collaborator

rustbot commented Nov 10, 2022

r? @thomcc

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

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Nov 10, 2022
@rustbot
Copy link
Collaborator

rustbot commented Nov 10, 2022

Hey! It looks like you've submitted a new PR for the library teams!

If this PR contains changes to any rust-lang/rust public library APIs then please comment with @rustbot label +T-libs-api -T-libs to tag it appropriately. If this PR contains changes to any unstable APIs please edit the PR description to add a link to the relevant API Change Proposal or create one if you haven't already. If you're unsure where your change falls no worries, just leave it as is and the reviewer will take a look and make a decision to forward on if necessary.

Examples of T-libs-api changes:

  • Stabilizing library features
  • Introducing insta-stable changes such as new implementations of existing stable traits on existing stable types
  • Introducing new or changing existing unstable library APIs (excluding permanently unstable features / features without a tracking issue)
  • Changing public documentation in ways that create new stability guarantees
  • Changing observable runtime behavior of library APIs

@faern
Copy link
Contributor Author

faern commented Nov 10, 2022

@rustbot label +T-libs-api -T-libs

@rustbot rustbot added T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. and removed T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Nov 10, 2022
@faern
Copy link
Contributor Author

faern commented Nov 11, 2022

Should moves like this mark the new types in core::net an unstable? I found no way of doing that. Maybe I made a mistake.

Also, what to do with all the existing stability attributes, such as:

#[stable(feature = "ip_shared", since = "1.12.0")]
pub const fn is_loopback(&self) -> bool {

Do we leave them as is in moves like this? I have not yet found another PR doing a similar move.

@slanterns
Copy link
Contributor

slanterns commented Nov 11, 2022

Should moves like this mark the new types in core::net an unstable? I found no way of doing that. Maybe I made a mistake.

I recall a similar attempt which moves Error into libcore. Maybe you can refer to #95956 and #99917.

@thomcc thomcc added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. S-blocked Status: Marked as blocked ❌ on something else such as an RFC or other implementation work. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 12, 2022
@thomcc
Copy link
Member

thomcc commented Nov 12, 2022

I think this is blocked on the RFC at the moment.

@bors
Copy link
Contributor

bors commented Nov 15, 2022

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

@pinkforest
Copy link
Contributor

pinkforest commented Jan 4, 2023

Has anyone done testing about code sizes in microcontroller / wasm32-u-u context / between code size sensitive targets ? I think tests should be essential to "bench" / measure these kind of things if core is to be added with this stuff that realistically should be standard library stuff - this would alleviate concerns that binary sizes are kept in check.

Use-cases are - measured in x86_64 host:
1/ std wasm32-unknown-unknown ~30 kB std
2/ std wasm32-wasi ~70 kB std
3/ no_std + detached standard alloc (dlmalloc crate) ~4 kB
4/ no_std + lol_alloc 0.3 - 2kB allocator depending on type (wee_alloc leaks)
5/ no_std + heapless (crate)
6/ no_std + no heap at all (e.g. no String/Vec)

e.g. w/ cdylib context

[profile.release]
codegen-units = 1
strip = "symbols"
debug = false
lto = true
opt-level = "z"
panic = 'abort'

Another no_std target that should be tested could be thumbv7em-none-eabi for code sizes.

@newAM
Copy link

newAM commented Jan 4, 2023

I have internet connected Cortex-M micros and can help with benchmarking, but I am confused about what is being measured. Embedded no_std binaries are entirely statically linked, and unused symbols are stripped. Is there something to measure or an assumption to check?

@pinkforest
Copy link
Contributor

pinkforest commented Jan 4, 2023

what is being measured.

Binary sizes - There was some other related effort out there somewhere else and might be worthwhile to check if anything was done re: in general and if this could be incorporated somehow there.

Embedded no_std binaries are entirely statically linked, and unused symbols are stripped.

Yes that is true and correct. However it could be helpful to come up with a test that stays around and ensures this is correct in case of core::net e.g. for wasm32-u-u that the symbol was stripped for completeness.

Question may / probably is how to test it if this is done and what are the downsides of such test if any ?

@newAM
Copy link

newAM commented Jan 5, 2023

Binary sizes - There was some other related effort out there somewhere else and might be worthwhile to check if anything was done re: in general and if this could be incorporated somehow there.

I checked binary sizes of the cortex-m-quickstart built for the thumbv7em-none-eabi target with and without this patch (with slight modifications to make the patch work with the 1.65.0 release), section sizes and symbol sizes are identical for both binaries. Rough work is here: core-net-benchmark.

Yes that is true and correct. However it could be helpful to come up with a test that stays around and ensures this is correct in case of core::net e.g. for wasm32-u-u that the symbol was stripped for completeness.

Is this not covered by existing dead code tests, such as src/test/codegen/link-dead-code.rs?

@faern
Copy link
Contributor Author

faern commented Jan 7, 2023

Rebased and updated. Since the RFC seems to be close to being merged.

Changed the std re-exports into type aliases so they can remain stable while the core versions are unstable (under the new feature ip_in_core). However, for Ipv6MulticastScope I kept it a pub use. Otherwise I ran into this error. And I don't think it should matter, because it's still an unstable type and I suppose it will be stabilized in core and std at the same time anyway. So no need to be able to have them separate?

Not going to touch anything regarding testing/benchmarking the size of core in this PR unless someone from the libs team tell me to. That concern seems unrelated to this PR and seems to be a concern regarding linker optimizations in general, not anything specific to IP types at all.

The CI failure is something I can reproduce locally but have not yet figured out how to solve 🤔

@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented Jan 22, 2023

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

@faern
Copy link
Contributor Author

faern commented Jan 25, 2023

I fixed the merge conflict and the CI error that existed. The stderr of a compiler error changed slightly, so I just needed to adapt the test's expected output.

@faern
Copy link
Contributor Author

faern commented Jan 25, 2023

To fix this error it looks like we need to update the book. But that's a separate git module. And it's also temporary, while the types are unstable in core... Will the book changes be merged before this PR is approved? I submitted the required change in rust-lang/book#3519

@bors
Copy link
Contributor

bors commented Feb 26, 2023

@faern: 🔑 Insufficient privileges: Not in reviewers

@albertlarsan68
Copy link
Member

albertlarsan68 commented Feb 26, 2023

@bors r=joshtriplett
There you go!

@bors
Copy link
Contributor

bors commented Feb 26, 2023

📌 Commit 1291216 has been approved by joshtriplett

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. S-blocked Status: Marked as blocked ❌ on something else such as an RFC or other implementation work. labels Feb 26, 2023
compiler-errors added a commit to compiler-errors/rust that referenced this pull request Feb 26, 2023
…riplett

Move IpAddr, SocketAddr and V4+V6 related types to `core`

Implements RFC rust-lang/rfcs#2832. The RFC has completed FCP with disposition merge, but is not yet merged.

Moves IP types to `core` as specified in the RFC.

The full list of moved types is: `IpAddr`, `Ipv4Addr`, `Ipv6Addr`, `SocketAddr`, `SocketAddrV4`, `SocketAddrV6`, `Ipv6MulticastScope` and `AddrParseError`.

Doing this move was one of the main driving arguments behind rust-lang#78802.
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Feb 27, 2023
…riplett

Move IpAddr, SocketAddr and V4+V6 related types to `core`

Implements RFC rust-lang/rfcs#2832. The RFC has completed FCP with disposition merge, but is not yet merged.

Moves IP types to `core` as specified in the RFC.

The full list of moved types is: `IpAddr`, `Ipv4Addr`, `Ipv6Addr`, `SocketAddr`, `SocketAddrV4`, `SocketAddrV6`, `Ipv6MulticastScope` and `AddrParseError`.

Doing this move was one of the main driving arguments behind rust-lang#78802.
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 27, 2023
…iaskrgr

Rollup of 8 pull requests

Successful merges:

 - rust-lang#104265 (Move IpAddr, SocketAddr and V4+V6 related types to `core`)
 - rust-lang#107110 ([stdio][windows] Use MBTWC and WCTMB)
 - rust-lang#108308 (Allow building serde and serde_derive in parallel)
 - rust-lang#108363 (Move the unused extern crate check back to the resolver.)
 - rust-lang#108519 (Bages for easy access links to Rust community)
 - rust-lang#108522 (Commit some new solver tests)
 - rust-lang#108523 (Avoid `&str` to `String` conversions)
 - rust-lang#108533 (diagnostics: avoid querying `associated_item` in the resolver)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit cf04603 into rust-lang:master Feb 27, 2023
@rustbot rustbot added this to the 1.69.0 milestone Feb 27, 2023
@@ -77,6 +78,9 @@
#![feature(iter_repeat_n)]
#![feature(iterator_try_collect)]
#![feature(iterator_try_reduce)]
#![feature(const_ip)]
#![feature(const_ipv4)]
#![feature(const_ipv6)]
Copy link
Member

Choose a reason for hiding this comment

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

I am very surprised that this does not need the ip_in_core feature? miri-test-libstd is failing due to that feature missing somewhere.

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 guess because core itself does not use anything from core::net (which is the unstable module). Submodules of core::net uses parts of itself, but I guess if you are inside an unstable module you can freely use the stuff in it?

Copy link
Member

Choose a reason for hiding this comment

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

This is a different crate though, it is the coretest crate, not the core crate.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, sorry. I misread the path! Yeah, that's very strange. But I see you have a PR up for fixing it 👍

Copy link
Member

Choose a reason for hiding this comment

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

Yeah it fixes miri-test-libstd. But still I am worried that the fact that it builds here without the feature flag might be indicative of a more fundamental problem -- as mentioned elsewhere, historically reexport stability did not work properly.

pub struct Ipv4Addr {
octets: [u8; 4],
}
pub use core::net::{Ipv4Addr, Ipv6Addr};
Copy link
Member

@RalfJung RalfJung Feb 28, 2023

Choose a reason for hiding this comment

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

FWIW, I was under the impression that pub use with different stability doesn't actually work -- that's why intrinsics::transmute has to be stable, so that it can be pub used in mem. IOW, all reexports of the same type/function must have the same stability. Has that been fixed?

See #18517, which is closed as a duplicate of an issue that is still open.

Copy link
Member

Choose a reason for hiding this comment

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

Quick testing indicates that the feature gate works as expected (except for the strange behavior in coretest).

Cc @petrochenkov your statement here sounds like reexport stability doesn't work properly, has that changed since last year?

Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Feb 28, 2023
add missing feature in core/tests

rust-lang#104265 introduced the `ip_in_core` feature. For some reason core tests seem to still build without that feature -- no idea how that is possible. Might be related to rust-lang#15702? I was under the impression that `pub use` with different stability doesn't actually work. That's why `intrinsics::transmute` is stable, for example.

Either way, core tests fail to build in miri-test-libstd, and adding the feature fixes that.

r? `@thomcc`
@klensy
Copy link
Contributor

klensy commented Feb 28, 2023

This reduced std crate size by 200kb (by reducing linked .rustc section) under x86_64-pc-windows-msvc, but i don't understand why.

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Feb 28, 2023
add missing feature in core/tests

rust-lang#104265 introduced the `ip_in_core` feature. For some reason core tests seem to still build without that feature -- no idea how that is possible. Might be related to rust-lang#15702? I was under the impression that `pub use` with different stability doesn't actually work. That's why `intrinsics::transmute` is stable, for example.

Either way, core tests fail to build in miri-test-libstd, and adding the feature fixes that.

r? ``@thomcc``
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Mar 1, 2023
add missing feature in core/tests

rust-lang#104265 introduced the `ip_in_core` feature. For some reason core tests seem to still build without that feature -- no idea how that is possible. Might be related to rust-lang#15702? I was under the impression that `pub use` with different stability doesn't actually work. That's why `intrinsics::transmute` is stable, for example.

Either way, core tests fail to build in miri-test-libstd, and adding the feature fixes that.

r? ```@thomcc```
thomcc pushed a commit to tcdi/postgrestd that referenced this pull request May 31, 2023
add missing feature in core/tests

rust-lang/rust#104265 introduced the `ip_in_core` feature. For some reason core tests seem to still build without that feature -- no idea how that is possible. Might be related to rust-lang/rust#15702? I was under the impression that `pub use` with different stability doesn't actually work. That's why `intrinsics::transmute` is stable, for example.

Either way, core tests fail to build in miri-test-libstd, and adding the feature fixes that.

r? ```@thomcc```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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.