Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add message type traits that can be declared in duplicate so that .proto.h can #18434

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions src/google/protobuf/compiler/cpp/file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1460,20 +1460,35 @@ class FileGenerator::ForwardDeclarations {
if (ShouldGenerateExternSpecializations(options)) {
for (const auto& c : classes_) {
if (!ShouldGenerateClass(c.second, options)) continue;
auto vars = p->WithVars(
{{"class", QualifiedClassName(c.second, options)},
{"default_name", QualifiedDefaultInstanceName(c.second, options,
/*split=*/false)}});
// To reduce total linker input size in large binaries we make these
// functions extern and define then in the pb.cc file. This avoids bloat
// in callers by having duplicate definitions of the template.
// However, it increases the size of the pb.cc translation units so it
// is a tradeoff.
p->Emit({{"class", QualifiedClassName(c.second, options)}}, R"cc(
p->Emit(R"cc(
extern template void* Arena::DefaultConstruct<$class$>(Arena*);
)cc");
if (!IsMapEntryMessage(c.second)) {
p->Emit({{"class", QualifiedClassName(c.second, options)}}, R"cc(
p->Emit(R"cc(
extern template void* Arena::CopyConstruct<$class$>(Arena*,
const void*);
)cc");
}
// We can't make a constexpr pointer to the global if we have DLL
// linkage so skip this.
// The fallback traits are slower, but correct.
if (options.dllexport_decl.empty()) {
p->Emit(R"cc(
template <>
internal::GeneratedMessageTraitsT<decltype($default_name$),
&$default_name$>
internal::MessageTraitsImpl::value<$class$>;
)cc");
}
}
}
}
Expand Down
14 changes: 0 additions & 14 deletions src/google/protobuf/compiler/cpp/message.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2041,18 +2041,6 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* p) {
$pbi$::ParseContext* ctx);
)cc");
}},
{"raw_default_instance",
[&] {
// We can't make a constexpr pointer to the global if we have DLL
// linkage so skip this. The fallback in
// `MessageLite::GetStrongPointerForType` will do the right thing in
// those platforms.
if (!options_.dllexport_decl.empty()) return;
p->Emit(R"cc(
static constexpr const void* _raw_default_instance_ =
&_$classname$_default_instance_;
)cc");
}},
{"decl_impl", [&] { GenerateImplDefinition(p); }},
{"classdata_type",
HasDescriptorMethods(descriptor_->file(), options_)
Expand Down Expand Up @@ -2210,8 +2198,6 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* p) {
$decl_data$;
$post_loop_handler$;

$raw_default_instance$;

friend class ::$proto_ns$::MessageLite;
friend class ::$proto_ns$::Arena;
template <typename T>
Expand Down
1 change: 0 additions & 1 deletion src/google/protobuf/compiler/java/java_features.pb.h

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

4 changes: 0 additions & 4 deletions src/google/protobuf/compiler/plugin.pb.h

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

1 change: 0 additions & 1 deletion src/google/protobuf/cpp_features.pb.h

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

33 changes: 0 additions & 33 deletions src/google/protobuf/descriptor.pb.h

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

Loading
Loading