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

[DO NOT MERGE] Expand core's prelude with more types #125107

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

ChrisDenton
Copy link
Contributor

@ChrisDenton ChrisDenton commented May 14, 2024

This adds some more types to the core prelude, to explore the proposed prelude policy.

Without any further context, types in the standard library are strongly associated with the standard library so they are good candidates for the prelude, assuming their name doesn't require a module to make sense of. As a bonus this avoids some of the repetition required for cell::Cell, pin::Pin, atomic::Atomic*, etc.

Currently this includes some nightly types. These should be removed before this is merged.

In summary, this PR currently exports the following from the prelude:

pub use core::cell::{Cell, LazyCell, OnceCell, RefCell, SyncUnsafeCell, UnsafeCell};
pub use core::ffi::{
    c_char, c_double, c_float, c_int, c_long, c_longlong, c_ptrdiff_t, c_schar, c_short, c_size_t,
    c_ssize_t, c_str, c_uchar, c_uint, c_ulong, c_ulonglong, c_ushort, c_void, CStr,
};
pub use core::io::{BorrowedBuf, BorrowedCursor};
pub use core::marker::{PhantomData, PhantomPinned};
pub use core::mem::{ManuallyDrop, MaybeUninit};
pub use core::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6};
pub use core::num::{
    NonZero, NonZeroI128, NonZeroI16, NonZeroI32, NonZeroI64, NonZeroI8, NonZeroIsize, NonZeroU128,
    NonZeroU16, NonZeroU32, NonZeroU64, NonZeroU8, NonZeroUsize,
};
pub use core::panic::PanicInfo;
pub use core::pin::Pin;
pub use core::ptr::NonNull;
pub use core::sync::atomic::{
    AtomicBool, AtomicI16, AtomicI32, AtomicI64, AtomicI8, AtomicIsize, AtomicPtr, AtomicU16,
    AtomicU32, AtomicU64, AtomicU8, AtomicUsize,
};
pub use core::time::Duration;
pub use core::ops::ControlFlow;

UPDATE:

There have so far been concerns raised about the following types:

  • Cell is maybe too generic a word to be in a prelude type
  • It is common for time libs to make their own Duration type so having it in the prelude may be confusing. This perhaps also suggests the design of std's Duration is not ideal but in any case that can't be changed at this point.

@rustbot
Copy link
Collaborator

rustbot commented May 14, 2024

r? @Nilstrieb

rustbot has assigned @Nilstrieb.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels May 14, 2024
@rust-log-analyzer

This comment has been minimized.

Copy link
Contributor

@workingjubilee workingjubilee left a comment

Choose a reason for hiding this comment

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

We should probably bias most heavily to the "this is basically a kind of primitive to the language runtime" cases. i.e. there may be other reasonable impls of Cell out there, but there sure isn't another one of UnsafeCell.


#[stable(feature = "core_prelude_extra", since = "CURRENT_RUSTC_VERSION")]
#[doc(no_inline)]
pub use crate::marker::{PhantomData, PhantomPinned};
Copy link
Contributor

Choose a reason for hiding this comment

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

...yeah, really want these two.

@@ -41,6 +41,67 @@ pub use crate::option::Option::{self, None, Some};
#[doc(no_inline)]
pub use crate::result::Result::{self, Err, Ok};

#[stable(feature = "core_prelude_extra", since = "CURRENT_RUSTC_VERSION")]
#[doc(no_inline)]
pub use crate::cell::{Cell, LazyCell, OnceCell, RefCell, SyncUnsafeCell, UnsafeCell};
Copy link
Contributor

Choose a reason for hiding this comment

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

hmm, the OnceCell case seems like it may risk confusion due to once_cell.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hm, I think that the parts of once_cell that overlap with std are considered deprecated in favour of std (MSRV willing).

Copy link
Contributor

Choose a reason for hiding this comment

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

I mean the author basically contributed the code, so yeah.


#[stable(feature = "core_prelude_extra", since = "CURRENT_RUSTC_VERSION")]
#[doc(no_inline)]
pub use crate::time::Duration;
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems like it would risk confusion because time::Duration exists.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That feels like an awkward one because, without further context, time::Duration is ambiguous too. I.e. is this the time crate or is there a use std::time somewhere?

Copy link
Contributor

Choose a reason for hiding this comment

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

right.

and don't forget chrono::Duration.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, I'm willing to see if crater has anything to say about this 😛

@workingjubilee
Copy link
Contributor

Obviously the crater run(?) will be educational in any case.

@rust-log-analyzer

This comment has been minimized.

@ChrisDenton
Copy link
Contributor Author

This will break src\tools\clippy\tests\ui\crashes\ice-6252.rs but I'm not sure if fixing would defeat the purpose of the test.

@workingjubilee
Copy link
Contributor

This will break src\tools\clippy\tests\ui\crashes\ice-6252.rs but I'm not sure if fixing would defeat the purpose of the test.

if he dies, he dies

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@ChrisDenton
Copy link
Contributor Author

@bors try

