Automated rollback of commit ee391369e6.

PiperOrigin-RevId: 681700370
pull/18601/head
Mike Kruskal 5 months ago committed by Copybara-Service
parent 25e50caa3e
commit 03aec42fcb
  1. 6
      src/google/protobuf/compiler/cpp/field.cc
  2. 3
      src/google/protobuf/compiler/cpp/field.h
  3. 6
      src/google/protobuf/compiler/cpp/field_generators/string_field.cc
  4. 3
      src/google/protobuf/compiler/cpp/field_generators/string_view_field.cc
  5. 17
      src/google/protobuf/compiler/cpp/helpers.cc
  6. 10
      src/google/protobuf/compiler/cpp/helpers.h
  7. 13
      src/google/protobuf/compiler/cpp/message.cc
  8. 14
      src/google/protobuf/descriptor.h
  9. 15
      src/google/protobuf/generated_message_reflection.cc
  10. 4
      src/google/protobuf/reflection_visit_field_info.h
  11. 37
      src/google/protobuf/reflection_visit_fields.h

@ -227,12 +227,6 @@ void FieldGeneratorBase::GenerateCopyConstructorCode(io::Printer* p) const {
}
}
pb::CppFeatures::StringType FieldGeneratorBase::GetDeclaredStringType() const {
return CppGenerator::GetResolvedSourceFeatures(*field_)
.GetExtension(pb::cpp)
.string_type();
}
namespace {
std::unique_ptr<FieldGeneratorBase> MakeGenerator(const FieldDescriptor* field,
const Options& options,

@ -25,7 +25,6 @@
#include "absl/types/span.h"
#include "google/protobuf/compiler/cpp/helpers.h"
#include "google/protobuf/compiler/cpp/options.h"
#include "google/protobuf/cpp_features.pb.h"
#include "google/protobuf/descriptor.h"
#include "google/protobuf/io/printer.h"
@ -200,8 +199,6 @@ class FieldGeneratorBase {
MessageSCCAnalyzer* scc_;
absl::flat_hash_map<absl::string_view, std::string> variables_;
pb::CppFeatures::StringType GetDeclaredStringType() const;
private:
bool should_split_ = false;
bool is_trivial_ = false;

@ -234,7 +234,8 @@ void SingularString::GenerateAccessorDeclarations(io::Printer* p) const {
// files that applied the ctype. The field can still be accessed via the
// reflection interface since the reflection interface is independent of
// the string's underlying representation.
bool unknown_ctype = GetDeclaredStringType() != pb::CppFeatures::STRING;
bool unknown_ctype =
field_->options().ctype() != internal::cpp::EffectiveStringCType(field_);
if (unknown_ctype) {
p->Emit(R"cc(
@ -819,7 +820,8 @@ class RepeatedString : public FieldGeneratorBase {
};
void RepeatedString::GenerateAccessorDeclarations(io::Printer* p) const {
bool unknown_ctype = GetDeclaredStringType() != pb::CppFeatures::STRING;
bool unknown_ctype =
field_->options().ctype() != internal::cpp::EffectiveStringCType(field_);
if (unknown_ctype) {
p->Emit(R"cc(

@ -637,7 +637,8 @@ class RepeatedStringView : public FieldGeneratorBase {
};
void RepeatedStringView::GenerateAccessorDeclarations(io::Printer* p) const {
bool unknown_ctype = GetDeclaredStringType() != pb::CppFeatures::VIEW;
bool unknown_ctype =
field_->options().ctype() != internal::cpp::EffectiveStringCType(field_);
if (unknown_ctype) {
p->Emit(R"cc(

@ -1094,8 +1094,18 @@ bool HasRepeatedFields(const FileDescriptor* file) {
return false;
}
static bool IsStringPieceField(const FieldDescriptor* field,
const Options& options) {
return field->cpp_type() == FieldDescriptor::CPPTYPE_STRING &&
internal::cpp::EffectiveStringCType(field) ==
FieldOptions::STRING_PIECE;
}
static bool HasStringPieceFields(const Descriptor* descriptor,
const Options& options) {
for (int i = 0; i < descriptor->field_count(); ++i) {
if (IsStringPieceField(descriptor->field(i), options)) return true;
}
for (int i = 0; i < descriptor->nested_type_count(); ++i) {
if (HasStringPieceFields(descriptor->nested_type(i), options)) return true;
}
@ -1109,10 +1119,15 @@ bool HasStringPieceFields(const FileDescriptor* file, const Options& options) {
return false;
}
static bool IsCordField(const FieldDescriptor* field, const Options& options) {
return field->cpp_type() == FieldDescriptor::CPPTYPE_STRING &&
internal::cpp::EffectiveStringCType(field) == FieldOptions::CORD;
}
static bool HasCordFields(const Descriptor* descriptor,
const Options& options) {
for (int i = 0; i < descriptor->field_count(); ++i) {
if (IsCord(descriptor->field(i))) return true;
if (IsCordField(descriptor->field(i), options)) return true;
}
for (int i = 0; i < descriptor->nested_type_count(); ++i) {
if (HasCordFields(descriptor->nested_type(i), options)) return true;

@ -330,15 +330,19 @@ inline bool IsWeak(const FieldDescriptor* field, const Options& options) {
inline bool IsCord(const FieldDescriptor* field) {
return field->cpp_type() == FieldDescriptor::CPPTYPE_STRING &&
field->cpp_string_type() == FieldDescriptor::CppStringType::kCord;
internal::cpp::EffectiveStringCType(field) == FieldOptions::CORD;
}
inline bool IsString(const FieldDescriptor* field) {
return field->cpp_type() == FieldDescriptor::CPPTYPE_STRING &&
(field->cpp_string_type() == FieldDescriptor::CppStringType::kString ||
field->cpp_string_type() == FieldDescriptor::CppStringType::kView);
internal::cpp::EffectiveStringCType(field) == FieldOptions::STRING;
}
inline bool IsStringPiece(const FieldDescriptor* field) {
return field->cpp_type() == FieldDescriptor::CPPTYPE_STRING &&
internal::cpp::EffectiveStringCType(field) ==
FieldOptions::STRING_PIECE;
}
bool IsProfileDriven(const Options& options);

@ -3880,16 +3880,21 @@ MessageGenerator::NewOpRequirements MessageGenerator::GetNewOp(
break;
case FieldDescriptor::CPPTYPE_STRING:
switch (field->cpp_string_type()) {
case FieldDescriptor::CppStringType::kCord:
switch (internal::cpp::EffectiveStringCType(field)) {
case FieldOptions::STRING_PIECE:
op.needs_arena_seeding = true;
print_arena_offset();
break;
case FieldOptions::CORD:
// Cord fields are currently rejected above because of ArenaDtor
// requirements.
ABSL_CHECK(op.needs_to_run_constructor);
break;
case FieldDescriptor::CppStringType::kView:
case FieldDescriptor::CppStringType::kString:
case FieldOptions::STRING:
op.needs_memcpy = true;
break;
default:
ABSL_LOG(FATAL);
}
break;
case FieldDescriptor::CPPTYPE_MESSAGE:

@ -2949,6 +2949,20 @@ PROTOBUF_EXPORT bool HasPreservingUnknownEnumSemantics(
PROTOBUF_EXPORT bool HasHasbit(const FieldDescriptor* field);
#ifndef SWIG
// For a string field, returns the effective ctype. If the actual ctype is
// not supported, returns the default of STRING.
template <typename FieldDesc = FieldDescriptor,
typename FieldOpts = FieldOptions>
typename FieldOpts::CType EffectiveStringCType(const FieldDesc* field) {
// TODO Replace this function with
// FieldDescriptor::cpp_string_type;
switch (field->cpp_string_type()) {
case FieldDescriptor::CppStringType::kCord:
return FieldOpts::CORD;
default:
return FieldOpts::STRING;
}
}
enum class Utf8CheckMode : uint8_t {
kStrict = 0, // Parsing will fail if non UTF-8 data is in string fields.

@ -33,7 +33,6 @@
#include "absl/synchronization/mutex.h"
#include "google/protobuf/descriptor.h"
#include "google/protobuf/descriptor.pb.h"
#include "google/protobuf/descriptor_lite.h"
#include "google/protobuf/extension_set.h"
#include "google/protobuf/generated_message_tctable_decl.h"
#include "google/protobuf/generated_message_tctable_gen.h"
@ -163,17 +162,6 @@ PROTOBUF_NOINLINE const std::string& NameOfDenseEnumSlow(
}
}
bool IsMatchingCType(const FieldDescriptor* field, int ctype) {
switch (field->cpp_string_type()) {
case FieldDescriptor::CppStringType::kCord:
return ctype == FieldOptions::CORD;
case FieldDescriptor::CppStringType::kView:
case FieldDescriptor::CppStringType::kString:
return ctype == FieldOptions::STRING;
}
internal::Unreachable();
}
} // namespace internal
// ===================================================================
@ -2681,7 +2669,8 @@ const void* Reflection::GetRawRepeatedField(const Message& message,
ReportReflectionUsageTypeError(descriptor_, field, "GetRawRepeatedField",
cpptype);
if (ctype >= 0)
ABSL_CHECK(IsMatchingCType(field, ctype)) << "subtype mismatch";
ABSL_CHECK_EQ(internal::cpp::EffectiveStringCType(field), ctype)
<< "subtype mismatch";
if (desc != nullptr)
ABSL_CHECK_EQ(field->message_type(), desc) << "wrong submessage type";
if (field->is_extension()) {

@ -117,8 +117,8 @@ struct DynamicFieldInfoHelper {
static absl::string_view GetStringView(const Reflection* reflection,
const Message& message,
const FieldDescriptor* field) {
auto string_type = field->cpp_string_type();
ABSL_DCHECK(string_type != FieldDescriptor::CppStringType::kCord);
auto ctype = cpp::EffectiveStringCType(field);
ABSL_DCHECK_NE(ctype, FieldOptions::CORD);
ABSL_DCHECK(!is_oneof || reflection->HasOneofField(message, field));
auto str = Get<ArenaStringPtr>(reflection, message, field);
ABSL_DCHECK(!str.IsDefault());

@ -174,10 +174,9 @@ void ReflectionVisit::VisitFields(MessageT& message, CallbackFn&& func,
reflection, message, field, rep}); \
}
switch (field->cpp_string_type()) {
case FieldDescriptor::CppStringType::kCord:
case FieldDescriptor::CppStringType::kView:
case FieldDescriptor::CppStringType::kString:
switch (cpp::EffectiveStringCType(field)) {
default:
case FieldOptions::STRING:
PROTOBUF_IMPL_STRING_CASE(std::string, String);
break;
}
@ -228,16 +227,13 @@ void ReflectionVisit::VisitFields(MessageT& message, CallbackFn&& func,
case FieldDescriptor::TYPE_BYTES:
case FieldDescriptor::TYPE_STRING: {
switch (field->cpp_string_type()) {
case FieldDescriptor::CppStringType::kCord:
func(CordDynamicFieldInfo<MessageT, true>{reflection, message,
auto ctype = cpp::EffectiveStringCType(field);
if (ctype == FieldOptions::CORD) {
func(CordDynamicFieldInfo<MessageT, true>{reflection, message,
field});
} else {
func(StringDynamicFieldInfo<MessageT, true>{reflection, message,
field});
break;
case FieldDescriptor::CppStringType::kString:
case FieldDescriptor::CppStringType::kView:
func(StringDynamicFieldInfo<MessageT, true>{reflection, message,
field});
break;
}
break;
}
@ -283,16 +279,13 @@ void ReflectionVisit::VisitFields(MessageT& message, CallbackFn&& func,
break;
case FieldDescriptor::TYPE_BYTES:
case FieldDescriptor::TYPE_STRING: {
switch (field->cpp_string_type()) {
case FieldDescriptor::CppStringType::kCord:
func(CordDynamicFieldInfo<MessageT, false>{reflection, message,
auto ctype = cpp::EffectiveStringCType(field);
if (ctype == FieldOptions::CORD) {
func(CordDynamicFieldInfo<MessageT, false>{reflection, message,
field});
} else {
func(StringDynamicFieldInfo<MessageT, false>{reflection, message,
field});
break;
case FieldDescriptor::CppStringType::kString:
case FieldDescriptor::CppStringType::kView:
func(StringDynamicFieldInfo<MessageT, false>{reflection, message,
field});
break;
}
break;
}

Loading…
Cancel
Save