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

Add From<{integer}> for f16/f128 impls #138363

Merged
merged 1 commit into from
Mar 17, 2025

Conversation

beetrees
Copy link
Contributor

@beetrees beetrees commented Mar 11, 2025

This PR adds impl From<{bool,i8,u8}> for f16 and impl From<{bool,i8,u8,i16,u16,i32,u32}> for f128.

The From<{i64,u64}> for f128 impls are left commented out as adding them would allow using f128 on stable before it is stabilised like in the following example:

fn f<T: From<u64>>(x: T) -> T { x }

fn main() {
    let x = f(1.0); // the type of the literal is inferred to be `f128`
}

None of the impls added in this PR have this issue as they are all, at minimum, also implemented by f64.

This PR will need a crater run for the From<{i32,u32}> impls, as f64 is no longer the only float type to implement them (similar to the cause of #125198).

cc @bjoernager
r? @tgross35

Tracking issue: #116909

@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 Mar 11, 2025
@rust-log-analyzer

This comment has been minimized.

@beetrees beetrees force-pushed the f16-f128-integer-convert branch from 8767c41 to 7c07265 Compare March 11, 2025 19:00
@compiler-errors
Copy link
Member

compiler-errors commented Mar 11, 2025

Obligatory crater run since we've had trouble with f16/f128 stdlib impls in the past :)

edit: oh i just read that you also asked for a crater run; yep, agreed lol

@bors try

bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 11, 2025
…=<try>

Add `From<{integer}>` for `f16`/`f128` impls

This PR adds `impl From<{bool,i8,u8}> for f16` and `impl From<{bool,i8,u8,i16,u16,i32,u32}> for f128`.

The `From<{i64,u64}> for f128` impls are left commented out as adding them would allow using `f128` on stable before it is stabilised like in the following example:
```rust
fn f<T: From<u64>>(x: T) -> T { x }

fn main() {
    let x = f(1.0); // the type of the literal is inferred to be `f128`
}
```
None of the impls added in this PR have this issue as they are all, at minimum, also implemented by `f64`.

This PR will need a crater run for the `From<{i32,u32}>` impls, as `f64` is no longer the only float type to implement them (similar to the cause of rust-lang#125198).

cc `@bjoernager`
r? `@tgross35`

Tracking issue: rust-lang#116909
@bors
Copy link
Contributor

bors commented Mar 11, 2025

⌛ Trying commit 7c07265 with merge 5e7498e...

@bors
Copy link
Contributor

bors commented Mar 11, 2025

☀️ Try build successful - checks-actions
Build commit: 5e7498e (5e7498e6740d105521420ac0ab146e2c7a21596d)

@tgross35
Copy link
Contributor

@craterbot check

@craterbot
Copy link
Collaborator

👌 Experiment pr-138363 created and queued.
🤖 Automatically detected try build 5e7498e
🔍 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 Mar 11, 2025
@tgross35
Copy link
Contributor

This LGTM assuming crater is okay, but somebody from libs-api will need to approve

r? @Amanieu

@rustbot rustbot assigned Amanieu and unassigned tgross35 Mar 11, 2025
@tgross35 tgross35 added F-f16_and_f128 `#![feature(f16)]`, `#![feature(f128)]` T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels Mar 11, 2025
@craterbot
Copy link
Collaborator

🚧 Experiment pr-138363 is now running

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

@craterbot
Copy link
Collaborator

🎉 Experiment pr-138363 is completed!
📊 7 regressed and 5 fixed (596183 total)
📰 Open the full report.

⚠️ If you notice any spurious failure please add them to the denylist!
ℹ️ 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 Mar 13, 2025
@beetrees
Copy link
Contributor Author

All regressions are spurious.

@Amanieu
Copy link
Member

Amanieu commented Mar 16, 2025

@bors r+

@bors
Copy link
Contributor

bors commented Mar 16, 2025

📌 Commit 7c07265 has been approved by Amanieu

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. labels Mar 16, 2025
@thaliaarchi
Copy link
Contributor

This is adding a bunch of new impls as if they were introduced in Rust 1.6.0. Shouldn't they be something like #[stable(feature = "lossless_float_conv_more", since = "CURRENT_RUSTC_VERSION")] instead of #[stable(feature = "lossless_float_conv", since = "1.6.0")]?


// signed integer -> float
impl_from!(i8 => f16, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
impl_from!(i8 => f16, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
impl_from!(i8 => f16, #[stable(feature = "lossless_float_conv", since = "CURRENT_RUSTC_VERSION")]);

Copy link
Member

Choose a reason for hiding this comment

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

though in practice these impls aren't actually useful yet, they should probably be updated once f16 is stable

@beetrees
Copy link
Contributor Author

The impls aren't actually being stabilised now, as f16 and f128 are still unstable (and therefore the impls aren't reachable from stable code). However, trying to use an #[unstable] attribute on a trait implementation gives a an `#[unstable]` annotation here has no effect error. The stability attributes here are temporary and can be replaced with #[stable(feature = "f16/f128", since = "CURRENT_RUSTC_VERSION")] attributes once the f16/f128 features are stabilised (this is the same as is already done with the f16/f128 float -> float impls elsewhere in the file).

jhpratt added a commit to jhpratt/rust that referenced this pull request Mar 16, 2025
… r=Amanieu

Add `From<{integer}>` for `f16`/`f128` impls

This PR adds `impl From<{bool,i8,u8}> for f16` and `impl From<{bool,i8,u8,i16,u16,i32,u32}> for f128`.

The `From<{i64,u64}> for f128` impls are left commented out as adding them would allow using `f128` on stable before it is stabilised like in the following example:
```rust
fn f<T: From<u64>>(x: T) -> T { x }

fn main() {
    let x = f(1.0); // the type of the literal is inferred to be `f128`
}
```
None of the impls added in this PR have this issue as they are all, at minimum, also implemented by `f64`.

This PR will need a crater run for the `From<{i32,u32}>` impls, as `f64` is no longer the only float type to implement them (similar to the cause of rust-lang#125198).

cc `@bjoernager`
r? `@tgross35`

Tracking issue: rust-lang#116909
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 16, 2025
Rollup of 7 pull requests

Successful merges:

 - rust-lang#136293 (document capacity for ZST as example)
 - rust-lang#136355 (Add `*_value` methods to proc_macro lib)
 - rust-lang#136359 (doc all differences of ptr:copy(_nonoverlapping) with memcpy and memmove)
 - rust-lang#136816 (refactor `notable_traits_button` to use iterator combinators  instead of for loop)
 - rust-lang#138363 (Add `From<{integer}>` for `f16`/`f128` impls)
 - rust-lang#138552 (Misc print request handling cleanups + a centralized test for print request stability gating)
 - rust-lang#138573 (Make `_Unwind_Action` a type alias, not enum)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors
Copy link
Contributor

bors commented Mar 17, 2025

⌛ Testing commit 7c07265 with merge c3dd4ee...

@bors
Copy link
Contributor

bors commented Mar 17, 2025

☀️ Test successful - checks-actions
Approved by: Amanieu
Pushing c3dd4ee to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Mar 17, 2025
@bors bors merged commit c3dd4ee into rust-lang:master Mar 17, 2025
7 checks passed
@rustbot rustbot added this to the 1.87.0 milestone Mar 17, 2025
Copy link

This is an experimental post-merge analysis report. You can ignore it.

Post-merge report

Comparing 227690a (base) -> c3dd4ee (this PR)

Test differences

  • f128::test_from: [missing] -> pass (J0)
  • f16::test_from: [missing] -> pass (J1)

Additionally, 6 doctest diffs were found. These are ignored, as they are noisy.

Job group index

  • J0: aarch64-apple, aarch64-gnu, arm-android, armhf-gnu, mingw-check, test-various, x86_64-apple-1, x86_64-gnu, x86_64-gnu-aux, x86_64-gnu-llvm-18-1, x86_64-gnu-llvm-18-2, x86_64-gnu-llvm-18-3, x86_64-gnu-llvm-19-1, x86_64-gnu-llvm-19-2, x86_64-gnu-llvm-19-3, x86_64-gnu-nopt, x86_64-gnu-stable, x86_64-msvc-1
  • J1: aarch64-apple, aarch64-gnu, arm-android, armhf-gnu, dist-i586-gnu-i586-i686-musl, i686-gnu-1, i686-gnu-nopt-1, i686-msvc-1, mingw-check, test-various, x86_64-apple-1, x86_64-gnu, x86_64-gnu-aux, x86_64-gnu-llvm-18-1, x86_64-gnu-llvm-18-2, x86_64-gnu-llvm-18-3, x86_64-gnu-llvm-19-1, x86_64-gnu-llvm-19-2, x86_64-gnu-llvm-19-3, x86_64-gnu-nopt, x86_64-gnu-stable, x86_64-msvc-1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F-f16_and_f128 `#![feature(f16)]`, `#![feature(f128)]` merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue. 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.

10 participants