Skip to content

Commit

Permalink
Use Sendable instead of @unchecked Sendable on LottieAnimation
Browse files Browse the repository at this point in the history
  • Loading branch information
calda committed Aug 2, 2023
1 parent b3ffa3f commit 347925e
Show file tree
Hide file tree
Showing 36 changed files with 77 additions and 44 deletions.
6 changes: 6 additions & 0 deletions Lottie.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3229,6 +3229,7 @@
MARKETING_VERSION = 1.0;
MODULE_VERIFIER_SUPPORTED_LANGUAGES = "objective-c objective-c++";
MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu11 gnu++17";
OTHER_SWIFT_FLAGS = "-warnings-as-errors";
PRODUCT_BUNDLE_IDENTIFIER = com.airbnb.Lottie;
PRODUCT_NAME = Lottie;
SKIP_INSTALL = YES;
Expand Down Expand Up @@ -3262,6 +3263,7 @@
MARKETING_VERSION = 1.0;
MODULE_VERIFIER_SUPPORTED_LANGUAGES = "objective-c objective-c++";
MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu11 gnu++17";
OTHER_SWIFT_FLAGS = "-warnings-as-errors";
PRODUCT_BUNDLE_IDENTIFIER = com.airbnb.Lottie;
PRODUCT_NAME = Lottie;
SKIP_INSTALL = YES;
Expand Down Expand Up @@ -3334,6 +3336,7 @@
MARKETING_VERSION = 1.0;
MODULE_VERIFIER_SUPPORTED_LANGUAGES = "objective-c objective-c++";
MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu11 gnu++17";
OTHER_SWIFT_FLAGS = "-warnings-as-errors";
PRODUCT_BUNDLE_IDENTIFIER = com.airbnb.Lottie;
PRODUCT_NAME = Lottie;
SDKROOT = macosx;
Expand Down Expand Up @@ -3368,6 +3371,7 @@
MARKETING_VERSION = 1.0;
MODULE_VERIFIER_SUPPORTED_LANGUAGES = "objective-c objective-c++";
MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu11 gnu++17";
OTHER_SWIFT_FLAGS = "-warnings-as-errors";
PRODUCT_BUNDLE_IDENTIFIER = com.airbnb.Lottie;
PRODUCT_NAME = Lottie;
SDKROOT = macosx;
Expand Down Expand Up @@ -3400,6 +3404,7 @@
MARKETING_VERSION = 1.0;
MODULE_VERIFIER_SUPPORTED_LANGUAGES = "objective-c objective-c++";
MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu11 gnu++17";
OTHER_SWIFT_FLAGS = "-warnings-as-errors";
PRODUCT_BUNDLE_IDENTIFIER = com.airbnb.Lottie;
PRODUCT_NAME = Lottie;
SDKROOT = appletvos;
Expand Down Expand Up @@ -3434,6 +3439,7 @@
MARKETING_VERSION = 1.0;
MODULE_VERIFIER_SUPPORTED_LANGUAGES = "objective-c objective-c++";
MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu11 gnu++17";
OTHER_SWIFT_FLAGS = "-warnings-as-errors";
PRODUCT_BUNDLE_IDENTIFIER = com.airbnb.Lottie;
PRODUCT_NAME = Lottie;
SDKROOT = appletvos;
Expand Down
8 changes: 8 additions & 0 deletions Sources/Private/Model/Assets/Asset.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

import Foundation

// MARK: - Asset

public class Asset: Codable, DictionaryInitializable {

// MARK: Lifecycle
Expand Down Expand Up @@ -41,3 +43,9 @@ public class Asset: Codable, DictionaryInitializable {
case id
}
}

// MARK: Sendable

/// Since `Asset` isn't `final`, we have to use `@unchecked Sendable` instead of `Sendable.`
/// All `Asset` subclasses are immutable `Sendable` values.
extension Asset: @unchecked Sendable { }
2 changes: 1 addition & 1 deletion Sources/Private/Model/Assets/AssetLibrary.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

