https://github.com/nhiroyasu/auto-sendable
A refactoring tool that ensures protocols, structs, enums, and classes conform to the Sendable protocol
https://github.com/nhiroyasu/auto-sendable
concurrency-checks refactoring-tools sendable swift swift6
Last synced: 5 months ago
JSON representation
A refactoring tool that ensures protocols, structs, enums, and classes conform to the Sendable protocol
- Host: GitHub
- URL: https://github.com/nhiroyasu/auto-sendable
- Owner: nhiroyasu
- Created: 2024-03-30T14:28:23.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-04-27T07:58:55.000Z (over 1 year ago)
- Last Synced: 2025-07-09T09:12:01.847Z (6 months ago)
- Topics: concurrency-checks, refactoring-tools, sendable, swift, swift6
- Language: Swift
- Homepage:
- Size: 47.9 KB
- Stars: 3
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# auto-sendable
A refactoring tool that ensures protocols, structs, enums, and classes conform to the Sendable protocol.
# Summary
This tool modifies Swift code to conform to the `Sendable` protocol under the following conditions:
- All `protocol` types.
- `struct` and `enum` types marked with the `public` modifier.
- `class` types that do not contain any `var` variables (the `final` modifier is also applied).
Additionally, the tool conforms types to `@unchecked Sendable` under the following condition:
- `class` types that contain `var` variables.
# Usage
## Swift Command
### Prepare
Clone this repository.
```sh
git clone https://github.com/nhiroyasu/auto-sendable.git
cd auto-sendable
```
### Execute
```sh
swift run auto-sendable ...
```
# Example
## `auto-sendable`
### Before
```swift
public struct Struct {}
public enum Enum {}
public protocol Protocol {}
public class Class {}
public class VariablesClass {
var variable: Int
}
```
### After
```swift
public struct Struct: Sendable {}
public enum Enum: Sendable {}
public protocol Protocol: Sendable {}
public final class Class: Sendable {}
public class VariablesClass: @unchecked Sendable {
var variable: Int
}
```
# Warning
The `auto-sendable` command enforces conformance to the `Sendable` protocol for `protocol`, `structs`, `enums`, and `classes`, even when they might not naturally conform to `Sendable` (for example, if they contain stored properties that are not `Sendable` themselves).
As a result, it is not possible to completely eliminate compiler warnings.
```swift
public struct Obj: Sendable { // warning: Obj struct isn't able to conform to the Sendable protocol.
var variable: Class
}
public class Class {
var count: Int
}
```