bors added a commit to rust-lang-ci/rust that referenced this pull request May 14, 2024
[DO NOT MERGE] Expand core's prelude with more types

This adds some more types to the core prelude, to explore the [proposed prelude policy](rust-lang/std-dev-guide#66).

Without any further context, types in the standard library are strongly associated with the standard library so they are good candidates for the prelude, assuming their name doesn't require a module to make sense of. As a bonus this avoids some of the repetition required for `cell::Cell`, `pin::Pin`, `atomic::Atomic*`, etc.

Currently this includes some nightly types. These should be removed before this is merged.
@bors
Copy link
Contributor

bors commented May 14, 2024

⌛ Trying commit a222427 with merge 9130c02...

@bors
Copy link
Contributor

bors commented May 14, 2024

☀️ Try build successful - checks-actions
Build commit: 9130c02 (9130c02509ce15f69dc5da6359bb9d140d41d4ac)

@ChrisDenton
Copy link
Contributor Author

@craterbot check

@craterbot
Copy link
Collaborator

👌 Experiment pr-125107 created and queued.
🤖 Automatically detected try build 9130c02
🔍 You can check out the queue and this experiment's details.

ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot craterbot added S-waiting-on-crater Status: Waiting on a crater run to be completed. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 15, 2024
@craterbot
Copy link
Collaborator

🚧 Experiment pr-125107 is now running

ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot
Copy link
Collaborator

🎉 Experiment pr-125107 is completed!
📊 159 regressed and 2 fixed (462054 total)
📰 Open the full report.

⚠️ If you notice any spurious failure please add them to the blacklist!
ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot craterbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-crater Status: Waiting on a crater run to be completed. labels May 21, 2024
@ChrisDenton
Copy link
Contributor Author

ChrisDenton commented May 21, 2024

Huh, there does seem to be genuine regressions there. E.g. This is ambiguous if Cell is in the prelude:

use Cell::A;

// The derive here is important but it doesn't particularly matter which trait is being derived.
#[derive(PartialEq)]
pub enum Cell {
    A
}

Example error message from crater:

[INFO] [stdout] error[E0659]: `Cell` is ambiguous
[INFO] [stdout]   --> src/puzzle.rs:5:5
[INFO] [stdout]    |
[INFO] [stdout] 5  | use Cell::{Empty, Unknown, ValA, ValB, ValC, ValD};
[INFO] [stdout]    |     ^^^^ ambiguous name
[INFO] [stdout]    |
[INFO] [stdout]    = note: ambiguous because of a conflict between a macro-expanded name and a less macro-expanded name from outer scope during import or macro resolution
[INFO] [stdout] note: `Cell` could refer to the enum defined here
[INFO] [stdout]   --> src/puzzle.rs:8:1
[INFO] [stdout]    |
[INFO] [stdout] 8  | / pub enum Cell {
[INFO] [stdout] 9  | |     ValA,
[INFO] [stdout] 10 | |     ValB,
[INFO] [stdout] 11 | |     ValC,
[INFO] [stdout] ...  |
[INFO] [stdout] 14 | |     Unknown,
[INFO] [stdout] 15 | | }
[INFO] [stdout]    | |_^
[INFO] [stdout]    = help: use `self::Cell` to refer to this enum unambiguously
[INFO] [stdout] note: `Cell` could also refer to a struct from prelude
[INFO] [stdout]   --> /rustc/9130c02509ce15f69dc5da6359bb9d140d41d4ac/library/std/src/prelude/mod.rs:148:13

Which means that the prelude does have more of an effect on name resolution than I realized.

@workingjubilee
Copy link
Contributor

workingjubilee commented May 21, 2024

Yeah, I figured Cell wouldn't be an option, not in a zillion years. It's not as ubiquitous as Node, but almost.

@workingjubilee
Copy link
Contributor

people are denying unused_qualifications? on g-d?

@ChrisDenton
Copy link
Contributor Author

Yeah, I figured Cell wouldn't be an option, not in a zillion years. It's not as ubiquitous as Node, but almost.

I was kinda hoping the prelude was special enough that this sort of issue didn't arise even if there are other good reasons not to have it in the prelude. But alas adding types to the prelude does come with some amount of risk.

people are denying unused_qualifications? on g-d?

I was kinda ignoring them because they're getting exactly what they're asking for 😉

@workingjubilee
Copy link
Contributor

workingjubilee commented May 21, 2024

@ChrisDenton Can you remove Cell and Duration and anything else that seems dicey to you, and we retry this with the smaller list? There's a way to tell craterbot "rerun this on just the regressions".

@ChrisDenton
Copy link
Contributor Author

Ok, I've removed a few things. I'm ignoring the unnecessary qualifications lint for now because if not breaking that is a requirement then we can never add anything to the prelude (except in a new edition).

I'm not sure about removing PhantomData. It's only two crates that break: one is outdated and the other one hasn't been updated in a couple of years.

@ChrisDenton
Copy link
Contributor Author

@bors try while I figure out the crater magic

bors added a commit to rust-lang-ci/rust that referenced this pull request May 21, 2024
[DO NOT MERGE] Expand core's prelude with more types

This adds some more types to the core prelude, to explore the [proposed prelude policy](rust-lang/std-dev-guide#66).

Without any further context, types in the standard library are strongly associated with the standard library so they are good candidates for the prelude, assuming their name doesn't require a module to make sense of. As a bonus this avoids some of the repetition required for `cell::Cell`, `pin::Pin`, `atomic::Atomic*`, etc.

Currently this includes some nightly types. These should be removed before this is merged.

In summary, this PR currently exports the following from the prelude:
```rust
pub use core::cell::{Cell, LazyCell, OnceCell, RefCell, SyncUnsafeCell, UnsafeCell};
pub use core::ffi::{
    c_char, c_double, c_float, c_int, c_long, c_longlong, c_ptrdiff_t, c_schar, c_short, c_size_t,
    c_ssize_t, c_str, c_uchar, c_uint, c_ulong, c_ulonglong, c_ushort, c_void, CStr,
};
pub use core::io::{BorrowedBuf, BorrowedCursor};
pub use core::marker::{PhantomData, PhantomPinned};
pub use core::mem::{ManuallyDrop, MaybeUninit};
pub use core::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6};
pub use core::num::{
    NonZero, NonZeroI128, NonZeroI16, NonZeroI32, NonZeroI64, NonZeroI8, NonZeroIsize, NonZeroU128,
    NonZeroU16, NonZeroU32, NonZeroU64, NonZeroU8, NonZeroUsize,
};
pub use core::panic::PanicInfo;
pub use core::pin::Pin;
pub use core::ptr::NonNull;
pub use core::sync::atomic::{
    AtomicBool, AtomicI16, AtomicI32, AtomicI64, AtomicI8, AtomicIsize, AtomicPtr, AtomicU16,
    AtomicU32, AtomicU64, AtomicU8, AtomicUsize,
};
pub use core::time::Duration;
pub use core::ops::ControlFlow;
```

UPDATE:

There have so far been concerns raised about the following types:

- `Cell` is maybe too generic a word to be in a prelude type
- It is common for time libs to make their own `Duration` type so having it in the prelude may be confusing. This perhaps also suggests the design of std's `Duration` is not ideal but in any case that can't be changed at this point.
@bors
Copy link
Contributor

bors commented May 21, 2024

⌛ Trying commit 8b2e9b1 with merge 341f4bd...

@workingjubilee
Copy link
Contributor

the relevant command looks like run mode=check crates=https://crater-reports.s3.amazonaws.com/pr-111063/retry-regressed-list.txt except I think you will want to pick uhhh the correct .txt instead of that one. :P

@ChrisDenton
Copy link
Contributor Author

Ah, I'll try that once the try build is finished.

@bors
Copy link
Contributor

bors commented May 21, 2024

☀️ Try build successful - checks-actions
Build commit: 341f4bd (341f4bdd14d8eff23af8ad0599c0e6f42d805538)

@ChrisDenton
Copy link
Contributor Author

@craterbot
Copy link
Collaborator

👌 Experiment pr-125107-1 created and queued.
🤖 Automatically detected try build 341f4bd
🔍 You can check out the queue and this experiment's details.

ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot craterbot added S-waiting-on-crater Status: Waiting on a crater run to be completed. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 21, 2024
@ChrisDenton
Copy link
Contributor Author

ChrisDenton commented May 22, 2024

Now that I look closer at the crater results, it seems all the Duration issues are caused by a single crate (embedded-time), which does the equivalent of:

mod duration {
    pub trait Duration {}
}
use duration::*;
use core::prelude::v1::*;

pub struct Timer<Dur: Duration> {
    dur: Dur
}

Which leads to "error[E0659]: Duration is ambiguous" and is responsible for a large chunk of the failures.


And just for completeness, here are minimized examples of the other failures...

error[E0530]: let bindings cannot shadow unit structs:

fn main() {
    let (PhantomData @ _) = ();
}

error[E0308]: mismatched types:

fn main() {
    let PhantomData = ();
}

@craterbot
Copy link
Collaborator

🚧 Experiment pr-125107-1 is now running

ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot
Copy link
Collaborator

🎉 Experiment pr-125107-1 is completed!
📊 25 regressed and 0 fixed (159 total)
📰 Open the full report.

⚠️ If you notice any spurious failure please add them to the blacklist!
ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot craterbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-crater Status: Waiting on a crater run to be completed. labels May 28, 2024
@ChrisDenton
Copy link
Contributor Author

ChrisDenton commented May 28, 2024

Ok, that's down to 25 regressions. 18 of those are caused by using #![deny(unused_qualifications)] or worse #![deny(warnings)].

The other failures are all caused by something like let PhatomData = ... in the two crates: safer_ffi-proc_macros-0.1.8 (an old version) and fuzzcheck_mutators_derive-0.12.0 (latest but not updated in years).

@workingjubilee
Copy link
Contributor

Time to send https://github.com/loiclec/fuzzcheck-rs a PR I guess.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants