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

Rollup of 6 pull requests #127924

Merged
merged 12 commits into from
Jul 18, 2024
Merged

Rollup of 6 pull requests #127924

merged 12 commits into from
Jul 18, 2024

Conversation

matthiaskrgr
Copy link
Member

Successful merges:

r? @ghost
@rustbot modify labels: rollup

Create a similar rollup

scottmcm and others added 12 commits July 15, 2024 00:34
In particular, remove the note saying cdylibs can't link against dylibs — that hasn't been true for over four years.

  * 2019-11-07: note is written: rust-lang@b54e8ec
  * 2020-01-23: restriction is lifted (without updating docs): rust-lang@72aaa3a
It can fail when in git is in detached HEAD mode.
This changes `ReentrantLock` to use `ThreadId` for the thread ownership check instead of the address of a thread local. Unlike TLS blocks, `ThreadId` is guaranteed to be unique across the lifetime of the process, so if any thread ever terminates while holding a `ReentrantLockGuard`, no other thread may ever acquire that lock again.

On platforms with 64-bit atomics, this is a very simple change. On other platforms, the approach used is slightly more involved, as explained in the module comment.

This also adds a `CURRENT_ID` thread local in addition to the already existing `CURRENT`. This allows us to access the current `ThreadId` without the relatively heavy machinery used by `thread::current().id()`.
Use ThreadId instead of TLS-address in `ReentrantLock`

Fixes rust-lang#123458

`ReentrantLock` currently uses the address of a thread local variable as an ID that's unique across all currently running threads. This can lead to uninituitive behavior as in rust-lang#123458 if TLS blocks get reused. This PR changes `ReentrantLock` to instead use the `ThreadId` provided by `std` as the unique ID. `ThreadId` guarantees uniqueness across the lifetime of the whole process, so we don't need to worry about reusing IDs of terminated threads. The main appeal of this PR is thus the possibility of changing the `ReentrantLock` API to guarantee that if a thread leaks a lock guard, no other thread may ever acquire that lock again.

