Automated rollback of commit 6722988db6.

PiperOrigin-RevId: 610415350
pull/15956/head
Protobuf Team Bot 12 months ago committed by Copybara-Service
parent 9f52d5e380
commit ed072f207c
  1. 4
      src/google/protobuf/compiler/cpp/field.cc
  2. 5
      src/google/protobuf/compiler/cpp/field_generators/message_field.cc
  3. 11
      src/google/protobuf/compiler/cpp/file.cc
  4. 7
      src/google/protobuf/compiler/cpp/helpers.cc
  5. 6
      src/google/protobuf/compiler/cpp/helpers.h
  6. 24
      src/google/protobuf/compiler/cpp/message.cc
  7. 4
      src/google/protobuf/compiler/java/java_features.pb.h
  8. 16
      src/google/protobuf/compiler/plugin.pb.h
  9. 4
      src/google/protobuf/cpp_features.pb.h
  10. 128
      src/google/protobuf/descriptor.pb.h
  11. 3
      src/google/protobuf/generated_message_util.cc
  12. 6
      src/google/protobuf/message.h
  13. 20
      src/google/protobuf/message_lite.h
  14. 28
      src/google/protobuf/port.h

@ -87,8 +87,8 @@ std::vector<Sub> FieldVars(const FieldDescriptor* field, const Options& opts) {
{"deprecated_attr", DeprecatedAttribute(opts, field)},
Sub("WeakDescriptorSelfPin",
UsingImplicitWeakDescriptor(field->file(), opts)
? absl::StrCat(
StrongReferenceToType(field->containing_type(), opts), ";")
? absl::StrCat("::", ProtobufNamespace(opts),
"::internal::StrongReference(default_instance());")
: "")
.WithSuffix(";"),
};

@ -72,8 +72,9 @@ std::vector<Sub> Vars(const FieldDescriptor* field, const Options& opts,
{"_weak", weak ? "_weak" : ""},
Sub("StrongRef",
!weak ? ""
: absl::StrCat(
StrongReferenceToType(field->message_type(), opts), ";"))
: absl::Substitute("::google::protobuf::internal::StrongReference("
"reinterpret_cast<const $0&>($1));\n",
qualified_type, default_ref))
.WithSuffix(";"),
};
}

