Skip to content

Commit

Permalink
Move some other tests off descriptor.proto.
Browse files Browse the repository at this point in the history
These don't need to use descriptor, they just needed some object hierarchy and
the ability to create extensions; so create custom types for this instead so
only tests that have to be on descriptor.proto are.
  • Loading branch information
thomasvl committed Aug 26, 2024
1 parent 564597a commit fef831d
Show file tree
Hide file tree
Showing 9 changed files with 1,692 additions and 7,263 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ package swift_descriptor_test;
// Use the option to test swift name generation.
option swift_prefix = "SDT";

import "google/protobuf/descriptor.proto";
import "pluginlib_descriptor_test_import.proto";

enum TopLevelEnum {
Expand Down Expand Up @@ -61,23 +60,23 @@ message TopLevelMessage2 {
}

message ExternalRefs {
optional google.protobuf.DescriptorProto desc = 1;
optional swift_descriptor_test.import.ExtendableOne one = 1;
optional swift_descriptor_test.import.Version ver = 2;
}

extend google.protobuf.FieldOptions {
extend swift_descriptor_test.import.ExtendableOne {
optional string ext_str = 90000;
}

message ScoperForExt {
extend google.protobuf.MessageOptions {
extend swift_descriptor_test.import.ExtendableOne.ExtendableTwo {
optional TopLevelEnum ext_enum = 99001;
optional TopLevelMessage2 ext_msg = 99002;
}
}

service SomeService {
rpc Foo(google.protobuf.DescriptorProto) returns (swift_descriptor_test.import.Version);
rpc Foo(swift_descriptor_test.import.ExtendableOne) returns (swift_descriptor_test.import.Version);
rpc Bar(TopLevelMessage) returns (TopLevelMessage2);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,14 @@ message Version {
optional int32 patch = 3;
optional string suffix = 4;
}

message ExtendableOne {

message ExtendableTwo {
extensions 1000 to max;
}

optional ExtendableTwo sub_msg_field = 1;

extensions 1000 to max;
}
Original file line number Diff line number Diff line change
Expand Up @@ -244,14 +244,14 @@ struct SDTExternalRefs: Sendable {
// `Message` and `Message+*Additions` files in the SwiftProtobuf library for
// methods supported on all messages.

var desc: SwiftProtobuf.Google_Protobuf_DescriptorProto {
get {return _desc ?? SwiftProtobuf.Google_Protobuf_DescriptorProto()}
set {_desc = newValue}
var one: SwiftDescriptorTest_Import_ExtendableOne {
get {return _one ?? SwiftDescriptorTest_Import_ExtendableOne()}
set {_one = newValue}
}
/// Returns true if `desc` has been explicitly set.
var hasDesc: Bool {return self._desc != nil}
/// Clears the value of `desc`. Subsequent reads from it will return its default value.
mutating func clearDesc() {self._desc = nil}
/// Returns true if `one` has been explicitly set.
var hasOne: Bool {return self._one != nil}
/// Clears the value of `one`. Subsequent reads from it will return its default value.
mutating func clearOne() {self._one = nil}

var ver: SwiftDescriptorTest_Import_Version {
get {return _ver ?? SwiftDescriptorTest_Import_Version()}
Expand All @@ -266,7 +266,7 @@ struct SDTExternalRefs: Sendable {

init() {}

fileprivate var _desc: SwiftProtobuf.Google_Protobuf_DescriptorProto? = nil
fileprivate var _one: SwiftDescriptorTest_Import_ExtendableOne? = nil
fileprivate var _ver: SwiftDescriptorTest_Import_Version? = nil
}

Expand Down Expand Up @@ -430,7 +430,7 @@ struct SDTProto2MessageForPresence: Sendable {
// declaration. To avoid naming collisions, the names are prefixed with the name of
// the scope where the extend directive occurs.

extension SwiftProtobuf.Google_Protobuf_FieldOptions {
extension SwiftDescriptorTest_Import_ExtendableOne {

var SDTextStr: String {
get {return getExtensionValue(ext: SDTExtensions_ext_str) ?? String()}
Expand All @@ -448,7 +448,7 @@ extension SwiftProtobuf.Google_Protobuf_FieldOptions {
}
}

extension SwiftProtobuf.Google_Protobuf_MessageOptions {
extension SwiftDescriptorTest_Import_ExtendableOne.ExtendableTwo {

var SDTScoperForExt_extEnum: SDTTopLevelEnum {
get {return getExtensionValue(ext: SDTScoperForExt.Extensions.ext_enum) ?? .valueZero}
Expand Down Expand Up @@ -498,19 +498,19 @@ let SDTPluginlibDescriptorTest_Extensions: SwiftProtobuf.SimpleExtensionMap = [
// constructing a `SimpleExtensionMap`, otherwise, use the above _Extension Properties_
// accessors for the extension fields on the messages directly.

let SDTExtensions_ext_str = SwiftProtobuf.MessageExtension<SwiftProtobuf.OptionalExtensionField<SwiftProtobuf.ProtobufString>, SwiftProtobuf.Google_Protobuf_FieldOptions>(
let SDTExtensions_ext_str = SwiftProtobuf.MessageExtension<SwiftProtobuf.OptionalExtensionField<SwiftProtobuf.ProtobufString>, SwiftDescriptorTest_Import_ExtendableOne>(
_protobuf_fieldNumber: 90000,
fieldName: "swift_descriptor_test.ext_str"
)

extension SDTScoperForExt {
enum Extensions {
static let ext_enum = SwiftProtobuf.MessageExtension<SwiftProtobuf.OptionalEnumExtensionField<SDTTopLevelEnum>, SwiftProtobuf.Google_Protobuf_MessageOptions>(
static let ext_enum = SwiftProtobuf.MessageExtension<SwiftProtobuf.OptionalEnumExtensionField<SDTTopLevelEnum>, SwiftDescriptorTest_Import_ExtendableOne.ExtendableTwo>(
_protobuf_fieldNumber: 99001,
fieldName: "swift_descriptor_test.ScoperForExt.ext_enum"
)

static let ext_msg = SwiftProtobuf.MessageExtension<SwiftProtobuf.OptionalMessageExtensionField<SDTTopLevelMessage2>, SwiftProtobuf.Google_Protobuf_MessageOptions>(
static let ext_msg = SwiftProtobuf.MessageExtension<SwiftProtobuf.OptionalMessageExtensionField<SDTTopLevelMessage2>, SwiftDescriptorTest_Import_ExtendableOne.ExtendableTwo>(
_protobuf_fieldNumber: 99002,
fieldName: "swift_descriptor_test.ScoperForExt.ext_msg"
)
Expand Down Expand Up @@ -868,12 +868,12 @@ extension SDTTopLevelMessage2: SwiftProtobuf.Message, SwiftProtobuf._MessageImpl
extension SDTExternalRefs: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding {
static let protoMessageName: String = _protobuf_package + ".ExternalRefs"
static let _protobuf_nameMap: SwiftProtobuf._NameMap = [
1: .same(proto: "desc"),
1: .same(proto: "one"),
2: .same(proto: "ver"),
]

public var isInitialized: Bool {
if let v = self._desc, !v.isInitialized {return false}
if let v = self._one, !v.isInitialized {return false}
return true
}

Expand All @@ -883,7 +883,7 @@ extension SDTExternalRefs: SwiftProtobuf.Message, SwiftProtobuf._MessageImplemen
// allocates stack space for every case branch when no optimizations are
// enabled. https://github.com/apple/swift-protobuf/issues/1034
switch fieldNumber {
case 1: try { try decoder.decodeSingularMessageField(value: &self._desc) }()
case 1: try { try decoder.decodeSingularMessageField(value: &self._one) }()
case 2: try { try decoder.decodeSingularMessageField(value: &self._ver) }()
default: break
}
Expand All @@ -895,7 +895,7 @@ extension SDTExternalRefs: SwiftProtobuf.Message, SwiftProtobuf._MessageImplemen
// 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._desc {
try { if let v = self._one {
try visitor.visitSingularMessageField(value: v, fieldNumber: 1)
} }()
try { if let v = self._ver {
Expand All @@ -905,7 +905,7 @@ extension SDTExternalRefs: SwiftProtobuf.Message, SwiftProtobuf._MessageImplemen
}

static func ==(lhs: SDTExternalRefs, rhs: SDTExternalRefs) -> Bool {
if lhs._desc != rhs._desc {return false}
if lhs._one != rhs._one {return false}
if lhs._ver != rhs._ver {return false}
if lhs.unknownFields != rhs.unknownFields {return false}
return true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,40 @@ struct SwiftDescriptorTest_Import_Version: Sendable {
fileprivate var _suffix: String? = nil
}

struct SwiftDescriptorTest_Import_ExtendableOne: SwiftProtobuf.ExtensibleMessage, Sendable {
// SwiftProtobuf.Message conformance is added in an extension below. See the
// `Message` and `Message+*Additions` files in the SwiftProtobuf library for
// methods supported on all messages.

var subMsgField: SwiftDescriptorTest_Import_ExtendableOne.ExtendableTwo {
get {return _subMsgField ?? SwiftDescriptorTest_Import_ExtendableOne.ExtendableTwo()}
set {_subMsgField = newValue}
}
/// Returns true if `subMsgField` has been explicitly set.
var hasSubMsgField: Bool {return self._subMsgField != nil}
/// Clears the value of `subMsgField`. Subsequent reads from it will return its default value.
mutating func clearSubMsgField() {self._subMsgField = nil}

var unknownFields = SwiftProtobuf.UnknownStorage()

struct ExtendableTwo: SwiftProtobuf.ExtensibleMessage, Sendable {
// SwiftProtobuf.Message conformance is added in an extension below. See the
// `Message` and `Message+*Additions` files in the SwiftProtobuf library for
// methods supported on all messages.

var unknownFields = SwiftProtobuf.UnknownStorage()

init() {}

var _protobuf_extensionFieldValues = SwiftProtobuf.ExtensionFieldValueSet()
}

init() {}

var _protobuf_extensionFieldValues = SwiftProtobuf.ExtensionFieldValueSet()
fileprivate var _subMsgField: SwiftDescriptorTest_Import_ExtendableOne.ExtendableTwo? = nil
}

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

fileprivate let _protobuf_package = "swift_descriptor_test.import"
Expand Down Expand Up @@ -145,3 +179,78 @@ extension SwiftDescriptorTest_Import_Version: SwiftProtobuf.Message, SwiftProtob
return true
}
}

extension SwiftDescriptorTest_Import_ExtendableOne: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding {
static let protoMessageName: String = _protobuf_package + ".ExtendableOne"
static let _protobuf_nameMap: SwiftProtobuf._NameMap = [
1: .standard(proto: "sub_msg_field"),
]

public var isInitialized: Bool {
if !_protobuf_extensionFieldValues.isInitialized {return false}
if let v = self._subMsgField, !v.isInitialized {return false}
return true
}

mutating func decodeMessage<D: SwiftProtobuf.Decoder>(decoder: inout D) throws {
while let fieldNumber = try decoder.nextFieldNumber() {
// 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 fieldNumber {
case 1: try { try decoder.decodeSingularMessageField(value: &self._subMsgField) }()
case 1000..<536870912:
try { try decoder.decodeExtensionField(values: &_protobuf_extensionFieldValues, messageType: SwiftDescriptorTest_Import_ExtendableOne.self, fieldNumber: fieldNumber) }()
default: break
}
}
}

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
try { if let v = self._subMsgField {
try visitor.visitSingularMessageField(value: v, fieldNumber: 1)
} }()
try visitor.visitExtensionFields(fields: _protobuf_extensionFieldValues, start: 1000, end: 536870912)
try unknownFields.traverse(visitor: &visitor)
}

static func ==(lhs: SwiftDescriptorTest_Import_ExtendableOne, rhs: SwiftDescriptorTest_Import_ExtendableOne) -> Bool {
if lhs._subMsgField != rhs._subMsgField {return false}
if lhs.unknownFields != rhs.unknownFields {return false}
if lhs._protobuf_extensionFieldValues != rhs._protobuf_extensionFieldValues {return false}
return true
}
}

extension SwiftDescriptorTest_Import_ExtendableOne.ExtendableTwo: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding {
static let protoMessageName: String = SwiftDescriptorTest_Import_ExtendableOne.protoMessageName + ".ExtendableTwo"
static let _protobuf_nameMap = SwiftProtobuf._NameMap()

public var isInitialized: Bool {
if !_protobuf_extensionFieldValues.isInitialized {return false}
return true
}

mutating func decodeMessage<D: SwiftProtobuf.Decoder>(decoder: inout D) throws {
while let fieldNumber = try decoder.nextFieldNumber() {
if (1000 <= fieldNumber && fieldNumber < 536870912) {
try decoder.decodeExtensionField(values: &_protobuf_extensionFieldValues, messageType: SwiftDescriptorTest_Import_ExtendableOne.ExtendableTwo.self, fieldNumber: fieldNumber)
}
}
}

func traverse<V: SwiftProtobuf.Visitor>(visitor: inout V) throws {
try visitor.visitExtensionFields(fields: _protobuf_extensionFieldValues, start: 1000, end: 536870912)
try unknownFields.traverse(visitor: &visitor)
}

static func ==(lhs: SwiftDescriptorTest_Import_ExtendableOne.ExtendableTwo, rhs: SwiftDescriptorTest_Import_ExtendableOne.ExtendableTwo) -> Bool {
if lhs.unknownFields != rhs.unknownFields {return false}
if lhs._protobuf_extensionFieldValues != rhs._protobuf_extensionFieldValues {return false}
return true
}
}
Loading

0 comments on commit fef831d

Please sign in to comment.