This does entail some complications:
- previously, the only way to retrieve the current thread ID would've been using `thread::current().id()` which creates a temporary `Arc` and which isn't available in TLS destructors. As part of this PR, the thread ID instead gets cached in its own thread local, as suggested [here](rust-lang#123458 (comment)).
- `ThreadId` is always 64-bit whereas the current implementation uses a usize-sized ID. Since this ID needs to be updated atomically, we can't simply use a single atomic variable on 32 bit platforms. Instead, we fall back to using a (sound) seqlock on 32-bit platforms, which works because only one thread at a time can write to the ID. This seqlock is technically susceptible to the ABA problem, but the attack vector to create actual unsoundness has to be very specific:
  - You would need to be able to lock+unlock the lock exactly 2^31 times (or a multiple thereof) while a thread trying to lock it sleeps
  - The sleeping thread would have to suspend after reading one half of the thread id but before reading the other half
  - The teared result from combining the halves of the thread ID would have to exactly line up with the sleeping thread's ID

The risk of this occurring seems slim enough to be acceptable to me, but correct me if I'm wrong. This also means that the size of the lock increases by 8 bytes on 32-bit platforms, but this also shouldn't be an issue.

Performance wise, I did some crude testing of the only case where this could lead to real slowdowns, which is the case of locking a `ReentrantLock` that's already locked by the current thread. On both aarch64 and x86-64, there is (expectedly) pretty much no performance hit. I didn't have any 32-bit platforms to test the seqlock performance on, so I did the next best thing and just forced the 64-bit platforms to use the seqlock implementation. There, the performance degraded by ~1-2ns/(lock+unlock) on x86-64 and ~6-8ns/(lock+unlock) on aarch64, which is measurable but seems acceptable to me seeing as 32-bit platforms should be a small minority anyways.

cc `@joboet` `@RalfJung` `@CAD97`
…_crate, r=petrochenkov

make pub_use_of_private_extern_crate show up in cargo's future breakage reports

This has been a lint for many years.

However, turns out that outright removing it right now would lead to [tons of crater regressions](rust-lang#127656 (comment)) due to crates depending on an ancient version of `bitflags`. So for now this PR just makes this future-compat lint show up in cargo's reports, so people are warned when they use a dependency that is affected by this.

r? `@petrochenkov`
Use Option's discriminant as its size hint

I was looking at this in MIR after a question on discord, and noticed that it ends up with a switch in MIR (<https://rust.godbolt.org/z/3q4cYnnb3>), which it doesn't need because (as `Option::as_slice` uses) the discriminant is already the length.
…t-lint, r=compiler-errors

Add internal lint for detecting non-glob imports of `rustc_type_ir::inherent`

rust-lang#127627 (comment)

r? compiler-errors
Update extern linking documentation

In particular, remove the note saying cdylibs can't link against dylibs — that hasn't been true for over four years.

  * 2019-11-07: note is written: rust-lang@b54e8ec
  * 2020-01-23: restriction is lifted (without updating docs): rust-lang@72aaa3a
Allow a git command for getting the current branch in bootstrap to fail

Found by `@lukas-code` [here](rust-lang#127680 (comment)). The bug was introduced in rust-lang#127680 (before, the command was allowed to fail).

r? `@onur-ozkan`
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. 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. rollup A PR which is a rollup labels Jul 18, 2024
@matthiaskrgr
Copy link
Member Author

@bors r+ rollup=never p=6

@bors
Copy link
Contributor

bors commented Jul 18, 2024

📌 Commit 6c10822 has been approved by matthiaskrgr

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 Jul 18, 2024
@bors
Copy link
Contributor

bors commented Jul 18, 2024

⌛ Testing commit 6c10822 with merge 5affbb1...

@bors
Copy link
Contributor

bors commented Jul 18, 2024

☀️ Test successful - checks-actions
Approved by: matthiaskrgr
Pushing 5affbb1 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Jul 18, 2024
@bors bors merged commit 5affbb1 into rust-lang:master Jul 18, 2024
7 checks passed
@rustbot rustbot added this to the 1.81.0 milestone Jul 18, 2024
@rust-timer
Copy link
Collaborator

📌 Perf builds for each rolled up PR:

PR# Message Perf Build Sha
#124881 Use ThreadId instead of TLS-address in ReentrantLock f3e2d7b00fef953b622e7279ec2034dc148edf5b (link)
#127656 make pub_use_of_private_extern_crate show up in cargo's fut… 76ac8089c823ae70b9ebb4e5edb139367d3eee0d (link)
#127748 Use Option's discriminant as its size hint aa1df6c0fa3fc77e234fb3cfc90a0a5b6f2ce5fa (link)
#127854 Add internal lint for detecting non-glob imports of `rustc_… 893582847b378789794e34c2bbfa09516b93ca7a (link)
#127908 Update extern linking documentation 63e5e227605687e7807fffc2c2ddf1c3047c8a27 (link)
#127919 Allow a git command for getting the current branch in boots… 1636e2ec0f14d37edc8c9f4761bce8861f70b866 (link)

previous master: 5753b30676

In the case of a perf regression, run the following command for each PR you suspect might be the cause: @rust-timer build $SHA

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (5affbb1): comparison URL.

Overall result: ❌✅ regressions and improvements - no action needed

@rustbot label: -perf-regression

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

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

Max RSS (memory usage)

Results (primary -1.5%)

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)
2.8% [2.4%, 3.4%] 3
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-4.7% [-7.8%, -1.8%] 4
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -1.5% [-7.8%, 3.4%] 7

Cycles

Results (secondary 2.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)
- - 0
Regressions ❌
(secondary)
2.7% [2.1%, 3.1%] 6
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-2.1% [-2.1%, -2.1%] 1
All ❌✅ (primary) - - 0

Binary size

Results (primary 0.0%, secondary 0.1%)

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)
0.1% [0.0%, 0.2%] 12
Regressions ❌
(secondary)
0.1% [0.1%, 0.2%] 38
Improvements ✅
(primary)
-0.1% [-0.2%, -0.1%] 5
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.0% [-0.2%, 0.2%] 17

Bootstrap: 768.843s -> 768.766s (-0.01%)
Artifact size: 328.71 MiB -> 328.72 MiB (0.00%)

@matthiaskrgr matthiaskrgr deleted the rollup-1gn6afv branch September 1, 2024 17:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. rollup A PR which is a rollup 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.

10 participants