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

Redefine FdFlag #393

Merged
merged 2 commits into from
Jul 31, 2024
Merged

Redefine FdFlag #393

merged 2 commits into from
Jul 31, 2024

Conversation

magicant
Copy link
Owner

@magicant magicant commented Jul 30, 2024

This pull request is part of #353 and replaces the FdFlag type with a platform-independent definition.

Summary by CodeRabbit

  • New Features

    • Enhanced flag management for file descriptors, allowing for multiple flags to be used simultaneously.
  • Bug Fixes

    • Updated assertions across tests to reflect the new EnumSet type for file descriptor flags, improving accuracy and consistency.
  • Refactor

    • Renamed flag fields and updated related logic to utilize EnumSet<FdFlag>, improving flexibility and clarity in flag handling.
  • Documentation

    • Revised comments and documentation to align with changes in flag naming conventions, enhancing readability and understanding.

@magicant magicant added this to the 0.1.0 β3 milestone Jul 30, 2024
@magicant magicant self-assigned this Jul 30, 2024
@magicant magicant mentioned this pull request Jul 30, 2024
17 tasks
Copy link

coderabbitai bot commented Jul 30, 2024

Walkthrough

This update enhances the yash-env project by reworking the handling of file descriptor flags, transitioning from singular flag types to an EnumSet<FdFlag> model. This change promotes more flexible and extensible flag management, allowing multiple flags to be used simultaneously. The modifications span various modules, improving clarity, functionality, and maintaining consistency throughout the codebase.

Changes

Files Change Summary
yash-builtin/src/source/semantics.rs Updated assertions in tests to utilize EnumSet<FdFlag> for flag handling.
yash-env/CHANGELOG.md Documented major type redefinitions and method signature changes for FdFlag and Mode.
yash-env/src/system.rs Updated System trait methods to use EnumSet<FdFlag> for handling flags instead of FdFlag.
yash-env/src/system/fd_flag.rs Introduced a new FdFlag enum with EnumSetType, enhancing flag management capabilities.
yash-env/src/system/real.rs Altered RealSystem methods to accept and return EnumSet<FdFlag> for file descriptor operations.
yash-env/src/system/shared.rs Updated SharedSystem to use EnumSet<FdFlag> in various file descriptor-related methods.
yash-env/src/system/virtual.rs Adjusted VirtualSystem to replace FdFlag with EnumSet<FdFlag> in flag handling.
yash-env/src/system/virtual/io.rs Changed FdBody structure to hold flags: EnumSet<FdFlag> instead of a single FdFlag.
yash-env/src/system/virtual/process.rs Renamed flag to flags in FdBody, updating logic to handle multiple flags.
yash-semantics/src/command/pipeline.rs Modified flag checks and assertions to utilize EnumSet for improved file descriptor management.
yash-semantics/src/redir.rs Renamed FD_CLOEXEC to CloseOnExec, updating function calls to reflect the new naming.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant System
    participant FdFlag
    participant EnumSet

    User->>System: Request file descriptor operation
    System->>FdFlag: Check flags
    FdFlag->>EnumSet: Convert to EnumSet<FdFlag>
    System->>EnumSet: Process multiple flags
    EnumSet-->>System: Return flag status
    System-->>User: Respond with operation result
Loading

🐇 In a world of flags so bright,
The rabbit hops with pure delight.
With EnumSet, we can now play,
Managing bits in a clever way!
Hooray for changes, let’s all cheer,
For clearer code and less to fear! 🌟


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 Configuration 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.

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: 0

Outside diff range, codebase verification and nitpick comments (3)
yash-env/src/system/real.rs (2)

213-214: Ensure all calls to dup use EnumSet<FdFlag>

The change to use EnumSet<FdFlag> improves flexibility. Ensure all calls to dup are updated to use the new flag type. The following instances need to be updated:

  • yash-semantics/src/redir.rs: .dup(target_fd, MIN_INTERNAL_FD, FdFlag::CloseOnExec.into())
  • yash-env/src/system/virtual.rs: let result = system.dup(Fd::STDOUT, Fd::STDERR, FdFlag::CloseOnExec.into());

Please update these instances to use EnumSet<FdFlag>.

Analysis chain

LGTM! Verify the usage of dup in the codebase.

The change to use EnumSet<FdFlag> improves flexibility. Ensure all calls to dup are updated to use the new flag type.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `dup` match the new signature.

# Test: Search for the function usage. Expect: Only occurrences of the new signature.
rg --type rust -A 5 $'dup'

Length of output: 12553


304-309: Update required for fcntl_setfd calls!

