From 1f0da1ba118addb60c471c6a1ee26671846e4d3f Mon Sep 17 00:00:00 2001 From: Chris Kennelly Date: Fri, 12 May 2023 12:03:16 -0700 Subject: [PATCH] Remove vestigal check for non-nullptr Arenas. When we are running the destructor, we do not have an Arena. Since the Arena is a runtime property, the compiler may not be able to optimize it out. PiperOrigin-RevId: 531568752 --- src/google/protobuf/compiler/cpp/message.cc | 12 +- src/google/protobuf/compiler/plugin.pb.cc | 24 +-- src/google/protobuf/descriptor.pb.cc | 168 ++++---------------- 3 files changed, 33 insertions(+), 171 deletions(-) diff --git a/src/google/protobuf/compiler/cpp/message.cc b/src/google/protobuf/compiler/cpp/message.cc index c8f5dfe487..949c31ce06 100644 --- a/src/google/protobuf/compiler/cpp/message.cc +++ b/src/google/protobuf/compiler/cpp/message.cc @@ -2896,20 +2896,10 @@ void MessageGenerator::GenerateStructors(io::Printer* p) { // or extensions) } else { p->Emit( - {{"arena_dtor", - [&] { - if (NeedsArenaDestructor() == ArenaDtorNeeds::kNone) return; - p->Emit("ArenaDtor(this);"); - }}}, R"cc( $classname$::~$classname$() { // @@protoc_insertion_point(destructor:$full_name$) - if (auto *arena = _internal_metadata_ - .DeleteReturnArena<$unknown_fields_type$>()) { - (void)arena; - $arena_dtor$; - return; - } + _internal_metadata_.DeleteReturnArena<$unknown_fields_type$>(); SharedDtor(); } )cc"); diff --git a/src/google/protobuf/compiler/plugin.pb.cc b/src/google/protobuf/compiler/plugin.pb.cc index b7f17a8e6a..b08dd41995 100644 --- a/src/google/protobuf/compiler/plugin.pb.cc +++ b/src/google/protobuf/compiler/plugin.pb.cc @@ -361,11 +361,7 @@ inline void Version::SharedCtor(::_pb::Arena* arena) { } Version::~Version() { // @@protoc_insertion_point(destructor:google.protobuf.compiler.Version) - if (auto *arena = _internal_metadata_ - .DeleteReturnArena<::google::protobuf::UnknownFieldSet>()) { - (void)arena; - return; - } + _internal_metadata_.DeleteReturnArena<::google::protobuf::UnknownFieldSet>(); SharedDtor(); } inline void Version::SharedDtor() { @@ -672,11 +668,7 @@ inline void CodeGeneratorRequest::SharedCtor(::_pb::Arena* arena) { } CodeGeneratorRequest::~CodeGeneratorRequest() { // @@protoc_insertion_point(destructor:google.protobuf.compiler.CodeGeneratorRequest) - if (auto *arena = _internal_metadata_ - .DeleteReturnArena<::google::protobuf::UnknownFieldSet>()) { - (void)arena; - return; - } + _internal_metadata_.DeleteReturnArena<::google::protobuf::UnknownFieldSet>(); SharedDtor(); } inline void CodeGeneratorRequest::SharedDtor() { @@ -1025,11 +1017,7 @@ inline void CodeGeneratorResponse_File::SharedCtor(::_pb::Arena* arena) { } CodeGeneratorResponse_File::~CodeGeneratorResponse_File() { // @@protoc_insertion_point(destructor:google.protobuf.compiler.CodeGeneratorResponse.File) - if (auto *arena = _internal_metadata_ - .DeleteReturnArena<::google::protobuf::UnknownFieldSet>()) { - (void)arena; - return; - } + _internal_metadata_.DeleteReturnArena<::google::protobuf::UnknownFieldSet>(); SharedDtor(); } inline void CodeGeneratorResponse_File::SharedDtor() { @@ -1339,11 +1327,7 @@ inline void CodeGeneratorResponse::SharedCtor(::_pb::Arena* arena) { } CodeGeneratorResponse::~CodeGeneratorResponse() { // @@protoc_insertion_point(destructor:google.protobuf.compiler.CodeGeneratorResponse) - if (auto *arena = _internal_metadata_ - .DeleteReturnArena<::google::protobuf::UnknownFieldSet>()) { - (void)arena; - return; - } + _internal_metadata_.DeleteReturnArena<::google::protobuf::UnknownFieldSet>(); SharedDtor(); } inline void CodeGeneratorResponse::SharedDtor() { diff --git a/src/google/protobuf/descriptor.pb.cc b/src/google/protobuf/descriptor.pb.cc index 79dc662ba7..4454c4741f 100644 --- a/src/google/protobuf/descriptor.pb.cc +++ b/src/google/protobuf/descriptor.pb.cc @@ -2013,11 +2013,7 @@ inline void FileDescriptorSet::SharedCtor(::_pb::Arena* arena) { } FileDescriptorSet::~FileDescriptorSet() { // @@protoc_insertion_point(destructor:google.protobuf.FileDescriptorSet) - if (auto *arena = _internal_metadata_ - .DeleteReturnArena<::google::protobuf::UnknownFieldSet>()) { - (void)arena; - return; - } + _internal_metadata_.DeleteReturnArena<::google::protobuf::UnknownFieldSet>(); SharedDtor(); } inline void FileDescriptorSet::SharedDtor() { @@ -2295,11 +2291,7 @@ inline void FileDescriptorProto::SharedCtor(::_pb::Arena* arena) { } FileDescriptorProto::~FileDescriptorProto() { // @@protoc_insertion_point(destructor:google.protobuf.FileDescriptorProto) - if (auto *arena = _internal_metadata_ - .DeleteReturnArena<::google::protobuf::UnknownFieldSet>()) { - (void)arena; - return; - } + _internal_metadata_.DeleteReturnArena<::google::protobuf::UnknownFieldSet>(); SharedDtor(); } inline void FileDescriptorProto::SharedDtor() { @@ -2875,11 +2867,7 @@ inline void DescriptorProto_ExtensionRange::SharedCtor(::_pb::Arena* arena) { } DescriptorProto_ExtensionRange::~DescriptorProto_ExtensionRange() { // @@protoc_insertion_point(destructor:google.protobuf.DescriptorProto.ExtensionRange) - if (auto *arena = _internal_metadata_ - .DeleteReturnArena<::google::protobuf::UnknownFieldSet>()) { - (void)arena; - return; - } + _internal_metadata_.DeleteReturnArena<::google::protobuf::UnknownFieldSet>(); SharedDtor(); } inline void DescriptorProto_ExtensionRange::SharedDtor() { @@ -3129,11 +3117,7 @@ inline void DescriptorProto_ReservedRange::SharedCtor(::_pb::Arena* arena) { } DescriptorProto_ReservedRange::~DescriptorProto_ReservedRange() { // @@protoc_insertion_point(destructor:google.protobuf.DescriptorProto.ReservedRange) - if (auto *arena = _internal_metadata_ - .DeleteReturnArena<::google::protobuf::UnknownFieldSet>()) { - (void)arena; - return; - } + _internal_metadata_.DeleteReturnArena<::google::protobuf::UnknownFieldSet>(); SharedDtor(); } inline void DescriptorProto_ReservedRange::SharedDtor() { @@ -3392,11 +3376,7 @@ inline void DescriptorProto::SharedCtor(::_pb::Arena* arena) { } DescriptorProto::~DescriptorProto() { // @@protoc_insertion_point(destructor:google.protobuf.DescriptorProto) - if (auto *arena = _internal_metadata_ - .DeleteReturnArena<::google::protobuf::UnknownFieldSet>()) { - (void)arena; - return; - } + _internal_metadata_.DeleteReturnArena<::google::protobuf::UnknownFieldSet>(); SharedDtor(); } inline void DescriptorProto::SharedDtor() { @@ -3906,11 +3886,7 @@ inline void ExtensionRangeOptions_Declaration::SharedCtor(::_pb::Arena* arena) { } ExtensionRangeOptions_Declaration::~ExtensionRangeOptions_Declaration() { // @@protoc_insertion_point(destructor:google.protobuf.ExtensionRangeOptions.Declaration) - if (auto *arena = _internal_metadata_ - .DeleteReturnArena<::google::protobuf::UnknownFieldSet>()) { - (void)arena; - return; - } + _internal_metadata_.DeleteReturnArena<::google::protobuf::UnknownFieldSet>(); SharedDtor(); } inline void ExtensionRangeOptions_Declaration::SharedDtor() { @@ -4248,11 +4224,7 @@ inline void ExtensionRangeOptions::SharedCtor(::_pb::Arena* arena) { } ExtensionRangeOptions::~ExtensionRangeOptions() { // @@protoc_insertion_point(destructor:google.protobuf.ExtensionRangeOptions) - if (auto *arena = _internal_metadata_ - .DeleteReturnArena<::google::protobuf::UnknownFieldSet>()) { - (void)arena; - return; - } + _internal_metadata_.DeleteReturnArena<::google::protobuf::UnknownFieldSet>(); SharedDtor(); } inline void ExtensionRangeOptions::SharedDtor() { @@ -4616,11 +4588,7 @@ inline void FieldDescriptorProto::SharedCtor(::_pb::Arena* arena) { } FieldDescriptorProto::~FieldDescriptorProto() { // @@protoc_insertion_point(destructor:google.protobuf.FieldDescriptorProto) - if (auto *arena = _internal_metadata_ - .DeleteReturnArena<::google::protobuf::UnknownFieldSet>()) { - (void)arena; - return; - } + _internal_metadata_.DeleteReturnArena<::google::protobuf::UnknownFieldSet>(); SharedDtor(); } inline void FieldDescriptorProto::SharedDtor() { @@ -5131,11 +5099,7 @@ inline void OneofDescriptorProto::SharedCtor(::_pb::Arena* arena) { } OneofDescriptorProto::~OneofDescriptorProto() { // @@protoc_insertion_point(destructor:google.protobuf.OneofDescriptorProto) - if (auto *arena = _internal_metadata_ - .DeleteReturnArena<::google::protobuf::UnknownFieldSet>()) { - (void)arena; - return; - } + _internal_metadata_.DeleteReturnArena<::google::protobuf::UnknownFieldSet>(); SharedDtor(); } inline void OneofDescriptorProto::SharedDtor() { @@ -5365,11 +5329,7 @@ inline void EnumDescriptorProto_EnumReservedRange::SharedCtor(::_pb::Arena* aren } EnumDescriptorProto_EnumReservedRange::~EnumDescriptorProto_EnumReservedRange() { // @@protoc_insertion_point(destructor:google.protobuf.EnumDescriptorProto.EnumReservedRange) - if (auto *arena = _internal_metadata_ - .DeleteReturnArena<::google::protobuf::UnknownFieldSet>()) { - (void)arena; - return; - } + _internal_metadata_.DeleteReturnArena<::google::protobuf::UnknownFieldSet>(); SharedDtor(); } inline void EnumDescriptorProto_EnumReservedRange::SharedDtor() { @@ -5618,11 +5578,7 @@ inline void EnumDescriptorProto::SharedCtor(::_pb::Arena* arena) { } EnumDescriptorProto::~EnumDescriptorProto() { // @@protoc_insertion_point(destructor:google.protobuf.EnumDescriptorProto) - if (auto *arena = _internal_metadata_ - .DeleteReturnArena<::google::protobuf::UnknownFieldSet>()) { - (void)arena; - return; - } + _internal_metadata_.DeleteReturnArena<::google::protobuf::UnknownFieldSet>(); SharedDtor(); } inline void EnumDescriptorProto::SharedDtor() { @@ -5968,11 +5924,7 @@ inline void EnumValueDescriptorProto::SharedCtor(::_pb::Arena* arena) { } EnumValueDescriptorProto::~EnumValueDescriptorProto() { // @@protoc_insertion_point(destructor:google.protobuf.EnumValueDescriptorProto) - if (auto *arena = _internal_metadata_ - .DeleteReturnArena<::google::protobuf::UnknownFieldSet>()) { - (void)arena; - return; - } + _internal_metadata_.DeleteReturnArena<::google::protobuf::UnknownFieldSet>(); SharedDtor(); } inline void EnumValueDescriptorProto::SharedDtor() { @@ -6260,11 +6212,7 @@ inline void ServiceDescriptorProto::SharedCtor(::_pb::Arena* arena) { } ServiceDescriptorProto::~ServiceDescriptorProto() { // @@protoc_insertion_point(destructor:google.protobuf.ServiceDescriptorProto) - if (auto *arena = _internal_metadata_ - .DeleteReturnArena<::google::protobuf::UnknownFieldSet>()) { - (void)arena; - return; - } + _internal_metadata_.DeleteReturnArena<::google::protobuf::UnknownFieldSet>(); SharedDtor(); } inline void ServiceDescriptorProto::SharedDtor() { @@ -6594,11 +6542,7 @@ inline void MethodDescriptorProto::SharedCtor(::_pb::Arena* arena) { } MethodDescriptorProto::~MethodDescriptorProto() { // @@protoc_insertion_point(destructor:google.protobuf.MethodDescriptorProto) - if (auto *arena = _internal_metadata_ - .DeleteReturnArena<::google::protobuf::UnknownFieldSet>()) { - (void)arena; - return; - } + _internal_metadata_.DeleteReturnArena<::google::protobuf::UnknownFieldSet>(); SharedDtor(); } inline void MethodDescriptorProto::SharedDtor() { @@ -7158,11 +7102,7 @@ inline void FileOptions::SharedCtor(::_pb::Arena* arena) { } FileOptions::~FileOptions() { // @@protoc_insertion_point(destructor:google.protobuf.FileOptions) - if (auto *arena = _internal_metadata_ - .DeleteReturnArena<::google::protobuf::UnknownFieldSet>()) { - (void)arena; - return; - } + _internal_metadata_.DeleteReturnArena<::google::protobuf::UnknownFieldSet>(); SharedDtor(); } inline void FileOptions::SharedDtor() { @@ -7952,11 +7892,7 @@ inline void MessageOptions::SharedCtor(::_pb::Arena* arena) { } MessageOptions::~MessageOptions() { // @@protoc_insertion_point(destructor:google.protobuf.MessageOptions) - if (auto *arena = _internal_metadata_ - .DeleteReturnArena<::google::protobuf::UnknownFieldSet>()) { - (void)arena; - return; - } + _internal_metadata_.DeleteReturnArena<::google::protobuf::UnknownFieldSet>(); SharedDtor(); } inline void MessageOptions::SharedDtor() { @@ -8334,11 +8270,7 @@ inline void FieldOptions::SharedCtor(::_pb::Arena* arena) { } FieldOptions::~FieldOptions() { // @@protoc_insertion_point(destructor:google.protobuf.FieldOptions) - if (auto *arena = _internal_metadata_ - .DeleteReturnArena<::google::protobuf::UnknownFieldSet>()) { - (void)arena; - return; - } + _internal_metadata_.DeleteReturnArena<::google::protobuf::UnknownFieldSet>(); SharedDtor(); } inline void FieldOptions::SharedDtor() { @@ -8812,11 +8744,7 @@ inline void OneofOptions::SharedCtor(::_pb::Arena* arena) { } OneofOptions::~OneofOptions() { // @@protoc_insertion_point(destructor:google.protobuf.OneofOptions) - if (auto *arena = _internal_metadata_ - .DeleteReturnArena<::google::protobuf::UnknownFieldSet>()) { - (void)arena; - return; - } + _internal_metadata_.DeleteReturnArena<::google::protobuf::UnknownFieldSet>(); SharedDtor(); } inline void OneofOptions::SharedDtor() { @@ -9032,11 +8960,7 @@ inline void EnumOptions::SharedCtor(::_pb::Arena* arena) { } EnumOptions::~EnumOptions() { // @@protoc_insertion_point(destructor:google.protobuf.EnumOptions) - if (auto *arena = _internal_metadata_ - .DeleteReturnArena<::google::protobuf::UnknownFieldSet>()) { - (void)arena; - return; - } + _internal_metadata_.DeleteReturnArena<::google::protobuf::UnknownFieldSet>(); SharedDtor(); } inline void EnumOptions::SharedDtor() { @@ -9326,11 +9250,7 @@ inline void EnumValueOptions::SharedCtor(::_pb::Arena* arena) { } EnumValueOptions::~EnumValueOptions() { // @@protoc_insertion_point(destructor:google.protobuf.EnumValueOptions) - if (auto *arena = _internal_metadata_ - .DeleteReturnArena<::google::protobuf::UnknownFieldSet>()) { - (void)arena; - return; - } + _internal_metadata_.DeleteReturnArena<::google::protobuf::UnknownFieldSet>(); SharedDtor(); } inline void EnumValueOptions::SharedDtor() { @@ -9563,11 +9483,7 @@ inline void ServiceOptions::SharedCtor(::_pb::Arena* arena) { } ServiceOptions::~ServiceOptions() { // @@protoc_insertion_point(destructor:google.protobuf.ServiceOptions) - if (auto *arena = _internal_metadata_ - .DeleteReturnArena<::google::protobuf::UnknownFieldSet>()) { - (void)arena; - return; - } + _internal_metadata_.DeleteReturnArena<::google::protobuf::UnknownFieldSet>(); SharedDtor(); } inline void ServiceOptions::SharedDtor() { @@ -9808,11 +9724,7 @@ inline void MethodOptions::SharedCtor(::_pb::Arena* arena) { } MethodOptions::~MethodOptions() { // @@protoc_insertion_point(destructor:google.protobuf.MethodOptions) - if (auto *arena = _internal_metadata_ - .DeleteReturnArena<::google::protobuf::UnknownFieldSet>()) { - (void)arena; - return; - } + _internal_metadata_.DeleteReturnArena<::google::protobuf::UnknownFieldSet>(); SharedDtor(); } inline void MethodOptions::SharedDtor() { @@ -10097,11 +10009,7 @@ inline void UninterpretedOption_NamePart::SharedCtor(::_pb::Arena* arena) { } UninterpretedOption_NamePart::~UninterpretedOption_NamePart() { // @@protoc_insertion_point(destructor:google.protobuf.UninterpretedOption.NamePart) - if (auto *arena = _internal_metadata_ - .DeleteReturnArena<::google::protobuf::UnknownFieldSet>()) { - (void)arena; - return; - } + _internal_metadata_.DeleteReturnArena<::google::protobuf::UnknownFieldSet>(); SharedDtor(); } inline void UninterpretedOption_NamePart::SharedDtor() { @@ -10401,11 +10309,7 @@ inline void UninterpretedOption::SharedCtor(::_pb::Arena* arena) { } UninterpretedOption::~UninterpretedOption() { // @@protoc_insertion_point(destructor:google.protobuf.UninterpretedOption) - if (auto *arena = _internal_metadata_ - .DeleteReturnArena<::google::protobuf::UnknownFieldSet>()) { - (void)arena; - return; - } + _internal_metadata_.DeleteReturnArena<::google::protobuf::UnknownFieldSet>(); SharedDtor(); } inline void UninterpretedOption::SharedDtor() { @@ -10804,11 +10708,7 @@ inline void SourceCodeInfo_Location::SharedCtor(::_pb::Arena* arena) { } SourceCodeInfo_Location::~SourceCodeInfo_Location() { // @@protoc_insertion_point(destructor:google.protobuf.SourceCodeInfo.Location) - if (auto *arena = _internal_metadata_ - .DeleteReturnArena<::google::protobuf::UnknownFieldSet>()) { - (void)arena; - return; - } + _internal_metadata_.DeleteReturnArena<::google::protobuf::UnknownFieldSet>(); SharedDtor(); } inline void SourceCodeInfo_Location::SharedDtor() { @@ -11126,11 +11026,7 @@ inline void SourceCodeInfo::SharedCtor(::_pb::Arena* arena) { } SourceCodeInfo::~SourceCodeInfo() { // @@protoc_insertion_point(destructor:google.protobuf.SourceCodeInfo) - if (auto *arena = _internal_metadata_ - .DeleteReturnArena<::google::protobuf::UnknownFieldSet>()) { - (void)arena; - return; - } + _internal_metadata_.DeleteReturnArena<::google::protobuf::UnknownFieldSet>(); SharedDtor(); } inline void SourceCodeInfo::SharedDtor() { @@ -11342,11 +11238,7 @@ inline void GeneratedCodeInfo_Annotation::SharedCtor(::_pb::Arena* arena) { } GeneratedCodeInfo_Annotation::~GeneratedCodeInfo_Annotation() { // @@protoc_insertion_point(destructor:google.protobuf.GeneratedCodeInfo.Annotation) - if (auto *arena = _internal_metadata_ - .DeleteReturnArena<::google::protobuf::UnknownFieldSet>()) { - (void)arena; - return; - } + _internal_metadata_.DeleteReturnArena<::google::protobuf::UnknownFieldSet>(); SharedDtor(); } inline void GeneratedCodeInfo_Annotation::SharedDtor() { @@ -11650,11 +11542,7 @@ inline void GeneratedCodeInfo::SharedCtor(::_pb::Arena* arena) { } GeneratedCodeInfo::~GeneratedCodeInfo() { // @@protoc_insertion_point(destructor:google.protobuf.GeneratedCodeInfo) - if (auto *arena = _internal_metadata_ - .DeleteReturnArena<::google::protobuf::UnknownFieldSet>()) { - (void)arena; - return; - } + _internal_metadata_.DeleteReturnArena<::google::protobuf::UnknownFieldSet>(); SharedDtor(); } inline void GeneratedCodeInfo::SharedDtor() {