-
Notifications
You must be signed in to change notification settings - Fork 353
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
Concurrency: Generalize UnblockCallback to MachineCallback #4106
base: master
Are you sure you want to change the base?
Concurrency: Generalize UnblockCallback to MachineCallback #4106
Conversation
@rustbot ready |
src/concurrency/thread.rs
Outdated
|
||
pub type DyMachineCallback<'tcx> = Box<dyn MachineCallback<'tcx> + 'tcx>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please call this DynMachineCallback<'tcx, T>
.
And then define DynUnblockCallback<'tcx>
as alias for DynMachineCallback<'tcx, UnblockKind>
.
src/concurrency/thread.rs
Outdated
} | ||
|
||
/// Generic callback trait for machine operations. | ||
pub trait MachineCallback<'tcx>: VisitProvenance { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please move this to machine.rs
.
src/concurrency/thread.rs
Outdated
|
||
pub type DyMachineCallback<'tcx> = Box<dyn MachineCallback<'tcx> + 'tcx>; | ||
|
||
/// Macro for creating machine callbacks | ||
#[macro_export] | ||
macro_rules! callback { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should also be in machine.rs
src/concurrency/thread.rs
Outdated
interp_ok(()) | ||
} | ||
MachineCallbackState::TimedOut => { | ||
panic!("Join thread operation received unexpected timeout state - operations do not support timeouts") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to write such a detailed error each time. Also, please avoid the rightwards drift. So instead of a match unblock
, just have something like
assert_eq!(unblock, UnblockKind::Ready);
at the beginning of the function, and then go on with the function body as before.
Thanks for the PR! I left some comments. @rustbot author |
5c8652c
to
7049aa6
Compare
Thank you for your thoughtful review and detailed comments. I've addressed all the feedback to improve the code's quality, ensuring the changes align with your recommendations on callback generics. The PR is now ready for your review, but I’m happy to make further refinements if needed to meet our quality standards. Please feel free to reach out if any part of the changes needs clarification or further attention. :) @rustbot ready |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! This is pretty close.
However, I am not entirely convinced by some of the comments you have been adding. Were they generated by an LLM? See the detailed review for more.
Generating comments with an LLM is fine but they should be reviewed for plausibility and usefulness before putting them in the codebase. I helps me do that review if you let me know which parts are LLM-generated.
src/concurrency/thread.rs
Outdated
} | ||
} | ||
/// Type alias for boxed machine callbacks with generic argument type. | ||
pub type DyMachineCallback<'tcx, T> = Box<dyn MachineCallback<'tcx, T> + 'tcx>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This type alias should also be in machine.rs
, next to the definition of MachineCallback
. Also, please consistently use the Dyn
prefix, not Dy
.
src/machine.rs
Outdated
/// Creates machine callbacks with captured variables and generic argument types. | ||
/// | ||
/// This macro generates the boilerplate needed to create type-safe callbacks: | ||
/// - Creates a struct to hold captured variables | ||
/// - Implements required traits (VisitProvenance, MachineCallback) | ||
/// - Handles proper lifetime and type parameters | ||
/// | ||
/// The callback body receives the interpreter context and completion argument. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again this is a lot of text but not very helpful text. Instead, can you put a small example of how to use the macro? That would be a lot more useful.
src/machine.rs
Outdated
macro_rules! callback { | ||
(@capture<$tcx:lifetime $(,)? $($lft:lifetime),*> | ||
{ $($name:ident: $type:ty),* $(,)? } | ||
@unblock = |$this:ident, $arg:ident: $arg_ty:ty| $body:expr $(,)?) => {{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove the @unblock =
everywhere. Now that there's only one function body here, it should not be needed any more.
src/machine.rs
Outdated
(@capture<$tcx:lifetime $(,)? $($lft:lifetime),*> | ||
{ $($name:ident: $type:ty),* $(,)? } | ||
@unblock = |$this:ident, $arg:ident: $arg_ty:ty| $body:expr $(,)?) => {{ | ||
// Create callback struct with the captured variables and generic type T |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove these comments, they don't add any information that's not already immediately obvious from looking at the code.
Comments are supposed to describe the code in a high-level way, helping the reader understand the goal of the low-level details visible in the code. These comments feel LLM-generated, and LLMs are pretty bad at generating good comments -- writing good comments requires actually understanding the code, which LLMs are not capable of.
src/shims/time.rs
Outdated
@unblock = |_this| { panic!("sleeping thread unblocked before time is up") } | ||
@timeout = |_this| { interp_ok(()) } | ||
@unblock = |_this, unblock: UnblockKind| { | ||
match unblock { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be an assert_eq!(unblock, UnblockKind::TimedOut);
(same below)
There are merge conflicts due to other PRs that landed recently in this repo. Please resolve the merge conflicts. @rustbot author |
* Introduce UnblockKind enum to represent operation outcomes * Consolidate unblock/timeout methods into single callback interface * Update thread blocking system to use new callback mechanism * Refactor mutex and condvar implementations for new callback pattern Signed-off-by: shamb0 <[email protected]>
124770d
to
42ef1d7
Compare
Thank you, @RalfJung, for your detailed feedback on the documentation. I appreciate your emphasis on keeping explanations concise, high-level, and focused on code intent rather than implementation details. I've updated the documentation based on your suggestions and will continue applying these principles to future Miri contributions. While I used an LLM to assist with refining the docstrings, I ensured the revisions align with your guidance to avoid verbosity and redundancy. Your earlier review comments have been addressed, but please let me know if there’s anything else that needs adjustment. I’m also working on gaining a deeper understanding of Miri’s documentation practices to ensure consistency across the codebase. @rustbot ready |
Key Changes:
This is the first PR in a series to add support for asynchronous file operations:
Reference: Requirements Discussion at Add support for vectorized read with libc::readv #4084 (comment)