Skip to content

Commit

Permalink
When not in custom vtable mode, strip the initializer code via prepro…
Browse files Browse the repository at this point in the history
…cessor.

The noop code was causing big .proto files to time out even though it had no
effect in the compilation after optimizing.

We tried avoiding the extra complexity of preprocessor checks on each use, but
it seems necessary for now.

PiperOrigin-RevId: 642691974
  • Loading branch information
protobuf-github-bot authored and copybara-github committed Jun 12, 2024
1 parent 1f98445 commit 4dffa93
Show file tree
Hide file tree
Showing 10 changed files with 680 additions and 51 deletions.
22 changes: 13 additions & 9 deletions src/google/protobuf/arena_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -182,20 +182,21 @@ void TestCtorAndDtorTraits(std::vector<absl::string_view> def,
: std::conditional_t<arena_ctor, ArenaCtorBase, EmptyBase<0>>,
std::conditional_t<arena_dtor, ArenaDtorBase, EmptyBase<1>>,
Message {
TraitsProber() : Message(nullptr) { actions.push_back("()"); }
TraitsProber(const TraitsProber&) : Message(nullptr) {
TraitsProber() : Message(nullptr, nullptr) { actions.push_back("()"); }
TraitsProber(const TraitsProber&) : Message(nullptr, nullptr) {
actions.push_back("(const T&)");
}
explicit TraitsProber(int) : Message(nullptr) {
explicit TraitsProber(int) : Message(nullptr, nullptr) {
actions.push_back("(int)");
}
explicit TraitsProber(Arena* arena) : Message(nullptr) {
explicit TraitsProber(Arena* arena) : Message(nullptr, nullptr) {
actions.push_back("(Arena)");
}
TraitsProber(Arena* arena, const TraitsProber&) : Message(nullptr) {
TraitsProber(Arena* arena, const TraitsProber&)
: Message(nullptr, nullptr) {
actions.push_back("(Arena, const T&)");
}
TraitsProber(Arena* arena, int) : Message(nullptr) {
TraitsProber(Arena* arena, int) : Message(nullptr, nullptr) {
actions.push_back("(Arena, int)");
}
~TraitsProber() { actions.push_back("~()"); }
Expand Down Expand Up @@ -519,9 +520,12 @@ class DispatcherTestProto : public Message {
using InternalArenaConstructable_ = void;
using DestructorSkippable_ = void;
// For the test below to construct.
explicit DispatcherTestProto(absl::in_place_t) : Message(nullptr) {}
explicit DispatcherTestProto(Arena*) : Message(nullptr) { ABSL_LOG(FATAL); }
DispatcherTestProto(Arena*, const DispatcherTestProto&) : Message(nullptr) {
explicit DispatcherTestProto(absl::in_place_t) : Message(nullptr, nullptr) {}
explicit DispatcherTestProto(Arena*) : Message(nullptr, nullptr) {
ABSL_LOG(FATAL);
}
DispatcherTestProto(Arena*, const DispatcherTestProto&)
: Message(nullptr, nullptr) {
ABSL_LOG(FATAL);
}
DispatcherTestProto* New(Arena*) const PROTOBUF_FINAL { ABSL_LOG(FATAL); }
Expand Down
31 changes: 29 additions & 2 deletions src/google/protobuf/compiler/cpp/message.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2143,9 +2143,14 @@ void MessageGenerator::GenerateClassMethods(io::Printer* p) {
}},
{"class_data", [&] { GenerateClassData(p); }}},
R"cc(
#if defined(PROTOBUF_CUSTOM_VTABLE)
$classname$::$classname$() : SuperType(_class_data_.base()) {}
$classname$::$classname$(::$proto_ns$::Arena* arena)
: SuperType(arena, _class_data_.base()) {}
#else // PROTOBUF_CUSTOM_VTABLE
$classname$::$classname$() : SuperType() {}
$classname$::$classname$(::$proto_ns$::Arena* arena) : SuperType(arena) {}
#endif // PROTOBUF_CUSTOM_VTABLE
$annotate_accessors$;
$verify$;
$class_data$;
Expand Down Expand Up @@ -2859,7 +2864,12 @@ void MessageGenerator::GenerateConstexprConstructor(io::Printer* p) {
//~ gcc 12 (warning in gcc 13).
template <typename>
$constexpr$ $classname$::$classname$(::_pbi::ConstantInitialized)
: $base$(_class_data_.base()) {}
#if defined(PROTOBUF_CUSTOM_VTABLE)
: $base$(_class_data_.base()){}
#else // PROTOBUF_CUSTOM_VTABLE
: $base$() {
}
#endif // PROTOBUF_CUSTOM_VTABLE
)cc");
return;
}
Expand All @@ -2881,8 +2891,13 @@ void MessageGenerator::GenerateConstexprConstructor(io::Printer* p) {
R"cc(
template <typename>
$constexpr$ $classname$::$classname$(::_pbi::ConstantInitialized)
#if defined(PROTOBUF_CUSTOM_VTABLE)
: $superclass$(_class_data_.base()),
_impl_(::_pbi::ConstantInitialized()) {}
#else // PROTOBUF_CUSTOM_VTABLE
: $superclass$(),
#endif // PROTOBUF_CUSTOM_VTABLE
_impl_(::_pbi::ConstantInitialized()) {
}
)cc");
}

Expand Down Expand Up @@ -3145,7 +3160,11 @@ void MessageGenerator::GenerateArenaEnabledCopyConstructor(io::Printer* p) {
::$proto_ns$::Arena* arena,
//~ force alignment
const $classname$& from)
#if defined(PROTOBUF_CUSTOM_VTABLE)
: $superclass$(arena, _class_data_.base()) {
#else // PROTOBUF_CUSTOM_VTABLE
: $superclass$(arena) {
#endif // PROTOBUF_CUSTOM_VTABLE
$classname$* const _this = this;
(void)_this;
_internal_metadata_.MergeFrom<$unknown_fields_type$>(
Expand Down Expand Up @@ -3191,7 +3210,11 @@ void MessageGenerator::GenerateStructors(io::Printer* p) {
},
R"cc(
$classname$::$classname$(::$proto_ns$::Arena* arena)
#if defined(PROTOBUF_CUSTOM_VTABLE)
: $superclass$(arena, _class_data_.base()) {
#else // PROTOBUF_CUSTOM_VTABLE
: $superclass$(arena) {
#endif // PROTOBUF_CUSTOM_VTABLE
$ctor_body$;
// @@protoc_insertion_point(arena_constructor:$full_name$)
}
Expand Down Expand Up @@ -3733,9 +3756,11 @@ void MessageGenerator::GenerateClassData(io::Printer* p) {
$on_demand_register_arena_dtor$,
$is_initialized$,
&$classname$::MergeImpl,
#if defined(PROTOBUF_CUSTOM_VTABLE)
$superclass$::GetDeleteImpl<$classname$>(),
$superclass$::GetNewImpl<$classname$>(),
$custom_vtable_methods$,
#endif // PROTOBUF_CUSTOM_VTABLE
PROTOBUF_FIELD_OFFSET($classname$, $cached_size$),
false,
},
Expand Down Expand Up @@ -3768,9 +3793,11 @@ void MessageGenerator::GenerateClassData(io::Printer* p) {
$on_demand_register_arena_dtor$,
$is_initialized$,
&$classname$::MergeImpl,
#if defined(PROTOBUF_CUSTOM_VTABLE)
$superclass$::GetDeleteImpl<$classname$>(),
$superclass$::GetNewImpl<$classname$>(),
$custom_vtable_methods$,
#endif // PROTOBUF_CUSTOM_VTABLE
PROTOBUF_FIELD_OFFSET($classname$, $cached_size$),
true,
},
Expand Down
13 changes: 12 additions & 1 deletion src/google/protobuf/compiler/java/java_features.pb.cc

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

68 changes: 64 additions & 4 deletions src/google/protobuf/compiler/plugin.pb.cc

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 4dffa93

Please sign in to comment.