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

Allow SharedSystem to be used behind a non-mutable reference #378

Merged
merged 4 commits into from
Jul 4, 2024

Conversation

magicant
Copy link
Owner

@magicant magicant commented Jul 3, 2024

Summary by CodeRabbit

  • New Features

    • Introduced SelectSystem for asynchronous I/O, signal handling, and timers coordination.
    • Added support for managing asynchronous events via AsyncIo, AsyncTime, and AsyncSignal.
  • Bug Fixes

    • Improved efficiency of handling I/O, signals, and timers.
  • Refactor

    • Integrated SharedSystem methods into SelectSystem.
  • Tests

    • Enhanced and added tests for new asynchronous components and functionalities.

To keep the system module focused on the System trait, this commit
extracts the SelectSystem struct and related items to a new file.
@magicant magicant self-assigned this Jul 3, 2024
Copy link

coderabbitai bot commented Jul 3, 2024

Walkthrough

The changes enhance asynchronous operations in the yash-env project by refactoring the SharedSystem methods into SelectSystem and introducing helper structs (AsyncIo, AsyncTime, AsyncSignal). It now allows non-mutable references for operations, covering asynchronous I/O, time management, and signal handling, improving modularity and maintainability.

Changes

File(s) Summary
.../CHANGELOG.md Updated to reflect allowing SharedSystem methods with non-mutable references and other refactoring details.
.../system.rs Added new modules, removed SharedSystem, integrated its methods into SelectSystem, and introduced helper structs.
.../system/select.rs Introduced SelectSystem along with related structs (AsyncIo, AsyncTime, AsyncSignal) and their methods.

Poem

Out of the code where logic streams,
Systems refactored with async dreams.
From shared to select, they elegantly flow,
In IO and time, their prowess will show.
A rabbit’s whisker guides these lines,
Through changes vast, the project shines.
🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

This commit updates the `SharedSystem` methods `set_nonblocking`,
`reset_nonblocking`, `read_async`, `write_all`, and `print_error` to
take immutable references (`&self`) instead of mutable references
(`&mut self`).

This change is made to reflect the fact that these methods do not
mutate the `SharedSystem` instance itself, but rather the `SelectSystem`
instance that it contains.

Previously, when you have a non-mutable reference to a `SharedSystem`,
you had to clone it to call these methods. Now, you can call them
directly.
@magicant magicant marked this pull request as ready for review July 4, 2024 15:41
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between a9248d1 and f5bea99.

Files selected for processing (4)
  • yash-env/CHANGELOG.md (1 hunks)
  • yash-env/src/system.rs (7 hunks)
  • yash-env/src/system/select.rs (1 hunks)
  • yash-env/src/system/shared.rs (1 hunks)
Additional context used
Learnings (1)
yash-env/CHANGELOG.md (2)
Learnt from: magicant
PR: magicant/yash-rs#367
File: yash-env/src/system.rs:57-57
Timestamp: 2024-06-08T02:51:51.839Z
Learning: The `yash-env/src/subshell.rs` module depends on `SigSet`, which requires `nix::sys::signal::Signal`. Plans are in place to remove `SigSet` in a future PR, and some existing methods like `tcsetpgrp_with_block` still depend on `nix::sys::signal::Signal`.
Learnt from: magicant
PR: magicant/yash-rs#367
File: yash-env/src/subshell.rs:40-40
Timestamp: 2024-06-08T02:49:23.406Z
Learning: The `yash-env/src/subshell.rs` module depends on `SigSet`, which requires `nix::sys::signal::Signal`. Plans are in place to remove `SigSet` in a future PR.
Markdownlint
yash-env/CHANGELOG.md

23-23: Expected: 2; Actual: 4
Unordered list indentation

(MD007, ul-indent)


28-28: Expected: 2; Actual: 4
Unordered list indentation

(MD007, ul-indent)


30-30: Expected: 2; Actual: 4
Unordered list indentation

(MD007, ul-indent)


32-32: Expected: 2; Actual: 4
Unordered list indentation

(MD007, ul-indent)


33-33: Expected: 2; Actual: 4
Unordered list indentation

(MD007, ul-indent)


34-34: Expected: 2; Actual: 4
Unordered list indentation

(MD007, ul-indent)

Additional comments not posted (15)
yash-env/src/system/select.rs (6)

1-16: File header looks good.

The licensing information is correctly formatted.


17-63: Struct definition looks good.

The SelectSystem struct is well-defined and the fields are appropriately documented.


65-76: Trait implementations look good.

The Deref and DerefMut trait implementations for SelectSystem are correct.


78-221: Method implementations look good.

The methods for SelectSystem are well-documented and follow standard practices. The logic appears correct and efficient.


224-463: Struct and method definitions look good.

The AsyncIo, FdAwaiter, AsyncTime, Timeout, and AsyncSignal structs, along with their methods, are well-defined and follow standard practices. The logic appears correct and efficient.


466-600: Test cases look good.

The test cases for the new components are comprehensive and cover various scenarios. They follow standard testing practices.

yash-env/src/system/shared.rs (4)

1-16: File header looks good.

The licensing information is correctly formatted.


17-121: Struct definition looks good.

The SharedSystem struct is well-defined and the fields are appropriately documented.


123-307: Method implementations look good.

The methods for SharedSystem are well-documented and follow standard practices. The logic appears correct and efficient.


310-679: Trait implementations look good.

The System and SignalSystem trait implementations for SharedSystem are correct and follow standard practices.