Some calls to fcntl_setfd still use FdFlag::CloseOnExec.into(). These need to be updated to use EnumSet<FdFlag> for consistency with the new function signature.

  • Files to update:
    • yash-semantics/src/redir.rs
    • yash-env/src/system/virtual.rs

Please update these calls to use EnumSet<FdFlag>.

Analysis chain

LGTM! Verify the usage of fcntl_setfd in the codebase.

The change to accept EnumSet<FdFlag> improves flexibility. Ensure all calls to fcntl_setfd are updated to use the new flag type.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `fcntl_setfd` match the new signature.

# Test: Search for the function usage. Expect: Only occurrences of the new signature.
rg --type rust -A 5 $'fcntl_setfd'

Length of output: 4455

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

319-319: Update required in dup function call

The dup function call in yash-semantics/src/redir.rs still uses FdFlag::CloseOnExec.into(). This needs to be updated to use EnumSet<FdFlag> to match the new function signature.

  • File: yash-semantics/src/redir.rs
  • Line: Update the dup call to use EnumSet<FdFlag>.
Analysis chain

LGTM! Verify the usage of dup in the codebase.

The change to use EnumSet<FdFlag> improves flexibility. Ensure all calls to dup are updated to use the new flag type.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `dup` match the new signature.

# Test: Search for the function usage. Expect: Only occurrences of the new signature.
rg --type rust -A 5 $'dup'

Length of output: 12553

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 2ae9caf and 7596630.

Files selected for processing (11)
  • yash-builtin/src/source/semantics.rs (2 hunks)
  • yash-env/CHANGELOG.md (2 hunks)
  • yash-env/src/system.rs (6 hunks)
  • yash-env/src/system/fd_flag.rs (1 hunks)
  • yash-env/src/system/real.rs (3 hunks)
  • yash-env/src/system/shared.rs (6 hunks)
  • yash-env/src/system/virtual.rs (10 hunks)
  • yash-env/src/system/virtual/io.rs (2 hunks)
  • yash-env/src/system/virtual/process.rs (2 hunks)
  • yash-semantics/src/command/pipeline.rs (6 hunks)
  • yash-semantics/src/redir.rs (5 hunks)
Files skipped from review due to trivial changes (1)
  • yash-semantics/src/redir.rs
Additional comments not posted (33)
yash-env/src/system/fd_flag.rs (4)

1-15: LGTM! Licensing information is correctly formatted.

The licensing information is complete and correctly formatted.


17-17: LGTM! Module-level documentation is clear and informative.

The module-level documentation provides a good overview of the module.


19-19: LGTM! Import statement is necessary and correctly used.

The import of EnumSetType is necessary for defining the FdFlag enum.


21-28: LGTM! FdFlag enum is correctly defined and well-documented.

The FdFlag enum is correctly defined using EnumSetType and includes necessary documentation for each variant. The TODO comment indicates future work.

yash-env/CHANGELOG.md (4)

Line range hint 12-30:
LGTM! "Added" section is accurate and well-documented.

The "Added" section for version 0.3.0 is accurate, complete, and well-documented.


31-43: LGTM! "Changed" section is accurate and well-documented.

The "Changed" section for version 0.3.0 is accurate, complete, and well-documented.


Line range hint 45-47:
LGTM! "Deprecated" section is accurate and well-documented.

The "Deprecated" section for version 0.3.0 is accurate, complete, and well-documented.


Line range hint 49-53:
LGTM! "Removed" section is accurate and well-documented.

The "Removed" section for version 0.3.0 is accurate, complete, and well-documented.

yash-builtin/src/source/semantics.rs (2)

166-166: LGTM! Import statement is necessary and correctly used.

The import of EnumSet is necessary for the updated assertion logic in the test suite.


263-263: LGTM! Updated assertion logic is correct and adheres to best practices.

The updated assertion logic using EnumSet::only(FdFlag::CloseOnExec) is correct and adheres to best practices.

yash-semantics/src/command/pipeline.rs (4)

22-22: Import statement approved.

The EnumSet import is necessary for the new EnumSet type used in the file.


309-309: Code change approved.

The update to use EnumSet::empty() instead of FdFlag::empty() aligns with the new implementation and ensures consistency.


655-656: Code change approved.

The update to check for flags instead of flag in the assertion aligns with the new implementation and ensures that the tests reflect the updated structure of the file descriptor representation.


674-676: Code change approved.

The update to check for flags instead of flag in the assertion aligns with the new implementation and ensures that the tests reflect the updated structure of the file descriptor representation.

Also applies to: 694-694

