Skip to content

Commit

Permalink
Always generate async code (#1384)
Browse files Browse the repository at this point in the history
* Always generate async code

Motivation:

Async code generation currently requires opting in. We should make it
the default alongside the NIO-based code so that it's easier to find.

Modifications:

- Remove the async options from the generator.
- Update the generator to always emit async code behind compiler guards.
- Update plugin docs.
- Regenerate code.

Result:

Async code is easier to find.

* Regenerate
  • Loading branch information
glbrntt authored Apr 4, 2022
1 parent c2e1e12 commit 6b1dc82
Show file tree
Hide file tree
Showing 20 changed files with 1,583 additions and 191 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ ${XCODEPROJ}:
protoc $< \
--proto_path=$(dir $<) \
--plugin=${PROTOC_GEN_GRPC_SWIFT} \
--grpc-swift_opt=Visibility=Public,ExperimentalAsyncClient=true,ExperimentalAsyncServer=true \
--grpc-swift_opt=Visibility=Public \
--grpc-swift_out=$(dir $<)

ECHO_PROTO=Sources/Examples/Echo/Model/echo.proto
Expand All @@ -78,7 +78,7 @@ ${ECHO_GRPC}: ${ECHO_PROTO} ${PROTOC_GEN_GRPC_SWIFT}
protoc $< \
--proto_path=$(dir $<) \
--plugin=${PROTOC_GEN_GRPC_SWIFT} \
--grpc-swift_opt=Visibility=Public,TestClient=true,ExperimentalAsyncClient=true,ExperimentalAsyncServer=true \
--grpc-swift_opt=Visibility=Public,TestClient=true \
--grpc-swift_out=$(dir $<)

# Generates protobufs and gRPC client and server for the Echo example
Expand Down
2 changes: 1 addition & 1 deletion Performance/QPSBenchmark/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ let package = Package(
.package(
name: "SwiftProtobuf",
url: "https://github.com/apple/swift-protobuf.git",
from: "1.9.0"
from: "1.19.0"
),
],
targets: [
Expand Down

Large diffs are not rendered by default.

187 changes: 136 additions & 51 deletions Performance/QPSBenchmark/Sources/QPSBenchmark/Model/control.pb.swift

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,14 @@ public struct Grpc_Core_Stats {
public init() {}
}

#if swift(>=5.5) && canImport(_Concurrency)
extension Grpc_Core_Bucket: @unchecked Sendable {}
extension Grpc_Core_Histogram: @unchecked Sendable {}
extension Grpc_Core_Metric: @unchecked Sendable {}
extension Grpc_Core_Metric.OneOf_Value: @unchecked Sendable {}
extension Grpc_Core_Stats: @unchecked Sendable {}
#endif // swift(>=5.5) && canImport(_Concurrency)

// MARK: - Code below here is support for the SwiftProtobuf runtime.

fileprivate let _protobuf_package = "grpc.core"
Expand Down Expand Up @@ -216,32 +224,39 @@ extension Grpc_Core_Metric: SwiftProtobuf.Message, SwiftProtobuf._MessageImpleme
switch fieldNumber {
case 1: try { try decoder.decodeSingularStringField(value: &self.name) }()
case 10: try {
if self.value != nil {try decoder.handleConflictingOneOf()}
var v: UInt64?
try decoder.decodeSingularUInt64Field(value: &v)
if let v = v {self.value = .count(v)}
if let v = v {
if self.value != nil {try decoder.handleConflictingOneOf()}
self.value = .count(v)
}
}()
case 11: try {
var v: Grpc_Core_Histogram?
var hadOneofValue = false
if let current = self.value {
try decoder.handleConflictingOneOf()
hadOneofValue = true
if case .histogram(let m) = current {v = m}
}
try decoder.decodeSingularMessageField(value: &v)
if let v = v {self.value = .histogram(v)}
if let v = v {
if hadOneofValue {try decoder.handleConflictingOneOf()}
self.value = .histogram(v)
}
}()
default: break
}
}
}

