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

More swift 6 fixes #105

Merged
merged 2 commits into from
Oct 21, 2024
Merged

More swift 6 fixes #105

merged 2 commits into from
Oct 21, 2024

Conversation

ubfelix
Copy link
Contributor

@ubfelix ubfelix commented Oct 14, 2024

Summary by CodeRabbit

  • New Features
    • Enhanced thread safety for token retrieval and request modification methods.
    • Updated method signatures to support concurrent execution safely.
    • Improved type safety and concurrency support for data loading and streaming methods.

Copy link

coderabbitai bot commented Oct 14, 2024

Walkthrough

The changes involve modifications to the UBURLRequestTokenAuthorization protocol and its extension in the UBURLRequestModifier+TokenAuthorization.swift file, as well as updates to the UBURLDataTask extension in UBURLDataTask+Concurrency.swift. The primary updates include the addition of the @Sendable attribute to completion handler parameters in the getToken and modifyRequest methods, and enhancements to type safety and concurrency support in the MetaData and TaskResult structs, along with various method signatures.

Changes

File Path Change Summary
Sources/UBFoundation/Networking/UBURLRequestModifier+TokenAuthorization.swift Updated method signatures for getToken and modifyRequest to include @Sendable in completion handlers.
Sources/UBFoundation/Networking/Concurrency/UBURLDataTask+Concurrency.swift Updated MetaData and TaskResult structs to conform to Sendable, and modified multiple loadOnce and startStream methods to require T: Sendable.

Possibly related PRs

  • Swift 6 Fixes #104: The changes in this PR involve adding the @Sendable attribute to closures in the UBPushManager class, similar to the modifications made to the getToken and modifyRequest methods in the main PR, which also enhance concurrency safety.

Suggested reviewers

  • Calculable

Poem

In the code where tokens play,
A rabbit hops, and changes sway.
With @Sendable now in sight,
Concurrency shines, a joyful light!
Hopping safe, no data race,
In our swift world, we find our place! 🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between b43e20a and 289eaaf.

📒 Files selected for processing (1)
  • Sources/UBFoundation/Networking/Concurrency/UBURLDataTask+Concurrency.swift (2 hunks)
🧰 Additional context used
🔇 Additional comments (4)
Sources/UBFoundation/Networking/Concurrency/UBURLDataTask+Concurrency.swift (4)

Line range hint 72-94: Ensure components of TaskResult<T> conform to Sendable

The TaskResult<T> struct now requires T: Sendable and conforms to Sendable. Since it stores a ResultTuple<T>, ensure that Result<T, UBNetworkingError> and MetaData also conform to Sendable. Verify that UBNetworkingError and MetaData are Sendable to maintain concurrency safety.

Run the following script to verify conformance:

#!/bin/bash
# Description: Check if UBNetworkingError and MetaData conform to Sendable

# Test: Verify UBNetworkingError conforms to Sendable
ast-grep --lang swift --pattern $'enum UBNetworkingError: Sendable { $$$ }'

# Test: Confirm MetaData conforms to Sendable
ast-grep --lang swift --pattern $'struct MetaData: Sendable { $$$ }'

Line range hint 97-139: Verify all usages of loadOnce comply with T: Sendable constraint

The loadOnce methods now constrain T to Sendable. This change may impact existing code where T does not conform to Sendable. Please ensure that all types used as T in calls to loadOnce conform to Sendable, and update any affected code accordingly.

Run the following script to find and inspect usages of loadOnce:

#!/bin/bash
# Description: Find all usages of `loadOnce` and list the types used for `T`

# Test: Locate calls to `loadOnce` and extract generic types
rg --type swift -A2 'UBURLDataTask\.loadOnce<' --no-filename --line-number

Line range hint 236-254: Verify all usages of startStream comply with T: Sendable constraint

The startStream methods now require T: Sendable. Existing code using types that do not conform to Sendable may be affected. Please check that all types used as T in startStream calls conform to Sendable, and update your code where necessary.

Run the following script to identify usages of startStream:

#!/bin/bash
# Description: Find all usages of `startStream` and list the types used for `T`

# Test: Locate calls to `startStream` and extract generic types
rg --type swift -A2 '\.startStream<' --no-filename --line-number

11-14: ⚠️ Potential issue

Ensure all stored properties in MetaData conform to Sendable

By conforming MetaData to Sendable, it's crucial that all its stored properties (info and response) also conform to Sendable. Please verify that UBNetworkingTaskInfo and HTTPURLResponse conform to Sendable to prevent any concurrency issues.

Run the following script to verify conformance:


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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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 using 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.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

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.

@ubfelix ubfelix requested review from maerki and Calculable October 14, 2024 07:06
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 and nitpick comments (2)
Sources/UBFoundation/Networking/UBURLRequestModifier+TokenAuthorization.swift (2)

20-20: Approve @Sendable addition and address line length

The addition of the @Sendable attribute to the completion handler of the modifyRequest method is excellent, consistent with the previous change, and provides the same thread safety benefits.

However, there's a minor formatting issue:

The line exceeds the recommended 120 character limit. Consider breaking it into multiple lines for better readability:

func modifyRequest(
    _ originalRequest: UBURLRequest,
    completion: @escaping @Sendable (Result<UBURLRequest, Error>) -> Void
) {
    // ... rest of the method implementation
}
🧰 Tools
🪛 SwiftLint

[Warning] 20-20: Line should be 120 characters or less; currently it has 128 characters

(line_length)


Line range hint 1-48: Consider future deprecation of synchronous API

The file currently maintains both synchronous (completion handler-based) and asynchronous (async/await) versions of the token authorization protocol. While this provides flexibility for different use cases, it's worth considering a plan to eventually deprecate the synchronous version in favor of the async version.

As Swift continues to evolve and async/await becomes more prevalent, maintaining a single, modern API could simplify the codebase and improve overall consistency. This is not an immediate action item but something to keep in mind for future updates.

Would you like assistance in creating a deprecation plan or drafting documentation for this potential future change?

🧰 Tools
🪛 SwiftLint

[Warning] 20-20: Line should be 120 characters or less; currently it has 128 characters

(line_length)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between e1c0935 and b43e20a.

📒 Files selected for processing (1)
  • Sources/UBFoundation/Networking/UBURLRequestModifier+TokenAuthorization.swift (1 hunks)
🧰 Additional context used
🪛 SwiftLint
Sources/UBFoundation/Networking/UBURLRequestModifier+TokenAuthorization.swift

[Warning] 20-20: Line should be 120 characters or less; currently it has 128 characters

(line_length)

🔇 Additional comments (1)
Sources/UBFoundation/Networking/UBURLRequestModifier+TokenAuthorization.swift (1)

15-15: Excellent addition of @Sendable attribute

The addition of the @Sendable attribute to the completion handler of the getToken method is a great improvement. This change enhances thread safety by explicitly indicating that the closure can be safely called from concurrent contexts. It aligns well with modern Swift concurrency practices and improves the protocol's compatibility with concurrent code.

Copy link

@maerki maerki merged commit fdc4907 into main Oct 21, 2024
4 checks passed
@maerki maerki deleted the swift-6-fixes branch October 21, 2024 12:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants