Skip to content

Add rustc_diagnostic_item to sys::Mutex methods #141690

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 3 commits into from
May 29, 2025

Conversation

Patrick-6
Copy link
Contributor

@Patrick-6 Patrick-6 commented May 28, 2025

For an ongoing project for adding a concurrency model checker to Miri we need to be able to intercept locking/unlocking operations on standard library mutexes.

This PR adds diagnostic items to the relevant calls lock, try_lock and unlock for the sys::Mutex implementation on the targets we care about.
This PR also makes the internals of pthread::Mutex less public, to reduce the chance of anyone locking/unlocking a mutex without going through the intercepted methods.

r? @RalfJung

@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. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels May 28, 2025
@RalfJung
Copy link
Member

RalfJung commented May 28, 2025

This LGTM, but someone on t-libs should be on-board with having Miri-specific diagnostic items in the code. We have clippy-specific diagnostic items so I hope this is acceptable. :)

r? @tgross35 or @joboet or @m-ou-se

@rustbot rustbot assigned tgross35 and unassigned RalfJung May 28, 2025
@m-ou-se
Copy link
Member

m-ou-se commented May 28, 2025

Please add a comment above each attribute explaining that it is for Miri's concurrency model checker.

r=me with those comments added.

@m-ou-se m-ou-se assigned m-ou-se and unassigned tgross35 May 28, 2025
@@ -6,7 +6,7 @@ use crate::sys::pal::sync as pal;
use crate::sys::sync::OnceBox;

pub struct Mutex {
pub pal: OnceBox<pal::Mutex>,
pub(in crate::sys::sync) pal: OnceBox<pal::Mutex>,
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this needed for Miri or just a pedantic change? Makes sense in either case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just a pedantic change.

Copy link
Member

Choose a reason for hiding this comment

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

To give more context -- the model checking for mutexes would become weird or even unsound if the mutex API is bypassed by directly accessing the underlying mutex operations, so we wanted to reduce the risk of that happening.

@Patrick-6
Copy link
Contributor Author

I've added the comments.

r? @m-ou-se

@rustbot
Copy link
Collaborator

rustbot commented May 28, 2025

Requested reviewer is already assigned to this pull request.

Please choose another assignee.

@m-ou-se
Copy link
Member

m-ou-se commented May 28, 2025

@bors r+ rollup

@bors
Copy link
Collaborator

bors commented May 28, 2025

📌 Commit 8237107 has been approved by m-ou-se

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 May 28, 2025
tgross35 added a commit to tgross35/rust that referenced this pull request May 28, 2025
Add `rustc_diagnostic_item` to `sys::Mutex` methods

For an ongoing project for adding a concurrency model checker to Miri we need to be able to intercept locking/unlocking operations on standard library mutexes.

This PR adds diagnostic items to the relevant calls `lock`, `try_lock` and `unlock` for the `sys::Mutex` implementation on the targets we care about.
This PR also makes the internals of `pthread::Mutex` less public, to reduce the chance of anyone locking/unlocking a mutex without going through the intercepted methods.

r? `@RalfJung`
bors added a commit that referenced this pull request May 28, 2025
Rollup of 8 pull requests

Successful merges:

 - #125087 (Optimize `Seek::stream_len` impl for `File`)
 - #138285 (Stabilize `repr128`)
 - #139994 (add `CStr::display`)
 - #141477 (Path::with_extension: show that it adds an extension where one did no…)
 - #141533 (clean up old rintf leftovers)
 - #141690 (Add `rustc_diagnostic_item` to `sys::Mutex` methods)
 - #141693 (Subtree update of `rust-analyzer`)
 - #141702 (Add eholk to compiler reviewer rotation)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit that referenced this pull request May 29, 2025
Rollup of 16 pull requests

Successful merges:

 - #136429 (GCI: At their def site, actually wfcheck the where-clause & always eval free lifetime-generic constants)
 - #138139 (Emit warning while outputs is not exe and prints linkage info)
 - #141104 (Test(fs): Fix `test_eq_windows_file_type` for Windows 7)
 - #141477 (Path::with_extension: show that it adds an extension where one did no…)
 - #141533 (clean up old rintf leftovers)
 - #141612 (Call out possibility of invariant result in variance markers)
 - #141638 (Use `builtin_index` instead of hand-rolling it)
 - #141643 (ci: verify that codebuild jobs use ghcr.io)
 - #141675 (Reorder `ast::ItemKind::{Struct,Enum,Union}` fields.)
 - #141680 (replace TraitRef link memory.md)
 - #141682 (interpret/allocation: Fixup type for `alloc_bytes`)
 - #141683 (Handle ed2021 precise capturing of unsafe binder)
 - #141684 (rustbook: Bump versions of `onig` and `onig_sys`)
 - #141687 (core: unstably expose atomic_compare_exchange so stdarch can use it)
 - #141690 (Add `rustc_diagnostic_item` to `sys::Mutex` methods)
 - #141702 (Add eholk to compiler reviewer rotation)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit e7ef07a into rust-lang:master May 29, 2025
7 checks passed
@rustbot rustbot added this to the 1.89.0 milestone May 29, 2025
rust-timer added a commit that referenced this pull request May 29, 2025
Rollup merge of #141690 - Patrick-6:intercept-mutex, r=m-ou-se

Add `rustc_diagnostic_item` to `sys::Mutex` methods

For an ongoing project for adding a concurrency model checker to Miri we need to be able to intercept locking/unlocking operations on standard library mutexes.

This PR adds diagnostic items to the relevant calls `lock`, `try_lock` and `unlock` for the `sys::Mutex` implementation on the targets we care about.
This PR also makes the internals of `pthread::Mutex` less public, to reduce the chance of anyone locking/unlocking a mutex without going through the intercepted methods.

r? ``@RalfJung``
github-actions bot pushed a commit to model-checking/verify-rust-std that referenced this pull request May 30, 2025
Add `rustc_diagnostic_item` to `sys::Mutex` methods

For an ongoing project for adding a concurrency model checker to Miri we need to be able to intercept locking/unlocking operations on standard library mutexes.

This PR adds diagnostic items to the relevant calls `lock`, `try_lock` and `unlock` for the `sys::Mutex` implementation on the targets we care about.
This PR also makes the internals of `pthread::Mutex` less public, to reduce the chance of anyone locking/unlocking a mutex without going through the intercepted methods.

r? ``@RalfJung``
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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. 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.

6 participants