Skip to content

Conversation

@leogdion
Copy link
Member

@leogdion leogdion commented Jul 17, 2025

Summary by CodeRabbit

  • New Features

    • Improved concurrency safety by marking various types, protocols, and closures as Sendable.
    • Added a static method for obtaining ISO8601 date formatters.
  • Refactor

    • Updated date parsing and formatting to use a new static factory method for ISO8601 date formatters instead of a shared global instance.

@coderabbitai
Copy link

coderabbitai bot commented Jul 17, 2025

Walkthrough

This update introduces Sendable protocol conformance to several types and protocols in the XMLCoder library, including DateBox, DynamicNodeEncoding, and types within XMLEncoder. It also replaces a shared global ISO8601DateFormatter instance with a static factory method, updating all usage sites accordingly.

Changes

File(s) Change Summary
Sources/XMLCoder/Auxiliaries/Box/DateBox.swift DateBox now conforms to Sendable; uses ISO8601DateFormatter.xmlCoderFormatter() instead of shared instance.
Sources/XMLCoder/Auxiliaries/ISO8601DateFormatter.swift Replaces global shared formatter with static method xmlCoderFormatter(); removes global instance and comments.
Sources/XMLCoder/Encoder/DynamicNodeEncoding.swift DynamicNodeEncoding protocol now conforms to Sendable.
Sources/XMLCoder/Encoder/XMLEncoder.swift Adds Sendable to OutputFormatting and NodeEncoding; marks relevant closures as @Sendable; updates default encoder logic for concurrency safety.

Possibly related PRs

  • Syndikit swift 6.2 #1: The main PR and the retrieved PR both make identical changes to DateBox and ISO8601DateFormatter by replacing a shared formatter instance with a static factory method and adding Sendable conformance, indicating they are directly related.

Poem

In the warren of code, where the dates used to share,
Now each formatter hops with its own little flair.
Sendable rabbits, concurrency in tow,
Safer and swifter, wherever you go!
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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.

@leogdion leogdion merged commit 8ba70f2 into main Jul 17, 2025
3 of 9 checks passed
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

🧹 Nitpick comments (2)
Sources/XMLCoder/Auxiliaries/ISO8601DateFormatter.swift (1)

17-17: Add missing trailing newline.

The file should end with a single trailing newline as indicated by SwiftLint.

 }
+
Sources/XMLCoder/Encoder/XMLEncoder.swift (1)

42-42: Fix colon spacing and approve Sendable conformance.

The Sendable conformance for NodeEncoding is appropriate since it's a simple enum with no associated values.

