Skip to content

Implement the internal feature cfg_target_has_reliable_f16_f128 #140323

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

Merged
merged 2 commits into from
Apr 29, 2025

Conversation

tgross35
Copy link
Contributor

@tgross35 tgross35 commented Apr 26, 2025

Support for f16 and f128 is varied across targets, backends, and backend versions. Eventually we would like to reach a point where all backends support these approximately equally, but until then we have to work around some of these nuances of support being observable.

Introduce the cfg_target_has_reliable_f16_f128 internal feature, which provides the following new configuration gates:

  • cfg(target_has_reliable_f16)
  • cfg(target_has_reliable_f16_math)
  • cfg(target_has_reliable_f128)
  • cfg(target_has_reliable_f128_math)

reliable_f16 and reliable_f128 indicate that basic arithmetic for the type works correctly. The _math versions indicate that anything relying on libm works correctly, since sometimes this hits a separate class of codegen bugs.

These options match configuration set by the build script at 1. The logic for LLVM support is duplicated as-is from the same script. There are a few possible updates that will come as a follow up.

The config introduced here is not planned to ever become stable, it is only intended to replace the build scripts for std tests and compiler-builtins that don't have any way to configure based on the codegen backend.

MCP: rust-lang/compiler-team#866
Closes: rust-lang/compiler-team#866


The second commit makes use of this config to replace cfg_{f16,f128}{,_math} in library/. I omitted providing a cfg(bootstrap) configuration to keep things simpler since the next beta branch is in two weeks.

try-job: aarch64-gnu
try-job: i686-msvc-1
try-job: test-various
try-job: x86_64-gnu
try-job: x86_64-msvc-ext2

r? @ghost

@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. labels Apr 26, 2025
@rust-log-analyzer

This comment has been minimized.

@tgross35 tgross35 added the rla-silenced Silences rust-log-analyzer postings to the PR it's added on. label Apr 26, 2025
@tgross35 tgross35 force-pushed the cfg-unstable-float branch 2 times, most recently from 98cf08a to e7fb9c5 Compare April 26, 2025 06:17
@tgross35
Copy link
Contributor Author

@bors try

bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 26, 2025
Implement the internal feature `cfg_target_has_reliable_f16_f128`

Support for `f16` and `f128` is varied across targets, backends, and backend versions. Eventually we would like to reach a point where all backends support these approximately equally, but until then we have to work around some of these nuances of support being observable.

Introduce the `target_has_reliable_f16_f128` configuration option, gated behind `cfg_target_has_reliable_f16_f128`, as an indicator for whether or not the backend supports these types to a point that they can and should be tested. The configuration mostly follows the logic used by `target_feature`, and similarly takes a value:

    #[cfg(target_has_reliable_f16_f128 = "f16")]

Accepted values are:

* `f16`
* `f16-math`
* `f128`
* `f128-math`

`f16` and `f128` indicate that basic arithmetic for the type works correctly. The `-math` versions indicate that anything relying on `libm` works correctly, since sometimes this hits a separate class of codegen bugs.

These options match configuration set by the build script at [1]. The logic for LLVM support is duplicated as-is from the same script. There are a few possible updates that will come as a follow up.

The config introduced here is not intended to ever become stable, it is only intended to replace the build scripts for `std` tests and in `compiler-builtins` that don't have any way to set configuration based on the codegen backend.

MCP: rust-lang/compiler-team#866
Closes: rust-lang/compiler-team#866

[1]: https://github.com/rust-lang/rust/blob/555e1d0386f024a8359645c3217f4b3eae9be042/library/std/build.rs#L84-L186

---

The second commit makes use of this config to replace `cfg_{f16,f128}{,_math}` in `library/`.

try-job: aarch64-gnu
try-job: i686-msvc-1
try-job: test-various
try-job: x86_64-gnu
try-job: x86_64-msvc-ext2
@bors
Copy link
Collaborator

bors commented Apr 26, 2025

⌛ Trying commit e7fb9c5 with merge 4055b73...

@tgross35 tgross35 marked this pull request as ready for review April 26, 2025 06:42
@rustbot
Copy link
Collaborator

rustbot commented Apr 26, 2025

Some changes occurred in compiler/rustc_codegen_ssa

cc @WaffleLapkin

Some changes occurred in compiler/rustc_codegen_cranelift

cc @bjorn3

Some changes occurred in cfg and check-cfg configuration

cc @Urgau

Some changes occurred in compiler/rustc_codegen_gcc

cc @antoyo, @GuillaumeGomez

@tgross35
Copy link
Contributor Author

r? compiler

