Remove codegen references to unused_field_stripping.

PiperOrigin-RevId: 499585080
pull/11460/head
Chris Kennelly 2 years ago committed by Copybara-Service
parent d5fd41d2d4
commit 46058d2c2d
  1. 2
      src/google/protobuf/compiler/cpp/field_generators/map_field.cc
  2. 80
      src/google/protobuf/compiler/cpp/field_generators/message_field.cc
  3. 6
      src/google/protobuf/compiler/cpp/helpers.h
  4. 90
      src/google/protobuf/compiler/cpp/message.cc
  5. 1
      src/google/protobuf/compiler/cpp/options.h
  6. 2
      src/google/protobuf/compiler/cpp/parse_function_generator.cc

@ -331,8 +331,6 @@ void MapFieldGenerator::GenerateAggregateInitializer(
} }
void MapFieldGenerator::GenerateDestructorCode(io::Printer* printer) const { void MapFieldGenerator::GenerateDestructorCode(io::Printer* printer) const {
GOOGLE_ABSL_CHECK(!IsFieldStripped(descriptor_, options_));
Formatter format(printer, variables_); Formatter format(printer, variables_);
if (ShouldSplit(descriptor_, options_)) { if (ShouldSplit(descriptor_, options_)) {
format("$cached_split_ptr$->$name$_.Destruct();\n"); format("$cached_split_ptr$->$name$_.Destruct();\n");

@ -199,41 +199,18 @@ void MessageFieldGenerator::GeneratePrivateMembers(io::Printer* printer) const {
void MessageFieldGenerator::GenerateAccessorDeclarations( void MessageFieldGenerator::GenerateAccessorDeclarations(
io::Printer* printer) const { io::Printer* printer) const {
Formatter format(printer, variables_); Formatter format(printer, variables_);
if (IsFieldStripped(descriptor_, options_)) {
format(
"$deprecated_attr$const $type$& ${1$$name$$}$() const { "
"__builtin_trap(); }\n"
"PROTOBUF_NODISCARD $deprecated_attr$$type$* "
"${1$$release_name$$}$() { "
"__builtin_trap(); }\n"
"$deprecated_attr$$type$* ${1$mutable_$name$$}$() { "
"__builtin_trap(); }\n"
"$deprecated_attr$void ${1$set_allocated_$name$$}$"
"($type$* $name$) { __builtin_trap(); }\n"
"$deprecated_attr$void "
"${1$unsafe_arena_set_allocated_$name$$}$(\n"
" $type$* $name$) { __builtin_trap(); }\n"
"$deprecated_attr$$type$* ${1$unsafe_arena_release_$name$$}$() { "
"__builtin_trap(); }\n",
descriptor_);
return;
}
format( format(
"$deprecated_attr$const $type$& ${1$$name$$}$() const;\n" "$deprecated_attr$const $type$& ${1$$name$$}$() const;\n"
"PROTOBUF_NODISCARD $deprecated_attr$$type$* " "PROTOBUF_NODISCARD $deprecated_attr$$type$* "
"${1$$release_name$$}$();\n" "${1$$release_name$$}$();\n"
"$deprecated_attr$$type$* ${1$mutable_$name$$}$();\n" "$deprecated_attr$$type$* ${1$mutable_$name$$}$();\n"
"$deprecated_attr$void ${1$set_allocated_$name$$}$" "$deprecated_attr$void ${1$set_allocated_$name$$}$"
"($type$* $name$);\n", "($type$* $name$);\n"
descriptor_);
if (!IsFieldStripped(descriptor_, options_)) {
format(
"private:\n" "private:\n"
"const $type$& ${1$_internal_$name$$}$() const;\n" "const $type$& ${1$_internal_$name$$}$() const;\n"
"$type$* ${1$_internal_mutable_$name$$}$();\n" "$type$* ${1$_internal_mutable_$name$$}$();\n"
"public:\n", "public:\n",
descriptor_); descriptor_);
}
format( format(
"$deprecated_attr$void " "$deprecated_attr$void "
"${1$unsafe_arena_set_allocated_$name$$}$(\n" "${1$unsafe_arena_set_allocated_$name$$}$(\n"
@ -461,8 +438,6 @@ void MessageFieldGenerator::GenerateInternalAccessorDefinitions(
} }
void MessageFieldGenerator::GenerateClearingCode(io::Printer* printer) const { void MessageFieldGenerator::GenerateClearingCode(io::Printer* printer) const {
GOOGLE_ABSL_CHECK(!IsFieldStripped(descriptor_, options_));
Formatter format(printer, variables_); Formatter format(printer, variables_);
if (!internal::cpp::HasHasbit(descriptor_)) { if (!internal::cpp::HasHasbit(descriptor_)) {
// If we don't have has-bits, message presence is indicated only by ptr != // If we don't have has-bits, message presence is indicated only by ptr !=
@ -479,8 +454,6 @@ void MessageFieldGenerator::GenerateClearingCode(io::Printer* printer) const {
void MessageFieldGenerator::GenerateMessageClearingCode( void MessageFieldGenerator::GenerateMessageClearingCode(
io::Printer* printer) const { io::Printer* printer) const {
GOOGLE_ABSL_CHECK(!IsFieldStripped(descriptor_, options_));
Formatter format(printer, variables_); Formatter format(printer, variables_);
if (!internal::cpp::HasHasbit(descriptor_)) { if (!internal::cpp::HasHasbit(descriptor_)) {
// If we don't have has-bits, message presence is indicated only by ptr != // If we don't have has-bits, message presence is indicated only by ptr !=
@ -498,8 +471,6 @@ void MessageFieldGenerator::GenerateMessageClearingCode(
} }
void MessageFieldGenerator::GenerateMergingCode(io::Printer* printer) const { void MessageFieldGenerator::GenerateMergingCode(io::Printer* printer) const {
GOOGLE_ABSL_CHECK(!IsFieldStripped(descriptor_, options_));
Formatter format(printer, variables_); Formatter format(printer, variables_);
if (implicit_weak_field_) { if (implicit_weak_field_) {
format( format(
@ -513,15 +484,11 @@ void MessageFieldGenerator::GenerateMergingCode(io::Printer* printer) const {
} }
void MessageFieldGenerator::GenerateSwappingCode(io::Printer* printer) const { void MessageFieldGenerator::GenerateSwappingCode(io::Printer* printer) const {
GOOGLE_ABSL_CHECK(!IsFieldStripped(descriptor_, options_));
Formatter format(printer, variables_); Formatter format(printer, variables_);
format("swap($field$, other->$field$);\n"); format("swap($field$, other->$field$);\n");
} }
void MessageFieldGenerator::GenerateDestructorCode(io::Printer* printer) const { void MessageFieldGenerator::GenerateDestructorCode(io::Printer* printer) const {
GOOGLE_ABSL_CHECK(!IsFieldStripped(descriptor_, options_));
Formatter format(printer, variables_); Formatter format(printer, variables_);
if (options_.opensource_runtime) { if (options_.opensource_runtime) {
// TODO(gerbens) Remove this when we don't need to destruct default // TODO(gerbens) Remove this when we don't need to destruct default
@ -542,8 +509,6 @@ using internal::cpp::HasHasbit;
void MessageFieldGenerator::GenerateCopyConstructorCode( void MessageFieldGenerator::GenerateCopyConstructorCode(
io::Printer* printer) const { io::Printer* printer) const {
GOOGLE_ABSL_CHECK(!IsFieldStripped(descriptor_, options_));
Formatter format(printer, variables_); Formatter format(printer, variables_);
if (HasHasbit(descriptor_)) { if (HasHasbit(descriptor_)) {
format( format(
@ -560,8 +525,6 @@ void MessageFieldGenerator::GenerateCopyConstructorCode(
void MessageFieldGenerator::GenerateSerializeWithCachedSizesToArray( void MessageFieldGenerator::GenerateSerializeWithCachedSizesToArray(
io::Printer* printer) const { io::Printer* printer) const {
GOOGLE_ABSL_CHECK(!IsFieldStripped(descriptor_, options_));
Formatter format(printer, variables_); Formatter format(printer, variables_);
if (descriptor_->type() == FieldDescriptor::TYPE_MESSAGE) { if (descriptor_->type() == FieldDescriptor::TYPE_MESSAGE) {
format( format(
@ -578,8 +541,6 @@ void MessageFieldGenerator::GenerateSerializeWithCachedSizesToArray(
} }
void MessageFieldGenerator::GenerateByteSize(io::Printer* printer) const { void MessageFieldGenerator::GenerateByteSize(io::Printer* printer) const {
GOOGLE_ABSL_CHECK(!IsFieldStripped(descriptor_, options_));
Formatter format(printer, variables_); Formatter format(printer, variables_);
format( format(
"total_size += $tag_size$ +\n" "total_size += $tag_size$ +\n"
@ -588,8 +549,6 @@ void MessageFieldGenerator::GenerateByteSize(io::Printer* printer) const {
} }
void MessageFieldGenerator::GenerateIsInitialized(io::Printer* printer) const { void MessageFieldGenerator::GenerateIsInitialized(io::Printer* printer) const {
GOOGLE_ABSL_CHECK(!IsFieldStripped(descriptor_, options_));
if (!has_required_fields_) return; if (!has_required_fields_) return;
Formatter format(printer, variables_); Formatter format(printer, variables_);
@ -768,8 +727,6 @@ void MessageOneofFieldGenerator::GenerateInlineAccessorDefinitions(
void MessageOneofFieldGenerator::GenerateClearingCode( void MessageOneofFieldGenerator::GenerateClearingCode(
io::Printer* printer) const { io::Printer* printer) const {
GOOGLE_ABSL_CHECK(!IsFieldStripped(descriptor_, options_));
Formatter format(printer, variables_); Formatter format(printer, variables_);
format( format(
"if (GetArenaForAllocation() == nullptr) {\n" "if (GetArenaForAllocation() == nullptr) {\n"
@ -836,34 +793,15 @@ void RepeatedMessageFieldGenerator::GeneratePrivateMembers(
void RepeatedMessageFieldGenerator::GenerateAccessorDeclarations( void RepeatedMessageFieldGenerator::GenerateAccessorDeclarations(
io::Printer* printer) const { io::Printer* printer) const {
Formatter format(printer, variables_); Formatter format(printer, variables_);
if (IsFieldStripped(descriptor_, options_)) {
format(
"$deprecated_attr$$type$* ${1$mutable_$name$$}$(int index) { "
"__builtin_trap(); }\n"
"$deprecated_attr$::$proto_ns$::RepeatedPtrField< $type$ >*\n"
" ${1$mutable_$name$$}$() { __builtin_trap(); }\n"
"$deprecated_attr$const $type$& ${1$$name$$}$(int index) const { "
"__builtin_trap(); }\n"
"$deprecated_attr$$type$* ${1$add_$name$$}$() { "
"__builtin_trap(); }\n"
"$deprecated_attr$const ::$proto_ns$::RepeatedPtrField< $type$ >&\n"
" ${1$$name$$}$() const { __builtin_trap(); }\n",
descriptor_);
return;
}
format( format(
"$deprecated_attr$$type$* ${1$mutable_$name$$}$(int index);\n" "$deprecated_attr$$type$* ${1$mutable_$name$$}$(int index);\n"
"$deprecated_attr$::$proto_ns$::RepeatedPtrField< $type$ >*\n" "$deprecated_attr$::$proto_ns$::RepeatedPtrField< $type$ >*\n"
" ${1$mutable_$name$$}$();\n", " ${1$mutable_$name$$}$();\n"
descriptor_);
if (!IsFieldStripped(descriptor_, options_)) {
format(
"private:\n" "private:\n"
"const $type$& ${1$_internal_$name$$}$(int index) const;\n" "const $type$& ${1$_internal_$name$$}$(int index) const;\n"
"$type$* ${1$_internal_add_$name$$}$();\n" "$type$* ${1$_internal_add_$name$$}$();\n"
"public:\n", "public:\n",
descriptor_); descriptor_);
}
format( format(
"$deprecated_attr$const $type$& ${1$$name$$}$(int index) const;\n" "$deprecated_attr$const $type$& ${1$$name$$}$(int index) const;\n"
"$deprecated_attr$$type$* ${1$add_$name$$}$();\n" "$deprecated_attr$$type$* ${1$add_$name$$}$();\n"
@ -937,24 +875,18 @@ void RepeatedMessageFieldGenerator::GenerateInlineAccessorDefinitions(
void RepeatedMessageFieldGenerator::GenerateClearingCode( void RepeatedMessageFieldGenerator::GenerateClearingCode(
io::Printer* printer) const { io::Printer* printer) const {
GOOGLE_ABSL_CHECK(!IsFieldStripped(descriptor_, options_));
Formatter format(printer, variables_); Formatter format(printer, variables_);
format("$field$.Clear();\n"); format("$field$.Clear();\n");
} }
void RepeatedMessageFieldGenerator::GenerateMergingCode( void RepeatedMessageFieldGenerator::GenerateMergingCode(
io::Printer* printer) const { io::Printer* printer) const {
GOOGLE_ABSL_CHECK(!IsFieldStripped(descriptor_, options_));
Formatter format(printer, variables_); Formatter format(printer, variables_);
format("_this->$field$.MergeFrom(from.$field$);\n"); format("_this->$field$.MergeFrom(from.$field$);\n");
} }
void RepeatedMessageFieldGenerator::GenerateSwappingCode( void RepeatedMessageFieldGenerator::GenerateSwappingCode(
io::Printer* printer) const { io::Printer* printer) const {
GOOGLE_ABSL_CHECK(!IsFieldStripped(descriptor_, options_));
Formatter format(printer, variables_); Formatter format(printer, variables_);
format("$field$.InternalSwap(&other->$field$);\n"); format("$field$.InternalSwap(&other->$field$);\n");
} }
@ -966,8 +898,6 @@ void RepeatedMessageFieldGenerator::GenerateConstructorCode(
void RepeatedMessageFieldGenerator::GenerateDestructorCode( void RepeatedMessageFieldGenerator::GenerateDestructorCode(
io::Printer* printer) const { io::Printer* printer) const {
GOOGLE_ABSL_CHECK(!IsFieldStripped(descriptor_, options_));
Formatter format(printer, variables_); Formatter format(printer, variables_);
if (implicit_weak_field_) { if (implicit_weak_field_) {
format("$field$.~WeakRepeatedPtrField();\n"); format("$field$.~WeakRepeatedPtrField();\n");
@ -978,8 +908,6 @@ void RepeatedMessageFieldGenerator::GenerateDestructorCode(
void RepeatedMessageFieldGenerator::GenerateSerializeWithCachedSizesToArray( void RepeatedMessageFieldGenerator::GenerateSerializeWithCachedSizesToArray(
io::Printer* printer) const { io::Printer* printer) const {
GOOGLE_ABSL_CHECK(!IsFieldStripped(descriptor_, options_));
Formatter format(printer, variables_); Formatter format(printer, variables_);
if (implicit_weak_field_) { if (implicit_weak_field_) {
format( format(
@ -1023,8 +951,6 @@ void RepeatedMessageFieldGenerator::GenerateSerializeWithCachedSizesToArray(
void RepeatedMessageFieldGenerator::GenerateByteSize( void RepeatedMessageFieldGenerator::GenerateByteSize(
io::Printer* printer) const { io::Printer* printer) const {
GOOGLE_ABSL_CHECK(!IsFieldStripped(descriptor_, options_));
Formatter format(printer, variables_); Formatter format(printer, variables_);
format( format(
"total_size += $tag_size$UL * this->_internal_$name$_size();\n" "total_size += $tag_size$UL * this->_internal_$name$_size();\n"
@ -1036,8 +962,6 @@ void RepeatedMessageFieldGenerator::GenerateByteSize(
void RepeatedMessageFieldGenerator::GenerateIsInitialized( void RepeatedMessageFieldGenerator::GenerateIsInitialized(
io::Printer* printer) const { io::Printer* printer) const {
GOOGLE_ABSL_CHECK(!IsFieldStripped(descriptor_, options_));
if (!has_required_fields_) return; if (!has_required_fields_) return;
Formatter format(printer, variables_); Formatter format(printer, variables_);

@ -408,12 +408,6 @@ inline bool IsFieldUsed(const FieldDescriptor* /* field */,
return true; return true;
} }
// Returns true if "field" is stripped.
inline bool IsFieldStripped(const FieldDescriptor* /*field*/,
const Options& /*options*/) {
return false;
}
// Does the file contain any definitions that need extension_set.h? // Does the file contain any definitions that need extension_set.h?
bool HasExtensionsOrExtendableMessage(const FileDescriptor* file); bool HasExtensionsOrExtendableMessage(const FileDescriptor* file);

@ -548,10 +548,6 @@ MessageGenerator::MessageGenerator(
// Compute optimized field order to be used for layout and initialization // Compute optimized field order to be used for layout and initialization
// purposes. // purposes.
for (auto field : FieldRange(descriptor_)) { for (auto field : FieldRange(descriptor_)) {
if (IsFieldStripped(field, options_)) {
continue;
}
if (IsWeak(field, options_)) { if (IsWeak(field, options_)) {
++num_weak_fields_; ++num_weak_fields_;
continue; continue;
@ -653,8 +649,7 @@ void MessageGenerator::GenerateFieldAccessorDeclarations(io::Printer* p) {
optimized_order_.end()); optimized_order_.end());
for (auto field : FieldRange(descriptor_)) { for (auto field : FieldRange(descriptor_)) {
if (!field->real_containing_oneof() && !field->options().weak() && if (!field->real_containing_oneof() && !field->options().weak()) {
!IsFieldStripped(field, options_)) {
continue; continue;
} }
ordered_fields.push_back(field); ordered_fields.push_back(field);
@ -681,17 +676,14 @@ void MessageGenerator::GenerateFieldAccessorDeclarations(io::Printer* p) {
)cc"); )cc");
} }
for (auto field : ordered_fields) { for (auto field : ordered_fields) {
bool stripped = IsFieldStripped(field, options_);
auto name = FieldName(field); auto name = FieldName(field);
auto v = p->WithVars(FieldVars(field, options_)); auto v = p->WithVars(FieldVars(field, options_));
auto t = p->WithVars(MakeTrackerCalls(field, options_)); auto t = p->WithVars(MakeTrackerCalls(field, options_));
p->Emit( p->Emit(
{{"field_comment", FieldComment(field)}, {{"field_comment", FieldComment(field)},
Sub("const_impl", !stripped ? "const;" : "const { __builtin_trap(); }") Sub("const_impl", "const;").WithSuffix(";"),
.WithSuffix(";"), Sub("impl", ";").WithSuffix(";"),
Sub("impl", !stripped ? ";" : " { __builtin_trap(); }")
.WithSuffix(";"),
{"sizer", {"sizer",
[&] { [&] {
if (!field->is_repeated()) return; if (!field->is_repeated()) return;
@ -701,7 +693,6 @@ void MessageGenerator::GenerateFieldAccessorDeclarations(io::Printer* p) {
$deprecated_attr $int $name_size$() $const_impl$; $deprecated_attr $int $name_size$() $const_impl$;
)cc"); )cc");
if (stripped) return;
p->Emit({Sub("_internal_name_size", p->Emit({Sub("_internal_name_size",
absl::StrCat("_internal_", name, "_size")) absl::StrCat("_internal_", name, "_size"))
.AnnotatedAs(field)}, .AnnotatedAs(field)},
@ -723,8 +714,7 @@ void MessageGenerator::GenerateFieldAccessorDeclarations(io::Printer* p) {
}}, }},
{"internal_hazzer", {"internal_hazzer",
[&] { [&] {
if (field->is_repeated() || !HasInternalHasMethod(field) || if (field->is_repeated() || !HasInternalHasMethod(field)) {
stripped) {
return; return;
} }
p->Emit( p->Emit(
@ -969,12 +959,6 @@ void MessageGenerator::GenerateSingularFieldHasBits(
const FieldDescriptor* field, io::Printer* p) { const FieldDescriptor* field, io::Printer* p) {
auto t = p->WithVars(MakeTrackerCalls(field, options_)); auto t = p->WithVars(MakeTrackerCalls(field, options_));
Formatter format(p); Formatter format(p);
if (IsFieldStripped(field, options_)) {
format(
"inline bool $classname$::has_$name$() const { "
"__builtin_trap(); }\n");
return;
}
if (field->options().weak()) { if (field->options().weak()) {
format( format(
"inline bool $classname$::has_$name$() const {\n" "inline bool $classname$::has_$name$() const {\n"
@ -1049,17 +1033,6 @@ void MessageGenerator::GenerateOneofMemberHasBits(const FieldDescriptor* field,
auto v = p->WithVars(OneofFieldVars(field)); auto v = p->WithVars(OneofFieldVars(field));
auto t = p->WithVars(MakeTrackerCalls(field, options_)); auto t = p->WithVars(MakeTrackerCalls(field, options_));
Formatter format(p); Formatter format(p);
if (IsFieldStripped(field, options_)) {
if (HasHasMethod(field)) {
format(
"inline bool $classname$::has_$name$() const { "
"__builtin_trap(); }\n");
}
format(
"inline void $classname$::set_has_$name$() { __builtin_trap(); "
"}\n");
return;
}
// Singular field in a oneof // Singular field in a oneof
// N.B.: Without field presence, we do not use has-bits or generate // N.B.: Without field presence, we do not use has-bits or generate
// has_$name$() methods, but oneofs still have set_has_$name$(). // has_$name$() methods, but oneofs still have set_has_$name$().
@ -1089,10 +1062,6 @@ void MessageGenerator::GenerateFieldClear(const FieldDescriptor* field,
bool is_inline, io::Printer* p) { bool is_inline, io::Printer* p) {
auto t = p->WithVars(MakeTrackerCalls(field, options_)); auto t = p->WithVars(MakeTrackerCalls(field, options_));
Formatter format(p); Formatter format(p);
if (IsFieldStripped(field, options_)) {
format("void $classname$::clear_$name$() { __builtin_trap(); }\n");
return;
}
// Generate clear_$name$(). // Generate clear_$name$().
if (is_inline) { if (is_inline) {
@ -1136,19 +1105,10 @@ void MessageGenerator::GenerateFieldAccessorDefinitions(io::Printer* p) {
for (auto field : FieldRange(descriptor_)) { for (auto field : FieldRange(descriptor_)) {
PrintFieldComment(format, field); PrintFieldComment(format, field);
if (IsFieldStripped(field, options_)) {
continue;
}
auto v = p->WithVars(FieldVars(field, options_)); auto v = p->WithVars(FieldVars(field, options_));
auto t = p->WithVars(MakeTrackerCalls(field, options_)); auto t = p->WithVars(MakeTrackerCalls(field, options_));
// Generate has_$name$() or $name$_size(). // Generate has_$name$() or $name$_size().
if (field->is_repeated()) { if (field->is_repeated()) {
if (IsFieldStripped(field, options_)) {
format(
"inline int $classname$::$name$_size() const { "
"__builtin_trap(); }\n");
} else {
format( format(
"inline int $classname$::_internal_$name$_size() const {\n" "inline int $classname$::_internal_$name$_size() const {\n"
" return $field$$1$.size();\n" " return $field$$1$.size();\n"
@ -1161,7 +1121,6 @@ void MessageGenerator::GenerateFieldAccessorDefinitions(io::Printer* p) {
field->message_type() field->message_type()
? ".weak" ? ".weak"
: ""); : "");
}
} else if (field->real_containing_oneof()) { } else if (field->real_containing_oneof()) {
GenerateOneofMemberHasBits(field, p); GenerateOneofMemberHasBits(field, p);
} else { } else {
@ -1173,9 +1132,7 @@ void MessageGenerator::GenerateFieldAccessorDefinitions(io::Printer* p) {
GenerateFieldClear(field, true, p); GenerateFieldClear(field, true, p);
} }
// Generate type-specific accessors. // Generate type-specific accessors.
if (!IsFieldStripped(field, options_)) {
field_generators_.get(field).GenerateInlineAccessorDefinitions(p); field_generators_.get(field).GenerateInlineAccessorDefinitions(p);
}
format("\n"); format("\n");
} }
@ -1827,18 +1784,14 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* p) {
" ::$proto_ns$::internal::ConstantInitialized _constinit_;\n", " ::$proto_ns$::internal::ConstantInitialized _constinit_;\n",
camel_oneof_name); camel_oneof_name);
for (auto field : FieldRange(oneof)) { for (auto field : FieldRange(oneof)) {
if (!IsFieldStripped(field, options_)) {
field_generators_.get(field).GeneratePrivateMembers(p); field_generators_.get(field).GeneratePrivateMembers(p);
} }
}
format.Outdent(); format.Outdent();
format("} $1$_;\n", oneof->name()); format("} $1$_;\n", oneof->name());
for (auto field : FieldRange(oneof)) { for (auto field : FieldRange(oneof)) {
if (!IsFieldStripped(field, options_)) {
field_generators_.get(field).GenerateStaticMembers(p); field_generators_.get(field).GenerateStaticMembers(p);
} }
} }
}
// Members assumed to align to 4 bytes: // Members assumed to align to 4 bytes:
@ -2003,9 +1956,6 @@ void MessageGenerator::GenerateClassMethods(io::Printer* p) {
for (auto field : FieldRange(descriptor_)) { for (auto field : FieldRange(descriptor_)) {
auto t = p->WithVars(MakeTrackerCalls(field, options_)); auto t = p->WithVars(MakeTrackerCalls(field, options_));
field_generators_.get(field).GenerateInternalAccessorDeclarations(p); field_generators_.get(field).GenerateInternalAccessorDeclarations(p);
if (IsFieldStripped(field, options_)) {
continue;
}
if (HasHasbit(field)) { if (HasHasbit(field)) {
int has_bit_index = HasBitIndex(field); int has_bit_index = HasBitIndex(field);
GOOGLE_ABSL_CHECK_NE(has_bit_index, kNoHasbit) << field->full_name(); GOOGLE_ABSL_CHECK_NE(has_bit_index, kNoHasbit) << field->full_name();
@ -2029,17 +1979,11 @@ void MessageGenerator::GenerateClassMethods(io::Printer* p) {
format.Outdent(); format.Outdent();
format("};\n\n"); format("};\n\n");
for (auto field : FieldRange(descriptor_)) { for (auto field : FieldRange(descriptor_)) {
if (!IsFieldStripped(field, options_)) {
field_generators_.get(field).GenerateInternalAccessorDefinitions(p); field_generators_.get(field).GenerateInternalAccessorDefinitions(p);
} }
}
// Generate non-inline field definitions. // Generate non-inline field definitions.
for (auto field : FieldRange(descriptor_)) { for (auto field : FieldRange(descriptor_)) {
if (IsFieldStripped(field, options_)) {
continue;
}
auto v = p->WithVars(FieldVars(field, options_)); auto v = p->WithVars(FieldVars(field, options_));
auto t = p->WithVars(MakeTrackerCalls(field, options_)); auto t = p->WithVars(MakeTrackerCalls(field, options_));
field_generators_.get(field).GenerateNonInlineAccessorDefinitions(p); field_generators_.get(field).GenerateNonInlineAccessorDefinitions(p);
@ -2188,10 +2132,6 @@ std::pair<size_t, size_t> MessageGenerator::GenerateOffsets(io::Printer* p) {
descriptor_->real_oneof_decl_count(); descriptor_->real_oneof_decl_count();
size_t entries = offsets; size_t entries = offsets;
for (auto field : FieldRange(descriptor_)) { for (auto field : FieldRange(descriptor_)) {
if (IsFieldStripped(field, options_)) {
format("~0u, // stripped\n");
continue;
}
// TODO(sbenza): We should not have an entry in the offset table for fields // TODO(sbenza): We should not have an entry in the offset table for fields
// that do not use them. // that do not use them.
if (field->options().weak() || field->real_containing_oneof()) { if (field->options().weak() || field->real_containing_oneof()) {
@ -2301,7 +2241,6 @@ void MessageGenerator::GenerateSharedConstructorCode(io::Printer* p) {
// Initialize member variables with arena constructor. // Initialize member variables with arena constructor.
for (auto field : optimized_order_) { for (auto field : optimized_order_) {
GOOGLE_ABSL_DCHECK(!IsFieldStripped(field, options_));
if (ShouldSplit(field, options_)) { if (ShouldSplit(field, options_)) {
continue; continue;
} }
@ -2468,7 +2407,6 @@ ArenaDtorNeeds MessageGenerator::NeedsArenaDestructor() const {
if (HasSimpleBaseClass(descriptor_, options_)) return ArenaDtorNeeds::kNone; if (HasSimpleBaseClass(descriptor_, options_)) return ArenaDtorNeeds::kNone;
ArenaDtorNeeds needs = ArenaDtorNeeds::kNone; ArenaDtorNeeds needs = ArenaDtorNeeds::kNone;
for (const auto* field : FieldRange(descriptor_)) { for (const auto* field : FieldRange(descriptor_)) {
if (IsFieldStripped(field, options_)) continue;
needs = needs =
std::max(needs, field_generators_.get(field).NeedsArenaDestructor()); std::max(needs, field_generators_.get(field).NeedsArenaDestructor());
} }
@ -2493,16 +2431,14 @@ void MessageGenerator::GenerateArenaDestructorCode(io::Printer* p) {
// Process non-oneof fields first. // Process non-oneof fields first.
for (auto field : optimized_order_) { for (auto field : optimized_order_) {
if (IsFieldStripped(field, options_) || ShouldSplit(field, options_)) if (ShouldSplit(field, options_)) continue;
continue;
field_generators_.get(field).GenerateArenaDestructorCode(p); field_generators_.get(field).GenerateArenaDestructorCode(p);
} }
if (ShouldSplit(descriptor_, options_)) { if (ShouldSplit(descriptor_, options_)) {
format("if (!_this->IsSplitMessageDefault()) {\n"); format("if (!_this->IsSplitMessageDefault()) {\n");
format.Indent(); format.Indent();
for (auto field : optimized_order_) { for (auto field : optimized_order_) {
if (IsFieldStripped(field, options_) || !ShouldSplit(field, options_)) if (!ShouldSplit(field, options_)) continue;
continue;
field_generators_.get(field).GenerateArenaDestructorCode(p); field_generators_.get(field).GenerateArenaDestructorCode(p);
} }
format.Outdent(); format.Outdent();
@ -2512,7 +2448,6 @@ void MessageGenerator::GenerateArenaDestructorCode(io::Printer* p) {
// Process oneof fields. // Process oneof fields.
for (auto oneof : OneOfRange(descriptor_)) { for (auto oneof : OneOfRange(descriptor_)) {
for (auto field : FieldRange(oneof)) { for (auto field : FieldRange(oneof)) {
if (IsFieldStripped(field, options_)) continue;
field_generators_.get(field).GenerateArenaDestructorCode(p); field_generators_.get(field).GenerateArenaDestructorCode(p);
} }
} }
@ -2841,9 +2776,7 @@ void MessageGenerator::GenerateStructors(io::Printer* p) {
for (auto field : FieldRange(oneof)) { for (auto field : FieldRange(oneof)) {
format("case k$1$: {\n", UnderscoresToCamelCase(field->name(), true)); format("case k$1$: {\n", UnderscoresToCamelCase(field->name(), true));
format.Indent(); format.Indent();
if (!IsFieldStripped(field, options_)) {
field_generators_.get(field).GenerateMergingCode(p); field_generators_.get(field).GenerateMergingCode(p);
}
format("break;\n"); format("break;\n");
format.Outdent(); format.Outdent();
format("}\n"); format("}\n");
@ -3133,7 +3066,7 @@ void MessageGenerator::GenerateOneofClear(io::Printer* p) {
format("case k$1$: {\n", UnderscoresToCamelCase(field->name(), true)); format("case k$1$: {\n", UnderscoresToCamelCase(field->name(), true));
format.Indent(); format.Indent();
// We clear only allocated objects in oneofs // We clear only allocated objects in oneofs
if (!IsStringOrMessage(field) || IsFieldStripped(field, options_)) { if (!IsStringOrMessage(field)) {
format("// No need to clear\n"); format("// No need to clear\n");
} else { } else {
field_generators_.get(field).GenerateClearingCode(p); field_generators_.get(field).GenerateClearingCode(p);
@ -3468,9 +3401,7 @@ void MessageGenerator::GenerateClassSpecificMergeImpl(io::Printer* p) {
for (auto field : FieldRange(oneof)) { for (auto field : FieldRange(oneof)) {
format("case k$1$: {\n", UnderscoresToCamelCase(field->name(), true)); format("case k$1$: {\n", UnderscoresToCamelCase(field->name(), true));
format.Indent(); format.Indent();
if (!IsFieldStripped(field, options_)) {
field_generators_.get(field).GenerateMergingCode(p); field_generators_.get(field).GenerateMergingCode(p);
}
format("break;\n"); format("break;\n");
format.Outdent(); format.Outdent();
format("}\n"); format("}\n");
@ -3875,9 +3806,6 @@ void MessageGenerator::GenerateSerializeWithCachedSizesBody(io::Printer* p) {
(i < descriptor_->field_count() && (i < descriptor_->field_count() &&
ordered_fields[i]->number() < sorted_extensions[j]->start)) { ordered_fields[i]->number() < sorted_extensions[j]->start)) {
const FieldDescriptor* field = ordered_fields[i++]; const FieldDescriptor* field = ordered_fields[i++];
if (IsFieldStripped(field, options_)) {
continue;
}
re.Flush(); re.Flush();
if (field->options().weak()) { if (field->options().weak()) {
largest_weak_field.ReplaceIfLarger(field); largest_weak_field.ReplaceIfLarger(field);
@ -4217,9 +4145,7 @@ void MessageGenerator::GenerateByteSize(io::Printer* p) {
PrintFieldComment(format, field); PrintFieldComment(format, field);
format("case k$1$: {\n", UnderscoresToCamelCase(field->name(), true)); format("case k$1$: {\n", UnderscoresToCamelCase(field->name(), true));
format.Indent(); format.Indent();
if (!IsFieldStripped(field, options_)) {
field_generators_.get(field).GenerateByteSize(p); field_generators_.get(field).GenerateByteSize(p);
}
format("break;\n"); format("break;\n");
format.Outdent(); format.Outdent();
format("}\n"); format("}\n");
@ -4316,9 +4242,7 @@ void MessageGenerator::GenerateIsInitialized(io::Printer* p) {
for (auto field : FieldRange(oneof)) { for (auto field : FieldRange(oneof)) {
format("case k$1$: {\n", UnderscoresToCamelCase(field->name(), true)); format("case k$1$: {\n", UnderscoresToCamelCase(field->name(), true));
format.Indent(); format.Indent();
if (!IsFieldStripped(field, options_)) {
field_generators_.get(field).GenerateIsInitialized(p); field_generators_.get(field).GenerateIsInitialized(p);
}
format("break;\n"); format("break;\n");
format.Outdent(); format.Outdent();
format("}\n"); format("}\n");

@ -81,7 +81,6 @@ struct Options {
bool bootstrap = false; bool bootstrap = false;
bool opensource_runtime = false; bool opensource_runtime = false;
bool annotate_accessor = false; bool annotate_accessor = false;
bool unused_field_stripping = false;
bool unverified_lazy_message_sets = false; bool unverified_lazy_message_sets = false;
bool profile_driven_inline_string = true; bool profile_driven_inline_string = true;
bool force_split = false; bool force_split = false;

@ -69,10 +69,8 @@ std::vector<const FieldDescriptor*> GetOrderedFields(
const Descriptor* descriptor, const Options& options) { const Descriptor* descriptor, const Options& options) {
std::vector<const FieldDescriptor*> ordered_fields; std::vector<const FieldDescriptor*> ordered_fields;
for (auto field : FieldRange(descriptor)) { for (auto field : FieldRange(descriptor)) {
if (!IsFieldStripped(field, options)) {
ordered_fields.push_back(field); ordered_fields.push_back(field);
} }
}
std::sort(ordered_fields.begin(), ordered_fields.end(), std::sort(ordered_fields.begin(), ordered_fields.end(),
[](const FieldDescriptor* a, const FieldDescriptor* b) { [](const FieldDescriptor* a, const FieldDescriptor* b) {
return a->number() < b->number(); return a->number() < b->number();

Loading…
Cancel
Save