-    public enum NodeEncoding : Sendable {
+    public enum NodeEncoding: Sendable {
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between efda1cc and a3838b1.

📒 Files selected for processing (4)
  • Sources/XMLCoder/Auxiliaries/Box/DateBox.swift (3 hunks)
  • Sources/XMLCoder/Auxiliaries/ISO8601DateFormatter.swift (1 hunks)
  • Sources/XMLCoder/Encoder/DynamicNodeEncoding.swift (1 hunks)
  • Sources/XMLCoder/Encoder/XMLEncoder.swift (4 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
Sources/XMLCoder/Auxiliaries/Box/DateBox.swift (1)
Sources/XMLCoder/Auxiliaries/ISO8601DateFormatter.swift (1)
  • xmlCoderFormatter (12-16)
Sources/XMLCoder/Encoder/XMLEncoder.swift (8)
Sources/XMLCoder/Encoder/DynamicNodeEncoding.swift (2)
  • nodeEncoding (48-50)
  • nodeEncoding (54-56)
Tests/XMLCoderTests/NodeEncodingStrategyTests.swift (2)
  • nodeEncoding (46-48)
  • nodeEncoding (72-74)
Tests/XMLCoderTests/AdvancedFeatures/AttributedIntrinsicLegacyTest.swift (4)
  • nodeEncoding (89-96)
  • nodeEncoding (116-123)
  • nodeEncoding (135-142)
  • nodeEncoding (178-185)
Tests/XMLCoderTests/AdvancedFeatures/DynamicNodeDecodingLegacyTest.swift (2)
  • nodeEncoding (134-139)
  • nodeEncoding (151-158)
Tests/XMLCoderTests/AdvancedFeatures/AttributedIntrinsicTest.swift (1)
  • nodeEncoding (143-150)
Tests/XMLCoderTests/EscapedCharactersTest.swift (1)
  • nodeEncoding (60-62)
Tests/XMLCoderTests/AdvancedFeatures/DynamicNodeEncodingTest.swift (3)
  • nodeEncoding (124-129)
  • nodeEncoding (141-148)
  • nodeEncoding (289-296)
Tests/XMLCoderTests/RootLevetExtraAttributesTests.swift (1)
  • nodeEncoding (55-60)
🪛 SwiftLint (0.57.0)
Sources/XMLCoder/Auxiliaries/ISO8601DateFormatter.swift

[Warning] 17-17: Files should have a single trailing newline

(trailing_newline)

Sources/XMLCoder/Encoder/XMLEncoder.swift

[Warning] 42-42: Colons should be next to the identifier when specifying a type and next to the key in dictionary literals

(colon)

🔇 Additional comments (7)
Sources/XMLCoder/Auxiliaries/ISO8601DateFormatter.swift (1)

11-17: Excellent refactoring for thread safety!

The change from a shared global ISO8601DateFormatter instance to a static factory method is a great improvement for concurrency safety. Each call creates a fresh formatter instance, eliminating any potential race conditions from shared state.

Sources/XMLCoder/Auxiliaries/Box/DateBox.swift (2)

47-47: LGTM: Proper usage of the new factory method.

The replacement of the global formatter with ISO8601DateFormatter.xmlCoderFormatter() is correct and maintains the same functionality while improving thread safety.


73-73: LGTM: Consistent usage of the new factory method.

The replacement maintains consistency with the other usage site and correctly applies the thread-safe pattern.

Sources/XMLCoder/Encoder/DynamicNodeEncoding.swift (1)

43-43: LGTM: Appropriate Sendable conformance for protocol.

Adding Sendable conformance to DynamicNodeEncoding is a good improvement for concurrency safety. This ensures that all conforming types will be required to be thread-safe, which aligns with the overall goal of making the XMLCoder library concurrency-safe.

Sources/XMLCoder/Encoder/XMLEncoder.swift (3)

16-16: LGTM: Appropriate Sendable conformance for OutputFormatting.

Adding Sendable conformance to OutputFormatting is correct since it's an OptionSet with a UInt raw value, making it inherently thread-safe.


236-237: LGTM: Proper @sendable annotations for closure typealiases.

The addition of @Sendable annotations to the closure typealiases is correct and ensures thread safety for encoding operations.


265-271: Smart compiler version handling for @sendable closures.

The conditional compilation approach is well-implemented:

  • For Swift 6.1+: Uses direct method reference which is automatically @Sendable
  • For older versions: Explicitly wraps in @Sendable closure

This ensures compatibility across compiler versions while maintaining thread safety.

import Foundation

struct DateBox: Equatable {
struct DateBox: Equatable, Sendable {
Copy link

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Verify Sendable compliance with DateFormatter case.

While adding Sendable conformance to DateBox is good for concurrency safety, the Format.formatter(DateFormatter) case may be problematic since DateFormatter is not Sendable. This could lead to compiler warnings or errors in strict concurrency mode.

Let me verify if DateFormatter conforms to Sendable:


🏁 Script executed:

#!/bin/bash
# Check if DateFormatter conforms to Sendable in the codebase
ast-grep --pattern '$_: DateFormatter' | head -20
rg -A 5 -B 5 "DateFormatter.*Sendable\|Sendable.*DateFormatter"

Length of output: 117


Let’s inspect the Format enum in DateBox.swift to confirm its Sendable conformance and associated cases:


🏁 Script executed:

#!/bin/bash
rg -n "enum Format" -A 10 Sources/XMLCoder/Auxiliaries/Box/DateBox.swift

Length of output: 345


Fix the non-Sendable DateFormatter case in DateBox.Format.

The Format.formatter(DateFormatter) associated value makes Format (and thus DateBox) fail strict-Sendable checks, since DateFormatter isn’t Sendable. To resolve this, either:

  • Replace the DateFormatter–based case with a thread-safe alternative (e.g. a format identifier or closure that’s Sendable),
  • Or explicitly opt out of automatic checking by marking the enum as @unchecked Sendable.

For example, at the bottom of Sources/XMLCoder/Auxiliaries/Box/DateBox.swift:

     enum Format: Equatable {
         case secondsSince1970
         case millisecondsSince1970
         case iso8601
         case formatter(DateFormatter)
     }
+
+    // DateFormatter is not @Sendable; opt out of checking here
+    @unchecked
+    extension DateBox.Format: Sendable {}

• Location to update:

  • Sources/XMLCoder/Auxiliaries/Box/DateBox.swift (lines 12–17)

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In Sources/XMLCoder/Auxiliaries/Box/DateBox.swift around lines 11 to 17, the
Format enum inside DateBox uses a DateFormatter in one of its cases, which is
not Sendable and causes strict Sendable conformance to fail. To fix this, either
replace the DateFormatter case with a thread-safe, Sendable alternative like a
format identifier or closure, or mark the Format enum with @unchecked Sendable
to opt out of automatic Sendable checking. This change will ensure DateBox
conforms to Sendable without errors.

@leogdion leogdion deleted the v1.0.0-alpha.1 branch July 17, 2025 19:22
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