Cc @bjorn3 @antoyo since this touches the backend interfaces.

@tgross35 tgross35 added the F-f16_and_f128 `#![feature(f16)]`, `#![feature(f128)]` label Apr 26, 2025
@tgross35 tgross35 force-pushed the cfg-unstable-float branch from e7fb9c5 to 4d7bb41 Compare April 26, 2025 07:16
@rustbot
Copy link
Collaborator

rustbot commented Apr 26, 2025

Some changes occurred in src/doc/rustc/src/check-cfg.md

cc @Urgau

@tgross35
Copy link
Contributor Author

Hm... I think I'm actually leaning toward four separate key-only cfg options here rather than a single key with multiple values. I don't think the current version works as-well, it's a bit bulky and redundant with f16_f128 in the name.

Will change it over tomorrow unless anyone has a stronger preference.

@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 26, 2025
@rustbot
Copy link
Collaborator

rustbot commented Apr 26, 2025

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@tgross35 tgross35 force-pushed the cfg-unstable-float branch 2 times, most recently from b1025c9 to 5abd112 Compare April 26, 2025 20:14
@tgross35
Copy link
Contributor Author

Changed so this is split across four different cfg options.

@rustbot review

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Apr 26, 2025
Urgau
Urgau previously requested changes Apr 27, 2025
@tgross35 tgross35 force-pushed the cfg-unstable-float branch 2 times, most recently from ac61743 to 304739d Compare April 27, 2025 17:41
@tgross35
Copy link
Contributor Author

tgross35 commented Apr 27, 2025

Since you have already started taking a look,

r? @Urgau

@tgross35
Copy link
Contributor Author

Thanks!

@bors r=Urgau

@bors
Copy link
Collaborator

bors commented Apr 28, 2025

📌 Commit dfa972e has been approved by Urgau

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 Apr 28, 2025
ChrisDenton added a commit to ChrisDenton/rust that referenced this pull request Apr 28, 2025
Implement the internal feature `cfg_target_has_reliable_f16_f128`

Support for `f16` and `f128` is varied across targets, backends, and backend versions. Eventually we would like to reach a point where all backends support these approximately equally, but until then we have to work around some of these nuances of support being observable.

Introduce the `cfg_target_has_reliable_f16_f128` internal feature, which provides the following new configuration gates:

* `cfg(target_has_reliable_f16)`
* `cfg(target_has_reliable_f16_math)`
* `cfg(target_has_reliable_f128)`
* `cfg(target_has_reliable_f128_math)`

`reliable_f16` and `reliable_f128` indicate that basic arithmetic for the type works correctly. The `_math` versions indicate that anything relying on `libm` works correctly, since sometimes this hits a separate class of codegen bugs.

These options match configuration set by the build script at [1]. The logic for LLVM support is duplicated as-is from the same script. There are a few possible updates that will come as a follow up.

The config introduced here is not planned to ever become stable, it is only intended to replace the build scripts for `std` tests and `compiler-builtins` that don't have any way to configure based on the codegen backend.

MCP: rust-lang/compiler-team#866
Closes: rust-lang/compiler-team#866

[1]: https://github.com/rust-lang/rust/blob/555e1d0386f024a8359645c3217f4b3eae9be042/library/std/build.rs#L84-L186

---

The second commit makes use of this config to replace `cfg_{f16,f128}{,_math}` in `library/`. I omitted providing a `cfg(bootstrap)` configuration to keep things simpler since the next beta branch is in two weeks.

