Skip to content

Commit da27442

Browse files
committed
Move from weak to unowned, past issues seem resolved.
1 parent 45e3aeb commit da27442

File tree

1 file changed

+17
-26
lines changed

1 file changed

+17
-26
lines changed

Sources/SwiftProtobufPluginLibrary/Descriptor.swift

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,6 @@
2222
///
2323
// -----------------------------------------------------------------------------
2424

25-
// NOTES:
26-
// 1. `lazy` and `weak` (or `unowned`) doesn't seem to work, so the impl here
27-
// can't simply keep the `Resolver` and look things up when first accessed
28-
// instead `bind()` is used to force those lookups to happen.
29-
// 2. Despite the Swift docs seeming to say `unowned` should work, there are
30-
// compile errors, `weak` ends up being used even though this code doesn't
31-
// need the zeroing behaviors. If it did, things will be a little faster
32-
// as the tracking for weak references wouldn't be needed.
33-
3425
import Foundation
3526
import SwiftProtobuf
3627

@@ -280,10 +271,10 @@ public final class Descriptor {
280271
public let index: Int
281272

282273
/// The .proto file in which this message type was defined.
283-
public private(set) weak var file: FileDescriptor!
274+
public private(set) unowned var file: FileDescriptor!
284275
/// If this Descriptor describes a nested type, this returns the type
285276
/// in which it is nested.
286-
public private(set) weak var containingType: Descriptor?
277+
public private(set) unowned var containingType: Descriptor?
287278

288279
/// The `Google_Protobuf_MessageOptions` set on this Message.
289280
public let options: Google_Protobuf_MessageOptions
@@ -459,10 +450,10 @@ public final class EnumDescriptor {
459450
public let index: Int
460451

461452
/// The .proto file in which this message type was defined.
462-
public private(set) weak var file: FileDescriptor!
453+
public private(set) unowned var file: FileDescriptor!
463454
/// If this Descriptor describes a nested type, this returns the type
464455
/// in which it is nested.
465-
public private(set) weak var containingType: Descriptor?
456+
public private(set) unowned var containingType: Descriptor?
466457

467458
/// The values defined for this enum. Guaranteed (by protoc) to be atleast
468459
/// one item. These are returned in the order they were defined in the .proto
@@ -543,9 +534,9 @@ public final class EnumValueDescriptor {
543534
public let number: Int32
544535

545536
/// The .proto file in which this message type was defined.
546-
public weak var file: FileDescriptor! { return enumType.file }
537+
public unowned var file: FileDescriptor! { return enumType.file }
547538
/// The type of this value.
548-
public private(set) weak var enumType: EnumDescriptor!
539+
public private(set) unowned var enumType: EnumDescriptor!
549540

550541
/// The `Google_Protobuf_EnumValueOptions` set on this value.
551542
public let options: Google_Protobuf_EnumValueOptions
@@ -554,7 +545,7 @@ public final class EnumValueDescriptor {
554545
// namer has apis around them, so figure out what's the right way to deal
555546
// with it, maybe moving it (and the naming support?) to the actual plugin
556547
// directory.
557-
public private(set) weak var aliasOf: EnumValueDescriptor?
548+
public private(set) unowned var aliasOf: EnumValueDescriptor?
558549
public fileprivate(set) var aliases: [EnumValueDescriptor] = []
559550

560551
fileprivate init(proto: Google_Protobuf_EnumValueDescriptorProto,
@@ -588,9 +579,9 @@ public final class OneofDescriptor {
588579
}
589580

590581
/// The .proto file in which this oneof type was defined.
591-
public weak var file: FileDescriptor! { return containingType.file }
582+
public unowned var file: FileDescriptor! { return containingType.file }
592583
/// If this Descriptor of the message that defines this oneof.
593-
public private(set) weak var containingType: Descriptor!
584+
public private(set) unowned var containingType: Descriptor!
594585

595586
/// The `Google_Protobuf_OneofOptions` set on this oneof.
596587
public let options: Google_Protobuf_OneofOptions
@@ -640,7 +631,7 @@ public final class FieldDescriptor {
640631
public let jsonName: String
641632

642633
/// File in which this field was defined.
643-
public private(set) weak var file: FileDescriptor!
634+
public private(set) unowned var file: FileDescriptor!
644635

645636
/// If this is an extension field.
646637
public let isExtension: Bool
@@ -736,7 +727,7 @@ public final class FieldDescriptor {
736727

737728
/// The `Descriptor` of the message which this is a field of. For extensions,
738729
/// this is the extended type.
739-
public private(set) weak var containingType: Descriptor!
730+
public private(set) unowned var containingType: Descriptor!
740731

741732
/// The oneof this field is a member of.
742733
public var containingOneof: OneofDescriptor? {
@@ -755,12 +746,12 @@ public final class FieldDescriptor {
755746
/// Extensions can be declared within the scope of another message. If this
756747
/// is an extension field, then this will be the scope it was declared in
757748
/// nil if was declared at a global scope.
758-
public private(set) weak var extensionScope: Descriptor?
749+
public private(set) unowned var extensionScope: Descriptor?
759750

760751
/// When this is a message field, the message's `Desciptor`.
761-
public private(set) weak var messageType: Descriptor!
752+
public private(set) unowned var messageType: Descriptor!
762753
/// When this is a enum field, the enum's `EnumDesciptor`.
763-
public private(set) weak var enumType: EnumDescriptor!
754+
public private(set) unowned var enumType: EnumDescriptor!
764755

765756
/// The FieldOptions for this field.
766757
public var options: Google_Protobuf_FieldOptions
@@ -847,7 +838,7 @@ public final class ServiceDescriptor {
847838
public let index: Int
848839

849840
/// The .proto file in which this service was defined
850-
public private(set) weak var file: FileDescriptor!
841+
public private(set) unowned var file: FileDescriptor!
851842

852843
/// Get `Google_Protobuf_ServiceOptions` for this service.
853844
public let options: Google_Protobuf_ServiceOptions
@@ -893,9 +884,9 @@ public final class MethodDescriptor {
893884
public let index: Int
894885

895886
/// The .proto file in which this service was defined
896-
public weak var file: FileDescriptor! { return service.file }
887+
public unowned var file: FileDescriptor! { return service.file }
897888
/// The service tha defines this method.
898-
public private(set) weak var service: ServiceDescriptor!
889+
public private(set) unowned var service: ServiceDescriptor!
899890

900891
/// The type of protocol message which this method accepts as input.
901892
public private(set) var inputType: Descriptor!

0 commit comments

Comments
 (0)