Skip to content

Add compiler-builtins as a subtree #141229

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

Draft
wants to merge 2,504 commits into
base: master
Choose a base branch
from

Conversation

tgross35
Copy link
Contributor

No description provided.

tgross35 and others added 30 commits January 23, 2025 22:30
Add `fminf16`, `fmaxf16`, `fminf128`, and `fmaxf128`
This can replace `fmod` and `fmodf`. As part of this change I was able
to replace some of the `while` loops with `leading_zeros`.
With the new routines, some of our tests are running close to their
timeouts. Increase the timeout for test jobs, and set a short timeout
for all other jobs that did not have one.
Certain functions (`fmodf128`) are significantly slower than others,
to the point that running the default number of tests adds tens of
minutes to PR CI and extensive test time increases to ~1day. It does not
make sense to do this by default; so, introduce `EXTREMELY_SLOW_TESTS`
to test configuration that allows setting specific tests that need to
have a reduced iteration count.
This function is significantly slower than all others so includes an
override in `EXTREMELY_SLOW_TESTS`. Without it, PR CI takes ~1hour and
the extensive tests in CI take ~1day.
A few new functions were added but this list did not get updated. Do so
here.
Since Rug 1.27.0, `az` is reexported. This means we no longer need to
track it as a separate dependency.
Rug 1.27.0 exposes `frexp`. Make use of it for our tests.
Rug 1.27.0 exposes `remquo`; make use of it for our tests. Removing our
workaround also allows removing the direct dependency on `gmp-mpfr-sys`
Upgrade all dependencies to the latest version
The Cargo feature `checked` was added in 410b0633a6b9 ("Overhaul tests")
and later removed in e4ac1399062c ("swap stable to be unstable, checked
is now debug_assertions"). However, there are a few remaining uses of
`feature = "checked"` that did not get removed. Clean these up here.
Currently the default release profile enables LTO and single CGU builds,
which is very slow to build. Most tests are better run with
optimizations enabled since it allows testing a much larger number of
inputs, so it is inconvenient that building can sometimes take
significantly longer than the tests.

Remedy this by doing the following:

* Move the existing `release` profile to `release-opt`.
* With the above, the default `release` profile is untouched (16 CGUs
  and thin local LTO).
* `release-checked` inherits `release`, so no LTO or single CGU.

This means that the simple `cargo test --release` becomes much faster
for local development. We are able to enable the other profiles as
needed in CI.

Tests should ideally still be run with `--profile release-checked` to
ensure there are no debug assetions or unexpected wrapping math hit.

`no-panic` still needs a single CGU, so must be run with `--profile
release-opt`. Since it is not possible to detect CGU or profilel
configuration from within build scripts, the `ENSURE_NO_PANIC`
environment variable must now always be set.
There seems to be a case of unsoundness with the `i586` version of
`atan2`. For the following test:

    assert_eq!(atan2(2.0, -1.0), atan(2.0 / -1.0) + PI);atan2(2.0, -1.0)

The output is optimization-dependent. The new `release-checked` profile
produces the following failure:

    thread 'math::atan2::sanity_check' panicked at src/math/atan2.rs:123:5:
    assertion `left == right` failed
      left: 2.0344439357957027
     right: 2.0344439357957027

Similarly, `sin::test_near_pi` fails with the following:

    thread 'math::sin::test_near_pi' panicked at src/math/sin.rs:91:5:
    assertion `left == right` failed
      left: 6.273720864039203e-7
     right: 6.273720864039205e-7

Mark the tests ignored on `i586` for now.
`#![feature(start)]` was removed in [1], but we make use of it in the
intrinsics example. Replace use of this feature with `#[no_mangle]`
applied to `#[main]`.

We don't actually run this example so it is not a problem if this is not
entirely accurate. Currently the example does not run to completion,
instead invoking `rust_begin_unwind`.

[1]: rust-lang#134299
…ates

Rework the available Cargo profiles
Rather than keeping a script that downloads the tarball, we can just add
musl as a submodule and let git handle the synchronizatoin. Do so here.
0.17.10 introduced a change that removes `Sync` from `ProgressStyle`,
which makes it more difficult to share in a callback. Pin the dependency
for now until we see if `indicatif` will change this back or if we need
to find a workaround.
llvm/llvm-project#116706 added Windows
support to cpu_model. Compiling for UEFI also goes through that
code path, because we treat it as a windows target. However,
including windows.h is not actually going to work (and the used
API would not be available in an UEFI environment).

Disable building of cpu_model on UEFI to fix this.
This reverts commit 1dacdabdb6186f97144c50f8952575576deb3730.
This isn't very useful for constants since the trait constants are
available, but does enable roundtripping via hex float syntax.
Add support for printing hex float syntax
Simplify the SPDX string to the user-facing version to make it easier for
users and tooling to understand. Contributions must still be `MIT OR Apache-2.0`. 

[ add commit body with context - Trevor ]
`EXP_MAX` sounds like it would be the maximum value representable by
that float type's exponent, rather than the maximum unsigned value of
its bits. Clarify this by renaming to `EXP_SAT`, the "saturated"
exponent representation.
github-actions bot and others added 13 commits May 4, 2025 18:52
Initially introduced in 63ccaf11f08fb5d0b39cc33884c5a1a63f547ace

Signed-off-by: ELginas <gintaras.z123@yahoo.com>
Since `crate::support` now works in both `compiler-builtins` and `libm`,
we can get rid of some of these unusual paths.
The `feature_detect` module is currently being built on all targets, but
the use of `AtomicU32` causes a problem if atomics are not available
(such as with `bpfel-unknown-none`). Gate this module behind
`target_has_atomic = "ptr"`.

The below now completes successfully:

    cargo build -p compiler_builtins --target=bpfel-unknown-none -Z build-std=core

Fixes: rust-lang/compiler-builtins#908
Foe the  bootstrap bump
Use the Josh [1] utility to add `compiler-builtins` as a subtree, which
will allow us to stop using crates.io for updates. This is intended to
help resolve some problems when unstable features change and require
code changes in `compiler-builtins`, which sometimes gets trapped in a
bootstrap cycle.

This was done using `josh-filter` built from the r24.10.04 tag:

    git fetch https://github.com/rust-lang/compiler-builtins.git 233434412fe7eced8f1ddbfeddabef1d55e493bd
    josh-filter ":prefix=library/compiler-builtins" FETCH_HEAD
    git merge --allow-unrelated FILTERED_HEAD

The HEAD in the `compiler-builtins` repository is 233434412f ("fix an if
statement that can be collapsed").

[1]: https://github.com/josh-project/josh
This will get checked in the compiler-builtins repository. The rules are
slightly different from rust-lang/rust since `use_small_heuristics =
"Max"` tends to create difficult to read output with math-heavy code
(e.g.  multiple `if` statements with numbers are small enough that they
sometimes get collapsed into a single line).
@rustbot rustbot added A-meta Area: Issues & PRs about the rust-lang/rust repository itself 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 18, 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 May 18, 2025
@tgross35 tgross35 force-pushed the builtins-josh-subtree branch from a4ba98d to 0821711 Compare May 18, 2025 16:22
@rustbot rustbot added A-tidy Area: The tidy tool T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) labels May 18, 2025
@tgross35
Copy link
Contributor Author

This doesn't yet use in-tree builtins anywhere because it turns the dependency graph into quite a mess (some deps of std depend on compiler-builtins), so I'm thinking it's easiest to only add the subtree for now then follow up with those changes.

@Kobzol what do you recommend doing for CI, should this get a bootstrap step? A basic cargo test --package builtins-test --package libm in the workspace root is likely sufficient to start, the whole test script is a bit complex https://github.com/rust-lang/compiler-builtins/blob/233434412fe7eced8f1ddbfeddabef1d55e493bd/ci/run.sh (which I plan to simplify a bit after this PR merges, since the default features for compiler-builtins are part of the complexity).

r? @Kobzol
cc @Amanieu @folkertdev
@bors rollup=never

@tgross35 tgross35 added the A-compiler-builtins Area: compiler-builtins (https://github.com/rust-lang/compiler-builtins) label May 18, 2025
@tgross35 tgross35 force-pushed the builtins-josh-subtree branch from 0821711 to 7ab785b Compare May 18, 2025 16:35
tgross35 added 2 commits May 18, 2025 17:12
compiler-builtins has a symlink to the `libm` source directory so the
two crates can share files but still act as two separate crates. This
causes problems with some sysroot-related tooling, however, since
directory symlinks seem to not be supported.

The reason this was a symlink in the first place is that there isn't an
easy for Cargo to publish two crates that share source (building works
fine but publishing rejects `include`d files from parent directories, as
well as nested package roots). However, after the switch to a subtree,
we no longer need to publish compiler-builtins; this means that we can
eliminate the link and just use `#[path]`.

If we need to publish compiler-builtins again for any reason, it would
be easy to revert this in a preprocess step.
@tgross35 tgross35 force-pushed the builtins-josh-subtree branch from 349c588 to 2c2c6f1 Compare May 20, 2025 13:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-compiler-builtins Area: compiler-builtins (https://github.com/rust-lang/compiler-builtins) A-meta Area: Issues & PRs about the rust-lang/rust repository itself A-tidy Area: The tidy tool rla-silenced Silences rust-log-analyzer postings to the PR it's added on. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) 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.