try-job: aarch64-gnu
try-job: i686-msvc-1
try-job: test-various
try-job: x86_64-gnu
try-job: x86_64-msvc-ext2
@@ -50,8 +50,15 @@ pub trait CodegenBackend {
/// - The second is like the first, but also includes unstable features.
///
/// RUSTC_SPECIFIC_FEATURES should be skipped here, those are handled outside codegen.
fn target_features_cfg(&self, _sess: &Session) -> (Vec<Symbol>, Vec<Symbol>) {
(vec![], vec![])
fn target_config(&self, _sess: &Session) -> TargetConfig {
Copy link
Member

Choose a reason for hiding this comment

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

Documentation of this function is outdated.

Also, why are the defaults true?

Copy link
Contributor Author

@tgross35 tgross35 Apr 28, 2025

Choose a reason for hiding this comment

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

Thanks for the documentation catch. Since the rollup is already testing, I'll fix this in a follow up.

true is the default since eventually we'll need to get there on (hopefully) all backends for the types to stabilize. It seemed better to make other backends explicitly ack that they don't support the type, than to quietly be skipping all f16/f128 tests and get a surprise when we go to delete this feature and stabilize.

bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 28, 2025
…enton

Rollup of 9 pull requests

Successful merges:

 - rust-lang#139308 (add autodiff inline)
 - rust-lang#140276 (Do not compute type_of for impl item if impl where clauses are unsatisfied)
 - rust-lang#140302 (Move inline asm check to typeck, properly handle aliases)
 - rust-lang#140323 (Implement the internal feature `cfg_target_has_reliable_f16_f128`)
 - rust-lang#140374 (Resolve instance for SymFn in global/naked asm)
 - rust-lang#140391 (Rename sub_ptr to offset_from_unsigned in docs)
 - rust-lang#140394 (Make bootstrap git tests more self-contained)
 - rust-lang#140396 (Workaround for windows-gnu rust-lld test failure)
 - rust-lang#140402 (only return nested goals for `Certainty::Yes`)

r? `@ghost`
`@rustbot` modify labels: rollup
ChrisDenton added a commit to ChrisDenton/rust that referenced this pull request Apr 28, 2025
Implement the internal feature `cfg_target_has_reliable_f16_f128`

Support for `f16` and `f128` is varied across targets, backends, and backend versions. Eventually we would like to reach a point where all backends support these approximately equally, but until then we have to work around some of these nuances of support being observable.

Introduce the `cfg_target_has_reliable_f16_f128` internal feature, which provides the following new configuration gates:

* `cfg(target_has_reliable_f16)`
* `cfg(target_has_reliable_f16_math)`
* `cfg(target_has_reliable_f128)`
* `cfg(target_has_reliable_f128_math)`

`reliable_f16` and `reliable_f128` indicate that basic arithmetic for the type works correctly. The `_math` versions indicate that anything relying on `libm` works correctly, since sometimes this hits a separate class of codegen bugs.

These options match configuration set by the build script at [1]. The logic for LLVM support is duplicated as-is from the same script. There are a few possible updates that will come as a follow up.

The config introduced here is not planned to ever become stable, it is only intended to replace the build scripts for `std` tests and `compiler-builtins` that don't have any way to configure based on the codegen backend.

MCP: rust-lang/compiler-team#866
Closes: rust-lang/compiler-team#866

[1]: https://github.com/rust-lang/rust/blob/555e1d0386f024a8359645c3217f4b3eae9be042/library/std/build.rs#L84-L186

---

The second commit makes use of this config to replace `cfg_{f16,f128}{,_math}` in `library/`. I omitted providing a `cfg(bootstrap)` configuration to keep things simpler since the next beta branch is in two weeks.

try-job: aarch64-gnu
try-job: i686-msvc-1
try-job: test-various
try-job: x86_64-gnu
try-job: x86_64-msvc-ext2
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 28, 2025
…enton

Rollup of 10 pull requests

Successful merges:

 - rust-lang#139308 (add autodiff inline)
 - rust-lang#139656 (Stabilize `slice_as_chunks` library feature)
 - rust-lang#140022 (allow deref patterns to move out of boxes)
 - rust-lang#140276 (Do not compute type_of for impl item if impl where clauses are unsatisfied)
 - rust-lang#140302 (Move inline asm check to typeck, properly handle aliases)
 - rust-lang#140323 (Implement the internal feature `cfg_target_has_reliable_f16_f128`)
 - rust-lang#140391 (Rename sub_ptr to offset_from_unsigned in docs)
 - rust-lang#140394 (Make bootstrap git tests more self-contained)
 - rust-lang#140396 (Workaround for windows-gnu rust-lld test failure)
 - rust-lang#140402 (only return nested goals for `Certainty::Yes`)

Failed merges:

 - rust-lang#139765 ([beta] Delay `hash_extract_if` stabilization from 1.87 to 1.88)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 29, 2025
…enton

Rollup of 10 pull requests

Successful merges:

 - rust-lang#139308 (add autodiff inline)
 - rust-lang#139656 (Stabilize `slice_as_chunks` library feature)
 - rust-lang#140022 (allow deref patterns to move out of boxes)
 - rust-lang#140276 (Do not compute type_of for impl item if impl where clauses are unsatisfied)
 - rust-lang#140302 (Move inline asm check to typeck, properly handle aliases)
 - rust-lang#140323 (Implement the internal feature `cfg_target_has_reliable_f16_f128`)
 - rust-lang#140391 (Rename sub_ptr to offset_from_unsigned in docs)
 - rust-lang#140394 (Make bootstrap git tests more self-contained)
 - rust-lang#140396 (Workaround for windows-gnu rust-lld test failure)
 - rust-lang#140402 (only return nested goals for `Certainty::Yes`)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 29, 2025
[experiment] reliable float experiments

Trying a few blocked things based on top of rust-lang#140323.

r? `@ghost`

try-job: aarch64-gnu
try-job: i686-gnu-1
try-job: i686-msvc-1
try-job: test-various
try-job: x86_64-gnu
try-job: x86_64-msvc-ext2
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 29, 2025
[experiment] reliable float experiments

Trying a few blocked things based on top of rust-lang#140323.

r? `@ghost`

try-job: x86_64-gnu-llvm-19-1
try-job: x86_64-gnu-llvm-20-1
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 29, 2025
[experiment] reliable float experiments

Trying a few blocked things based on top of rust-lang#140323.

r? `@ghost`

try-job: aarch64-gnu
try-job: i686-gnu-1
try-job: i686-msvc-1
try-job: test-various
try-job: x86_64-gnu
try-job: x86_64-msvc-ext2
try-job: x86_64-gnu-llvm-19-1
try-job: x86_64-gnu-llvm-20-1
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 29, 2025
[experiment] reliable float experiments

Trying a few blocked things based on top of rust-lang#140323.

r? `@ghost`

try-job: aarch64-gnu
try-job: i686-gnu-1
try-job: i686-msvc-1
try-job: test-various
try-job: x86_64-gnu
try-job: x86_64-msvc-ext2
try-job: x86_64-gnu-llvm-19-1
try-job: x86_64-gnu-llvm-20-1
@bors bors merged commit e082bf3 into rust-lang:master Apr 29, 2025
7 checks passed
@rustbot rustbot added this to the 1.88.0 milestone Apr 29, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Apr 29, 2025
Rollup merge of rust-lang#140323 - tgross35:cfg-unstable-float, r=Urgau

Implement the internal feature `cfg_target_has_reliable_f16_f128`

Support for `f16` and `f128` is varied across targets, backends, and backend versions. Eventually we would like to reach a point where all backends support these approximately equally, but until then we have to work around some of these nuances of support being observable.

Introduce the `cfg_target_has_reliable_f16_f128` internal feature, which provides the following new configuration gates:

* `cfg(target_has_reliable_f16)`
* `cfg(target_has_reliable_f16_math)`
* `cfg(target_has_reliable_f128)`
* `cfg(target_has_reliable_f128_math)`

`reliable_f16` and `reliable_f128` indicate that basic arithmetic for the type works correctly. The `_math` versions indicate that anything relying on `libm` works correctly, since sometimes this hits a separate class of codegen bugs.

These options match configuration set by the build script at [1]. The logic for LLVM support is duplicated as-is from the same script. There are a few possible updates that will come as a follow up.

The config introduced here is not planned to ever become stable, it is only intended to replace the build scripts for `std` tests and `compiler-builtins` that don't have any way to configure based on the codegen backend.

MCP: rust-lang/compiler-team#866
Closes: rust-lang/compiler-team#866

[1]: https://github.com/rust-lang/rust/blob/555e1d0386f024a8359645c3217f4b3eae9be042/library/std/build.rs#L84-L186

---

The second commit makes use of this config to replace `cfg_{f16,f128}{,_math}` in `library/`. I omitted providing a `cfg(bootstrap)` configuration to keep things simpler since the next beta branch is in two weeks.

try-job: aarch64-gnu
try-job: i686-msvc-1
try-job: test-various
try-job: x86_64-gnu
try-job: x86_64-msvc-ext2
@tgross35 tgross35 deleted the cfg-unstable-float branch April 29, 2025 05:37
tgross35 added a commit to tgross35/rust that referenced this pull request Apr 29, 2025
This was missed as part of [1].

[1]: rust-lang#140323
Zalathar added a commit to Zalathar/rust that referenced this pull request Apr 29, 2025
…, r=jieyouxu

Update documentation for `fn target_config`

This was missed as part of [1].

[1]: rust-lang#140323
tgross35 added a commit to tgross35/rust that referenced this pull request Apr 29, 2025
…, r=jieyouxu

Update documentation for `fn target_config`

This was missed as part of [1].

[1]: rust-lang#140323
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Apr 29, 2025
Rollup merge of rust-lang#140432 - tgross35:target-config-docs-update, r=jieyouxu

Update documentation for `fn target_config`

This was missed as part of [1].

[1]: rust-lang#140323
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)]` rla-silenced Silences rust-log-analyzer postings to the PR it's added on. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add #[cfg(target_has_unstable_float = "...")]
7 participants