yash-env/src/system/virtual/io.rs (3)

23-23: Import statement approved.

The EnumSet import is necessary for the new EnumSet type used in the file.


244-244: Code change approved.

The update to use EnumSet<FdFlag> instead of a single FdFlag enhances the flexibility of the FdBody structure by allowing it to hold multiple flags simultaneously.


249-250: Code change approved.

The update to compare the new flags field instead of the previous flag field in the PartialEq implementation ensures that the comparison now reflects the potential for multiple flags.

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

20-20: Module introduction approved.

The fd_flag module is necessary for better organization and encapsulation of the file descriptor flag-related functionality.


34-34: Code change approved.

The update to use the new fd_flag module for the FdFlag import aligns with the new module structure and ensures consistency.


122-122: Code change approved.

The update to use EnumSet<FdFlag> instead of FdFlag in the dup method signature enhances the flexibility of the method by allowing it to accept multiple flags simultaneously.


167-167: Code change approved.

The update to return Result<EnumSet<FdFlag>> instead of Result<FdFlag> in the fcntl_getfd method signature enhances the flexibility of the method by allowing it to return multiple flags simultaneously.


172-172: Code change approved.

The update to accept EnumSet<FdFlag> instead of FdFlag in the fcntl_setfd method signature enhances the flexibility of the method by allowing it to accept multiple flags simultaneously.

yash-env/src/system/real.rs (1)

294-301: LGTM! Verify the usage of fcntl_getfd in the codebase.

The change to return EnumSet<FdFlag> improves flexibility. Ensure all calls to fcntl_getfd are updated to handle the new return type.

yash-env/src/system/virtual/process.rs (1)

Line range hint 598-661: LGTM! Verify the usage of FdBody in the codebase.

The change to use EnumSet<FdFlag> improves flexibility. Ensure all instances of FdBody are updated to handle the new flag type.

Verification successful

All instances of FdBody have been updated to handle the new flag type EnumSet<FdFlag>.

The changes are consistent across the codebase, ensuring proper handling of the new flag type.

  • yash-env/src/system/virtual.rs
  • yash-env/src/system/virtual/process.rs
  • yash-env/src/system/virtual/io.rs
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all instances of `FdBody` are updated to handle the new flag type.

# Test: Search for the struct usage. Expect: Only occurrences of the new flag type.
rg --type rust -A 5 $'FdBody'

Length of output: 7413

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

346-346: LGTM! Verify the usage of fcntl_getfd in the codebase.

The change to return EnumSet<FdFlag> improves flexibility. Ensure all calls to fcntl_getfd are updated to handle the new return type.

Verification successful

LGTM! Verify the usage of fcntl_getfd in the codebase.

The change to return EnumSet<FdFlag> improves flexibility. Ensure all calls to fcntl_getfd are updated to handle the new return type.

  • yash-semantics/src/redir.rs: The call to fcntl_getfd correctly uses the contains method.
  • yash-env/src/system/virtual.rs: The calls to fcntl_getfd correctly use the unwrap method and handle EnumSet<FdFlag>.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `fcntl_getfd` match the new return type.

# Test: Search for the function usage. Expect: Only occurrences of the new return type.
rg --type rust -A 5 $'fcntl_getfd'

Length of output: 4215


349-349: LGTM! Verify the usage of fcntl_setfd in the codebase.

The change to accept EnumSet<FdFlag> improves flexibility. Ensure all calls to fcntl_setfd are updated to use the new flag type.

yash-env/src/system/virtual.rs (7)

165-165: LGTM!

The initialization of flags with EnumSet::empty() aligns with the new flag management strategy.


402-406: LGTM!

The initialization of flags with EnumSet::empty() aligns with the new flag management strategy.


418-421: LGTM!

The update to accept EnumSet<FdFlag> for flags and setting the flags field aligns with the new flag management strategy.


428-428: LGTM!

Setting the flags field to EnumSet::empty() aligns with the new flag management strategy.


499-502: LGTM!

The conditional initialization of the flags field with EnumSet::only(FdFlag::CloseOnExec) or EnumSet::empty() aligns with the new flag management strategy.


558-561: LGTM!

The update to return EnumSet<FdFlag> for fcntl_getfd aligns with the new flag management strategy.


564-567: LGTM!

The update to accept EnumSet<FdFlag> for fcntl_setfd and setting the flags field aligns with the new flag management strategy.

@magicant magicant merged commit 6b484d8 into master Jul 31, 2024
6 checks passed
@magicant magicant deleted the fd-flag branch July 31, 2024 14:46
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