final class AssetLibrary: Codable, AnyInitializable {
final class AssetLibrary: Codable, AnyInitializable, Sendable {

// MARK: Lifecycle

Expand Down
2 changes: 1 addition & 1 deletion Sources/Private/Model/Assets/ImageAsset.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Foundation

// MARK: - ImageAsset

public final class ImageAsset: Asset {
public final class ImageAsset: Asset, Sendable {

// MARK: Lifecycle

Expand Down
2 changes: 1 addition & 1 deletion Sources/Private/Model/Assets/PrecompAsset.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

final class PrecompAsset: Asset {
final class PrecompAsset: Asset, Sendable {

// MARK: Lifecycle

Expand Down
4 changes: 4 additions & 0 deletions Sources/Private/Model/Keyframes/KeyframeGroup.swift
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,10 @@ extension KeyframeGroup: Hashable where T: Hashable {
}
}

// MARK: Sendable

extension KeyframeGroup: Sendable where T: Sendable { }

extension Keyframe {
/// Creates a copy of this `Keyframe` with the same timing data, but a different value
func withValue<Value>(_ newValue: Value) -> Keyframe<Value> {
Expand Down
2 changes: 1 addition & 1 deletion Sources/Private/Model/Layers/ImageLayerModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import Foundation

/// A layer that holds an image.
final class ImageLayerModel: LayerModel {
final class ImageLayerModel: LayerModel, Sendable {

// MARK: Lifecycle

Expand Down
6 changes: 6 additions & 0 deletions Sources/Private/Model/Layers/LayerModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -226,3 +226,9 @@ extension Array where Element == LayerModel {
}
}
}

// MARK: - LayerModel + Sendable

/// Since `LayerModel` isn't `final`, we have to use `@unchecked Sendable` instead of `Sendable.`
/// All `LayerModel` subclasses are immutable `Sendable` values.
extension LayerModel: @unchecked Sendable { }
2 changes: 1 addition & 1 deletion Sources/Private/Model/Layers/PreCompLayerModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import Foundation

/// A layer that holds another animation composition.
final class PreCompLayerModel: LayerModel {
final class PreCompLayerModel: LayerModel, Sendable {

// MARK: Lifecycle

Expand Down
2 changes: 1 addition & 1 deletion Sources/Private/Model/Layers/ShapeLayerModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import Foundation

/// A layer that holds vector shape objects.
final class ShapeLayerModel: LayerModel {
final class ShapeLayerModel: LayerModel, Sendable {

// MARK: Lifecycle

Expand Down
2 changes: 1 addition & 1 deletion Sources/Private/Model/Layers/SolidLayerModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import Foundation

/// A layer that holds a solid color.
final class SolidLayerModel: LayerModel {
final class SolidLayerModel: LayerModel, Sendable {

// MARK: Lifecycle

Expand Down
2 changes: 1 addition & 1 deletion Sources/Private/Model/Layers/TextLayerModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import Foundation

/// A layer that holds text.
final class TextLayerModel: LayerModel {
final class TextLayerModel: LayerModel, Sendable {

// MARK: Lifecycle

Expand Down
2 changes: 1 addition & 1 deletion Sources/Private/Model/Objects/Marker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import Foundation

/// A time marker
final class Marker: Codable, DictionaryInitializable {
final class Marker: Codable, Sendable, DictionaryInitializable {

// MARK: Lifecycle

Expand Down
2 changes: 1 addition & 1 deletion Sources/Private/Model/ShapeItems/Ellipse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ enum PathDirection: Int, Codable {

// MARK: - Ellipse

final class Ellipse: ShapeItem {
final class Ellipse: ShapeItem, Sendable {

// MARK: Lifecycle

Expand Down
2 changes: 1 addition & 1 deletion Sources/Private/Model/ShapeItems/Fill.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ enum FillRule: Int, Codable {

// MARK: - Fill

final class Fill: ShapeItem {
final class Fill: ShapeItem, Sendable {

// MARK: Lifecycle

Expand Down
4 changes: 2 additions & 2 deletions Sources/Private/Model/ShapeItems/GradientFill.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ import Foundation

// MARK: - GradientType

enum GradientType: Int, Codable {
enum GradientType: Int, Codable, Sendable {
case none
case linear
case radial
}

// MARK: - GradientFill

final class GradientFill: ShapeItem {
final class GradientFill: ShapeItem, Sendable {

// MARK: Lifecycle

Expand Down
6 changes: 3 additions & 3 deletions Sources/Private/Model/ShapeItems/GradientStroke.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Foundation

// MARK: - LineCap

enum LineCap: Int, Codable {
enum LineCap: Int, Codable, Sendable {
case none
case butt
case round
Expand All @@ -18,7 +18,7 @@ enum LineCap: Int, Codable {

// MARK: - LineJoin

enum LineJoin: Int, Codable {
enum LineJoin: Int, Codable, Sendable {
case none
case miter
case round
Expand All @@ -27,7 +27,7 @@ enum LineJoin: Int, Codable {

// MARK: - GradientStroke

final class GradientStroke: ShapeItem {
final class GradientStroke: ShapeItem, Sendable {

// MARK: Lifecycle

Expand Down
2 changes: 1 addition & 1 deletion Sources/Private/Model/ShapeItems/Group.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import Foundation

/// An item that define a a group of shape items
final class Group: ShapeItem {
final class Group: ShapeItem, Sendable {

// MARK: Lifecycle

Expand Down
4 changes: 2 additions & 2 deletions Sources/Private/Model/ShapeItems/Merge.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Foundation

// MARK: - MergeMode

enum MergeMode: Int, Codable {
enum MergeMode: Int, Codable, Sendable {
case none
case merge
case add
Expand All @@ -20,7 +20,7 @@ enum MergeMode: Int, Codable {

// MARK: - Merge

final class Merge: ShapeItem {
final class Merge: ShapeItem, Sendable {

// MARK: Lifecycle

Expand Down
2 changes: 1 addition & 1 deletion Sources/Private/Model/ShapeItems/Rectangle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

final class Rectangle: ShapeItem {
final class Rectangle: ShapeItem, Sendable {

// MARK: Lifecycle

Expand Down
2 changes: 1 addition & 1 deletion Sources/Private/Model/ShapeItems/Repeater.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

final class Repeater: ShapeItem {
final class Repeater: ShapeItem, Sendable {

// MARK: Lifecycle

Expand Down
2 changes: 1 addition & 1 deletion Sources/Private/Model/ShapeItems/RoundedCorners.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Foundation

// MARK: - RoundedCorners

final class RoundedCorners: ShapeItem {
final class RoundedCorners: ShapeItem, Sendable {

// MARK: Lifecycle

Expand Down
2 changes: 1 addition & 1 deletion Sources/Private/Model/ShapeItems/Shape.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import Foundation

/// An item that defines an custom shape
final class Shape: ShapeItem {
final class Shape: ShapeItem, Sendable {

// MARK: Lifecycle

Expand Down
8 changes: 7 additions & 1 deletion Sources/Private/Model/ShapeItems/ShapeItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ extension ShapeType: ClassFamily {

// MARK: - ShapeType

enum ShapeType: String, Codable {
enum ShapeType: String, Codable, Sendable {
case ellipse = "el"
case fill = "fl"
case gradientFill = "gf"
Expand Down Expand Up @@ -165,3 +165,9 @@ extension Array where Element == ShapeItem {
}
}
}

// MARK: - ShapeItem + Sendable

/// Since `ShapeItem` isn't `final`, we have to use `@unchecked Sendable` instead of `Sendable.`
/// All `ShapeItem` subclasses are immutable `Sendable` values.
extension ShapeItem: @unchecked Sendable { }
2 changes: 1 addition & 1 deletion Sources/Private/Model/ShapeItems/ShapeTransform.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

final class ShapeTransform: ShapeItem {
final class ShapeTransform: ShapeItem, Sendable {

// MARK: Lifecycle

Expand Down
4 changes: 2 additions & 2 deletions Sources/Private/Model/ShapeItems/Star.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ import Foundation

// MARK: - StarType

enum StarType: Int, Codable {
enum StarType: Int, Codable, Sendable {
case none
case star
case polygon
}

// MARK: - Star

final class Star: ShapeItem {
final class Star: ShapeItem, Sendable {

// MARK: Lifecycle

Expand Down
2 changes: 1 addition & 1 deletion Sources/Private/Model/ShapeItems/Stroke.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

final class Stroke: ShapeItem {
final class Stroke: ShapeItem, Sendable {

// MARK: Lifecycle

Expand Down
2 changes: 1 addition & 1 deletion Sources/Private/Model/ShapeItems/Trim.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ enum TrimType: Int, Codable {

// MARK: - Trim

final class Trim: ShapeItem {
final class Trim: ShapeItem, Sendable {

// MARK: Lifecycle

Expand Down
4 changes: 2 additions & 2 deletions Sources/Private/Model/Text/Font.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Foundation

// MARK: - Font

final class Font: Codable, DictionaryInitializable {
final class Font: Codable, Sendable, DictionaryInitializable {

// MARK: Lifecycle

Expand Down Expand Up @@ -41,7 +41,7 @@ final class Font: Codable, DictionaryInitializable {
// MARK: - FontList

/// A list of fonts
final class FontList: Codable, DictionaryInitializable {
final class FontList: Codable, Sendable, DictionaryInitializable {

// MARK: Lifecycle

Expand Down
2 changes: 1 addition & 1 deletion Sources/Private/Model/Text/Glyph.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import Foundation

/// A model that holds a vector character
final class Glyph: Codable, DictionaryInitializable {
final class Glyph: Codable, Sendable, DictionaryInitializable {

// MARK: Lifecycle

Expand Down
2 changes: 1 addition & 1 deletion Sources/Private/Utility/Primitives/VectorsExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ extension Double {
// MARK: - LottieVector2D

/// Needed for decoding json {x: y:} to a CGPoint
public struct LottieVector2D: Codable, Hashable {
public struct LottieVector2D: Codable, Hashable, Sendable {

// MARK: Lifecycle

Expand Down
Loading

0 comments on commit 347925e

Please sign in to comment.