public func traverse<V: SwiftProtobuf.Visitor>(visitor: inout V) throws {
// The use of inline closures is to circumvent an issue where the compiler
// allocates stack space for every if/case branch local when no optimizations
// are enabled. https://github.com/apple/swift-protobuf/issues/1034 and
// https://github.com/apple/swift-protobuf/issues/1182
if !self.name.isEmpty {
try visitor.visitSingularStringField(value: self.name, fieldNumber: 1)
}
// The use of inline closures is to circumvent an issue where the compiler
// allocates stack space for every case branch when no optimizations are
// enabled. https://github.com/apple/swift-protobuf/issues/1034
switch self.value {
case .count?: try {
guard case .count(let v)? = self.value else { preconditionFailure() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,26 @@ public struct Grpc_Testing_LoadBalancerStatsResponse {
public init() {}
}

#if swift(>=5.5) && canImport(_Concurrency)
extension Grpc_Testing_PayloadType: @unchecked Sendable {}
extension Grpc_Testing_GrpclbRouteType: @unchecked Sendable {}
extension Grpc_Testing_BoolValue: @unchecked Sendable {}
extension Grpc_Testing_Payload: @unchecked Sendable {}
extension Grpc_Testing_EchoStatus: @unchecked Sendable {}
extension Grpc_Testing_SimpleRequest: @unchecked Sendable {}
extension Grpc_Testing_SimpleResponse: @unchecked Sendable {}
extension Grpc_Testing_StreamingInputCallRequest: @unchecked Sendable {}
extension Grpc_Testing_StreamingInputCallResponse: @unchecked Sendable {}
extension Grpc_Testing_ResponseParameters: @unchecked Sendable {}
extension Grpc_Testing_StreamingOutputCallRequest: @unchecked Sendable {}
extension Grpc_Testing_StreamingOutputCallResponse: @unchecked Sendable {}
extension Grpc_Testing_ReconnectParams: @unchecked Sendable {}
extension Grpc_Testing_ReconnectInfo: @unchecked Sendable {}
extension Grpc_Testing_LoadBalancerStatsRequest: @unchecked Sendable {}
extension Grpc_Testing_LoadBalancerStatsResponse: @unchecked Sendable {}
extension Grpc_Testing_LoadBalancerStatsResponse.RpcsByPeer: @unchecked Sendable {}
#endif // swift(>=5.5) && canImport(_Concurrency)

// MARK: - Code below here is support for the SwiftProtobuf runtime.

fileprivate let _protobuf_package = "grpc.testing"
Expand Down Expand Up @@ -689,30 +709,34 @@ extension Grpc_Testing_SimpleRequest: SwiftProtobuf.Message, SwiftProtobuf._Mess
}

public func traverse<V: SwiftProtobuf.Visitor>(visitor: inout V) throws {
// The use of inline closures is to circumvent an issue where the compiler
// allocates stack space for every if/case branch local when no optimizations
// are enabled. https://github.com/apple/swift-protobuf/issues/1034 and
// https://github.com/apple/swift-protobuf/issues/1182
if self.responseType != .compressable {
try visitor.visitSingularEnumField(value: self.responseType, fieldNumber: 1)
}
if self.responseSize != 0 {
try visitor.visitSingularInt32Field(value: self.responseSize, fieldNumber: 2)
}
if let v = self._payload {
try { if let v = self._payload {
try visitor.visitSingularMessageField(value: v, fieldNumber: 3)
}
} }()
if self.fillUsername != false {
try visitor.visitSingularBoolField(value: self.fillUsername, fieldNumber: 4)
}
if self.fillOauthScope != false {
try visitor.visitSingularBoolField(value: self.fillOauthScope, fieldNumber: 5)
}
if let v = self._responseCompressed {
try { if let v = self._responseCompressed {
try visitor.visitSingularMessageField(value: v, fieldNumber: 6)
}
if let v = self._responseStatus {
} }()
try { if let v = self._responseStatus {
try visitor.visitSingularMessageField(value: v, fieldNumber: 7)
}
if let v = self._expectCompressed {
} }()
try { if let v = self._expectCompressed {
try visitor.visitSingularMessageField(value: v, fieldNumber: 8)
}
} }()
if self.fillServerID != false {
try visitor.visitSingularBoolField(value: self.fillServerID, fieldNumber: 9)
}
Expand Down Expand Up @@ -767,9 +791,13 @@ extension Grpc_Testing_SimpleResponse: SwiftProtobuf.Message, SwiftProtobuf._Mes
}

public func traverse<V: SwiftProtobuf.Visitor>(visitor: inout V) throws {
if let v = self._payload {
// The use of inline closures is to circumvent an issue where the compiler
// allocates stack space for every if/case branch local when no optimizations
// are enabled. https://github.com/apple/swift-protobuf/issues/1034 and
// https://github.com/apple/swift-protobuf/issues/1182
try { if let v = self._payload {
try visitor.visitSingularMessageField(value: v, fieldNumber: 1)
}
} }()
if !self.username.isEmpty {
try visitor.visitSingularStringField(value: self.username, fieldNumber: 2)
}
Expand Down Expand Up @@ -821,12 +849,16 @@ extension Grpc_Testing_StreamingInputCallRequest: SwiftProtobuf.Message, SwiftPr
}

public func traverse<V: SwiftProtobuf.Visitor>(visitor: inout V) throws {
if let v = self._payload {
// The use of inline closures is to circumvent an issue where the compiler
// allocates stack space for every if/case branch local when no optimizations
// are enabled. https://github.com/apple/swift-protobuf/issues/1034 and
// https://github.com/apple/swift-protobuf/issues/1182
try { if let v = self._payload {
try visitor.visitSingularMessageField(value: v, fieldNumber: 1)
}
if let v = self._expectCompressed {
} }()
try { if let v = self._expectCompressed {
try visitor.visitSingularMessageField(value: v, fieldNumber: 2)
}
} }()
try unknownFields.traverse(visitor: &visitor)
}

Expand Down Expand Up @@ -893,15 +925,19 @@ extension Grpc_Testing_ResponseParameters: SwiftProtobuf.Message, SwiftProtobuf.
}

public func traverse<V: SwiftProtobuf.Visitor>(visitor: inout V) throws {
// The use of inline closures is to circumvent an issue where the compiler
// allocates stack space for every if/case branch local when no optimizations
// are enabled. https://github.com/apple/swift-protobuf/issues/1034 and
// https://github.com/apple/swift-protobuf/issues/1182
if self.size != 0 {
try visitor.visitSingularInt32Field(value: self.size, fieldNumber: 1)
}
if self.intervalUs != 0 {
try visitor.visitSingularInt32Field(value: self.intervalUs, fieldNumber: 2)
}
if let v = self._compressed {
try { if let v = self._compressed {
try visitor.visitSingularMessageField(value: v, fieldNumber: 3)
}
} }()
try unknownFields.traverse(visitor: &visitor)
}

Expand Down Expand Up @@ -939,18 +975,22 @@ extension Grpc_Testing_StreamingOutputCallRequest: SwiftProtobuf.Message, SwiftP
}

public func traverse<V: SwiftProtobuf.Visitor>(visitor: inout V) throws {
// The use of inline closures is to circumvent an issue where the compiler
// allocates stack space for every if/case branch local when no optimizations
// are enabled. https://github.com/apple/swift-protobuf/issues/1034 and
// https://github.com/apple/swift-protobuf/issues/1182
if self.responseType != .compressable {
try visitor.visitSingularEnumField(value: self.responseType, fieldNumber: 1)
}
if !self.responseParameters.isEmpty {
try visitor.visitRepeatedMessageField(value: self.responseParameters, fieldNumber: 2)
}
if let v = self._payload {
try { if let v = self._payload {
try visitor.visitSingularMessageField(value: v, fieldNumber: 3)
}
if let v = self._responseStatus {
} }()
try { if let v = self._responseStatus {
try visitor.visitSingularMessageField(value: v, fieldNumber: 7)
}
} }()
try unknownFields.traverse(visitor: &visitor)
}

Expand Down Expand Up @@ -983,9 +1023,13 @@ extension Grpc_Testing_StreamingOutputCallResponse: SwiftProtobuf.Message, Swift
}