yash-env/src/system.rs (5)

Line range hint 1-708:
Overall consistency of the file.

The file is consistent with the changes including the addition of new modules and usages, and the removal of SharedSystem.


37-38: Usages of SelectSystem and SignalStatus added.

The addition of the usages of SelectSystem and SignalStatus looks good.

Verify the usages of SelectSystem and SignalStatus to ensure they are correctly implemented.

Verification successful

Usages of SelectSystem and SignalStatus are correctly implemented.

The usages of SelectSystem and SignalStatus have been verified across multiple files and appear to be correctly implemented.

  • SelectSystem is defined and used in system.rs, select.rs, shared.rs, virtual.rs, and process.rs.
  • SignalStatus is defined and used in system.rs, select.rs, and shared.rs.

All usages align with their respective imports and definitions.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usages of `SelectSystem` and `SignalStatus`.

# Test: List the usages of `SelectSystem` and `SignalStatus`. Expect: Correct implementation of the usages.
rg --type rust 'SelectSystem'
rg --type rust 'SignalStatus'

Length of output: 4794


39-39: Removal of SharedSystem.

The removal of SharedSystem looks good.

Verify the impact of the removal of SharedSystem to ensure it does not affect the functionality.


707-708: Tests updated to use SharedSystem.

The updates to the tests to use SharedSystem look good.

Verify the correctness of the updated tests to ensure they correctly use SharedSystem.

Verification successful

Verified the usage of Poll and Duration.

The imports std::task::Poll and std::time::Duration are correctly used in the codebase, particularly in yash-env/src/system.rs and related files. Their usage in various assertions and logic confirms their necessity.

  • Poll is used in multiple assertions and logic checks.
  • Duration is used in time calculations and comparisons.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the correctness of the updated tests.

# Test: Run the updated tests. Expect: All tests pass.
cargo test

Length of output: 85


Script:

#!/bin/bash
# Searching for the usage of `Poll` in the codebase
rg 'Poll' 

# Searching for the usage of `Duration` in the codebase
rg 'Duration'

Length of output: 6076


23-24: Modules select and shared added.

The addition of the select and shared modules looks good.

Verify the contents of the new modules to ensure they are correctly implemented.

Verification successful

Modules select and shared are correctly implemented.

The contents of the select.rs and shared.rs modules have been verified and are correctly implemented with detailed structures and functions.

  • select.rs implements SelectSystem with extensive functionalities for handling asynchronous I/O, signals, and timers.
  • shared.rs implements SharedSystem with detailed methods for asynchronous interactions and system operations.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the contents of the new modules `select` and `shared`.

# Test: List the contents of the new modules. Expect: Correct implementation of the modules.
fd select.rs
fd shared.rs

Length of output: 89


Script:

#!/bin/bash
# Description: Verify the contents of the new modules `select` and `shared`.

# Test: Display the contents of the new modules to ensure correct implementation.
cat yash-env/src/system/select.rs
cat yash-env/src/system/shared.rs

Length of output: 44430

Comment on lines +22 to +23
- `impl System for &SharedSystem` and `impl trap::SignalSystem for &SharedSystem`
- This allows `SharedSystem` to be used as a system behind a non-mutable reference.
Copy link

Choose a reason for hiding this comment

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

Fix unordered list indentation.

The indentation for the unordered list items is incorrect.

-    - This allows `SharedSystem` to be used as a system behind a non-mutable reference.
+  - This allows `SharedSystem` to be used as a system behind a non-mutable reference.
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- `impl System for &SharedSystem` and `impl trap::SignalSystem for &SharedSystem`
- This allows `SharedSystem` to be used as a system behind a non-mutable reference.
- `impl System for &SharedSystem` and `impl trap::SignalSystem for &SharedSystem`
- This allows `SharedSystem` to be used as a system behind a non-mutable reference.
Tools
Markdownlint

23-23: Expected: 2; Actual: 4
Unordered list indentation

(MD007, ul-indent)

Comment on lines +31 to +34
- All inherent methods of `SharedSystem` now take `&self` instead of `&mut self`:
- `SharedSystem::read_async`
- `SharedSystem::write_all`
- `SharedSystem::print_error`
Copy link

Choose a reason for hiding this comment

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

Fix unordered list indentation.

The indentation for the unordered list items is incorrect.

-    - `SharedSystem::read_async`
-    - `SharedSystem::write_all`
-    - `SharedSystem::print_error`
+  - `SharedSystem::read_async`
+  - `SharedSystem::write_all`
+  - `SharedSystem::print_error`
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- All inherent methods of `SharedSystem` now take `&self` instead of `&mut self`:
- `SharedSystem::read_async`
- `SharedSystem::write_all`
- `SharedSystem::print_error`
- All inherent methods of `SharedSystem` now take `&self` instead of `&mut self`:
- `SharedSystem::read_async`
- `SharedSystem::write_all`
- `SharedSystem::print_error`
Tools
Markdownlint

32-32: Expected: 2; Actual: 4
Unordered list indentation

(MD007, ul-indent)


33-33: Expected: 2; Actual: 4
Unordered list indentation

(MD007, ul-indent)


34-34: Expected: 2; Actual: 4
Unordered list indentation

(MD007, ul-indent)

@magicant magicant merged commit 1f9e997 into master Jul 4, 2024
6 checks passed
@magicant magicant deleted the shared-system branch July 4, 2024 16:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

1 participant