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

Strict mode for concurrency - Swift 6 support #82

Merged
merged 34 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
51ae84f
Save repository enhacements workl for now
kyzmitch Apr 8, 2024
173be97
Enable strict concurency checks and fix compilation
kyzmitch Apr 8, 2024
ba92083
Fix the sequence of app start to register use cases before using them…
kyzmitch Apr 8, 2024
67230b6
Make DefaultTabProvider as a global actor and fix compilation
kyzmitch Apr 9, 2024
40ff848
Update alamofire, fix several warnings
kyzmitch Apr 10, 2024
8e1e802
Saved not finished warning fixes
kyzmitch Apr 10, 2024
1c94699
Fix compilation for iso 18 beta - SwiftUI framework now also has Tab …
kyzmitch Jun 14, 2024
664ff6a
Fix compilation in Xcode 16 beta 4 - WebKit function was updated
kyzmitch Jul 27, 2024
6aaa061
Fix compilation in current Xcode 15.4 by partly reverting older function
kyzmitch Jul 28, 2024
55ab985
Fix CoreData crash after renaming of Tab type
kyzmitch Jul 30, 2024
e5057f2
Fix swift 6 errors - part 1
kyzmitch Aug 4, 2024
dc45f79
Fix swift 6 errors - part 2
kyzmitch Aug 5, 2024
071f399
Fix swift 6 errors - part 3
kyzmitch Aug 7, 2024
16f3e93
Fix swift 6 errors - part 4
kyzmitch Aug 7, 2024
ee1c1a0
Fix swift 6 errors - part 5
kyzmitch Aug 7, 2024
08f985f
Fix swift 6 errors - part 6
kyzmitch Aug 11, 2024
52e1f72
Fix swift 6 errors - part 7
kyzmitch Aug 11, 2024
c214c6c
Fix swift 6 errors - part 8
kyzmitch Aug 11, 2024
bbcf064
Fix swift 6 errors - part 9
kyzmitch Aug 11, 2024
5a39de4
Add comments about @retroactive
kyzmitch Aug 11, 2024
cce4bdd
Fix ToolbarContent compilation on Swift 6.0 or Xcode 16 beta 4
kyzmitch Aug 12, 2024
439421a
Remove TabContentDefaultState and replace it with existing Tab.Conten…
kyzmitch Aug 17, 2024
e6b640c
Better comments, Database class update
kyzmitch Aug 17, 2024
8d8fe19
Another set of detailed comments about sendable
kyzmitch Aug 17, 2024
8d1eabc
Fix service locator crash
kyzmitch Aug 25, 2024
daaa4a4
Another set of review fixes
kyzmitch Aug 25, 2024
c064621
More doc comments
kyzmitch Aug 25, 2024
496b9c4
Merge branch 'feature/more_canonical_tabs_repository' of github.com:k…
kyzmitch Aug 25, 2024
d4df746
Disable CottonData unit tests for now because Swiftymocky doesn't wor…
kyzmitch Aug 27, 2024
16f01a5
Fix plugins comment
kyzmitch Sep 1, 2024
05d26b4
Add atomics for the Database
kyzmitch Sep 2, 2024
fb2c725
Improve database class
kyzmitch Sep 3, 2024
c34dcd6
Merge branch 'develop' into feature/more_canonical_tabs_repository
kyzmitch Sep 3, 2024
5899128
Xcode 16 RC fixes
kyzmitch Sep 11, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//

import CottonRestKit
import Alamofire
@preconcurrency import Alamofire
import CottonBase

