Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 5a6249c

Browse filesBrowse files
Internal change
PiperOrigin-RevId: 758423057
1 parent c515701 commit 5a6249c
Copy full SHA for 5a6249c

File tree

9 files changed

+152
-111
lines changed
Filter options

9 files changed

+152
-111
lines changed

‎editions/golden/compare_cpp_codegen_failure.txt

Copy file name to clipboardExpand all lines: editions/golden/compare_cpp_codegen_failure.txt
+7-7
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@
3434
if ((cached_has_bits & 0x00000001U) != 0) {
3535
total_size += ::_pbi::WireFormatLite::Int32SizePlusOne(
3636
@@ @@
37-
::_pbi::v2::BatchSizeHelper helper;
37+
(void)helper;
3838

39-
{
40-
- // optional int32 int32_field = 1;
41-
+ // int32 int32_field = 1;
42-
cached_has_bits = this_._impl_._has_bits_[0];
43-
if ((cached_has_bits & 0x00000001U) != 0) {
44-
helper.AddInt32();
39+
cached_has_bits = this_._impl_._has_bits_[0];
40+
- // optional int32 int32_field = 1;
41+
+ // int32 int32_field = 1;
42+
if ((cached_has_bits & 0x00000001U) != 0) {
43+
helper.AddInt32();
44+
}
4545
[ FAILED ] third_party/protobuf/editions/golden/simple_proto3.pb.cc
4646
[ RUN ] third_party/protobuf/editions/golden/simple_proto3.pb.h
4747
@@ @@

‎editions/golden/compare_cpp_codegen_failure.xml

Copy file name to clipboardExpand all lines: editions/golden/compare_cpp_codegen_failure.xml
+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<testsuites tests="1" name="AllTests">
33
<testsuite name="EditionsCodegenTests">
44
<testcase name="third_party/protobuf/editions/golden/simple_proto3.pb.cc" status="run" result="completed" classname="DiffTest">
5-
<failure message="Value of: third_party/protobuf/editions/golden/simple_proto3.pb.cc&#x0A;Expected: &#x0A;// Generated by the protocol buffer compiler. DO NOT EDIT!&#x0A;// NO CHECKED-IN PROTOBUF GENCODE&#x0A;// source: third_party/protobuf/editions/golden/simple_proto3.proto&#x0A;&#x0A;#include &quot;third_party/protobuf/editions/golden/simple_proto3.pb.h&quot;&#x0A;&#x0A;#include &lt;algorithm&gt;&#x0A;#include &lt;type_traits&gt;&#x0A;#include &quot;third_party/protobuf/io/coded_stream.h&quot;&#x0A;#include &quot;third_party/protobuf/generated_message_tctable_impl.h&quot;&#x0A;#include &quot;third_party/protobuf/extension_set.h&quot;&#x0A;#include &quot;third_party/protobuf/generated_message_util.h&quot;&#x0A;#include &quot;third_party/protobuf/wire_format_lite.h&quot;&#x0A;#include &quot;third_party/protobuf/io/zero_copy_stream_impl_lite.h&quot;&#x0A;#include &quot;third_party/protobuf/v2/generated_message_table_impl.h&quot;&#x0A;// @@protoc_insertion_point(includes)&#x0A;&#x0A;// Must be included last.&#x0A;, with the difference:&#x0A;@@ @@&#x0A; ::_pbi::TcParser::GetTable&lt;::protobuf_editions_test::golden::SimpleProto3&gt;(), // to_prefetch&#x0A; #endif // PROTOBUF_PREFETCH_PARSE_TABLE&#x0A; }, {{&#x0A;- // optional int32 int32_field = 1;&#x0A;+ // int32 int32_field = 1;&#x0A; {::_pbi::TcParser::FastV32S1,&#x0A; {8, 0, 0, PROTOBUF_FIELD_OFFSET(SimpleProto3, _impl_.int32_field_)}},&#x0A; }}, {{&#x0A; 65535, 65535&#x0A; }}, {{&#x0A;- // optional int32 int32_field = 1;&#x0A;+ // int32 int32_field = 1;&#x0A; {PROTOBUF_FIELD_OFFSET(SimpleProto3, _impl_.int32_field_), _Internal::kHasBitsOffset + 0, 0, (0 | ::_fl::kFcOptional | ::_fl::kInt32)},&#x0A; }},&#x0A; // no aux_entries&#x0A;@@ @@&#x0A; (void)cached_has_bits;&#x0A; &#x0A; cached_has_bits = this_._impl_._has_bits_[0];&#x0A;- // optional int32 int32_field = 1;&#x0A;+ // int32 int32_field = 1;&#x0A; if ((cached_has_bits &amp; 0x00000001U) != 0) {&#x0A; target =&#x0A; ::proto2::internal::WireFormatLite::WriteInt32ToArrayWithField&lt;1&gt;(&#x0A;@@ @@&#x0A; (void)cached_has_bits;&#x0A; &#x0A; {&#x0A;- // optional int32 int32_field = 1;&#x0A;+ // int32 int32_field = 1;&#x0A; cached_has_bits = this_._impl_._has_bits_[0];&#x0A; if ((cached_has_bits &amp; 0x00000001U) != 0) {&#x0A; total_size += ::_pbi::WireFormatLite::Int32SizePlusOne(&#x0A;@@ @@&#x0A; ::_pbi::v2::BatchSizeHelper helper;&#x0A; &#x0A; {&#x0A;- // optional int32 int32_field = 1;&#x0A;+ // int32 int32_field = 1;&#x0A; cached_has_bits = this_._impl_._has_bits_[0];&#x0A; if ((cached_has_bits &amp; 0x00000001U) != 0) {&#x0A; helper.AddInt32();" type=""></failure>
5+
<failure message="Value of: third_party/protobuf/editions/golden/simple_proto3.pb.cc&#x0A;Expected: &#x0A;// Generated by the protocol buffer compiler. DO NOT EDIT!&#x0A;// NO CHECKED-IN PROTOBUF GENCODE&#x0A;// source: third_party/protobuf/editions/golden/simple_proto3.proto&#x0A;&#x0A;#include &quot;third_party/protobuf/editions/golden/simple_proto3.pb.h&quot;&#x0A;&#x0A;#include &lt;algorithm&gt;&#x0A;#include &lt;type_traits&gt;&#x0A;#include &quot;third_party/protobuf/io/coded_stream.h&quot;&#x0A;#include &quot;third_party/protobuf/generated_message_tctable_impl.h&quot;&#x0A;#include &quot;third_party/protobuf/extension_set.h&quot;&#x0A;#include &quot;third_party/protobuf/generated_message_util.h&quot;&#x0A;#include &quot;third_party/protobuf/wire_format_lite.h&quot;&#x0A;#include &quot;third_party/protobuf/io/zero_copy_stream_impl_lite.h&quot;&#x0A;#include &quot;third_party/protobuf/v2/generated_message_table_impl.h&quot;&#x0A;// @@protoc_insertion_point(includes)&#x0A;&#x0A;// Must be included last.&#x0A;, with the difference:&#x0A;@@ @@&#x0A; ::_pbi::TcParser::GetTable&lt;::protobuf_editions_test::golden::SimpleProto3&gt;(), // to_prefetch&#x0A; #endif // PROTOBUF_PREFETCH_PARSE_TABLE&#x0A; }, {{&#x0A;- // optional int32 int32_field = 1;&#x0A;+ // int32 int32_field = 1;&#x0A; {::_pbi::TcParser::FastV32S1,&#x0A; {8, 0, 0, PROTOBUF_FIELD_OFFSET(SimpleProto3, _impl_.int32_field_)}},&#x0A; }}, {{&#x0A; 65535, 65535&#x0A; }}, {{&#x0A;- // optional int32 int32_field = 1;&#x0A;+ // int32 int32_field = 1;&#x0A; {PROTOBUF_FIELD_OFFSET(SimpleProto3, _impl_.int32_field_), _Internal::kHasBitsOffset + 0, 0, (0 | ::_fl::kFcOptional | ::_fl::kInt32)},&#x0A; }},&#x0A; // no aux_entries&#x0A;@@ @@&#x0A; (void)cached_has_bits;&#x0A; &#x0A; cached_has_bits = this_._impl_._has_bits_[0];&#x0A;- // optional int32 int32_field = 1;&#x0A;+ // int32 int32_field = 1;&#x0A; if ((cached_has_bits &amp; 0x00000001U) != 0) {&#x0A; target =&#x0A; ::proto2::internal::WireFormatLite::WriteInt32ToArrayWithField&lt;1&gt;(&#x0A;@@ @@&#x0A; (void)cached_has_bits;&#x0A; &#x0A; {&#x0A;- // optional int32 int32_field = 1;&#x0A;+ // int32 int32_field = 1;&#x0A; cached_has_bits = this_._impl_._has_bits_[0];&#x0A; if ((cached_has_bits &amp; 0x00000001U) != 0) {&#x0A; total_size += ::_pbi::WireFormatLite::Int32SizePlusOne(&#x0A;@@ @@&#x0A; (void)helper;&#x0A; &#x0A; cached_has_bits = this_._impl_._has_bits_[0];&#x0A;- // optional int32 int32_field = 1;&#x0A;+ // int32 int32_field = 1;&#x0A; if ((cached_has_bits &amp; 0x00000001U) != 0) {&#x0A; helper.AddInt32();&#x0A; }" type=""></failure>
66
</testcase>
77
<testcase name="third_party/protobuf/editions/golden/simple_proto3.pb.h" status="run" result="completed" classname="DiffTest">
88
<failure message="Value of: third_party/protobuf/editions/golden/simple_proto3.pb.h&#x0A;Expected: &#x0A;// Generated by the protocol buffer compiler. DO NOT EDIT!&#x0A;// NO CHECKED-IN PROTOBUF GENCODE&#x0A;// source: third_party/protobuf/editions/golden/simple_proto3.proto&#x0A;&#x0A;#ifndef third_5fparty_2fprotobuf_2feditions_2fgolden_2fsimple_5fproto3_2eproto_2epb_2eh&#x0A;#define third_5fparty_2fprotobuf_2feditions_2fgolden_2fsimple_5fproto3_2eproto_2epb_2eh&#x0A;&#x0A;#include &lt;limits&gt;&#x0A;#include &lt;string&gt;&#x0A;#include &lt;type_traits&gt;&#x0A;#include &lt;utility&gt;&#x0A;&#x0A;#include &quot;third_party/protobuf/runtime_version.h&quot;&#x0A;#include &quot;third_party/protobuf/io/coded_stream.h&quot;&#x0A;#include &quot;third_party/protobuf/arena.h&quot;&#x0A;#include &quot;third_party/protobuf/arenastring.h&quot;&#x0A;#include &quot;third_party/protobuf/generated_message_tctable_decl.h&quot;&#x0A;#include &quot;third_party/protobuf/v2/generated_message_table.h&quot;&#x0A;#include &quot;third_party/protobuf/v2/generated_message_table_impl.h&quot;&#x0A;#include &quot;third_party/protobuf/v2/batch_builder.h&quot;&#x0A;#include &quot;third_party/protobuf/v2/batch_wire_format.h&quot;&#x0A;#include &quot;third_party/protobuf/generated_message_util.h&quot;&#x0A;#include &quot;third_party/protobuf/metadata_lite.h&quot;&#x0A;#include &quot;third_party/protobuf/message_lite.h&quot;&#x0A;// @@protoc_insertion_point(includes)&#x0A;&#x0A;// Must be included last.&#x0A;&#x0A;#endif // third_5fparty_2fprotobuf_2feditions_2fgolden_2fsimple_5fproto3_2eproto_2epb_2eh&#x0A;, with the difference:&#x0A;@@ @@&#x0A; enum : int {&#x0A; kInt32FieldFieldNumber = 1,&#x0A; };&#x0A;- // optional int32 int32_field = 1;&#x0A;+ // int32 int32_field = 1;&#x0A; bool has_int32_field() const;&#x0A; void clear_int32_field() ;&#x0A; ::int32_t int32_field() const;&#x0A;@@ @@&#x0A; &#x0A; // SimpleProto3&#x0A; &#x0A;-// optional int32 int32_field = 1;&#x0A;+// int32 int32_field = 1;&#x0A; inline bool SimpleProto3::has_int32_field() const {&#x0A; bool value = (_impl_._has_bits_[0] &amp; 0x00000001U) != 0;&#x0A; return value;" type=""></failure>

‎src/google/protobuf/compiler/cpp/field_chunk.cc

Copy file name to clipboardExpand all lines: src/google/protobuf/compiler/cpp/field_chunk.cc
+22-7
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
#include "google/protobuf/compiler/cpp/field_chunk.h"
22

3+
#include <algorithm>
34
#include <cstddef>
45
#include <cstdint>
56
#include <vector>
67

78
#include "absl/log/absl_check.h"
9+
#include "absl/types/span.h"
10+
#include "google/protobuf/compiler/cpp/helpers.h"
11+
#include "google/protobuf/compiler/cpp/options.h"
812
#include "google/protobuf/descriptor.h"
913

14+
// must be last
15+
#include "google/protobuf/port_def.inc"
16+
1017
namespace google {
1118
namespace protobuf {
1219
namespace compiler {
@@ -15,16 +22,15 @@ namespace cpp {
1522
namespace {
1623

1724
int GetHasWordIdx(const FieldDescriptor* field,
18-
const std::vector<int>& has_bit_indices) {
25+
absl::Span<const int> has_bit_indices) {
1926
return has_bit_indices[static_cast<size_t>(field->index())] / 32;
2027
}
2128

2229
// Returns the (common) hasbit index offset. Callers must guarantee "fields" is
2330
// not empty. Debug-check fails if it sees different hasbit index offset in
2431
// "fields".
25-
int GetCommonHasbitIndexOffset(
26-
const std::vector<const FieldDescriptor*>& fields,
27-
const std::vector<int>& has_bit_indices) {
32+
int GetCommonHasbitIndexOffset(absl::Span<const FieldDescriptor*> fields,
33+
absl::Span<const int> has_bit_indices) {
2834
ABSL_CHECK(!fields.empty());
2935

3036
int word_idx = GetHasWordIdx(fields.front(), has_bit_indices);
@@ -36,14 +42,15 @@ int GetCommonHasbitIndexOffset(
3642

3743
// Checks if chunks in [it, end) share hasbit index offset.
3844
void CheckSameHasbitIndexOffset(ChunkIterator it, ChunkIterator end,
39-
const std::vector<int>& has_bit_indices) {
45+
absl::Span<const int> has_bit_indices) {
4046
ABSL_CHECK(it != end);
4147
int prev_offset = -1;
4248
for (; it != end; ++it) {
4349
// Skip empty chunks (likely due to extraction).
4450
if (it->fields.empty()) continue;
4551

46-
int offset = GetCommonHasbitIndexOffset(it->fields, has_bit_indices);
52+
int offset =
53+
GetCommonHasbitIndexOffset(absl::MakeSpan(it->fields), has_bit_indices);
4754
ABSL_CHECK(prev_offset == -1 || prev_offset == offset);
4855
prev_offset = offset;
4956
}
@@ -56,6 +63,11 @@ void CheckSameHasbitIndexOffset(ChunkIterator it, ChunkIterator end,
5663
// masked to tell if any thing in "fields" is present.
5764
uint32_t GenChunkMask(const std::vector<const FieldDescriptor*>& fields,
5865
const std::vector<int>& has_bit_indices) {
66+
return GenChunkMask(absl::MakeSpan(fields), absl::MakeSpan(has_bit_indices));
67+
}
68+
69+
uint32_t GenChunkMask(absl::Span<const FieldDescriptor* const> fields,
70+
absl::Span<const int> has_bit_indices) {
5971
if (fields.empty()) return 0u;
6072

6173
int first_index_offset = GetHasWordIdx(fields.front(), has_bit_indices);
@@ -76,7 +88,7 @@ uint32_t GenChunkMask(ChunkIterator it, ChunkIterator end,
7688
const std::vector<int>& has_bit_indices) {
7789
ABSL_CHECK(it != end);
7890

79-
CheckSameHasbitIndexOffset(it, end, has_bit_indices);
91+
CheckSameHasbitIndexOffset(it, end, absl::MakeSpan(has_bit_indices));
8092

8193
uint32_t chunk_mask = 0u;
8294
for (; it != end; ++it) {
@@ -87,7 +99,10 @@ uint32_t GenChunkMask(ChunkIterator it, ChunkIterator end,
8799
return chunk_mask;
88100
}
89101

102+
90103
} // namespace cpp
91104
} // namespace compiler
92105
} // namespace protobuf
93106
} // namespace google
107+
108+
#include "google/protobuf/port_undef.inc"

‎src/google/protobuf/compiler/cpp/field_chunk.h

Copy file name to clipboardExpand all lines: src/google/protobuf/compiler/cpp/field_chunk.h
+8
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
#ifndef GOOGLE_PROTOBUF_COMPILER_CPP_FIELD_CHUNK_H__
22
#define GOOGLE_PROTOBUF_COMPILER_CPP_FIELD_CHUNK_H__
33

4+
#include <cstddef>
45
#include <cstdint>
6+
#include <utility>
57
#include <vector>
68

9+
#include "absl/types/span.h"
710
#include "google/protobuf/compiler/cpp/helpers.h"
811
#include "google/protobuf/compiler/cpp/options.h"
912
#include "google/protobuf/descriptor.h"
@@ -31,13 +34,18 @@ struct FieldChunk {
3134

3235
using ChunkIterator = std::vector<FieldChunk>::iterator;
3336

37+
PROTOC_EXPORT uint32_t
38+
GenChunkMask(absl::Span<const FieldDescriptor* const> fields,
39+
absl::Span<const int> has_bit_indices);
40+
3441
PROTOC_EXPORT uint32_t
3542
GenChunkMask(const std::vector<const FieldDescriptor*>& fields,
3643
const std::vector<int>& has_bit_indices);
3744

3845
PROTOC_EXPORT uint32_t GenChunkMask(ChunkIterator it, ChunkIterator end,
3946
const std::vector<int>& has_bit_indices);
4047

48+
4149
// Breaks down a single chunk of fields into a few chunks that share attributes
4250
// controlled by "equivalent" predicate. Returns an array of chunks.
4351
template <typename Predicate>

‎src/google/protobuf/compiler/cpp/field_chunk_test.cc

Copy file name to clipboardExpand all lines: src/google/protobuf/compiler/cpp/field_chunk_test.cc
+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "google/protobuf/compiler/cpp/field_chunk.h"
22

3+
#include <cstddef>
34
#include <cstdint>
45
#include <vector>
56

@@ -177,6 +178,7 @@ TEST(GenChunkMaskTest, ValidMaskFromChunks) {
177178
EXPECT_EQ(mask, (1 << kHasbitIdxAt0) | (1 << kHasbitIdxAt1));
178179
}
179180

181+
180182
} // namespace
181183
} // namespace cpp
182184
} // namespace compiler

‎src/google/protobuf/compiler/cpp/helpers.cc

Copy file name to clipboardExpand all lines: src/google/protobuf/compiler/cpp/helpers.cc
+7
Original file line numberDiff line numberDiff line change
@@ -1347,6 +1347,13 @@ bool IsEligibleForV2Batching(const FieldDescriptor* field) {
13471347
!field->is_map() &&
13481348
field->number() < std::numeric_limits<uint16_t>::max();
13491349
}
1350+
1351+
bool HasFieldEligibleForV2Batching(const Descriptor* descriptor) {
1352+
for (const auto& field : FieldRange(descriptor)) {
1353+
if (IsEligibleForV2Batching(field)) return true;
1354+
}
1355+
return false;
1356+
}
13501357
#endif // PROTOBUF_INTERNAL_V2_EXPERIMENT
13511358

13521359
bool HasV2MessageTable(const FileDescriptor* file, const Options& options) {

‎src/google/protobuf/compiler/cpp/helpers.h

Copy file name to clipboardExpand all lines: src/google/protobuf/compiler/cpp/helpers.h
+1
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,7 @@ bool IsV2EnabledForMessage(const Descriptor* descriptor,
517517
#ifdef PROTOBUF_INTERNAL_V2_EXPERIMENT
518518
// Returns true if a field can be batched.
519519
bool IsEligibleForV2Batching(const FieldDescriptor* field);
520+
bool HasFieldEligibleForV2Batching(const Descriptor* descriptor);
520521
#endif // PROTOBUF_INTERNAL_V2_EXPERIMENT
521522

522523
// Does this file have generated parsing, serialization, and other

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.