From c4aa132cb863b7933e3b24bfb5835fad44964d98 Mon Sep 17 00:00:00 2001 From: George Miao Date: Mon, 27 Oct 2025 17:31:48 -0400 Subject: [PATCH 1/2] ci: add job to check code format --- .github/workflows/ci_format.yml | 24 ++++++++++++++ compio-fs/src/file.rs | 16 +++++----- compio-runtime/src/runtime/scheduler/mod.rs | 35 ++++++++++++--------- compio-runtime/tests/drop.rs | 3 +- 4 files changed, 55 insertions(+), 23 deletions(-) create mode 100644 .github/workflows/ci_format.yml diff --git a/.github/workflows/ci_format.yml b/.github/workflows/ci_format.yml new file mode 100644 index 00000000..59a11f31 --- /dev/null +++ b/.github/workflows/ci_format.yml @@ -0,0 +1,24 @@ +name: Check Code Format + +on: + push: + branches: + - master + pull_request: + branches: + - master + +env: + RUST_BACKTRACE: 1 + +jobs: + check: + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v4 + - name: Setup Rust Toolchain + run: | + rustup default nightly + rustup component add rustfmt + - name: Check Format + run: cargo fmt --all -- --check diff --git a/compio-fs/src/file.rs b/compio-fs/src/file.rs index dded606b..3f376b17 100644 --- a/compio-fs/src/file.rs +++ b/compio-fs/src/file.rs @@ -23,11 +23,11 @@ use crate::{Metadata, OpenOptions, Permissions}; /// it was opened with. The `File` type provides **positional** read and write /// operations. The file does not maintain an internal cursor. The caller is /// required to specify an offset when issuing an operation. -/// -/// -/// If you'd like to use methods from [`AsyncRead`](`compio_io::AsyncRead`) or [`AsyncWrite`](`compio_io::AsyncWrite`) traits, -/// you can wrap `File` with [`std::io::Cursor`]. -/// # Examples +/// +/// +/// If you'd like to use methods from [`AsyncRead`](`compio_io::AsyncRead`) or +/// [`AsyncWrite`](`compio_io::AsyncWrite`) traits, you can wrap `File` with +/// [`std::io::Cursor`]. # Examples /// ```ignore /// use compio::fs::File; /// use compio::buf::BufResult; @@ -35,13 +35,13 @@ use crate::{Metadata, OpenOptions, Permissions}; /// /// let file = File::open("foo.txt").await?; /// let cursor = Cursor::new(file); -/// +/// /// let int = cursor.read_u32().await?; /// let float = cursor.read_f32().await?; -/// +/// /// let mut string = String::new(); /// let BufResult(result, string) = cursor.read_to_string(string).await; -/// +/// /// let mut buf = vec![0; 1024]; /// let BufResult(result, buf) = cursor.read_exact(buf).await; /// ``` diff --git a/compio-runtime/src/runtime/scheduler/mod.rs b/compio-runtime/src/runtime/scheduler/mod.rs index 10aa64d8..93f935ae 100644 --- a/compio-runtime/src/runtime/scheduler/mod.rs +++ b/compio-runtime/src/runtime/scheduler/mod.rs @@ -1,11 +1,13 @@ -use crate::runtime::scheduler::{ - drop_hook::DropHook, local_queue::LocalQueue, send_wrapper::SendWrapper, -}; +use std::{cell::RefCell, future::Future, marker::PhantomData, rc::Rc, sync::Arc, task::Waker}; + use async_task::{Runnable, Task}; use compio_driver::NotifyHandle; use crossbeam_queue::SegQueue; use slab::Slab; -use std::{cell::RefCell, future::Future, marker::PhantomData, rc::Rc, sync::Arc, task::Waker}; + +use crate::runtime::scheduler::{ + drop_hook::DropHook, local_queue::LocalQueue, send_wrapper::SendWrapper, +}; mod drop_hook; mod local_queue; @@ -28,8 +30,8 @@ impl TaskQueue { /// Pushes a `Runnable` task to the appropriate queue. /// - /// If the current thread is the same as the creator thread, push to the local queue. - /// Otherwise, push to the sync queue. + /// If the current thread is the same as the creator thread, push to the + /// local queue. Otherwise, push to the sync queue. fn push(&self, runnable: Runnable, notify: &NotifyHandle) { if let Some(local_queue) = self.local_queue.get() { local_queue.push(runnable); @@ -41,7 +43,8 @@ impl TaskQueue { } } - /// Pops at most one task from each queue and returns them as `(local_task, sync_task)`. + /// Pops at most one task from each queue and returns them as `(local_task, + /// sync_task)`. /// /// # Safety /// @@ -52,7 +55,8 @@ impl TaskQueue { let local_task = local_queue.pop(); - // Perform an empty check as a fast path, since `SegQueue::pop()` is more expensive. + // Perform an empty check as a fast path, since `SegQueue::pop()` is more + // expensive. let sync_task = if self.sync_queue.is_empty() { None } else { @@ -145,13 +149,15 @@ impl Scheduler { }; let schedule = { - // The schedule closure is managed by the `Waker` and may be dropped on another thread, - // so use `Weak` to ensure the `TaskQueue` is always dropped on the creator thread. + // The schedule closure is managed by the `Waker` and may be dropped on another + // thread, so use `Weak` to ensure the `TaskQueue` is always dropped + // on the creator thread. let task_queue = Arc::downgrade(&self.task_queue); move |runnable| { - // The `upgrade()` never fails because all tasks are dropped when the `Scheduler` is dropped, - // if a `Waker` is used after that, the schedule closure will never be called. + // The `upgrade()` never fails because all tasks are dropped when the + // `Scheduler` is dropped, if a `Waker` is used after that, the + // schedule closure will never be called. task_queue.upgrade().unwrap().push(runnable, ¬ify); } }; @@ -216,8 +222,9 @@ impl Scheduler { // Then drop all scheduled tasks, which will drop all futures. // // SAFETY: - // Since spawned tasks are not required to be `Send`, they must always be dropped - // on the same thread. Because `Scheduler` is `!Send` and `!Sync`, this is safe. + // Since spawned tasks are not required to be `Send`, they must always be + // dropped on the same thread. Because `Scheduler` is `!Send` and + // `!Sync`, this is safe. // // This method is only called on `TaskQueue`'s creator thread // because `Scheduler` is `!Send` and `!Sync`. diff --git a/compio-runtime/tests/drop.rs b/compio-runtime/tests/drop.rs index 136b4e22..f5cc34e7 100644 --- a/compio-runtime/tests/drop.rs +++ b/compio-runtime/tests/drop.rs @@ -1,4 +1,3 @@ -use futures_util::task::AtomicWaker; use std::{ future::Future, pin::Pin, @@ -7,6 +6,8 @@ use std::{ thread::{self, ThreadId}, }; +use futures_util::task::AtomicWaker; + struct DropWatcher { waker: Arc, thread_id: ThreadId, From f2cd177c1dfad797464eacea5f2a547e430b4311 Mon Sep 17 00:00:00 2001 From: Pop Date: Mon, 27 Oct 2025 17:35:45 -0400 Subject: [PATCH 2/2] style: compio-fs/src/file.rs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- compio-fs/src/file.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/compio-fs/src/file.rs b/compio-fs/src/file.rs index 3f376b17..4afbd150 100644 --- a/compio-fs/src/file.rs +++ b/compio-fs/src/file.rs @@ -27,7 +27,9 @@ use crate::{Metadata, OpenOptions, Permissions}; /// /// If you'd like to use methods from [`AsyncRead`](`compio_io::AsyncRead`) or /// [`AsyncWrite`](`compio_io::AsyncWrite`) traits, you can wrap `File` with -/// [`std::io::Cursor`]. # Examples +/// [`std::io::Cursor`]. +/// +/// # Examples /// ```ignore /// use compio::fs::File; /// use compio::buf::BufResult;