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

[ECO-4968] Added missed NS_SWIFT_SENDABLE #1973

Closed
wants to merge 6 commits into from

Conversation

maratal
Copy link
Collaborator

@maratal maratal commented Sep 12, 2024

By analogy with ARTRealtimePresenceQuery (which causes warning in Xcode 16) I've added NS_SWIFT_SENDABLE to other query types as well.

Closes #1971

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced the ARTBaseQuery component, enhancing query capabilities within the Ably framework.
    • Added properties to various query classes, allowing for more granular control over query parameters, including start, end, limit, and direction.
    • Enhanced presence query functionality with new properties for improved control over synchronization behavior.
    • Improved handling of statistics queries with a new granularity unit.
    • Added Swift concurrency attributes to ARTChannelOptions and ARTRealtimeChannelOptions for improved interoperability.
  • Bug Fixes

    • Improved immutability checks for query objects to prevent modifications after they are marked as "frozen."
    • Enhanced handling of nil values during encoding and decoding processes to prevent unexpected behavior.
  • Tests

    • Expanded the test suite to include checks for exception handling when modifying frozen query properties, ensuring robustness and reliability.

Copy link

coderabbitai bot commented Sep 12, 2024

Walkthrough

The pull request introduces the ARTBaseQuery component to the Ably project, adding new header and implementation files. It enhances existing classes with immutability features and integrates Swift concurrency annotations (NS_SWIFT_SENDABLE) for improved compatibility. Additionally, the changes include new tests to validate the behavior of query objects under various conditions, ensuring data integrity and adherence to concurrency rules.

Changes

Files Change Summary
Ably.xcodeproj/project.pbxproj Added new files for ARTBaseQuery and included them in the project configuration.
Source/ARTBaseQuery.m Introduced the ARTBaseQuery class with a basic structure and an empty implementation.
Source/include/Ably/ARTBaseQuery.h Defined the ARTBaseQuery interface with a frozen property and custom getter.
Source/ARTDataQuery.m Enhanced ARTDataQuery and ARTRealtimeHistoryQuery with new properties and methods, ensuring immutability.
Source/ARTRealtimePresence.m Introduced new properties and methods to ARTRealtimePresenceQuery, enforcing immutability.
Source/ARTRestPresence.m Enhanced ARTPresenceQuery with new properties and methods, ensuring immutability.
Source/ARTStats.m Introduced _unit property to ARTStatsQuery with appropriate getter and setter methods.
Test/Tests/RealtimeClientChannelTests.swift Added tests for query object's behavior when untilAttach is set to false.
Test/Tests/RealtimeClientPresenceTests.swift Added tests for immutability checks on ARTRealtimePresenceQuery.
Test/Tests/RestClientChannelTests.swift Added tests verifying exceptions when modifying properties of a frozen query object.
Test/Tests/RestClientPresenceTests.swift Added tests for immutability checks on ARTPresenceQuery properties.
Test/Tests/RestClientStatsTests.swift Added tests for behavior of the query.unit property when frozen.
Source/include/Ably/ARTChannelOptions.h Added NS_SWIFT_SENDABLE attribute to ARTChannelOptions.
Source/include/Ably/ARTRealtimeChannelOptions.h Added NS_SWIFT_SENDABLE attribute to ARTRealtimeChannelOptions.

Assessment against linked issues

