From 65106ad740bc73713275f154f9d1a655183dd805 Mon Sep 17 00:00:00 2001 From: Samuel Benzaquen Date: Tue, 18 Aug 2026 14:29:52 -0700 Subject: [PATCH] Continue cleaning up after the GLOBALS experiment. Remove TcParser::GetTable and migrate callers to MessageTraits::tc_table. PiperOrigin-RevId: 966808631 --- src/google/protobuf/compiler/cpp/message.cc | 7 +------ .../compiler/cpp/parse_function_generator.cc | 10 +--------- .../compiler/cpp/parse_function_generator.h | 3 --- .../protobuf/edition_message_unittest.cc | 18 +++--------------- .../protobuf/generated_message_tctable_impl.h | 11 ----------- .../protobuf/message_unittest_legacy_apis.inc | 11 ----------- 6 files changed, 5 insertions(+), 55 deletions(-) diff --git a/src/google/protobuf/compiler/cpp/message.cc b/src/google/protobuf/compiler/cpp/message.cc index 9874c2be4d2f2..f6b22c1c23bbd 100644 --- a/src/google/protobuf/compiler/cpp/message.cc +++ b/src/google/protobuf/compiler/cpp/message.cc @@ -1394,9 +1394,7 @@ void MessageGenerator::GenerateMapEntryClassDefinition(io::Printer* p) { }}, {"decl_annotate", [&] { GenerateAnnotationDecl(p); }}, {"alias_parse_table_type", - [&] { parse_function_generator_->GenerateAliasParseTableType(p); }}, - {"parse_decls", - [&] { parse_function_generator_->GenerateDataDecls(p); }}}, + [&] { parse_function_generator_->GenerateAliasParseTableType(p); }}}, R"cc( class $unused $$Msg$ final : public $pbi$::MapEntry<$key_cpp$, $val_cpp$, @@ -1431,7 +1429,6 @@ void MessageGenerator::GenerateMapEntryClassDefinition(io::Printer* p) { $alias_parse_table_type$; static constexpr ParseTableT_ InternalGenerateParseTable_( const $pbi$::ClassData* $nonnull$ class_data); - $parse_decls$; $decl_annotate$; const $pbi$::ClassData* $nonnull$ GetClassData() const PROTOBUF_FINAL; @@ -2080,7 +2077,6 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* p) { }}, {"alias_parse_table_type", [&] { parse_function_generator_->GenerateAliasParseTableType(p); }}, - {"decl_data", [&] { parse_function_generator_->GenerateDataDecls(p); }}, {"post_loop_handler", [&] { if (!NeedsPostLoopHandler(descriptor_, options_)) return; @@ -2250,7 +2246,6 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* p) { $alias_parse_table_type$; static constexpr ParseTableT_ InternalGenerateParseTable_( const $pbi$::ClassData* $nonnull$ class_data); - $decl_data$; $post_loop_handler$; friend class $pb$::MessageLite; diff --git a/src/google/protobuf/compiler/cpp/parse_function_generator.cc b/src/google/protobuf/compiler/cpp/parse_function_generator.cc index e25fc3fa49bb0..b832a95d9972d 100644 --- a/src/google/protobuf/compiler/cpp/parse_function_generator.cc +++ b/src/google/protobuf/compiler/cpp/parse_function_generator.cc @@ -151,14 +151,6 @@ void ParseFunctionGenerator::GenerateAliasParseTableType(io::Printer* p) { )cc"); } -void ParseFunctionGenerator::GenerateDataDecls(io::Printer* p) { - auto v = p->WithVars(variables_); - // TODO: Remove this once we remove TcParser::GetTable. - p->Emit(R"cc( - friend class $pbi$::TcParser; - )cc"); -} - static std::string TcParseFunctionName(internal::TcParseFunction func) { #define PROTOBUF_TC_PARSE_FUNCTION_X(value) #value, static constexpr absl::string_view kNames[] = { @@ -260,7 +252,7 @@ void ParseFunctionGenerator::GenerateParseTableHelperDefinition( options_)}}, R"cc( #ifdef PROTOBUF_PREFETCH_PARSE_TABLE - ::_pbi::TcParser::GetTable<$hot_type$>(), // to_prefetch + ::_pbi::MessageTraits<$hot_type$>::tc_table(), // to_prefetch #endif // PROTOBUF_PREFETCH_PARSE_TABLE)cc"); }}}, // clang-format off diff --git a/src/google/protobuf/compiler/cpp/parse_function_generator.h b/src/google/protobuf/compiler/cpp/parse_function_generator.h index 9549c0ce12206..55a91d91c5e81 100644 --- a/src/google/protobuf/compiler/cpp/parse_function_generator.h +++ b/src/google/protobuf/compiler/cpp/parse_function_generator.h @@ -76,9 +76,6 @@ class ParseFunctionGenerator { // Emit alias parse table type. void GenerateAliasParseTableType(io::Printer* printer); - // Emits class-level data member declarations to `printer`: - void GenerateDataDecls(io::Printer* printer); - // Emits the helper function definition to `printer`: void GenerateParseTableHelperDefinition(io::Printer* printer); diff --git a/src/google/protobuf/edition_message_unittest.cc b/src/google/protobuf/edition_message_unittest.cc index c2ae350793d5f..63e6981bc79e0 100644 --- a/src/google/protobuf/edition_message_unittest.cc +++ b/src/google/protobuf/edition_message_unittest.cc @@ -57,25 +57,13 @@ namespace internal { namespace { -template -static const TcParseTableBase* GetTableIfAvailable(...) { - return nullptr; -} - -template -static const TcParseTableBase* GetTableIfAvailable( - decltype(TcParser::GetTable())) { - return TcParser::GetTable(); -} - TEST(EditionMessageTest, TestRegressionInlinedStringAuxIdxMismatchOnFastParser) { using Proto = UNITTEST::InlinedStringIdxRegressionProto; - auto* table = GetTableIfAvailable(nullptr); - // Only test when TDP is on, and we have these fields inlined. - if (table != nullptr && - table->fast_entry(1)->target() == TcParser::FastBiS1) { + auto* table = MessageTraits::tc_table(); + // Only test when we have these fields inlined. + if (table->fast_entry(1)->target() == TcParser::FastBiS1) { // optional string str1 = 1; // The aux_idx points to the inlined_string_idx and not the actual aux_idx. EXPECT_EQ(table->fast_entry(1)->bits.aux_idx(), 1); diff --git a/src/google/protobuf/generated_message_tctable_impl.h b/src/google/protobuf/generated_message_tctable_impl.h index 91b76a03acd10..34a2a826aa3f5 100644 --- a/src/google/protobuf/generated_message_tctable_impl.h +++ b/src/google/protobuf/generated_message_tctable_impl.h @@ -376,17 +376,6 @@ enum class TcParseFunction : uint8_t { kNone, PROTOBUF_TC_PARSE_FUNCTION_LIST }; // TcParser implements most of the parsing logic for tailcall tables. class PROTOBUF_EXPORT TcParser final { public: - template -#ifndef PROTOBUF_MESSAGE_GLOBALS - static constexpr auto GetTable() -> decltype(&T::_table_.header) { - return &T::_table_.header; - } -#else - static const TcParseTableBase* GetTable() { - return MessageTraits::tc_table(); - } -#endif - static PROTOBUF_ALWAYS_INLINE const char* ParseMessage( MessageLite* msg, const char* ptr, ParseContext* ctx, const TcParseTableBase* tc_table) { diff --git a/src/google/protobuf/message_unittest_legacy_apis.inc b/src/google/protobuf/message_unittest_legacy_apis.inc index b4f9bc660c760..2960445b69a9e 100644 --- a/src/google/protobuf/message_unittest_legacy_apis.inc +++ b/src/google/protobuf/message_unittest_legacy_apis.inc @@ -79,18 +79,7 @@ TEST(MESSAGE_TEST_NAME, LegacyAddMethodsOnRepeatedStringField) { } -namespace { -template -static const internal::TcParseTableBase* GetTableIfAvailable(...) { - return nullptr; -} -template -static const internal::TcParseTableBase* GetTableIfAvailable( - decltype(internal::TcParser::GetTable())) { - return internal::TcParser::GetTable(); -} -} // namespace } // namespace protobuf } // namespace google