Skip to content

Merge compiler-builtins as a Josh 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

Merged
merged 2,504 commits into from
Jun 3, 2025

Conversation

tgross35
Copy link
Contributor

@tgross35 tgross35 commented May 18, 2025

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").

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.
@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Collaborator

bors commented Jun 2, 2025

💔 Test failed - checks-actions

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Jun 2, 2025
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]`.

Similarly, the LICENSE file was symlinked so it could live in the
repository root but be included in the package. This is also removed as
it caused problems with the dist job (error from bootstrap's
`tarball.rs`, "generated a symlink in a tarball").

If we need to publish compiler-builtins again for any reason, it would
be easy to revert these changes in a preprocess step.
@tgross35 tgross35 force-pushed the builtins-josh-subtree branch from e8a36fb to aff21f6 Compare June 3, 2025 00:02
@rustbot

This comment was marked as off-topic.

@tgross35
Copy link
Contributor Author

tgross35 commented Jun 3, 2025

It seems the dist jobs very much do not like links. I removed the LICENSE symlink.

@bors r=Kobzol

@bors
Copy link
Collaborator

bors commented Jun 3, 2025

📌 Commit aff21f6 has been approved by Kobzol

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 Jun 3, 2025
@Kobzol
Copy link
Contributor

Kobzol commented Jun 3, 2025

Hmm, for these simple cases we should teach bootstrap to just unwrap the symlinks.

@RalfJung
Copy link
Member

RalfJung commented Jun 3, 2025 via email

@tgross35
Copy link
Contributor Author

tgross35 commented Jun 3, 2025

It still exists at the repo root. It was just symlinked to within the compiler-builtins crate so it would get included in the package (Cargo unfortunately doesn't like ../LICENSE.txt) which shouldn't matter anymore if we're not publishing it.

@tgross35
Copy link
Contributor Author

tgross35 commented Jun 3, 2025

@bors p=1 subtree + followup work

@bors
Copy link
Collaborator

bors commented Jun 3, 2025

⌛ Testing commit aff21f6 with merge 59aa1e8...

@bors
Copy link
Collaborator

bors commented Jun 3, 2025

☀️ Test successful - checks-actions
Approved by: Kobzol
Pushing 59aa1e8 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Jun 3, 2025
@bors bors merged commit 59aa1e8 into rust-lang:master Jun 3, 2025
11 checks passed
@rustbot rustbot added this to the 1.89.0 milestone Jun 3, 2025
Copy link
Contributor

github-actions bot commented Jun 3, 2025

What is this? This is an experimental post-merge analysis report that shows differences in test outcomes between the merged PR and its parent PR.

Comparing a124fb3 (parent) -> 59aa1e8 (this PR)

Test differences

No test diffs found

Test dashboard

Run

cargo run --manifest-path src/ci/citool/Cargo.toml -- \
    test-dashboard 59aa1e873028948faaf8b97e5e02d4db340ad7b1 --output-dir test-dashboard

And then open test-dashboard/index.html in your browser to see an overview of all executed tests.

Job duration changes

  1. dist-aarch64-linux: 5443.9s -> 8079.9s (48.4%)
  2. x86_64-apple-1: 9194.8s -> 6891.9s (-25.0%)
  3. mingw-check-1: 1956.1s -> 1591.0s (-18.7%)
  4. mingw-check-2: 2231.4s -> 1839.8s (-17.6%)
  5. dist-ohos-aarch64: 5003.1s -> 4213.6s (-15.8%)
  6. aarch64-apple: 5625.5s -> 4860.9s (-13.6%)
  7. i686-gnu-2: 6023.6s -> 5276.7s (-12.4%)
  8. i686-gnu-1: 8060.1s -> 7165.5s (-11.1%)
  9. x86_64-gnu-debug: 6002.3s -> 5360.4s (-10.7%)
  10. i686-gnu-nopt-1: 7977.5s -> 7134.5s (-10.6%)
How to interpret the job duration changes?

Job durations can vary a lot, based on the actual runner instance
that executed the job, system noise, invalidated caches, etc. The table above is provided
mostly for t-infra members, for simpler debugging of potential CI slow-downs.

@tgross35 tgross35 deleted the builtins-josh-subtree branch June 3, 2025 23:18
@rust-log-analyzer
Copy link
Collaborator

A job failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
Version: 4.2.2
Digest: sha256:ccb2698953eaebd21c7bf6268a94f9c26518a7e38e27e0b83c1fe1ad049819b1
Source commit SHA: 11bd71901bbe5b1630ceea73d27597364c9af683
##[endgroup]
Complete job name: DockerHub mirror
##[group]Run actions/checkout@v4
with:
  persist-credentials: false
  repository: rust-lang/rust
  token: ***

@Kobzol
Copy link
Contributor

Kobzol commented Jun 4, 2025

Oh crap, the compiler-builtins repository has its own submodule? 🥶 I wonder what problems that will cause.. 😆 The above CI error is the first one.

@tgross35
Copy link
Contributor Author

tgross35 commented Jun 4, 2025

It's only used for testing, so never needs to be checked out by default here. I can switch it to a download script though, seeing as any other workaround is probably more difficult.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (59aa1e8): comparison URL.

Overall result: no relevant changes - no action needed

@rustbot label: -perf-regression

Instruction count

This benchmark run did not return any relevant results for this metric.

Max RSS (memory usage)

Results (primary 1.3%, secondary 3.2%)

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
1.3% [1.3%, 1.3%] 1
Regressions ❌
(secondary)
5.3% [4.7%, 5.9%] 2
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-1.2% [-1.2%, -1.2%] 1
All ❌✅ (primary) 1.3% [1.3%, 1.3%] 1

Cycles

Results (primary 1.8%, secondary -3.0%)

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
1.8% [1.8%, 1.8%] 1
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-3.0% [-3.0%, -3.0%] 1
All ❌✅ (primary) 1.8% [1.8%, 1.8%] 1

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 745.424s -> 745.508s (0.01%)
Artifact size: 372.33 MiB -> 372.31 MiB (-0.00%)

@durin42
Copy link
Contributor

durin42 commented Jun 4, 2025

Oh crap, the compiler-builtins repository has its own submodule? 🥶 I wonder what problems that will cause.. 😆 The above CI error is the first one.

Anecdotally, I can't do anything terribly interesting with git submodule now, which has broken a CI job we run to keep Rust HEAD green against LLVM HEAD. Probably the submodule reference needs to get pruned on the way in...

@lambdageek
Copy link
Contributor

lambdageek commented Jun 4, 2025

This broke my workflow, too. Would just adding the submodule to the .gitmodules in the repo root fix it (it fixes the issue for me locally, but I'm not sure if it's the right approach) #142029

@tgross35
Copy link
Contributor Author

tgross35 commented Jun 4, 2025

Sorry this broke some things; this will be removed in #142036

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 has-merge-commits PR has merge commits, merge with caution. merged-by-bors This PR was explicitly merged by bors. 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-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.