Skip to content

Commit

Permalink
Remove macro based guard for the table-driven parser.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 524003062
  • Loading branch information
protobuf-github-bot authored and copybara-github committed Apr 13, 2023
1 parent 41b7500 commit 31f649f
Show file tree
Hide file tree
Showing 6 changed files with 1 addition and 61 deletions.
2 changes: 0 additions & 2 deletions src/google/protobuf/compiler/cpp/generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,6 @@ bool CppGenerator::Generate(const FileDescriptor* file,
} else if (key == "experimental_tail_call_table_mode") {
if (value == "never") {
file_options.tctable_mode = Options::kTCTableNever;
} else if (value == "guarded") {
file_options.tctable_mode = Options::kTCTableGuarded;
} else if (value == "always") {
file_options.tctable_mode = Options::kTCTableAlways;
} else {
Expand Down
6 changes: 1 addition & 5 deletions src/google/protobuf/compiler/cpp/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,7 @@ struct Options {
std::string annotation_guard_name;
FieldListenerOptions field_listener_options;
EnforceOptimizeMode enforce_mode = EnforceOptimizeMode::kNoEnforcement;
enum {
kTCTableNever,
kTCTableGuarded,
kTCTableAlways
} tctable_mode = kTCTableNever;
enum { kTCTableNever, kTCTableAlways } tctable_mode = kTCTableNever;
int num_cc_files = 0;
bool safe_boundary_check = false;
bool proto_h = false;
Expand Down
40 changes: 0 additions & 40 deletions src/google/protobuf/compiler/cpp/parse_function_generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -152,20 +152,6 @@ void ParseFunctionGenerator::GenerateMethodDecls(io::Printer* printer) {
return;
}
Formatter format(printer, variables_);
if (should_generate_tctable()) {
format.Outdent();
if (should_generate_guarded_tctable()) {
format("#ifdef PROTOBUF_TAIL_CALL_TABLE_PARSER_ENABLED\n");
}
format(
" private:\n"
" static const char* Tct_ParseFallback(PROTOBUF_TC_PARAM_DECL);\n"
" public:\n");
if (should_generate_guarded_tctable()) {
format("#endif\n");
}
format.Indent();
}
format(
"const char* _InternalParse(const char* ptr, "
"::$proto_ns$::internal::ParseContext* ctx) final;\n");
Expand Down Expand Up @@ -202,19 +188,9 @@ void ParseFunctionGenerator::GenerateMethodImpls(io::Printer* printer) {
}
return;
}
if (should_generate_guarded_tctable()) {
format("#ifdef PROTOBUF_TAIL_CALL_TABLE_PARSER_ENABLED\n\n");
}
if (need_parse_function) {
GenerateTailcallParseFunction(format);
}
if (should_generate_guarded_tctable()) {
if (need_parse_function) {
format("\n#else // PROTOBUF_TAIL_CALL_TABLE_PARSER_ENABLED\n\n");
GenerateLoopingParseFunction(format);
}
format("\n#endif // PROTOBUF_TAIL_CALL_TABLE_PARSER_ENABLED\n");
}
}

bool ParseFunctionGenerator::should_generate_tctable() const {
Expand Down Expand Up @@ -278,11 +254,6 @@ void ParseFunctionGenerator::GenerateDataDecls(io::Printer* printer) {
return;
}
Formatter format(printer, variables_);
if (should_generate_guarded_tctable()) {
format.Outdent();
format("#ifdef PROTOBUF_TAIL_CALL_TABLE_PARSER_ENABLED\n");
format.Indent();
}
auto field_num_to_entry_table = MakeNumToEntryTable(ordered_fields_);
format(
"friend class ::$proto_ns$::internal::TcParser;\n"
Expand All @@ -292,25 +263,14 @@ void ParseFunctionGenerator::GenerateDataDecls(io::Printer* printer) {
tc_table_info_->aux_entries.size(),
FieldNameDataSize(tc_table_info_->field_name_data),
field_num_to_entry_table.size16());
if (should_generate_guarded_tctable()) {
format.Outdent();
format("#endif // PROTOBUF_TAIL_CALL_TABLE_PARSER_ENABLED\n");
format.Indent();
}
}

void ParseFunctionGenerator::GenerateDataDefinitions(io::Printer* printer) {
if (!should_generate_tctable()) {
return;
}
Formatter format(printer, variables_);
if (should_generate_guarded_tctable()) {
format("#ifdef PROTOBUF_TAIL_CALL_TABLE_PARSER_ENABLED\n");
}
GenerateTailCallTable(format);
if (should_generate_guarded_tctable()) {
format("#endif // PROTOBUF_TAIL_CALL_TABLE_PARSER_ENABLED\n");
}
}

void ParseFunctionGenerator::GenerateLoopingParseFunction(Formatter& format) {
Expand Down
7 changes: 0 additions & 7 deletions src/google/protobuf/compiler/cpp/parse_function_generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,6 @@ class ParseFunctionGenerator {
// Returns true if tailcall table code should be generated.
bool should_generate_tctable() const;

// Returns true if tailcall table code should be generated, but inside an
// #ifdef guard.
bool should_generate_guarded_tctable() const {
return should_generate_tctable() &&
options_.tctable_mode == Options::kTCTableGuarded;
}

// Generates a tail-calling `_InternalParse` function.
void GenerateTailcallParseFunction(Formatter& format);

Expand Down
6 changes: 0 additions & 6 deletions src/google/protobuf/port_def.inc
Original file line number Diff line number Diff line change
Expand Up @@ -824,12 +824,6 @@ static_assert(PROTOBUF_CPLUSPLUS_MIN(201402L), "Protobuf only supports C++14 and
# endif
#endif

// Tail call table-driven parsing is enabled by default.
#ifdef PROTOBUF_TAIL_CALL_TABLE_PARSER_ENABLED
#error PROTOBUF_TAIL_CALL_TABLE_PARSER_ENABLED was previously declared
#endif
#define PROTOBUF_TAIL_CALL_TABLE_PARSER_ENABLED 1

#ifdef PROTOBUF_USE_TABLE_PARSER_ON_REFLECTION
#error PROTOBUF_USE_TABLE_PARSER_ON_REFLECTION was previously defined
#endif
Expand Down
1 change: 0 additions & 1 deletion src/google/protobuf/port_undef.inc
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@
#undef PROTOBUF_ASAN
#undef PROTOBUF_MSAN
#undef PROTOBUF_TSAN
#undef PROTOBUF_TAIL_CALL_TABLE_PARSER_ENABLED
#undef PROTOBUF_USE_TABLE_PARSER_ON_REFLECTION
#undef PROTOBUF_TC_PARAM_DECL
#undef PROTOBUF_EXCLUSIVE_LOCKS_REQUIRED
Expand Down

0 comments on commit 31f649f

Please sign in to comment.