public func traverse<V: SwiftProtobuf.Visitor>(visitor: inout V) throws {
if let v = self._payload {
// The use of inline closures is to circumvent an issue where the compiler
// allocates stack space for every if/case branch local when no optimizations
// are enabled. https://github.com/apple/swift-protobuf/issues/1034 and
// https://github.com/apple/swift-protobuf/issues/1182
try { if let v = self._payload {
try visitor.visitSingularMessageField(value: v, fieldNumber: 1)
}
} }()
try unknownFields.traverse(visitor: &visitor)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,14 @@ public struct Grpc_Testing_PayloadConfig {
public init() {}
}

#if swift(>=5.5) && canImport(_Concurrency)
extension Grpc_Testing_ByteBufferParams: @unchecked Sendable {}
extension Grpc_Testing_SimpleProtoParams: @unchecked Sendable {}
extension Grpc_Testing_ComplexProtoParams: @unchecked Sendable {}
extension Grpc_Testing_PayloadConfig: @unchecked Sendable {}
extension Grpc_Testing_PayloadConfig.OneOf_Payload: @unchecked Sendable {}
#endif // swift(>=5.5) && canImport(_Concurrency)

// MARK: - Code below here is support for the SwiftProtobuf runtime.

fileprivate let _protobuf_package = "grpc.testing"
Expand Down Expand Up @@ -254,30 +262,42 @@ extension Grpc_Testing_PayloadConfig: SwiftProtobuf.Message, SwiftProtobuf._Mess
switch fieldNumber {
case 1: try {
var v: Grpc_Testing_ByteBufferParams?
var hadOneofValue = false
if let current = self.payload {
try decoder.handleConflictingOneOf()
hadOneofValue = true
if case .bytebufParams(let m) = current {v = m}
}
try decoder.decodeSingularMessageField(value: &v)
if let v = v {self.payload = .bytebufParams(v)}
if let v = v {
if hadOneofValue {try decoder.handleConflictingOneOf()}
self.payload = .bytebufParams(v)
}
}()
case 2: try {
var v: Grpc_Testing_SimpleProtoParams?
var hadOneofValue = false
if let current = self.payload {
try decoder.handleConflictingOneOf()
hadOneofValue = true
if case .simpleParams(let m) = current {v = m}
}
try decoder.decodeSingularMessageField(value: &v)
if let v = v {self.payload = .simpleParams(v)}
if let v = v {
if hadOneofValue {try decoder.handleConflictingOneOf()}
self.payload = .simpleParams(v)
}
}()
case 3: try {
var v: Grpc_Testing_ComplexProtoParams?
var hadOneofValue = false
if let current = self.payload {
try decoder.handleConflictingOneOf()
hadOneofValue = true
if case .complexParams(let m) = current {v = m}
}
try decoder.decodeSingularMessageField(value: &v)
if let v = v {self.payload = .complexParams(v)}
if let v = v {
if hadOneofValue {try decoder.handleConflictingOneOf()}
self.payload = .complexParams(v)
}
}()
default: break
}
Expand All @@ -286,8 +306,9 @@ extension Grpc_Testing_PayloadConfig: SwiftProtobuf.Message, SwiftProtobuf._Mess

public func traverse<V: SwiftProtobuf.Visitor>(visitor: inout V) throws {
// The use of inline closures is to circumvent an issue where the compiler
// allocates stack space for every case branch when no optimizations are
// enabled. https://github.com/apple/swift-protobuf/issues/1034
// allocates stack space for every if/case branch local when no optimizations
// are enabled. https://github.com/apple/swift-protobuf/issues/1034 and
// https://github.com/apple/swift-protobuf/issues/1182
switch self.payload {
case .bytebufParams?: try {
guard case .bytebufParams(let v)? = self.payload else { preconditionFailure() }
Expand Down
Loading

0 comments on commit 6b1dc82

Please sign in to comment.