Objective Addressed Explanation
Add Swift concurrency annotations ( #1971 )
Add Swift concurrency annotations ( #1962 ) The changes implement NS_SWIFT_SENDABLE for multiple classes, addressing concurrency concerns.

Possibly related issues

Possibly related PRs

Suggested reviewers

  • lawrence-forooghian: Suggested reviewer based on involvement with related issues.

Poem

In the meadow where queries play,
A rabbit hops, brightening the day.
With ARTBaseQuery, swift and free,
Concurrency blooms, as sweet as can be.
Immutable paths, no changes to fear,
Hooray for the code, let’s give a cheer! 🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between e20d783 and 756a383.

📒 Files selected for processing (3)
  • Test/Test Utilities/TestUtilities.swift (2 hunks)
  • Test/Tests/RealtimeClientChannelsTests.swift (1 hunks)
  • Test/Tests/RestClientChannelsTests.swift (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • Test/Test Utilities/TestUtilities.swift
  • Test/Tests/RealtimeClientChannelsTests.swift
  • Test/Tests/RestClientChannelsTests.swift

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.

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

Outside diff range and nitpick comments (1)
Source/ARTDataQuery.m (1)

Line range hint 100-131: LGTM, but consider adding documentation comments.

The new instance variable _untilAttach and its corresponding getter and setter methods are implemented correctly in the ARTRealtimeHistoryQuery class. The setter method includes the necessary safeguard to prevent changes when the object is frozen, and the exception provides a clear reason for the failure.

However, the purpose of the untilAttach property is not immediately clear from its name. Consider adding documentation comments to clarify its behavior and usage.

+ /**
+  * Whether the query should continue until an attachment occurs.
+  */
- (BOOL)untilAttach {
     return _untilAttach;
}

+ /**
+  * Sets whether the query should continue until an attachment occurs.
+  *
+  * @param value Whether the query should continue until an attachment occurs.
+  * @throws NSObjectInaccessibleException If the query is frozen.
+  */
- (void)setUntilAttach:(BOOL)value {
     ...
}
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 80f05fd and 179db8e.

Files selected for processing (19)
  • Ably.xcodeproj/project.pbxproj (9 hunks)
  • Source/ARTBaseQuery.m (1 hunks)
  • Source/ARTDataQuery.m (3 hunks)
  • Source/ARTRealtimePresence.m (3 hunks)
  • Source/ARTRest.m (1 hunks)
  • Source/ARTRestChannel.m (1 hunks)
  • Source/ARTRestPresence.m (4 hunks)
  • Source/ARTStats.m (2 hunks)
  • Source/Ably.modulemap (1 hunks)
  • Source/include/Ably/ARTBaseQuery.h (1 hunks)
  • Source/include/Ably/ARTDataQuery.h (3 hunks)
  • Source/include/Ably/ARTRealtimePresence.h (1 hunks)
  • Source/include/Ably/ARTRestPresence.h (2 hunks)
  • Source/include/Ably/ARTStats.h (1 hunks)
  • Test/Tests/RealtimeClientChannelTests.swift (1 hunks)
  • Test/Tests/RealtimeClientPresenceTests.swift (2 hunks)
  • Test/Tests/RestClientChannelTests.swift (1 hunks)
  • Test/Tests/RestClientPresenceTests.swift (1 hunks)
  • Test/Tests/RestClientStatsTests.swift (1 hunks)
Files skipped from review due to trivial changes (1)
  • Source/ARTBaseQuery.m
Additional comments not posted (43)
Source/include/Ably/ARTDataQuery.h (4)

2-2: LGTM!

The import statement is correct and consistent with the change in the base class of ARTDataQuery.


17-17: LGTM!

The addition of the NS_SWIFT_SENDABLE attribute to ARTDataQuery is consistent with the PR objective to enhance compatibility with Swift's concurrency model. This change allows instances of ARTDataQuery to be safely used across Swift concurrency domains.


45-45: LGTM!

The addition of the NS_SWIFT_SENDABLE attribute to ARTRealtimeHistoryQuery is consistent with the PR objective to enhance compatibility with Swift's concurrency model. This change allows instances of ARTRealtimeHistoryQuery to be safely used across Swift concurrency domains.


18-18: Verify the impact of inheriting from ARTBaseQuery.

The change in the base class of ARTDataQuery from NSObject to ARTBaseQuery suggests a refactoring effort to leverage common functionality from a base query class. While this is a good approach to promote code reuse and maintainability, it's crucial to ensure that this change doesn't break existing functionality or introduce unexpected behavior.

Please run the following script to verify the impact of this change:

Source/include/Ably/ARTRestPresence.h (2)

5-5: LGTM!

The import statement is necessary and correctly placed to support the change in the inheritance structure of ARTPresenceQuery class.


14-15: Verify the impact of the changes.

The modifications to the ARTPresenceQuery class declaration look good! The changes align with the PR objectives and enhance the functionality of the class.

However, please ensure that:

  1. The change in the inheritance structure does not introduce any unintended side effects or break existing functionality.
  2. All the necessary adjustments are made in the implementation file (ARTRestPresence.m) to accommodate the new inheritance structure.
  3. The addition of the NS_SWIFT_SENDABLE attribute does not lead to any unexpected behavior or performance issues when used in Swift code.

Run the following script to verify the impact of the changes:

Please review the results of the above tests and confirm if any additional changes are required to ensure the stability and correctness of the codebase.

Verification successful

Changes verified successfully.

The modifications to the ARTPresenceQuery class, including the change in inheritance and the addition of the NS_SWIFT_SENDABLE attribute, have been verified. The usage and initialization patterns are consistent with the rest of the codebase, and no issues or unintended side effects were found. The changes align well with the PR objectives and enhance the functionality of the class.

  • The ARTPresenceQuery class is used appropriately in both Objective-C and Swift code.
  • The inheritance from ARTBaseQuery is consistent with other query classes.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the impact of the changes to `ARTPresenceQuery` class.

echo "Checking the usage of ARTPresenceQuery..."
# Test 1: Search for the usage of `ARTPresenceQuery`. 
# Expect: Occurrences in the implementation file and Swift code (if any).
rg --type objc --type swift -w $'ARTPresenceQuery'

echo "Checking the initialization of ARTPresenceQuery..."
# Test 2: Search for the initialization of `ARTPresenceQuery`. 
# Expect: Initialization using the designated initializers declared in the header file.
rg --type objc --type swift -w $'ARTPresenceQuery alloc] init'

echo "Checking the usage of ARTBaseQuery..."
# Test 3: Search for the usage of `ARTBaseQuery`. 
# Expect: Occurrences in other query classes (if any).
rg --type objc --type swift -w $'ARTBaseQuery'

Length of output: 2445

Source/Ably.modulemap (1)

17-17: LGTM!

The addition of ARTBaseQuery.h to the Private module of the Ably framework appears to be a valid change that aligns with the PR objective of adding Swift concurrency annotations to query types. This change expands the module's internal capabilities related to query handling, as indicated by the AI-generated summary.

Source/ARTDataQuery.m (4)

4-9: LGTM!

The new instance variables are declared correctly and follow good encapsulation practices by keeping them private to the class.


46-57: LGTM!

The getter and setter methods for the start property are implemented correctly. The setter method includes the necessary safeguard to prevent changes when the object is frozen, and the exception provides a clear reason for the failure.


72-83: LGTM!

The getter and setter methods for the limit property are implemented correctly. The setter method includes the necessary safeguard to prevent changes when the object is frozen, and the exception provides a clear reason for the failure.


85-96: LGTM!

The getter and setter methods for the direction property are implemented correctly. The setter method includes the necessary safeguard to prevent changes when the object is frozen, and the exception provides a clear reason for the failure.

Source/ARTStats.m (3)

4-6: LGTM!

The addition of the _unit instance variable to the ARTStatsQuery class enhances its functionality by allowing the specification of a granularity unit for statistics queries. The default initialization to ARTStatsGranularityMinute in the init method provides a sensible default value. The code changes are consistent with the existing codebase and follow the Objective-C naming conventions.


39-41: LGTM!

The unit method provides a getter for the _unit instance variable, allowing external code to retrieve the current granularity unit of the query. The method follows the Objective-C naming convention for getter methods and is simple and straightforward.


43-50: LGTM!

The setUnit: method provides a setter for the _unit instance variable, allowing external code to modify the granularity unit of the query. The method follows the Objective-C naming convention for setter methods.

The check to prevent modification of a frozen query object is important to maintain the integrity of the query once it has been passed to a receiver. The exception thrown in case of an attempt to modify a frozen query provides a clear and informative error message.

Source/ARTRestPresence.m (6)

17-21: LGTM!

The addition of the new instance variables _limit, _clientId, and _connectionId to the ARTPresenceQuery class aligns with the PR objectives. The variables are declared as private, which is a good practice for encapsulation, and the naming convention is consistent with the existing codebase.


56-67: LGTM!

The getter and setter methods for the limit property provide a clean interface for accessing and modifying the property. The check in the setter method to prevent modifications after the query is frozen is a good practice to maintain the integrity of the query, and the exception thrown provides a clear explanation of the error.


69-80: LGTM!

The getter and setter methods for the clientId property provide a clean interface for accessing and modifying the property. The check in the setter method to prevent modifications after the query is frozen is a good practice to maintain the integrity of the query, and the exception thrown provides a clear explanation of the error.


82-93: LGTM!

The getter and setter methods for the connectionId property provide a clean interface for accessing and modifying the property. The check in the setter method to prevent modifications after the query is frozen is a good practice to maintain the integrity of the query, and the exception thrown provides a clear explanation of the error.


176-177: LGTM!

Setting the frozen state of the query to true after it is used in the get method is a good practice to ensure that the query parameters cannot be altered post-processing. This change aligns with the PR objectives of enhancing the robustness of the ARTPresenceQuery class by enforcing stricter control over its state and parameters.


223-224: LGTM!

Setting the frozen state of the query to true after it is used in the history method is a good practice to ensure that the query parameters cannot be altered post-processing. This change aligns with the PR objectives of enhancing the robustness of the ARTPresenceQuery class by enforcing stricter control over its state and parameters.

Source/include/Ably/ARTRealtimePresence.h (1)

13-13: LGTM!

The addition of the NS_SWIFT_SENDABLE annotation to the ARTRealtimePresenceQuery interface is a valid change that enhances compatibility with Swift's concurrency model. It aligns with the PR objectives and does not alter the existing functionality or logic of the interface.

Source/include/Ably/ARTStats.h (1)

33-33: LGTM!

The addition of the NS_SWIFT_SENDABLE attribute to the ARTStatsQuery interface is a valid change that aligns with the PR objectives. It ensures that instances of this type can be safely used across concurrency domains in Swift, enhancing compatibility with Swift's concurrency model.

Test/Tests/RestClientStatsTests.swift (1)

114-118: LGTM!

The test case is well-structured and follows the given-when-then pattern. It is focused on a specific behavior and has clear assertions. The use of tryInObjC to capture the Objective-C exception and the XCTAssertNotNil and XCTAssertEqual assertions to verify the expected behavior are good practices.

Source/ARTRestChannel.m (1)

164-165: LGTM!

Freezing the query object after this point is a good practice to ensure immutability and thread-safety.

Verify if the frozen property is part of the public API of ARTDataQuery. If so, consider adding documentation to explain its purpose and behavior.

Verification successful

Confirm frozen Property as Public API

The frozen property is part of the public API of ARTDataQuery through its inheritance from ARTBaseQuery. Consider adding documentation to explain its purpose and behavior, as it ensures the immutability of the query object.

  • Source/include/Ably/ARTBaseQuery.h: @property (nonatomic, getter=isFrozen) BOOL frozen;
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify if `frozen` is a public property of `ARTDataQuery` and suggest adding documentation if necessary.

# Test: Search for the declaration of the `frozen` property in `ARTDataQuery`.
# Expect: The property to be declared in the header file, indicating it's part of the public API.
rg --type objc $'@property.*frozen' -- '*.h'

Length of output: 89


Script:

#!/bin/bash
# Locate the definition of the `ARTDataQuery` class to find the correct file.
ast-grep --lang objc --pattern 'interface ARTDataQuery { $$$ }'

# Once the file is located, search for the `frozen` property declaration within it.
# This will help determine if `frozen` is part of the public API.
fd -e h | xargs rg --type objc $'@property.*frozen'

Length of output: 542


Script:

#!/bin/bash
# Search for the definition of `ARTDataQuery` to check its inheritance hierarchy.
rg --type objc 'interface ARTDataQuery' -A 5

Length of output: 845

Test/Tests/RestClientPresenceTests.swift (1)

78-99: LGTM!

The test case is well-structured and comprehensively covers the expected behavior of the limit property on the ARTPresenceQuery class. The addition of the exception handling tests for the frozen query object aligns with the PR objective of adding the NS_SWIFT_SENDABLE annotation to query types.

I particularly like the improvement in the test case where a new instance of ARTPresenceQuery (query2) is used for the successful call to channel.presence.get(query) with a limit of 1000, instead of reusing the frozen query object. This ensures that the test accurately reflects the expected behavior when the query is not frozen.

Source/ARTRest.m (1)

670-671: LGTM!

Freezing the query object before validating the limit and executing the request is a good practice to ensure the query remains unmodified throughout the stats method. This change enhances the robustness and predictability of the method.

Source/ARTRealtimePresence.m (3)

34-36: LGTM!

The waitForSync method provides public read access to the private _waitForSync instance variable. This flag seems to be used to control whether the query should wait for synchronization before returning results.


38-45: LGTM!

The setWaitForSync: method allows setting the value of the private _waitForSync flag. The check to prevent modification of a frozen query is a good practice to ensure immutability and avoid unexpected behavior. Throwing an exception with a clear message is an appropriate way to handle the case when attempting to modify a frozen query.


239-239: LGTM!

Setting the frozen property to true ensures that the query becomes immutable after being passed to the get method. This aligns with the immutability check introduced in the setWaitForSync: method and helps maintain a consistent state throughout the processing of the get request.

Test/Tests/RestClientChannelTests.swift (6)

595-618: LGTM!

The test covers the scenario described in the linked issue #1074 and verifies that publishing messages with no clientId in the client options and credentials that can assume any clientId does not fail.


Line range hint 619-630: LGTM!

The test verifies that publishing with a mismatched clientId fails with an expected error message.


Line range hint 631-694: LGTM!

The test verifies that the extras are correctly included when publishing a message and can be retrieved from history.


Line range hint 695-715: LGTM!

The test verifies that the attributes supplied by the caller, such as id, name, and data, are correctly included in the encoded message when publishing.


Line range hint 716-751: LGTM!

The test verifies that the channel status API returns a channel details object populated with the expected channel metrics when there are subscribers. It checks metrics such as connections, publishers, subscribers, presenceMembers, presenceConnections, and presenceSubscribers.


Line range hint 752-771: LGTM!

The test verifies that when a channel name contains a slash character, it is correctly URL-encoded in the REST request path. This ensures that the slash is properly handled and does not cause issues with the request URL.

Test/Tests/RealtimeClientPresenceTests.swift (2)

3248-3252: LGTM!

Good test case to verify that the waitForSync property of ARTRealtimePresenceQuery cannot be modified after initialization, as expected. The object should be frozen.


3555-3561: Looks good!

Another good test to ensure the untilAttach property of ARTRealtimeHistoryQuery is also frozen after initialization, matching the immutability semantics tested for waitForSync above.

Test/Tests/RealtimeClientChannelTests.swift (1)

3664-3669: Test looks good!

The test correctly verifies that when publishing a message with both name and data set:

  1. The client connects and reaches the connected state
  2. The published message's name and data are sent in the ProtocolMessage
  3. The ProtocolMessage also contains the correct connectionId
Ably.xcodeproj/project.pbxproj (5)

302-304: LGTM!

Adding ARTBaseQuery.h to the "Headers" build phase with the private attribute is the correct way to include it in the project.


305-307: LGTM!

Adding ARTBaseQuery.m to the "Sources" build phase is the correct way to include it in the project.


1254-1255: LGTM!

The file references for ARTBaseQuery.h and ARTBaseQuery.m are correctly added. The header file is placed in the include/Ably directory, and the implementation file is at the root level, which follows the project's file structure conventions.


2136-2137: LGTM!

Adding ARTBaseQuery.h and ARTBaseQuery.m to this group of files is appropriate, as it keeps related files together in the project structure.


2245-2245: LGTM!

Adding ARTBaseQuery.h to the "Headers" build phase is consistent with the previous changes and ensures that the header file is included in the appropriate build phase.

Source/include/Ably/ARTBaseQuery.h Outdated Show resolved Hide resolved
Source/ARTDataQuery.m Outdated Show resolved Hide resolved
…code 16) I've added `NS_SWIFT_SENDABLE` to other query types as well.

Also added NS_SWIFT_SENDABLE to `ARTChannelProperties`.
@maratal maratal force-pushed the fix/1971-swift-concurrency-annotations branch from 179db8e to bfaaba1 Compare September 12, 2024 18:42
@github-actions github-actions bot temporarily deployed to staging/pull/1973/features September 12, 2024 18:43 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/1973/jazzydoc September 12, 2024 18:46 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/1973/features September 12, 2024 20:20 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/1973/jazzydoc September 12, 2024 20:23 Inactive
@umair-ably
Copy link
Contributor

ARTChannelProperties also needs to be Sendable

@github-actions github-actions bot temporarily deployed to staging/pull/1973/features September 17, 2024 12:55 Inactive
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: 4

Outside diff range and nitpick comments (1)
Test/Tests/RestClientChannelsTests.swift (1)

6-6: Improve the code comment for clarity

Consider rephrasing the comment to be more informative and professional. Instead of stating that "Swift isn't yet smart enough," you might specify the limitation or refer to the issue with bridging Objective-C APIs in Swift versions prior to Swift 6.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between e22ff7c and 42e5ba9.

Files selected for processing (4)
  • Source/ARTDataEncoder.m (2 hunks)
  • Test/Test Utilities/TestUtilities.swift (2 hunks)
  • Test/Tests/RealtimeClientChannelsTests.swift (1 hunks)
  • Test/Tests/RestClientChannelsTests.swift (1 hunks)
Additional comments not posted (2)
Test/Tests/RestClientChannelsTests.swift (1)

5-11: Conditional conformance implementation is appropriate

The use of conditional compilation to provide retroactive conformance to Sequence for Swift versions 6 and above is a good approach to maintain compatibility across different Swift versions.

Test/Tests/RealtimeClientChannelsTests.swift (1)

5-12: Appropriate use of @retroactive attribute for Swift 6 and above

The conditional compilation correctly applies the @retroactive attribute to the Sequence conformance for Swift versions 6 and above. This ensures compatibility with the latest Swift features while maintaining functionality for earlier versions of Swift.

Also applies to: 19-19

Test/Tests/RestClientChannelsTests.swift Outdated Show resolved Hide resolved
Source/ARTDataEncoder.m Outdated Show resolved Hide resolved
Source/ARTDataEncoder.m Outdated Show resolved Hide resolved
Test/Test Utilities/TestUtilities.swift Show resolved Hide resolved
@github-actions github-actions bot temporarily deployed to staging/pull/1973/jazzydoc September 17, 2024 13:00 Inactive
@maratal maratal force-pushed the fix/1971-swift-concurrency-annotations branch from 42e5ba9 to 75e9554 Compare September 17, 2024 13:23
@github-actions github-actions bot temporarily deployed to staging/pull/1973/features September 17, 2024 13:24 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/1973/jazzydoc September 17, 2024 13:28 Inactive
@umair-ably
Copy link
Contributor

LGTM - I checked this against the sending and receiving messages work and I have no warnings 🎉

worth checking if @lawrence-forooghian wants to give it another once over

maratal added a commit to ably/ably-chat-swift that referenced this pull request Sep 22, 2024
maratal added a commit to ably/ably-chat-swift that referenced this pull request Sep 22, 2024
@umair-ably
Copy link
Contributor

Also ARTRealtimeChannelOptions please 🙏

@maratal maratal changed the title [ECO-4968] Added NS_SWIFT_SENDABLE to all query types [ECO-4968] Added missed NS_SWIFT_SENDABLE Sep 22, 2024
@maratal maratal requested a review from umair-ably September 22, 2024 23:57
@github-actions github-actions bot temporarily deployed to staging/pull/1973/features September 22, 2024 23:58 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/1973/jazzydoc September 23, 2024 00:01 Inactive
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: 1

Outside diff range and nitpick comments (2)
Source/include/Ably/ARTChannelOptions.h (2)

Line range hint 20-20: Address TODO comment for missing docstring.

There's a TODO comment indicating a missing docstring for the initWithCipher: method. It would be beneficial to add a proper documentation comment here to improve code clarity and maintainability.

Consider adding a docstring that explains the purpose of this method, its parameters, and return value. For example:

/**
 * Initializes a new instance of ARTChannelOptions with the specified cipher parameters.
 *
 * @param cipherParams The cipher parameters to be used for encryption. Pass nil for no encryption.
 * @return An initialized ARTChannelOptions instance.
 */
- (instancetype)initWithCipher:(id<ARTCipherParamsCompatible> _Nullable)cipherParams;

Line range hint 28-30: Enhance docstring for initWithCipherKey: method.

While the current docstring provides basic information, it could be more detailed to improve clarity and usability.

Consider expanding the docstring to provide more context and details:

/**
 * Creates an ARTChannelOptions object with encryption enabled using the specified key.
 *
 * @param key A private key used to encrypt and decrypt payloads. The key should be compatible with the ARTCipherKeyCompatible protocol.
 *
 * @return An initialized ARTChannelOptions instance with encryption enabled.
 *
 * @note This method simplifies the process of setting up channel encryption by allowing you to provide just the key. For more advanced encryption options, use initWithCipher: instead.
 */
- (instancetype)initWithCipherKey:(id<ARTCipherKeyCompatible>)key;
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 75e9554 and e20d783.

Files selected for processing (2)
  • Source/include/Ably/ARTChannelOptions.h (1 hunks)
  • Source/include/Ably/ARTRealtimeChannelOptions.h (1 hunks)
Additional comments not posted (3)
Source/include/Ably/ARTChannelOptions.h (1)

11-11: LGTM: NS_SWIFT_SENDABLE attribute added correctly.

The addition of the NS_SWIFT_SENDABLE attribute to the ARTChannelOptions interface is correct and aligns with the PR objectives. This change enhances compatibility with Swift's concurrency model and addresses potential warnings in Xcode 16.

To ensure consistency across the codebase, let's check if other similar types have been annotated:

This will help us identify if there are other interfaces that might benefit from the same annotation.

Verification successful

LGTM: NS_SWIFT_SENDABLE attribute added correctly.

The addition of the NS_SWIFT_SENDABLE attribute to the ARTChannelOptions interface is correct and aligns with the PR objectives. This change enhances compatibility with Swift's concurrency model and maintains consistency with similar annotations across the codebase.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for other types that might need NS_SWIFT_SENDABLE annotation

# Search for interface declarations in header files
rg --type objc -g '*.h' '^\s*@interface' -A 1

# Search for NS_SWIFT_SENDABLE usage
rg --type objc -g '*.h' 'NS_SWIFT_SENDABLE'

Length of output: 43252

Source/include/Ably/ARTRealtimeChannelOptions.h (2)

Line range hint 8-8: Acknowledge correct use of NS_SWIFT_SENDABLE on ARTChannelMode

The NS_SWIFT_SENDABLE attribute on ARTChannelMode is correctly applied. This is consistent with the goal of improving Swift concurrency support throughout the codebase.

To improve documentation, consider adding a comment explaining the thread-safety implications, such as:

/**
 * ARTChannelMode is marked as Sendable, indicating that it can be safely used across different threads or tasks in Swift concurrency contexts.
 * This is inherently true for option sets, which are value types.
 */

Line range hint 1-48: Summary: Improved Swift concurrency support

The changes in this file successfully improve Swift concurrency support by adding NS_SWIFT_SENDABLE to ARTRealtimeChannelOptions. This, along with the existing annotation on ARTChannelMode, enhances the compatibility of these types with Swift's concurrency model.

These modifications align well with the PR objectives and address the concerns raised in the linked issues. The changes should help reduce warnings in Xcode 16 and improve the overall robustness of the codebase when used in concurrent Swift contexts.

To further enhance the documentation, consider adding thread-safety notes to both ARTChannelMode and ARTRealtimeChannelOptions as suggested in the previous comments.

@lawrence-forooghian
Copy link
Collaborator

lawrence-forooghian commented Sep 23, 2024

@maratal the Xcode 16 and Swift 6 stuff is unrelated to this PR; please can you put it in a separate PR?

/// :nodoc:
@interface ARTBaseQuery : NSObject

@property (nonatomic, getter=isFrozen) BOOL frozen;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is this property part of the public API?

@@ -3245,6 +3245,11 @@ class RealtimeClientPresenceTests: XCTestCase {
let params = ARTRealtimePresenceQuery()
params.waitForSync = true
channel.presence.get(params, callback: callback)
let exception = tryInObjC {
Copy link
Collaborator

Choose a reason for hiding this comment

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

As mentioned in another PR, it's quite confusing to have this extra stuff in tests without even an explanation of why it's there; it isn't obviously related to the core of the test. I think best to go in a separate test. Ditto elsewhere.

@@ -8,6 +8,7 @@ NS_ASSUME_NONNULL_BEGIN
/**
* Passes additional properties to an `ARTRestChannel` object, such as encryption.
*/
NS_SWIFT_SENDABLE
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why have you marked the mutable options / query types as NS_SWIFT_SENDABLE? They’re not sendable; they don't synchronise access to their mutable state and aren't safe to share between isolation domains. You didn't mark ARTChannelOptions as sendable in #1963; why would these types be different?

I think it would be helpful for you to explain in more detail what was the motivation for the current PR, so that we can figure out how to solve it. Marking these types (at least in their current state) as sendable isn't correct.

@maratal
Copy link
Collaborator Author

maratal commented Sep 26, 2024

As mentioned by @lawrence-forooghian, it's wrong to mark those types as Sendable. Re ARTRealtimePresenceQuery solved here.

@maratal maratal closed this Sep 26, 2024
@lawrence-forooghian
Copy link
Collaborator

Re ARTRealtimePresenceQuery solved here.

I’m not sure "solved" is the right word; more like "worked around in Chat for now"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Add the rest of swift concurrency annotations
3 participants