@ -1264,10 +1264,13 @@ void FileGenerator::GenerateReflectionInitializationCode(io::Printer* p) {
if (UsingImplicitWeakDescriptor(file_, options_)) {
for (auto* pinned : GetMessagesToPinGloballyForWeakDescriptors(file_)) {
static_initializers_.push_back([this, pinned](auto* p) {
p->Emit({{"pin", StrongReferenceToType(pinned, options_)}},
R"cc(
$pin$,
)cc");
p->Emit(
{
{"default", QualifiedDefaultInstanceName(pinned, options_)},
},
R"cc(
::_pbi::StrongPointer(&$default$),
)cc");
});
}
}

@ -1489,13 +1489,6 @@ bool UsingImplicitWeakDescriptor(const FileDescriptor* file,
!options.opensource_runtime;
}
std::string StrongReferenceToType(const Descriptor* desc,
const Options& options) {
const auto name = QualifiedDefaultInstanceName(desc, options);
return absl::StrFormat("::%s::internal::StrongPointer<decltype(%s)*, &%s>()",
ProtobufNamespace(options), name, name);
}
std::string WeakDescriptorDataSection(absl::string_view prefix,
const Descriptor* descriptor,
int index_in_file_messages,

@ -786,11 +786,7 @@ void ListAllTypesForServices(const FileDescriptor* fd,
bool UsingImplicitWeakDescriptor(const FileDescriptor* file,
const Options& options);
// Generates a strong reference to the message in `desc`, as a statement.
std::string StrongReferenceToType(const Descriptor* desc,
const Options& options);
// Generates the section name to be used for a data object when using implicit
// Generate the section name to be used for a data object when using implicit
// weak descriptors. The prefix determines the kind of object and the section it
// will be merged into afterwards.
// See `UsingImplicitWeakDescriptor` above.

@ -489,7 +489,8 @@ std::vector<Sub> ClassVars(const Descriptor* desc, Options opts) {
Sub("WeakDescriptorSelfPin",
UsingImplicitWeakDescriptor(desc->file(), opts)
? absl::StrCat(StrongReferenceToType(desc, opts), ";")
? absl::StrCat("::", ProtobufNamespace(opts),
"::internal::StrongReference(default_instance());")
: "")
.WithSuffix(";"),
};
@ -2028,10 +2029,6 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* p) {
$decl_oneof_has$;
$decl_data$;
$post_loop_handler$;
static constexpr const void* _raw_default_instance_ =
&_$classname$_default_instance_;
friend class ::$proto_ns$::MessageLite;
friend class ::$proto_ns$::Arena;
template <typename T>
@ -3529,10 +3526,9 @@ void MessageGenerator::GenerateClassData(io::Printer* p) {
const auto pin_weak_descriptor = [&] {
if (!UsingImplicitWeakDescriptor(descriptor_->file(), options_)) return;
p->Emit({{"pin", StrongReferenceToType(descriptor_, options_)}},
R"cc(
$pin$;
)cc");
p->Emit(R"cc(
::_pbi::StrongPointer(&_$classname$_default_instance_);
)cc");
// For CODE_SIZE types, we need to pin the submessages too.
// SPEED types will pin them via the TcParse table automatically.
@ -3540,11 +3536,11 @@ void MessageGenerator::GenerateClassData(io::Printer* p) {
for (int i = 0; i < descriptor_->field_count(); ++i) {
auto* field = descriptor_->field(i);
if (field->type() != field->TYPE_MESSAGE) continue;
p->Emit(
{{"pin", StrongReferenceToType(field->message_type(), options_)}},
R"cc(
$pin$;
)cc");
p->Emit({{"sub_default_name", QualifiedDefaultInstanceName(
field->message_type(), options_)}},
R"cc(
::_pbi::StrongPointer(&$sub_default_name$);
)cc");
}
};
p->Emit(

@ -275,10 +275,6 @@ class PROTOC_EXPORT JavaFeatures final : public ::google::protobuf::Message
1, 2, 1,
0, 2>
_table_;
static constexpr const void* _raw_default_instance_ =
&_JavaFeatures_default_instance_;
friend class ::google::protobuf::MessageLite;
friend class ::google::protobuf::Arena;
template <typename T>

@ -302,10 +302,6 @@ class PROTOC_EXPORT Version final : public ::google::protobuf::Message
2, 4, 0,
47, 2>
_table_;
static constexpr const void* _raw_default_instance_ =
&_Version_default_instance_;
friend class ::google::protobuf::MessageLite;
friend class ::google::protobuf::Arena;
template <typename T>
@ -535,10 +531,6 @@ class PROTOC_EXPORT CodeGeneratorResponse_File final : public ::google::protobuf
2, 4, 1,
86, 2>
_table_;
static constexpr const void* _raw_default_instance_ =
&_CodeGeneratorResponse_File_default_instance_;
friend class ::google::protobuf::MessageLite;
friend class ::google::protobuf::Arena;
template <typename T>
@ -791,10 +783,6 @@ class PROTOC_EXPORT CodeGeneratorResponse final : public ::google::protobuf::Mes
3, 5, 1,
60, 2>
_table_;
static constexpr const void* _raw_default_instance_ =
&_CodeGeneratorResponse_default_instance_;
friend class ::google::protobuf::MessageLite;
friend class ::google::protobuf::Arena;
template <typename T>
@ -1054,10 +1042,6 @@ class PROTOC_EXPORT CodeGeneratorRequest final : public ::google::protobuf::Mess
3, 5, 3,
79, 2>
_table_;
static constexpr const void* _raw_default_instance_ =
&_CodeGeneratorRequest_default_instance_;
friend class ::google::protobuf::MessageLite;
friend class ::google::protobuf::Arena;
template <typename T>

@ -277,10 +277,6 @@ class PROTOBUF_EXPORT CppFeatures final : public ::google::protobuf::Message
1, 2, 1,
0, 2>
_table_;
static constexpr const void* _raw_default_instance_ =
&_CppFeatures_default_instance_;
friend class ::google::protobuf::MessageLite;
friend class ::google::protobuf::Arena;
template <typename T>

@ -860,10 +860,6 @@ class PROTOBUF_EXPORT UninterpretedOption_NamePart final : public ::google::prot
1, 2, 0,
62, 2>
_table_;
static constexpr const void* _raw_default_instance_ =
&_UninterpretedOption_NamePart_default_instance_;
friend class ::google::protobuf::MessageLite;
friend class ::google::protobuf::Arena;
template <typename T>
@ -1124,10 +1120,6 @@ class PROTOBUF_EXPORT SourceCodeInfo_Location final : public ::google::protobuf:
3, 5, 0,
106, 2>
_table_;
static constexpr const void* _raw_default_instance_ =
&_SourceCodeInfo_Location_default_instance_;
friend class ::google::protobuf::MessageLite;
friend class ::google::protobuf::Arena;
template <typename T>
@ -1383,10 +1375,6 @@ class PROTOBUF_EXPORT GeneratedCodeInfo_Annotation final : public ::google::prot
3, 5, 1,
64, 2>
_table_;
static constexpr const void* _raw_default_instance_ =
&_GeneratedCodeInfo_Annotation_default_instance_;
friend class ::google::protobuf::MessageLite;
friend class ::google::protobuf::Arena;
template <typename T>
@ -1578,10 +1566,6 @@ class PROTOBUF_EXPORT FieldOptions_EditionDefault final : public ::google::proto
1, 2, 1,
57, 2>
_table_;
static constexpr const void* _raw_default_instance_ =
&_FieldOptions_EditionDefault_default_instance_;
friend class ::google::protobuf::MessageLite;
friend class ::google::protobuf::Arena;
template <typename T>
@ -2111,10 +2095,6 @@ class PROTOBUF_EXPORT FeatureSet final : public ::google::protobuf::Message
3, 6, 6,
0, 2>
_table_;
static constexpr const void* _raw_default_instance_ =
&_FeatureSet_default_instance_;
friend class ::google::protobuf::MessageLite;
friend class ::google::protobuf::Arena;
template <typename T>
@ -2349,10 +2329,6 @@ class PROTOBUF_EXPORT ExtensionRangeOptions_Declaration final : public ::google:
3, 5, 0,
71, 2>
_table_;
static constexpr const void* _raw_default_instance_ =
&_ExtensionRangeOptions_Declaration_default_instance_;
friend class ::google::protobuf::MessageLite;
friend class ::google::protobuf::Arena;
template <typename T>
@ -2537,10 +2513,6 @@ class PROTOBUF_EXPORT EnumDescriptorProto_EnumReservedRange final : public ::goo
1, 2, 0,
0, 2>
_table_;
static constexpr const void* _raw_default_instance_ =
&_EnumDescriptorProto_EnumReservedRange_default_instance_;
friend class ::google::protobuf::MessageLite;
friend class ::google::protobuf::Arena;
template <typename T>
@ -2722,10 +2694,6 @@ class PROTOBUF_EXPORT DescriptorProto_ReservedRange final : public ::google::pro
1, 2, 0,
0, 2>
_table_;
static constexpr const void* _raw_default_instance_ =
&_DescriptorProto_ReservedRange_default_instance_;
friend class ::google::protobuf::MessageLite;
friend class ::google::protobuf::Arena;
template <typename T>
@ -2992,10 +2960,6 @@ class PROTOBUF_EXPORT UninterpretedOption final : public ::google::protobuf::Mes
3, 7, 1,
75, 2>
_table_;
static constexpr const void* _raw_default_instance_ =
&_UninterpretedOption_default_instance_;
friend class ::google::protobuf::MessageLite;
friend class ::google::protobuf::Arena;
template <typename T>
@ -3177,10 +3141,6 @@ class PROTOBUF_EXPORT SourceCodeInfo final : public ::google::protobuf::Message
0, 1, 1,
0, 2>
_table_;
static constexpr const void* _raw_default_instance_ =
&_SourceCodeInfo_default_instance_;
friend class ::google::protobuf::MessageLite;
friend class ::google::protobuf::Arena;
template <typename T>
@ -3355,10 +3315,6 @@ class PROTOBUF_EXPORT GeneratedCodeInfo final : public ::google::protobuf::Messa
0, 1, 1,
0, 2>
_table_;
static constexpr const void* _raw_default_instance_ =
&_GeneratedCodeInfo_default_instance_;
friend class ::google::protobuf::MessageLite;
friend class ::google::protobuf::Arena;
template <typename T>
@ -3542,10 +3498,6 @@ class PROTOBUF_EXPORT FeatureSetDefaults_FeatureSetEditionDefault final : public
1, 2, 2,
0, 2>
_table_;
static constexpr const void* _raw_default_instance_ =
&_FeatureSetDefaults_FeatureSetEditionDefault_default_instance_;
friend class ::google::protobuf::MessageLite;
friend class ::google::protobuf::Arena;
template <typename T>
@ -3928,10 +3880,6 @@ class PROTOBUF_EXPORT ServiceOptions final : public ::google::protobuf::Message
2, 3, 2,
0, 12>
_table_;
static constexpr const void* _raw_default_instance_ =
&_ServiceOptions_default_instance_;
friend class ::google::protobuf::MessageLite;
friend class ::google::protobuf::Arena;
template <typename T>
@ -4304,10 +4252,6 @@ class PROTOBUF_EXPORT OneofOptions final : public ::google::protobuf::Message
2, 2, 2,
0, 7>
_table_;
static constexpr const void* _raw_default_instance_ =
&_OneofOptions_default_instance_;
friend class ::google::protobuf::MessageLite;
friend class ::google::protobuf::Arena;
template <typename T>
@ -4723,10 +4667,6 @@ class PROTOBUF_EXPORT MethodOptions final : public ::google::protobuf::Message
3, 4, 3,
0, 12>
_table_;
static constexpr const void* _raw_default_instance_ =
&_MethodOptions_default_instance_;
friend class ::google::protobuf::MessageLite;
friend class ::google::protobuf::Arena;
template <typename T>
@ -5160,10 +5100,6 @@ class PROTOBUF_EXPORT MessageOptions final : public ::google::protobuf::Message
3, 7, 2,
0, 7>
_table_;
static constexpr const void* _raw_default_instance_ =
&_MessageOptions_default_instance_;
friend class ::google::protobuf::MessageLite;
friend class ::google::protobuf::Arena;
template <typename T>
@ -5848,10 +5784,6 @@ class PROTOBUF_EXPORT FileOptions final : public ::google::protobuf::Message
5, 21, 3,
202, 12>
_table_;
static constexpr const void* _raw_default_instance_ =
&_FileOptions_default_instance_;
friend class ::google::protobuf::MessageLite;
friend class ::google::protobuf::Arena;
template <typename T>
@ -6476,10 +6408,6 @@ class PROTOBUF_EXPORT FieldOptions final : public ::google::protobuf::Message
4, 13, 7,
0, 7>
_table_;
static constexpr const void* _raw_default_instance_ =
&_FieldOptions_default_instance_;
friend class ::google::protobuf::MessageLite;
friend class ::google::protobuf::Arena;
template <typename T>
@ -6692,10 +6620,6 @@ class PROTOBUF_EXPORT FeatureSetDefaults final : public ::google::protobuf::Mess
1, 3, 3,
0, 2>
_table_;
static constexpr const void* _raw_default_instance_ =
&_FeatureSetDefaults_default_instance_;
friend class ::google::protobuf::MessageLite;
friend class ::google::protobuf::Arena;
template <typename T>
@ -7117,10 +7041,6 @@ class PROTOBUF_EXPORT ExtensionRangeOptions final : public ::google::protobuf::M
3, 4, 4,
0, 12>
_table_;
static constexpr const void* _raw_default_instance_ =
&_ExtensionRangeOptions_default_instance_;
friend class ::google::protobuf::MessageLite;
friend class ::google::protobuf::Arena;
template <typename T>
@ -7518,10 +7438,6 @@ class PROTOBUF_EXPORT EnumValueOptions final : public ::google::protobuf::Messag
3, 4, 2,
0, 7>
_table_;
static constexpr const void* _raw_default_instance_ =
&_EnumValueOptions_default_instance_;
friend class ::google::protobuf::MessageLite;
friend class ::google::protobuf::Arena;
template <typename T>
@ -7931,10 +7847,6 @@ class PROTOBUF_EXPORT EnumOptions final : public ::google::protobuf::Message
3, 5, 2,
0, 7>
_table_;
static constexpr const void* _raw_default_instance_ =
&_EnumOptions_default_instance_;
friend class ::google::protobuf::MessageLite;
friend class ::google::protobuf::Arena;
template <typename T>
@ -8130,10 +8042,6 @@ class PROTOBUF_EXPORT OneofDescriptorProto final : public ::google::protobuf::Me
1, 2, 1,
49, 2>
_table_;
static constexpr const void* _raw_default_instance_ =
&_OneofDescriptorProto_default_instance_;
friend class ::google::protobuf::MessageLite;
friend class ::google::protobuf::Arena;
template <typename T>
@ -8385,10 +8293,6 @@ class PROTOBUF_EXPORT MethodDescriptorProto final : public ::google::protobuf::M
3, 6, 1,
71, 2>
_table_;
static constexpr const void* _raw_default_instance_ =
&_MethodDescriptorProto_default_instance_;
friend class ::google::protobuf::MessageLite;
friend class ::google::protobuf::Arena;
template <typename T>
@ -8771,10 +8675,6 @@ class PROTOBUF_EXPORT FieldDescriptorProto final : public ::google::protobuf::Me
4, 11, 3,
96, 2>
_table_;
static constexpr const void* _raw_default_instance_ =
&_FieldDescriptorProto_default_instance_;
friend class ::google::protobuf::MessageLite;
friend class ::google::protobuf::Arena;
template <typename T>
@ -8987,10 +8887,6 @@ class PROTOBUF_EXPORT EnumValueDescriptorProto final : public ::google::protobuf
2, 3, 1,
53, 2>
_table_;
static constexpr const void* _raw_default_instance_ =
&_EnumValueDescriptorProto_default_instance_;
friend class ::google::protobuf::MessageLite;
friend class ::google::protobuf::Arena;
template <typename T>
@ -9189,10 +9085,6 @@ class PROTOBUF_EXPORT DescriptorProto_ExtensionRange final : public ::google::pr
2, 3, 1,
0, 2>
_table_;
static constexpr const void* _raw_default_instance_ =
&_DescriptorProto_ExtensionRange_default_instance_;
friend class ::google::protobuf::MessageLite;
friend class ::google::protobuf::Arena;
template <typename T>
@ -9403,10 +9295,6 @@ class PROTOBUF_EXPORT ServiceDescriptorProto final : public ::google::protobuf::
2, 3, 2,
51, 2>
_table_;
static constexpr const void* _raw_default_instance_ =
&_ServiceDescriptorProto_default_instance_;
friend class ::google::protobuf::MessageLite;
friend class ::google::protobuf::Arena;
template <typename T>
@ -9665,10 +9553,6 @@ class PROTOBUF_EXPORT EnumDescriptorProto final : public ::google::protobuf::Mes
3, 5, 3,
61, 2>
_table_;
static constexpr const void* _raw_default_instance_ =
&_EnumDescriptorProto_default_instance_;
friend class ::google::protobuf::MessageLite;
friend class ::google::protobuf::Arena;
template <typename T>
@ -10020,10 +9904,6 @@ class PROTOBUF_EXPORT DescriptorProto final : public ::google::protobuf::Message
4, 10, 8,
65, 2>
_table_;
static constexpr const void* _raw_default_instance_ =
&_DescriptorProto_default_instance_;
friend class ::google::protobuf::MessageLite;
friend class ::google::protobuf::Arena;
template <typename T>
@ -10426,10 +10306,6 @@ class PROTOBUF_EXPORT FileDescriptorProto final : public ::google::protobuf::Mes
4, 13, 7,
79, 2>
_table_;
static constexpr const void* _raw_default_instance_ =
&_FileDescriptorProto_default_instance_;
friend class ::google::protobuf::MessageLite;
friend class ::google::protobuf::Arena;
template <typename T>
@ -10616,10 +10492,6 @@ class PROTOBUF_EXPORT FileDescriptorSet final : public ::google::protobuf::Messa
0, 1, 1,
0, 2>
_table_;
static constexpr const void* _raw_default_instance_ =
&_FileDescriptorSet_default_instance_;
friend class ::google::protobuf::MessageLite;
friend class ::google::protobuf::Arena;
template <typename T>

@ -69,8 +69,7 @@ extern const char __start_pb_defaults;
extern const char __stop_pb_defaults;
}
static void InitWeakDefaults() {
// force link the dummy entry.
StrongPointer<DummyWeakDefault*, &dummy_weak_default>();
StrongPointer(&dummy_weak_default); // force link the dummy entry.
// We don't know the size of each object, but we know the layout of the tail.
// It contains a WeakDescriptorDefaultTail object.
// As such, we iterate the section backwards.

@ -1412,7 +1412,7 @@ const T* DynamicCastToGenerated(const Message* from) {
(void)unused;
#if PROTOBUF_RTTI
internal::StrongReferenceToType<T>();
internal::StrongReference(T::default_instance());
return dynamic_cast<const T*>(from);
#else
bool ok = from != nullptr &&
@ -1451,7 +1451,7 @@ T& DynamicCastToGenerated(Message& from) {
// instance T and T is a type derived from base Message class.
template <typename T>
const T* DownCastToGenerated(const Message* from) {
internal::StrongReferenceToType<T>();
internal::StrongReference(T::default_instance());
ABSL_DCHECK(DynamicCastToGenerated<T>(from) == from)
<< "Cannot downcast " << from->GetTypeName() << " to "
<< T::default_instance().GetTypeName();
@ -1499,7 +1499,7 @@ T& DownCastToGenerated(Message& from) {
// of loops (on x86-64 it compiles into two "mov" instructions).
template <typename T>
void LinkMessageReflection() {
internal::StrongReferenceToType<T>();
internal::StrongReference(T::default_instance);
}
// =============================================================================

@ -675,26 +675,6 @@ class PROTOBUF_EXPORT MessageLite {
void LogInitializationErrorMessage() const;
bool MergeFromImpl(io::CodedInputStream* input, ParseFlags parse_flags);
template <typename T, const void* ptr = T::_raw_default_instance_>
static constexpr auto GetStrongPointerForTypeImpl(int) {
return ptr;
}
template <typename T>
static constexpr auto GetStrongPointerForTypeImpl(char) {
return &T::default_instance;
}
// Return a pointer we can use to make a strong reference to a type.
// Ideally, this is a pointer to the default instance.
// If we can't get that, then we use a pointer to the `default_instance`
// function. The latter always works but pins the function artificially into
// the binary so we avoid it.
template <typename T>
static constexpr auto GetStrongPointerForType() {
return GetStrongPointerForTypeImpl<T>(0);
}
template <typename T>
friend void internal::StrongReferenceToType();
};
namespace internal {

@ -39,7 +39,7 @@ class MessageLite;
namespace internal {
template <typename T>
inline PROTOBUF_ALWAYS_INLINE void StrongPointer(T* var) {
void StrongPointer(T* var) {
#if defined(__GNUC__)
asm("" : : "r"(var));
#else
@ -48,32 +48,6 @@ inline PROTOBUF_ALWAYS_INLINE void StrongPointer(T* var) {
#endif
}
// Similar to the overload above, but optimized for constant inputs.
template <typename T, T ptr>
inline PROTOBUF_ALWAYS_INLINE void StrongPointer() {
#if defined(__x86_64__) && defined(__linux__) && !defined(__APPLE__) && \
defined(__clang__) && __clang_major__ >= 19 && \
!defined(PROTOBUF_INTERNAL_TEMPORARY_STRONG_POINTER_OPT_OUT)
// This injects a relocation in the code path without having to run code, but
// we can only do it with a newer clang.
asm(".reloc ., BFD_RELOC_NONE, %p0" ::"Ws"(ptr));
#else
StrongPointer(ptr);
#endif
}
template <typename T>
inline PROTOBUF_ALWAYS_INLINE void StrongReferenceToType() {
constexpr auto ptr = T::template GetStrongPointerForType<T>();
#if defined(__cpp_nontype_template_args) && \
__cpp_nontype_template_args >= 201411L
// We can only use `ptr` as a template parameter since C++17
return StrongPointer<decltype(ptr), ptr>();
#else
return StrongPointer(ptr);
#endif
}
// See comments on `AllocateAtLeast` for information on size returning new.
struct SizedPtr {

Loading…
Cancel
Save