public final class AlamofireReachabilityAdaptee<S: ServerDescription>: NetworkReachabilityAdapter {
Expand Down
2 changes: 1 addition & 1 deletion catowseriOS/BrowserNetworking/Downloadable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import Foundation
import Alamofire
import ReactiveSwift
@preconcurrency import ReactiveSwift
#if canImport(CryptoKit)
import CryptoKit
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import CottonRestKit
import CottonBase
import ReactiveHttpKit
import ReactiveSwift
@preconcurrency import ReactiveSwift
#if canImport(Combine)
import Combine
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import CottonRestKit
import Combine
import ReactiveSwift
@preconcurrency import ReactiveSwift
import CottonBase
import ReactiveHttpKit
import Alamofire
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import CottonRestKit
import CottonBase
import ReactiveHttpKit
import ReactiveSwift
@preconcurrency import ReactiveSwift
#if canImport(Combine)
import Combine
#endif
Expand Down
2 changes: 1 addition & 1 deletion catowseriOS/BrowserNetworking/HttpClient+Alamofire.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//

import CottonRestKit
import ReactiveSwift
@preconcurrency import ReactiveSwift
import CottonBase

/// This typealias could be an issue, because the same defined in ReactiveSwift HttpClient+RxSwift.swift
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ extension OpenSearch {
case xIcon = "image/x-icon"
}

public enum ImageParseResult {
public enum ImageParseResult: Sendable {
case base64(Data)
case url(URL)
case none
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@
import Foundation
import CottonBase

/// Alamofire's http method type can't be retroactivly silenced because sendable is a system protocol.
extension HTTPMethod: @unchecked Sendable { }

/// The model for OpenSearch format URL
public struct SearchEngine {
public struct SearchEngine: Sendable {
/// Name e.g. "DuckDuckGo"
let shortName: String
/// Valid components for final URL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import CottonRestKit
import ReactiveHttpKit
import Alamofire
import ReactiveSwift
@preconcurrency import ReactiveSwift
#if canImport(Combine)
import Combine
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
// Copyright © 2021 Cotton/Catowser Andrei Ermoshin. All rights reserved.
//

import AutoMockable
import CottonRestKit
import ReactiveHttpKit
import Alamofire
import ReactiveSwift
@preconcurrency import ReactiveSwift
#if canImport(Combine)
import Combine
#endif
Expand Down Expand Up @@ -104,8 +105,13 @@ extension URLRequest /* : URLRequestCreatable */ {
}
}

/// Wrapper around Alamofire method
extension JSONEncoding: JSONRequestEncodable {
/// Wrapper around Alamofire method.
/// Can't be retroactive because it is from 3rd party Alamofire lib.
extension JSONEncoding: @unchecked Sendable {}
/// Can be retroactivly Auto mockable because it is our own protocol which can't be known by Alamofire devs.
extension JSONEncoding: @retroactive AutoMockable {}
/// Can be retroactivly conforming to JSONRequestEncodable because Alamofire devs won't know that protocol for sure.
extension JSONEncoding: @retroactive JSONRequestEncodable {
public func encodeRequest(_ urlRequest: URLRequestCreatable, with parameters: [String: Any]?) throws -> URLRequest {
return try encode(urlRequest.convertToURLRequest(), with: parameters)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import CottonRestKit
import Alamofire
import ReactiveSwift
@preconcurrency import ReactiveSwift
#if canImport(Combine)
import Combine
#endif
Expand Down
2 changes: 1 addition & 1 deletion catowseriOS/CoreBrowser/Filesystem/ResourceReader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import Foundation

public enum KnownSearchPluginName: String {
public enum KnownSearchPluginName: String, Sendable {
case google
case duckduckgo
}
Expand Down
12 changes: 8 additions & 4 deletions catowseriOS/CoreBrowser/History/DomainsHistory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@
import CottonBase
import AutoMockable

/// Interface for known domain checks. Has to have async methods because actual class is a global actor
public protocol KnownDomainsSource: AutoMockable {
/// Interface for known domain checks. Has to have async methods because actual class is a global actor.
///
/// Can be sendable because implementation is a global actor.
public protocol KnownDomainsSource: AutoMockable, Sendable {
func domainNames(whereURLContains filter: String) async -> [String]
}

/// Interface for domain checks. Has to have async methods because actual class is a global actor
public protocol DomainsHistory {
/// Interface for domain checks. Has to have async methods because actual class is a global actor.
///
/// Can be sendable because implementation is a global actor.
public protocol DomainsHistory: Sendable {
kyzmitch marked this conversation as resolved.
Show resolved Hide resolved
func remember(host: CottonBase.Host) async
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ private let filename = "topdomains"

@globalActor
public final class InMemoryDomainSearchProvider {
public static let shared = Provider()
public static let shared = StateHolder()

public actor Provider {
public actor StateHolder {
fileprivate let storage: Trie

init() {
storage = Trie()
let bundle = Bundle(for: Provider.self)
let bundle = Bundle(for: StateHolder.self)

guard let filePath = bundle.path(forResource: filename, ofType: "txt") else {
assertionFailure("Failed to find \"\(filename)\" file in framework bundle")
Expand All @@ -39,7 +39,9 @@ public final class InMemoryDomainSearchProvider {
}
}

extension InMemoryDomainSearchProvider.Provider: DomainsHistory {
extension CottonBase.Host: @unchecked Sendable {}
kyzmitch marked this conversation as resolved.
Show resolved Hide resolved

extension InMemoryDomainSearchProvider.StateHolder: DomainsHistory {
public func remember(host: CottonBase.Host) async {
storage.insert(word: host.rawString)
if let withoutWww = host.rawString.withoutPrefix("www.") {
Expand All @@ -48,7 +50,7 @@ extension InMemoryDomainSearchProvider.Provider: DomainsHistory {
}
}

extension InMemoryDomainSearchProvider.Provider: KnownDomainsSource {
extension InMemoryDomainSearchProvider.StateHolder: KnownDomainsSource {
public func domainNames(whereURLContains filter: String) async -> [String] {
let words: [String] = storage.findWordsWithPrefix(prefix: filter)
return words
Expand Down
20 changes: 10 additions & 10 deletions catowseriOS/CoreBrowser/Models/Tab.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Tab.swift
// CoreBrowser.Tab.swift
// catowser
//
// Created by admin on 12/06/2017.
Expand All @@ -9,8 +9,8 @@
import CottonBase

/// Site is an obj-c type.
/// https://github.com/apple/swift-evolution/blob/main/proposals/0302-concurrent-value-and-concurrent-closures.md
extension Site: @unchecked Sendable {}
/// can mark with retroactive because Site type is from my CottonBase library
extension Site: @unchecked @retroactive Sendable {}

public extension Tab {
enum ContentType: Sendable {
Expand Down Expand Up @@ -43,7 +43,7 @@ public extension Tab {
return .blank
case 1:
guard let actualSite = site else {
print("No site instance for Tab.ContentType site \(rawValue)")
print("No site instance for CoreBrowser.Tab.ContentType site \(rawValue)")
return nil
}
return .site(actualSite)
Expand All @@ -54,7 +54,7 @@ public extension Tab {
case 4:
return .topSites
default:
print("Unexpected Tab.ContentType \(rawValue)")
print("Unexpected CoreBrowser.Tab.ContentType \(rawValue)")
return nil
}
}
Expand Down Expand Up @@ -101,7 +101,7 @@ public extension Tab {
}

extension Tab.ContentType: CaseIterable {
public static var allCases: [Tab.ContentType] {
public static var allCases: [CoreBrowser.Tab.ContentType] {
[.blank, .homepage, .topSites, .favorites]
}
}
Expand All @@ -127,7 +127,7 @@ extension Tab.ContentType: CustomDebugStringConvertible {
}

extension Tab.ContentType: Equatable {
public static func == (lhs: Tab.ContentType, rhs: Tab.ContentType) -> Bool {
public static func == (lhs: CoreBrowser.Tab.ContentType, rhs: CoreBrowser.Tab.ContentType) -> Bool {
switch (lhs, rhs) {
case (.site(let lSite), .site(let rSite)):
return lSite.compareWith(rSite)
Expand Down Expand Up @@ -210,7 +210,7 @@ public struct Tab: Sendable {
}

/**
Initializes an instance of `Tab` type.
Initializes an instance of `CoreBrowser.Tab` type.
*/
public init(contentType: ContentType,
idenifier: UUID = .init(),
Expand All @@ -220,11 +220,11 @@ public struct Tab: Sendable {
id = idenifier
}

public static let blank: Tab = Tab(contentType: .blank)
public static let blank: CoreBrowser.Tab = CoreBrowser.Tab(contentType: .blank)
}

extension Tab: Equatable {
public static func == (lhs: Tab, rhs: Tab) -> Bool {
public static func == (lhs: CoreBrowser.Tab, rhs: CoreBrowser.Tab) -> Bool {
return lhs.id == rhs.id
}
}
Expand Down
2 changes: 1 addition & 1 deletion catowseriOS/CoreBrowser/Tabs/TabAddStates.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Foundation

/// Describes how new tab is added to the list.
/// Uses `Int` as raw value to be able to store it in settings.
public enum AddedTabPosition: Int, CaseIterable {
public enum AddedTabPosition: Int, CaseIterable, Sendable {
case listEnd = 0
case afterSelected = 1
}
Expand Down
6 changes: 3 additions & 3 deletions catowseriOS/CoreBrowser/Tabs/TabContentState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@

import Foundation

/// Twin type for `Tab.ContentType` to have `rawValue`
/// Twin type for `CoreBrowser.Tab.ContentType` to have `rawValue`
/// and use it for settings.
public enum TabContentDefaultState: Int, CaseIterable, CustomStringConvertible {
public enum TabContentDefaultState: Int, CaseIterable, CustomStringConvertible, Sendable {
kyzmitch marked this conversation as resolved.
Show resolved Hide resolved
case blank
case homepage
case favorites
case topSites

public var contentType: Tab.ContentType {
public var contentType: CoreBrowser.Tab.ContentType {
switch self {
case .blank:
return .blank
Expand Down
6 changes: 4 additions & 2 deletions catowseriOS/CoreBrowser/Tabs/TabSelectionStrategy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ public protocol IndexSelectionContext: AutoMockable {
var currentlySelectedIndex: Int { get async }
}

public protocol TabSelectionStrategy: AutoMockable {
/// CoreBrowser.Tab selection protocol can be sendable, because implementation
/// only hold a constant which can't be mutated, so that, no any mutable state for now.
public protocol TabSelectionStrategy: AutoMockable, Sendable {
/**
A Tab selection strategy (Compositor) defines the algorithms of tab selection in specific cases
A CoreBrowser.Tab selection strategy (Compositor) defines the algorithms of tab selection in specific cases
- when tab was removed and need to select another
*/
func autoSelectedIndexAfterTabRemove(_ context: IndexSelectionContext, removedIndex: Int) async -> Int
Expand Down
Loading