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

Portability fixes #1469

Merged
merged 8 commits into from
Jul 23, 2024
Merged

Portability fixes #1469

merged 8 commits into from
Jul 23, 2024

Conversation

dhardy
Copy link
Member

@dhardy dhardy commented Jul 18, 2024

  • Added a CHANGELOG.md entry

Summary

Fixes some of the smaller issues noted here. Specifically:

  • Fix portability of choose_multiple_array
  • Fix portability of rand::distributions::Slice

Further, this makes it more explicit which target_pointer_width sizes SmallRng backends are intended to support (the 16-bit choice is not intended to be optimal).

@dhardy dhardy requested a review from MichaelOwenDyer July 18, 2024 08:03
Copy link
Member

@newpavlov newpavlov left a comment

Choose a reason for hiding this comment

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

It may be worth to add a build-only CI job for a 16-bit target to prevent regressions in future.

@@ -10,10 +10,10 @@

use rand_core::{RngCore, SeedableRng};

#[cfg(any(target_pointer_width = "32", target_pointer_width = "16"))]
Copy link
Member

Choose a reason for hiding this comment

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

Why change it from not(target_pointer_width = "64")? Even with hypothetical 128-bit targets it's better to use Xoshiro128++ than to break builds. Alternatively, it's worth to at least add a compile_error! stating that we support only 16, 32, and 64 bit targets.

Copy link
Member Author

Choose a reason for hiding this comment

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

  1. Because this is explicit about what is supported and recommended
  2. Effectively it is a compile error
  3. I don't care about theoretical targets. If people want to target 16- or 128-bits on rand, they can submit patches.

#[cfg(feature = "alloc")]
use alloc::string::String;

#[cfg(not(any(target_pointer_width = "32", target_pointer_width = "64")))]
const _: () = assert!(false, "unsupported pointer width");
Copy link
Member

Choose a reason for hiding this comment

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

Why not use compile_error! here? Also, why can't we use UniformSize::U32 on 16-bit targets?

Copy link
Member Author

Choose a reason for hiding this comment

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

  1. I forgot about it — I'll switch to compile_error!
  2. Dependencies don't compile and it seems like no-one cares much about 16-bit (Supported target_pointer_width: 32, 64-bit only? #1468), so there's no point wasting time here.

Comment on lines +20 to +24
enum UniformUsize {
U32(Uniform<u32>),
#[cfg(target_pointer_width = "64")]
U64(Uniform<u64>),
}
Copy link
Member Author

Choose a reason for hiding this comment

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

As with gen_index, this should probably be exposed somehow (left for a future PR).

@dhardy dhardy added the D-review Do: needs review label Jul 20, 2024
@dhardy dhardy requested a review from newpavlov July 23, 2024 10:00
@dhardy dhardy merged commit 605476c into rust-random:master Jul 23, 2024
14 checks passed
@dhardy dhardy deleted the portability-fixes branch July 23, 2024 13:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
D-review Do: needs review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants