Skip to content

Commit cdc667c

Browse files
authored
Merge branch 'release/1.x' into v1/max-age
2 parents 172b611 + 532dfc6 commit cdc667c

File tree

4 files changed

+87
-68
lines changed

4 files changed

+87
-68
lines changed

.github/workflows/ci.yaml

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
name: License Header and Formatting Checks
1010
runs-on: ubuntu-latest
1111
container:
12-
image: swift:6.0-jammy
12+
image: swift:6.1
1313
steps:
1414
- name: "Checkout repository"
1515
uses: actions/checkout@v4
@@ -25,18 +25,9 @@ jobs:
2525
fail-fast: false
2626
matrix:
2727
include:
28-
- image: swiftlang/swift:nightly-jammy
29-
# No TSAN because of: https://github.com/apple/swift/issues/59068
30-
# swift-test-flags: "--sanitize=thread"
28+
- image: swift:6.1
3129
- image: swift:6.0-jammy
32-
# No TSAN because of: https://github.com/apple/swift/issues/59068
33-
# swift-test-flags: "--sanitize=thread"
3430
- image: swift:5.10.1-noble
35-
# No TSAN because of: https://github.com/apple/swift/issues/59068
36-
# swift-test-flags: "--sanitize=thread"
37-
- image: swift:5.9-jammy
38-
# No TSAN because of: https://github.com/apple/swift/issues/59068
39-
# swift-test-flags: "--sanitize=thread"
4031
name: Build and Test on ${{ matrix.image }}
4132
runs-on: ubuntu-latest
4233
container:
@@ -54,8 +45,8 @@ jobs:
5445
fail-fast: false
5546
matrix:
5647
include:
57-
- image: swiftlang/swift:nightly-jammy
58-
swift-version: 'main'
48+
- image: swift:6.1
49+
swift-version: '6.1'
5950
env:
6051
MAX_ALLOCS_ALLOWED_bidi_1k_rpcs_10_requests: 323000
6152
MAX_ALLOCS_ALLOWED_bidi_1k_rpcs_1_request: 161000
@@ -87,17 +78,6 @@ jobs:
8778
MAX_ALLOCS_ALLOWED_unary_1k_ping_pong: 163000
8879
MAX_ALLOCS_ALLOWED_unary_1k_ping_pong_interceptors_client: 170000
8980
MAX_ALLOCS_ALLOWED_unary_1k_ping_pong_interceptors_server: 170000
90-
- image: swift:5.9-jammy
91-
swift-version: 5.9
92-
env:
93-
MAX_ALLOCS_ALLOWED_bidi_1k_rpcs_10_requests: 323000
94-
MAX_ALLOCS_ALLOWED_bidi_1k_rpcs_1_request: 161000
95-
MAX_ALLOCS_ALLOWED_embedded_server_bidi_1k_rpcs_10_small_requests: 110000
96-
MAX_ALLOCS_ALLOWED_embedded_server_bidi_1k_rpcs_1_small_request: 65000
97-
MAX_ALLOCS_ALLOWED_embedded_server_unary_1k_rpcs_1_small_request: 61000
98-
MAX_ALLOCS_ALLOWED_unary_1k_ping_pong: 163000
99-
MAX_ALLOCS_ALLOWED_unary_1k_ping_pong_interceptors_client: 170000
100-
MAX_ALLOCS_ALLOWED_unary_1k_ping_pong_interceptors_server: 170000
10181
name: Performance Tests on ${{ matrix.image }}
10282
runs-on: ubuntu-latest
10383
container:
@@ -113,14 +93,12 @@ jobs:
11393
fail-fast: false
11494
matrix:
11595
include:
116-
- image: swiftlang/swift:nightly-jammy
117-
swift-tools-version: '6.0'
96+
- image: swift:6.1
97+
swift-tools-version: '6.1'
11898
- image: swift:6.0-jammy
11999
swift-tools-version: '6.0'
120100
- image: swift:5.10.1-noble
121101
swift-tools-version: '5.10'
122-
- image: swift:5.9-jammy
123-
swift-tools-version: '5.9'
124102
name: Integration Tests on ${{ matrix.image }}
125103
runs-on: ubuntu-latest
126104
container:

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version:5.9
1+
// swift-tools-version:5.10
22
/*
33
* Copyright 2017, gRPC Authors All rights reserved.
44
*

Sources/protoc-gen-grpc-swift/Generator-Client+AsyncAwait.swift

Lines changed: 68 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -95,49 +95,79 @@ extension Generator {
9595
self.method = method
9696

9797
let rpcType = streamingType(self.method)
98-
let callType = Types.call(for: rpcType)
99-
let callTypeWithoutPrefix = Types.call(for: rpcType, withGRPCPrefix: false)
98+
printRPCFunctionImplementation(rpcType: rpcType)
99+
printRPCFunctionWrapper(rpcType: rpcType)
100+
}
101+
}
102+
}
100103

101-
switch rpcType {
102-
case .unary, .serverStreaming:
103-
self.printFunction(
104-
name: self.methodMakeFunctionCallName,
105-
arguments: [
106-
"_ request: \(self.methodInputName)",
107-
"callOptions: \(Types.clientCallOptions)? = nil",
108-
],
109-
returnType: "\(callType)<\(self.methodInputName), \(self.methodOutputName)>",
110-
access: self.access
111-
) {
112-
self.withIndentation("return self.make\(callTypeWithoutPrefix)", braces: .round) {
113-
self.println("path: \(self.methodPathUsingClientMetadata),")
114-
self.println("request: request,")
115-
self.println("callOptions: callOptions ?? self.defaultCallOptions,")
116-
self.println(
117-
"interceptors: self.interceptors?.\(self.methodInterceptorFactoryName)() ?? []"
118-
)
119-
}
120-
}
104+
private func printRPCFunctionImplementation(rpcType: StreamingType) {
105+
let argumentsBuilder: (() -> Void)?
106+
switch rpcType {
107+
case .unary, .serverStreaming:
108+
argumentsBuilder = {
109+
self.println("request: request,")
110+
}
111+
default:
112+
argumentsBuilder = nil
113+
}
114+
let callTypeWithoutPrefix = Types.call(for: rpcType, withGRPCPrefix: false)
115+
printRPCFunction(rpcType: rpcType, name: self.methodMakeFunctionCallName) {
116+
self.withIndentation("return self.make\(callTypeWithoutPrefix)", braces: .round) {
117+
self.println("path: \(self.methodPathUsingClientMetadata),")
118+
argumentsBuilder?()
119+
self.println("callOptions: callOptions ?? self.defaultCallOptions,")
120+
self.println(
121+
"interceptors: self.interceptors?.\(self.methodInterceptorFactoryName)() ?? []"
122+
)
123+
}
124+
}
125+
}
121126

122-
case .clientStreaming, .bidirectionalStreaming:
123-
self.printFunction(
124-
name: self.methodMakeFunctionCallName,
125-
arguments: ["callOptions: \(Types.clientCallOptions)? = nil"],
126-
returnType: "\(callType)<\(self.methodInputName), \(self.methodOutputName)>",
127-
access: self.access
128-
) {
129-
self.withIndentation("return self.make\(callTypeWithoutPrefix)", braces: .round) {
130-
self.println("path: \(self.methodPathUsingClientMetadata),")
131-
self.println("callOptions: callOptions ?? self.defaultCallOptions,")
132-
self.println(
133-
"interceptors: self.interceptors?.\(self.methodInterceptorFactoryName)() ?? []"
134-
)
135-
}
136-
}
137-
}
127+
private func printRPCFunctionWrapper(rpcType: StreamingType) {
128+
let functionName = methodMakeFunctionCallName
129+
let functionWrapperName = methodMakeFunctionCallWrapperName
130+
guard functionName != functionWrapperName else { return }
131+
self.println()
132+
133+
let argumentsBuilder: (() -> Void)?
134+
switch rpcType {
135+
case .unary, .serverStreaming:
136+
argumentsBuilder = {
137+
self.println("request,")
138+
}
139+
default:
140+
argumentsBuilder = nil
141+
}
142+
printRPCFunction(rpcType: rpcType, name: functionWrapperName) {
143+
self.withIndentation("return self.\(functionName)", braces: .round) {
144+
argumentsBuilder?()
145+
self.println("callOptions: callOptions")
138146
}
139147
}
140148
}
149+
150+
private func printRPCFunction(rpcType: StreamingType, name: String, bodyBuilder: (() -> Void)?) {
151+
let callType = Types.call(for: rpcType)
152+
self.printFunction(
153+
name: name,
154+
arguments: rpcFunctionArguments(rpcType: rpcType),
155+
returnType: "\(callType)<\(self.methodInputName), \(self.methodOutputName)>",
156+
access: self.access,
157+
bodyBuilder: bodyBuilder
158+
)
159+
}
160+
161+
private func rpcFunctionArguments(rpcType: StreamingType) -> [String] {
162+
var arguments = ["callOptions: \(Types.clientCallOptions)? = nil"]
163+
switch rpcType {
164+
case .unary, .serverStreaming:
165+
arguments.insert("_ request: \(self.methodInputName)", at: .zero)
166+
default:
167+
break
168+
}
169+
return arguments
170+
}
141171
}
142172

143173
// MARK: - Client protocol extension: "Simple, but safe" call wrappers.

Sources/protoc-gen-grpc-swift/Generator-Names.swift

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@ extension Generator {
129129

130130
internal var methodMakeFunctionCallName: String {
131131
let name: String
132-
133132
if self.options.keepMethodCasing {
134133
name = self.method.name
135134
} else {
@@ -140,6 +139,18 @@ extension Generator {
140139
return self.sanitize(fieldName: fnName)
141140
}
142141

142+
internal var methodMakeFunctionCallWrapperName: String {
143+
return "make\(methodComposableName)Call"
144+
}
145+
146+
internal var methodComposableName: String {
147+
var name = method.name
148+
if !options.keepMethodCasing {
149+
name = name.prefix(1).uppercased() + name.dropFirst()
150+
}
151+
return name
152+
}
153+
143154
internal func sanitize(fieldName string: String) -> String {
144155
if quotableFieldNames.contains(string) {
145156
return "`\(string)`"

0 commit comments

Comments
 (0)