Automated rollback of commit 2641517150.

PiperOrigin-RevId: 581037871
pull/14715/head
Protobuf Team Bot 1 year ago committed by Copybara-Service
parent 8522fbbacd
commit ecc2bac638
  1. 33
      src/google/protobuf/compiler/cpp/parse_function_generator.cc
  2. 37
      src/google/protobuf/generated_message_tctable_full.cc
  3. 28
      src/google/protobuf/generated_message_tctable_gen.cc
  4. 81
      src/google/protobuf/generated_message_tctable_impl.h
  5. 6
      src/google/protobuf/generated_message_tctable_lite.cc
  6. 2
      src/google/protobuf/parse_context.h
  7. 2
      src/google/protobuf/wire_format_unittest.inc

@ -51,7 +51,8 @@ bool UseDirectTcParserTable(const FieldDescriptor* field,
const Options& options) {
if (field->cpp_type() != field->CPPTYPE_MESSAGE) return false;
auto* m = field->message_type();
return m->file()->options().optimize_for() != FileOptions::CODE_SIZE &&
return !m->options().message_set_wire_format() &&
m->file()->options().optimize_for() != FileOptions::CODE_SIZE &&
!HasSimpleBaseClass(m, options) && !HasTracker(m, options) &&
!HasWeakFields(m)
; // NOLINT(whitespace/semicolon)
@ -115,12 +116,9 @@ ParseFunctionGenerator::ParseFunctionGenerator(
if (should_generate_tctable()) {
tc_table_info_.reset(new TailCallTableInfo(
descriptor_, ordered_fields_,
{
/* is_lite */ GetOptimizeFor(descriptor->file(), options_) ==
FileOptions::LITE_RUNTIME,
/* uses_codegen */ true,
options_.profile_driven_cluster_aux_subtable,
},
{/* is_lite */ GetOptimizeFor(descriptor->file(), options_) ==
FileOptions::LITE_RUNTIME,
/* uses_codegen */ true, options_.profile_driven_cluster_aux_subtable},
GeneratedOptionProvider(this), has_bit_indices,
inlined_string_indices));
}
@ -145,15 +143,18 @@ void ParseFunctionGenerator::GenerateMethodImpls(io::Printer* printer) {
Formatter format(printer, variables_);
if (descriptor_->options().message_set_wire_format()) {
// Special-case MessageSet.
printer->Emit(
R"cc(
const char* $classname$::_InternalParse(const char* ptr,
::_pbi::ParseContext* ctx) {
$annotate_deserialize$;
return $extensions$.ParseMessageSet(
ptr, internal_default_instance(), &_internal_metadata_, ctx);
}
)cc");
format(
"const char* $classname$::_InternalParse(const char* ptr,\n"
" ::_pbi::ParseContext* ctx) {\n"
"$annotate_deserialize$");
if (ShouldVerify(descriptor_, options_, scc_analyzer_)) {
format(
" ctx->set_lazy_eager_verify_func(&$classname$::InternalVerify);\n");
}
format(
" return $extensions$.ParseMessageSet(ptr, \n"
" internal_default_instance(), &_internal_metadata_, ctx);\n"
"}\n");
return;
}
if (HasWeakFields(descriptor_)) {

@ -91,43 +91,6 @@ const char* TcParser::ReflectionParseLoop(PROTOBUF_TC_PARAM_DECL) {
return WireFormat::_InternalParse(DownCast<Message*>(msg), ptr, ctx);
}
const char* TcParser::MessageSetWireFormatParseLoop(
PROTOBUF_TC_PARAM_NO_DATA_DECL) {
PROTOBUF_MUSTTAIL return MessageSetWireFormatParseLoopImpl<Message>(
PROTOBUF_TC_PARAM_NO_DATA_PASS);
}
template <typename TagType>
inline PROTOBUF_ALWAYS_INLINE const char* TcParser::MessageSetMessage(
PROTOBUF_TC_PARAM_DECL) {
if (PROTOBUF_PREDICT_FALSE(data.coded_tag<TagType>() != 0)) {
PROTOBUF_MUSTTAIL return MiniParse(PROTOBUF_TC_PARAM_NO_DATA_PASS);
}
ptr += sizeof(TagType);
hasbits |= (uint64_t{1} << data.hasbit_idx());
SyncHasbits(msg, hasbits, table);
auto& field = RefAt<MessageLite*>(msg, data.offset());
const auto* inner_table = table->field_aux(data.aux_idx())->table;
if (field == nullptr) {
field = inner_table->default_instance->New(msg->GetArena());
}
return ctx->ParseLengthDelimitedInlined(ptr, [&](const char* ptr) {
return RefAt<ExtensionSet>(field, inner_table->extension_offset)
.ParseMessageSet(
ptr, static_cast<const Message*>(inner_table->default_instance),
&field->_internal_metadata_, ctx);
});
}
const char* TcParser::FastMSS1(PROTOBUF_TC_PARAM_DECL) {
PROTOBUF_MUSTTAIL return MessageSetMessage<uint8_t>(PROTOBUF_TC_PARAM_PASS);
}
const char* TcParser::FastMSS2(PROTOBUF_TC_PARAM_DECL) {
PROTOBUF_MUSTTAIL return MessageSetMessage<uint16_t>(PROTOBUF_TC_PARAM_PASS);
}
} // namespace internal
} // namespace protobuf
} // namespace google

@ -196,14 +196,10 @@ TailCallTableInfo::FastFieldInfo::Field MakeFastFieldEntry(
break;
case FieldDescriptor::TYPE_MESSAGE:
picked =
HasLazyRep(field, options) ? PROTOBUF_PICK_SINGLE_FUNCTION(kFastMl)
: message_options.uses_codegen && !message_options.is_lite &&
field->message_type()->options().message_set_wire_format() &&
!field->is_repeated()
? PROTOBUF_PICK_SINGLE_FUNCTION(kFastMS)
: options.use_direct_tcparser_table
? PROTOBUF_PICK_REPEATABLE_FUNCTION(kFastMt)
: PROTOBUF_PICK_REPEATABLE_FUNCTION(kFastMd);
(HasLazyRep(field, options) ? PROTOBUF_PICK_SINGLE_FUNCTION(kFastMl)
: options.use_direct_tcparser_table
? PROTOBUF_PICK_REPEATABLE_FUNCTION(kFastMt)
: PROTOBUF_PICK_REPEATABLE_FUNCTION(kFastMd));
break;
case FieldDescriptor::TYPE_GROUP:
picked = (options.use_direct_tcparser_table
@ -737,22 +733,6 @@ TailCallTableInfo::TailCallTableInfo(
const OptionProvider& option_provider,
const std::vector<int>& has_bit_indices,
const std::vector<int>& inlined_string_indices) {
if (descriptor->options().message_set_wire_format()) {
ABSL_DCHECK(ordered_fields.empty());
ABSL_DCHECK(inlined_string_indices.empty());
fast_path_fields = {{TailCallTableInfo::FastFieldInfo::NonField{
message_options.is_lite
? TcParseFunction::kMessageSetWireFormatParseLoopLite
: TcParseFunction::kMessageSetWireFormatParseLoop,
0, 0}}};
table_size_log2 = 0;
num_to_entry_table = MakeNumToEntryTable(ordered_fields);
field_name_data = GenerateFieldNames(descriptor, field_entries,
message_options, option_provider);
return;
}
ABSL_DCHECK(std::is_sorted(ordered_fields.begin(), ordered_fields.end(),
[](const auto* lhs, const auto* rhs) {
return lhs->number() < rhs->number();

@ -328,36 +328,33 @@ inline void AlignFail(std::integral_constant<size_t, 1>,
// Examples:
// FastV8S1, FastZ64S2, FastEr1P2, FastBcS1, FastMtR2, FastEndG1
//
#define PROTOBUF_TC_PARSE_FUNCTION_LIST \
PROTOBUF_TC_PARSE_FUNCTION_LIST_PACKED(FastV8) \
PROTOBUF_TC_PARSE_FUNCTION_LIST_PACKED(FastV32) \
PROTOBUF_TC_PARSE_FUNCTION_LIST_PACKED(FastV64) \
PROTOBUF_TC_PARSE_FUNCTION_LIST_PACKED(FastZ32) \
PROTOBUF_TC_PARSE_FUNCTION_LIST_PACKED(FastZ64) \
PROTOBUF_TC_PARSE_FUNCTION_LIST_PACKED(FastF32) \
PROTOBUF_TC_PARSE_FUNCTION_LIST_PACKED(FastF64) \
PROTOBUF_TC_PARSE_FUNCTION_LIST_PACKED(FastEv) \
PROTOBUF_TC_PARSE_FUNCTION_LIST_PACKED(FastEr) \
PROTOBUF_TC_PARSE_FUNCTION_LIST_PACKED(FastEr0) \
PROTOBUF_TC_PARSE_FUNCTION_LIST_PACKED(FastEr1) \
PROTOBUF_TC_PARSE_FUNCTION_LIST_REPEATED(FastB) \
PROTOBUF_TC_PARSE_FUNCTION_LIST_REPEATED(FastS) \
PROTOBUF_TC_PARSE_FUNCTION_LIST_REPEATED(FastU) \
PROTOBUF_TC_PARSE_FUNCTION_LIST_SINGLE(FastBi) \
PROTOBUF_TC_PARSE_FUNCTION_LIST_SINGLE(FastSi) \
PROTOBUF_TC_PARSE_FUNCTION_LIST_SINGLE(FastUi) \
PROTOBUF_TC_PARSE_FUNCTION_LIST_SINGLE(FastBc) \
PROTOBUF_TC_PARSE_FUNCTION_LIST_SINGLE(FastSc) \
PROTOBUF_TC_PARSE_FUNCTION_LIST_SINGLE(FastUc) \
PROTOBUF_TC_PARSE_FUNCTION_LIST_REPEATED(FastGd) \
PROTOBUF_TC_PARSE_FUNCTION_LIST_REPEATED(FastGt) \
PROTOBUF_TC_PARSE_FUNCTION_LIST_REPEATED(FastMd) \
PROTOBUF_TC_PARSE_FUNCTION_LIST_REPEATED(FastMt) \
PROTOBUF_TC_PARSE_FUNCTION_LIST_SINGLE(FastMS) \
PROTOBUF_TC_PARSE_FUNCTION_LIST_SINGLE(FastMl) \
PROTOBUF_TC_PARSE_FUNCTION_LIST_END_GROUP() \
PROTOBUF_TC_PARSE_FUNCTION_X(MessageSetWireFormatParseLoopLite) \
PROTOBUF_TC_PARSE_FUNCTION_X(MessageSetWireFormatParseLoop)
#define PROTOBUF_TC_PARSE_FUNCTION_LIST \
PROTOBUF_TC_PARSE_FUNCTION_LIST_PACKED(FastV8) \
PROTOBUF_TC_PARSE_FUNCTION_LIST_PACKED(FastV32) \
PROTOBUF_TC_PARSE_FUNCTION_LIST_PACKED(FastV64) \
PROTOBUF_TC_PARSE_FUNCTION_LIST_PACKED(FastZ32) \
PROTOBUF_TC_PARSE_FUNCTION_LIST_PACKED(FastZ64) \
PROTOBUF_TC_PARSE_FUNCTION_LIST_PACKED(FastF32) \
PROTOBUF_TC_PARSE_FUNCTION_LIST_PACKED(FastF64) \
PROTOBUF_TC_PARSE_FUNCTION_LIST_PACKED(FastEv) \
PROTOBUF_TC_PARSE_FUNCTION_LIST_PACKED(FastEr) \
PROTOBUF_TC_PARSE_FUNCTION_LIST_PACKED(FastEr0) \
PROTOBUF_TC_PARSE_FUNCTION_LIST_PACKED(FastEr1) \
PROTOBUF_TC_PARSE_FUNCTION_LIST_REPEATED(FastB) \
PROTOBUF_TC_PARSE_FUNCTION_LIST_REPEATED(FastS) \
PROTOBUF_TC_PARSE_FUNCTION_LIST_REPEATED(FastU) \
PROTOBUF_TC_PARSE_FUNCTION_LIST_SINGLE(FastBi) \
PROTOBUF_TC_PARSE_FUNCTION_LIST_SINGLE(FastSi) \
PROTOBUF_TC_PARSE_FUNCTION_LIST_SINGLE(FastUi) \
PROTOBUF_TC_PARSE_FUNCTION_LIST_SINGLE(FastBc) \
PROTOBUF_TC_PARSE_FUNCTION_LIST_SINGLE(FastSc) \
PROTOBUF_TC_PARSE_FUNCTION_LIST_SINGLE(FastUc) \
PROTOBUF_TC_PARSE_FUNCTION_LIST_REPEATED(FastGd) \
PROTOBUF_TC_PARSE_FUNCTION_LIST_REPEATED(FastGt) \
PROTOBUF_TC_PARSE_FUNCTION_LIST_REPEATED(FastMd) \
PROTOBUF_TC_PARSE_FUNCTION_LIST_REPEATED(FastMt) \
PROTOBUF_TC_PARSE_FUNCTION_LIST_SINGLE(FastMl) \
PROTOBUF_TC_PARSE_FUNCTION_LIST_END_GROUP()
#define PROTOBUF_TC_PARSE_FUNCTION_X(value) k##value,
enum class TcParseFunction : uint8_t { kNone, PROTOBUF_TC_PARSE_FUNCTION_LIST };
@ -393,14 +390,6 @@ class PROTOBUF_EXPORT TcParser final {
static const char* ReflectionFallback(PROTOBUF_TC_PARAM_DECL);
static const char* ReflectionParseLoop(PROTOBUF_TC_PARAM_DECL);
// These follow the "fast" function ABI but implement the whole loop for
// message_set_wire_format types.
// They provide the same code _InternalParse does for these types.
static const char* MessageSetWireFormatParseLoop(
PROTOBUF_TC_PARAM_NO_DATA_DECL);
static const char* MessageSetWireFormatParseLoopLite(
PROTOBUF_TC_PARAM_NO_DATA_DECL);
PROTOBUF_NOINLINE
static const char* ParseLoop(MessageLite* msg, const char* ptr,
ParseContext* ctx,
@ -542,7 +531,7 @@ class PROTOBUF_EXPORT TcParser final {
// Functions referenced by generated fast tables (message types):
// M: message G: group
// d: default* t: TcParseTable* l: lazy S: MessageSet
// d: default* t: TcParseTable* (the contents of aux) l: lazy
// S: singular R: repeated
// 1/2: tag length (bytes)
PROTOBUF_NOINLINE static const char* FastMdS1(PROTOBUF_TC_PARAM_DECL);
@ -566,9 +555,6 @@ class PROTOBUF_EXPORT TcParser final {
PROTOBUF_NOINLINE static const char* FastMlS1(PROTOBUF_TC_PARAM_DECL);
PROTOBUF_NOINLINE static const char* FastMlS2(PROTOBUF_TC_PARAM_DECL);
PROTOBUF_NOINLINE static const char* FastMSS1(PROTOBUF_TC_PARAM_DECL);
PROTOBUF_NOINLINE static const char* FastMSS2(PROTOBUF_TC_PARAM_DECL);
// NOTE: Do not dedup RefAt by having one call the other with a const_cast. It
// causes ICEs of gcc 7.5.
// https://github.com/protocolbuffers/protobuf/issues/13715
@ -709,8 +695,6 @@ class PROTOBUF_EXPORT TcParser final {
static inline const char* RepeatedParseMessageAuxImpl(PROTOBUF_TC_PARAM_DECL);
template <typename TagType>
static inline const char* LazyMessage(PROTOBUF_TC_PARAM_DECL);
template <typename TagType>
static inline const char* MessageSetMessage(PROTOBUF_TC_PARAM_DECL);
template <typename TagType>
static const char* FastEndGroupImpl(PROTOBUF_TC_PARAM_DECL);
@ -794,15 +778,6 @@ class PROTOBUF_EXPORT TcParser final {
}
}
template <class MessageBaseT>
static const char* MessageSetWireFormatParseLoopImpl(
PROTOBUF_TC_PARAM_NO_DATA_DECL) {
return RefAt<ExtensionSet>(msg, table->extension_offset)
.ParseMessageSet(
ptr, static_cast<const MessageBaseT*>(table->default_instance),
&msg->_internal_metadata_, ctx);
}
// Note: `inline` is needed on template function declarations below to avoid
// -Wattributes diagnostic in GCC.

@ -2801,12 +2801,6 @@ PROTOBUF_NOINLINE const char* TcParser::MpMap(PROTOBUF_TC_PARAM_DECL) {
PROTOBUF_MUSTTAIL return ToTagDispatch(PROTOBUF_TC_PARAM_NO_DATA_PASS);
}
const char* TcParser::MessageSetWireFormatParseLoopLite(
PROTOBUF_TC_PARAM_NO_DATA_DECL) {
PROTOBUF_MUSTTAIL return MessageSetWireFormatParseLoopImpl<MessageLite>(
PROTOBUF_TC_PARAM_NO_DATA_PASS);
}
std::string TypeCardToString(uint16_t type_card) {
// In here we convert the runtime value of entry.type_card back into a
// sequence of literal enum labels. We use the mnenonic labels for nicer

@ -1121,7 +1121,7 @@ PROTOBUF_NODISCARD const char* ParseContext::ParseMessage(T* msg,
}
template <typename Func>
PROTOBUF_NODISCARD inline PROTOBUF_ALWAYS_INLINE const char*
PROTOBUF_NODISCARD PROTOBUF_ALWAYS_INLINE const char*
ParseContext::ParseLengthDelimitedInlined(const char* ptr, const Func& func) {
LimitToken old;
ptr = ReadSizeAndPushLimitAndDepthInlined(ptr, &old);

@ -689,7 +689,7 @@ void ValidateTestMessageSet(const std::string& test_case,
.GetPrototype(
PROTO2_WIREFORMAT_UNITTEST::TestMessageSet::descriptor())
->New());
ASSERT_TRUE(msg->ParseFromString(data));
msg->ParseFromString(data);
auto* reflection = msg->GetReflection();
std::vector<const FieldDescriptor*> fields;
reflection->ListFields(*msg, &fields);

Loading…
Cancel
Save