Skip to content

Commit 274d19b

Browse files
authored
Adopt ExistentialAny, MemberImportVisibility, InternalImportsByDefault, and NonIsolatedNonSendingByDefault (#38)
# Motivation There are a few upcoming language features that we want to adopt to adhere to the latest best practices # Modifications This PR enables these language features and fixes all errors and warnings # Result Following the latest recommendations
1 parent d73d24a commit 274d19b

File tree

243 files changed

+558
-445
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

243 files changed

+558
-445
lines changed

.licenseignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
.spi.yml
77
.swift-format
88
.github/
9+
Makefile
910
**.md
1011
**.txt
1112
**.pb.swift

Examples/AsyncActivities/FilmPermitActivities.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ import FoundationNetworking
2121

2222
/// Activities for processing NYC film permits.
2323
@ActivityContainer
24-
public struct FilmPermitActivities {
24+
struct FilmPermitActivities {
2525
// MARK: - Data Models
2626

27-
public struct FilmPermit: Codable, Sendable {
27+
struct FilmPermit: Codable, Sendable {
2828
let eventId: String
2929
let eventType: String
3030
let startDateTime: String
@@ -52,13 +52,13 @@ public struct FilmPermitActivities {
5252
}
5353
}
5454

55-
public struct ValidationResult: Codable, Sendable {
55+
struct ValidationResult: Codable, Sendable {
5656
let permitId: String
5757
let isValid: Bool
5858
let issues: [String]
5959
}
6060

61-
public struct LocationAnalysis: Codable, Sendable {
61+
struct LocationAnalysis: Codable, Sendable {
6262
let permitId: String
6363
let borough: String
6464
let precinct: String?
@@ -67,23 +67,23 @@ public struct FilmPermitActivities {
6767
let estimatedStreetCount: Int
6868
}
6969

70-
public struct PermitCategory: Codable, Sendable {
70+
struct PermitCategory: Codable, Sendable {
7171
let permitId: String
7272
let category: String
7373
let subcategory: String
7474
let eventType: String
7575
let isCommercial: Bool
7676
}
7777

78-
public struct PermitAnalysis: Codable, Sendable {
78+
struct PermitAnalysis: Codable, Sendable {
7979
let permit: FilmPermit
8080
let validation: ValidationResult
8181
let location: LocationAnalysis
8282
let category: PermitCategory
8383
let processingTimeMs: Double
8484
}
8585

86-
public struct AnalyticsReport: Codable, Sendable {
86+
struct AnalyticsReport: Codable, Sendable {
8787
let totalPermits: Int
8888
let validPermits: Int
8989
let byBorough: [String: Int]

Examples/AsyncActivities/FilmPermitWorkflow.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,23 @@ import Temporal
1717

1818
/// Workflow for processing NYC film permits with parallel and sequential modes.
1919
@Workflow
20-
public final class FilmPermitWorkflow {
21-
public enum ProcessingMode: String, Codable, Sendable {
20+
final class FilmPermitWorkflow {
21+
enum ProcessingMode: String, Codable, Sendable {
2222
case sequential
2323
case parallel
2424
}
2525

26-
public struct BatchRequest: Codable, Sendable {
26+
struct BatchRequest: Codable, Sendable {
2727
let permits: [FilmPermitActivities.FilmPermit]
2828
let mode: ProcessingMode
2929
}
3030

31-
public struct BatchResult: Codable, Sendable {
31+
struct BatchResult: Codable, Sendable {
3232
let report: FilmPermitActivities.AnalyticsReport
3333
let processingTimeMs: Double
3434
}
3535

36-
public func run(input: BatchRequest) async throws -> BatchResult {
36+
func run(input: BatchRequest) async throws -> BatchResult {
3737
let startTime = Date()
3838

3939
// Process permits based on mode (permits already fetched)

Examples/ChildWorkflows/PizzaOrderWorkflow.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
//
1313
//===----------------------------------------------------------------------===//
1414

15+
import Foundation
1516
import Temporal
1617

1718
/// Parent workflow that orchestrates pizza order fulfillment.

Examples/ErrorHandling/ErrorHandlingActivities.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@ struct ErrorHandlingActivities {
4646

4747
// MARK: - Fake Services
4848

49-
private let reservationService: ReservationService
50-
private let paymentService: PaymentServiceProtocol
49+
private let reservationService: any ReservationService
50+
private let paymentService: any PaymentServiceProtocol
5151

5252
init(
53-
reservationService: ReservationService,
54-
paymentService: PaymentServiceProtocol
53+
reservationService: any ReservationService,
54+
paymentService: any PaymentServiceProtocol
5555
) {
5656
self.reservationService = reservationService
5757
self.paymentService = paymentService

Examples/ErrorHandling/ErrorHandlingWorkflow.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
//
1313
//===----------------------------------------------------------------------===//
1414

15+
import Foundation
1516
import Temporal
1617

1718
/// Demonstrates error handling and compensation patterns in Temporal workflows.

Examples/MultipleActivities/MultipleActivitiesActivities.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,18 @@ struct MultipleActivitiesActivities {
4949
let orderId: String
5050
let status: String
5151
}
52-
private let inventoryService: InventoryService
53-
private let paymentService: PaymentService
54-
private let shippingService: ShippingService
55-
private let notificationService: NotificationService
56-
private let orderDatabase: OrderDatabase
52+
private let inventoryService: any InventoryService
53+
private let paymentService: any PaymentService
54+
private let shippingService: any ShippingService
55+
private let notificationService: any NotificationService
56+
private let orderDatabase: any OrderDatabase
5757

5858
init(
59-
inventoryService: InventoryService,
60-
paymentService: PaymentService,
61-
shippingService: ShippingService,
62-
notificationService: NotificationService,
63-
orderDatabase: OrderDatabase
59+
inventoryService: any InventoryService,
60+
paymentService: any PaymentService,
61+
shippingService: any ShippingService,
62+
notificationService: any NotificationService,
63+
orderDatabase: any OrderDatabase
6464
) {
6565
self.inventoryService = inventoryService
6666
self.paymentService = paymentService

Makefile

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
PROTO_OUT := ./Sources/Temporal/protos
2+
PROTO_BASE := ./dependencies/sdk-core/sdk-core-protos/protos
3+
PROTO_FILES := $(shell find $(PROTO_BASE) -name "*.proto" -not -path "*/google/*" -not -path "*/health/*")
4+
5+
SWIFT_CONFIGURATION ?= debug
6+
SWIFT_BIN_PATH := $(shell swift build -c $(SWIFT_CONFIGURATION) --show-bin-path)
7+
8+
PROTOC_GEN_SWIFT := $(shell swift build -c release --show-bin-path)/protoc-gen-swift
9+
PROTOC_GEN_GRPC_SWIFT := $(shell swift build -c release --show-bin-path)/protoc-gen-grpc-swift-2
10+
11+
# Build swift protobuf generation tool using swift build for use in other steps
12+
$(PROTOC_GEN_SWIFT): Package.swift
13+
swift build -c release --product protoc-gen-swift
14+
swift build -c release --product protoc-gen-grpc-swift-2
15+
16+
.PHONY: build-protos
17+
build-protos: $(PROTOC_GEN_SWIFT) $(PROTOC_GEN_GRPC_SWIFT) ./dependencies/sdk-core/sdk-core-protos/protos
18+
rm -rf $(PROTO_OUT)
19+
mkdir -p $(PROTO_OUT)
20+
protoc --plugin $(PROTOC_GEN_SWIFT) \
21+
--swift_out $(PROTO_OUT) \
22+
--swift_opt=FileNaming=PathToUnderscores \
23+
--swift_opt=Visibility=Package \
24+
--swift_opt=UseAccessLevelOnImports=true \
25+
-I ./dependencies/sdk-core/sdk-core-protos/protos/api_cloud_upstream \
26+
-I ./dependencies/sdk-core/sdk-core-protos/protos/api_upstream \
27+
-I ./dependencies/sdk-core/sdk-core-protos/protos/google \
28+
-I ./dependencies/sdk-core/sdk-core-protos/protos/grpc \
29+
-I ./dependencies/sdk-core/sdk-core-protos/protos/local \
30+
-I ./dependencies/sdk-core/sdk-core-protos/protos/testsrv_upstream \
31+
${PROTO_FILES}
32+
protoc --plugin $(PROTOC_GEN_GRPC_SWIFT) \
33+
--grpc-swift-2_out $(PROTO_OUT) \
34+
--grpc-swift-2_opt=FileNaming=PathToUnderscores \
35+
--grpc-swift-2_opt=Visibility=Package \
36+
--grpc-swift-2_opt=UseAccessLevelOnImports=true \
37+
--grpc-swift-2_opt=Client=true \
38+
--grpc-swift-2_opt=Server=false \
39+
-I ./dependencies/sdk-core/sdk-core-protos/protos/api_cloud_upstream \
40+
-I ./dependencies/sdk-core/sdk-core-protos/protos/api_upstream \
41+
-I ./dependencies/sdk-core/sdk-core-protos/protos/google \
42+
-I ./dependencies/sdk-core/sdk-core-protos/protos/grpc \
43+
-I ./dependencies/sdk-core/sdk-core-protos/protos/local \
44+
-I ./dependencies/sdk-core/sdk-core-protos/protos/testsrv_upstream \
45+
${PROTO_FILES}

Package.swift

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,3 +255,25 @@ let package = Package(
255255
),
256256
]
257257
)
258+
259+
for target in package.targets
260+
where [.executable, .test, .regular].contains(
261+
target.type
262+
) {
263+
var settings = target.swiftSettings ?? []
264+
265+
// https://github.com/apple/swift-evolution/blob/main/proposals/0335-existential-any.md
266+
// Require `any` for existential types.
267+
settings.append(.enableUpcomingFeature("ExistentialAny"))
268+
269+
// https://github.com/swiftlang/swift-evolution/blob/main/proposals/0444-member-import-visibility.md
270+
settings.append(.enableUpcomingFeature("MemberImportVisibility"))
271+
272+
// https://github.com/swiftlang/swift-evolution/blob/main/proposals/0409-access-level-on-imports.md
273+
settings.append(.enableUpcomingFeature("InternalImportsByDefault"))
274+
275+
// https://github.com/swiftlang/swift-evolution/blob/main/proposals/0461-async-function-isolation.md
276+
settings.append(.enableUpcomingFeature("NonIsolatedNonSendingByDefault"))
277+
278+
target.swiftSettings = settings
279+
}

Sources/Temporal/API/Common/Callback.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
//
1313
//===----------------------------------------------------------------------===//
1414

15-
import struct Foundation.Data
15+
public import struct Foundation.Data
1616

1717
/// Callback to attach to various events in the system (workflow run completion).
1818
public struct Callback: Hashable, Sendable {

0 commit comments

Comments
 (0)