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

Commits on Jul 15, 2024

  1. Configuration menu
    Copy the full SHA
    eb3cc5f View commit details
    Browse the repository at this point in the history

Commits on Jul 18, 2024

  1. 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
    fasterthanlime authored Jul 18, 2024
    Configuration menu
    Copy the full SHA
    d3303b0 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    2507301 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    0871175 View commit details
    Browse the repository at this point in the history
  4. Allow a git command for getting the current branch in bootstrap to fail

    It can fail when in git is in detached HEAD mode.
    Kobzol committed Jul 18, 2024
    Configuration menu
    Copy the full SHA
    4dc8e66 View commit details
    Browse the repository at this point in the history
  5. Update ReentrantLock implementation, add CURRENT_ID thread local.

    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()`.
    Sp00ph committed Jul 18, 2024
    Configuration menu
    Copy the full SHA
    fe89962 View commit details
    Browse the repository at this point in the history
  6. Rollup merge of rust-lang#124881 - Sp00ph:reentrant_lock_tid, r=joboet

    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`
    matthiaskrgr authored Jul 18, 2024
    Configuration menu
    Copy the full SHA
    f62aa41 View commit details
    Browse the repository at this point in the history
  7. Rollup merge of rust-lang#127656 - RalfJung:pub_use_of_private_extern…

    …_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`
    matthiaskrgr authored Jul 18, 2024
    Configuration menu
    Copy the full SHA
    ec6110f View commit details
    Browse the repository at this point in the history
  8. Rollup merge of rust-lang#127748 - scottmcm:option_len, r=joboet

    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.
    matthiaskrgr authored Jul 18, 2024
    Configuration menu
    Copy the full SHA
    6f7fa03 View commit details
    Browse the repository at this point in the history
  9. Rollup merge of rust-lang#127854 - fmease:glob-import-type_ir_inheren…

    …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
    matthiaskrgr authored Jul 18, 2024
    Configuration menu
    Copy the full SHA
    4ad2c99 View commit details
    Browse the repository at this point in the history
  10. Rollup merge of rust-lang#127908 - fasterthanlime:patch-1, r=jieyouxu

    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
    matthiaskrgr authored Jul 18, 2024
    Configuration menu
    Copy the full SHA
    ac26f6a View commit details
    Browse the repository at this point in the history
  11. Rollup merge of rust-lang#127919 - Kobzol:fix-git-command, r=onur-ozkan

    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`
    matthiaskrgr authored Jul 18, 2024
    Configuration menu
    Copy the full SHA
    6c10822 View commit details
    Browse the repository at this point in the history