Commit graph

137 commits

Author SHA1 Message Date
rgoldfinger6
4b269eb436 Updating version.json and repo version numbers to: 37.0-dev (#28425)
NOTE: This should be reviewed and imported via Copybara per the normal PR review process.

Closes #28425

PiperOrigin-RevId: 945675238
2026-07-10 06:22:59 -07:00
Samuel Benzaquen
d0b28360c1 Move unknown_field_set.h to protobuf_lite to allow direct usage from the parser without a virtual dispatch.
Move the minimal set of function from `unknown_field_set.cc` to `unknown_field_set_lite.cc`

Change the parser fallback function to separate the extensions case from the unknown field case. This makes both cases faster.

PiperOrigin-RevId: 940598545
2026-06-30 12:33:53 -07:00
Samuel Benzaquen
fe51a8722a Improve handling of split fields.
Refactor many operations to move the split section handing into an out-of-line function. This makes the main function leaner. It includes destruction, merging, clearing, and byte size calculation.

Change serialization to skip split fields by checking first on the default
check. It can skip sequential fields in a single check.

Change merging algorithm to only "prepare" the split section if we need to write to it. Previously it was preparing it if the source had a split section. This is suboptimal because the source might have allocated a split section but not using it anymore (for example, after a `Clear()`).

Changed copy constructor to invoke the out-of-line merger logic for split fields.

PiperOrigin-RevId: 933816045
2026-06-17 11:00:05 -07:00
Samuel Benzaquen
a338d072d2 Add an internal Super_ alias and replace most uses of $superclass$ with it.
This simplifies generated code.

PiperOrigin-RevId: 925512429
2026-06-02 12:26:57 -07:00
Clayton Knittel
558f23d574 Refactor MessageGenerator::GenerateClear to use the modern io::Printer API.
PiperOrigin-RevId: 924980896
2026-06-01 16:44:18 -07:00
Samuel Benzaquen
e6ee74af87 Updating version.json and repo version numbers to: 36.0-dev (#26991)
NOTE: This should be reviewed and imported via Copybara per the normal PR review process.

Closes #26991

PiperOrigin-RevId: 902788011
2026-04-20 13:14:04 -07:00
Samuel Benzaquen
8798103587 Cleanups to CachedSize class.
* Remove dead functions
 * Reduce code duplication
 * Simplify callers by using the default constructor

PiperOrigin-RevId: 900370807
2026-04-15 15:25:00 -07:00
Protobuf Team Bot
63b05729a8 Don't use .data.rel.ro for PROTOBUF_MESSAGE_GLOBALS if __powerpc__.
To work around PowerPC platform complaining about section type mismatch.

PiperOrigin-RevId: 899769016
2026-04-14 14:16:25 -07:00
Samuel Benzaquen
f494cbd530 Remove two redundant data members in GLOBALS mode.
PiperOrigin-RevId: 895944019
2026-04-07 09:41:32 -07:00
Protobuf Team Bot
da35171ff6 Use .data.rel.ro section for message globals.
Putting message globals on .data.rel.ro section has two benefits:

(1) makes it truly read only and forces seg faults rather than subtle bug when
    users unintentionally mutate the default instance.
(2) collocates it on the same section where the type's other const data (vtbl).

PiperOrigin-RevId: 895408151
2026-04-06 11:07:46 -07:00
Protobuf Team Bot
8d70e9f290 Rename global objects to avoid UB.
'_' followed by a capital letter is not allowed and UB. Also, AI review pointed
out that '__' in split default is also UB. Let's fix that as well.

Specifically, this CL renames _MessageName_globals_ &
_MessageName__Impl_Split_default_instance_ to avoid UB.

PiperOrigin-RevId: 894162111
2026-04-03 11:09:08 -07:00
Protobuf Team Bot
3dc53ae357 Use $Msg$ instead of $classname$.
PiperOrigin-RevId: 893766268
2026-04-02 16:41:21 -07:00
Protobuf Team Bot
9a98a0e12c Make message-globals "const" #ifdef PROTOBUF_MESSAGE_GLOBALS
PiperOrigin-RevId: 893738253
2026-04-02 15:41:00 -07:00
Protobuf Team Bot
b5e6cfb8d4 Refactoring how message globals are defined.
PiperOrigin-RevId: 893592023
2026-04-02 10:55:07 -07:00
Protobuf Team Bot
e42b3ac215 Move parse tables to message globals to improve spatial locality.
PiperOrigin-RevId: 893028080
2026-04-01 11:30:39 -07:00
Protobuf Team Bot
4e0e1dc6d7 Add missing "nonnull".
PiperOrigin-RevId: 892991918
2026-04-01 10:13:30 -07:00
Protobuf Team Bot
bf3677a938 Refactor code to generate parse-init code to a helper for future use.
PiperOrigin-RevId: 892909838
2026-04-01 07:07:31 -07:00
Protobuf Team Bot
51d411f054 Move ClassData(Full|Lite) to MessageGlobalsBase #ifdef PROTOBUF_MESSAGE_GLOBALS.
Collocating ClassData and default_instance improves spatial locality.

PiperOrigin-RevId: 891009555
2026-03-28 12:22:46 -07:00
Protobuf Team Bot
259481c7d3 Add a dummy pointer to MessageGlobalsBase #ifdef PROTOBUF_MESSAGE_GLOBALS.
To flush out cases that assume globals == default_instance, add a dummy
pointer #ifdef PROTOBUF_MESSAGE_GLOBALS. Fix those assumptions by explicitly
getting default_instance from globals. This includes how parsers may store
globals.

This CL is no-op #ifndef PROTOBUF_MESSAGE_GLOBALS.

PiperOrigin-RevId: 883399940
2026-03-13 16:50:13 -07:00
Protobuf Team Bot
7d5a477615 Make Reflection work with message globals rather than default instances.
With globals == default_instance, this CL is no-op but enables future CLs
that actually break that assumption. This allows collocating default instances,
class data, and parse tables.

PiperOrigin-RevId: 882671564
2026-03-12 10:46:30 -07:00
Clayton Knittel
523108b5b7 Add repeated_type option to C++ features.
In the future this option will be used by the field generators to decide which interface to generate for each repeated field, either proxy or legacy.

PiperOrigin-RevId: 879936002
2026-03-06 20:06:10 -08:00
Protobuf Team Bot
85404834b2 Use internal::MessageGlobalsBase and default_instance() API.
Using `MessageGlobalsBase::default_instance(const void*)` allows transparent
handling of returning default instance at an arbitrary (but constant) offset
from "message globals".

PiperOrigin-RevId: 868373777
2026-02-10 16:38:29 -08:00
Protobuf Team Bot
acddf37316 #ifdef PROTOBUF_MESSAGE_GLOBALS, move mutable fields to ReflectionData.
ClassDataFull currently contains mutable fields for lazy descriptor init.
Mutable fields prevent message globals placed on read only section and
those fields are not hot either. Moving those fields to a separate data
structure (ReflectionData) improves data locality and enables write-protection.

PiperOrigin-RevId: 866532011
2026-02-06 11:03:20 -08:00
Protobuf Team Bot
97fa2a7e25 Move Message::kDescriptorMethods to proto2::internal::kDescriptorMethods.
This allows upcoming changes to direclty instantiate ReflectionData by
removing protected accesses to a static member.

PiperOrigin-RevId: 866063775
2026-02-05 12:34:54 -08:00
Protobuf Team Bot
33e255c076 Rename default instances.
This CL prepares upcoming changes to collocate message-globals under a single
wrapper (go/proto-msg-globals). The plan is to keep dual state guarded by
PROTOBUF_MESSAGE_GLOBALS, which allows smaller CLs and potential A/B experiments.

Exising code exposes a raw default instance to messages that contain the type
to support constinit or constexpr. Using `T::default_instance()` would encapsulate
#ifdef'ing but I didn't find a way to achieve that. (Also, constexpr doesn't allow
reinterpret_cast.)

This CL renames existing raw default instances so that both branches (#ifdef & #ifndef)
can refer to the same name.

```
// Before:
struct FooDefaultTypeInternal;
extern FooDefaultTypeInternal _Foo_default_instance_;
DoSomething(_Foo_default_instance_._instance);

// After
struct FooGlobalsTypeInternal;
extern FooGlobalsTypeInternal _Foo_globals_;
DoSomething(_Foo_globals_._default);
```

Note that this is meant to be name changes only.

PiperOrigin-RevId: 864580684
2026-02-02 16:57:40 -08:00
Protobuf Team Bot
8227cf1630 Updating version.json and repo version numbers to: 35-dev 2026-01-22 07:25:02 -08:00
Mike Kruskal
7f431bb54a Remove PROTOBUF_CONSTEXPR to unconditionally use constexpr
#test-continuous

This was a legacy shim for C++11 and C++14 support, that's no longer needed.  It also seems to be causing potential issues for unsupported compilers, when we disable it.

PiperOrigin-RevId: 853822318
2026-01-08 11:37:29 -08:00
Chris Kennelly
1a7e200aac Add nodiscard to generated APIs.
This covers two types of failures:
* Methods that are logically const and failure to consume the result indicates a bug
  (an unnecessary call, etc.)
* Methods that return significant errors (failure to parse, etc.) that should not be
  unintentionally ignored.

PiperOrigin-RevId: 852406706
2026-01-05 12:23:55 -08:00
Samuel Benzaquen
49e15fecf6 Refactor how inline string fields are tracked for donation.
Instead of a separate HasBits object with one bit per field we track donation in one arbitrary bit in the capacity.
When the string IsLong that bit in the capacity determines if it is donated.

We also remove all the plumbing for these donation bits, on demand arena destructor, etc.

PiperOrigin-RevId: 843790247
2025-12-12 12:29:05 -08:00
Protobuf Team Bot
c50fb166d9 Automated rollback of commit d170d28b0d.
PiperOrigin-RevId: 842620254
2025-12-10 02:09:10 -08:00
Chris Kennelly
d170d28b0d Add [[nodiscard]] to many APIs.
This covers two types of failures:
* Methods that are logically const and failure to consume the result indicates a bug
  (an unnecessary call, etc.)
* Methods that return significant errors (failure to parse, etc.) that should not be
  unintentionally ignored.

PiperOrigin-RevId: 842042770
2025-12-08 21:06:53 -08:00
Clayton Knittel
1b2ad8f1ca Align generated code with new RepeatedPtrField paradigm.
All changes to generated code are protected by `PROTOBUF_INTERNAL_REMOVE_ARENA_PTRS_REPEATED_PTR_FIELD`.

With this change, code will now compile with `PROTOBUF_INTERNAL_REMOVE_ARENA_PTRS_REPEATED_PTR_FIELD` enabled.

This change is a no-op and does not enable the change. All generated code is annotated with both the current behavior and the new behavior, and defining PROTOBUF_INTERNAL_REMOVE_ARENA_PTRS will turn the feature on (with no change to codegen needed).

PiperOrigin-RevId: 817848228
2025-10-10 17:40:37 -07:00
honglooker
6d00d87830 Updating version.json and repo version numbers to: 34.0-dev (#23738)
NOTE: This should be reviewed and imported via Copybara per the normal PR review process.

Closes #23738

PiperOrigin-RevId: 814297739
2025-10-02 10:51:16 -07:00
Tony Liao
945a10a6ef Refactor GenerateFastFieldEntries in protoc to use io::Printer and Emit.
PiperOrigin-RevId: 804575738
2025-09-08 14:04:48 -07:00
Protobuf Team Bot
c79881258f Internal change
PiperOrigin-RevId: 803558174
2025-09-05 12:22:54 -07:00
Protobuf Team Bot
4e8f3a221c Internal change
PiperOrigin-RevId: 796518869
2025-08-18 12:05:07 -07:00
Clayton Knittel
134a63cf58 Rename VerifyHasBitConsistency to CheckHasBitConsistency.
Check makes clearer that this method crashes on failure. In a future cl, Verify* will return a status, which is more ergonomic for testing.

PiperOrigin-RevId: 790860983
2025-08-04 13:03:57 -07:00
Clayton Knittel
3729c5d7bf Use modern io::Printer::Emit functions over Formatter in message CopyFrom generator.
This reads much more clearly.

PiperOrigin-RevId: 789682422
2025-08-01 02:47:53 -07:00
Clayton Knittel
d4cabc8727 Refactor GenerateClassSpecificMergeImpl to use modern printer API.
PiperOrigin-RevId: 788554734
2025-07-29 12:16:40 -07:00
Clayton Knittel
553df9983f Wrap hasbit checks in inline functions.
PiperOrigin-RevId: 786826500
2025-07-24 14:01:29 -07:00
Adam Cozzette
00c3c30cbc Updating version.json and repo version numbers to: 33.0-dev (#22710)
NOTE: This should be reviewed and imported via Copybara per the normal PR review process.

Closes #22710

PiperOrigin-RevId: 785626334
2025-07-21 17:02:17 -07:00
Clayton Knittel
e0aa99cd36 Verify message hasbits in debug/sanitizer builds.
PiperOrigin-RevId: 783855798
2025-07-16 12:42:55 -07:00
Sandy Zhang
6a3b9aa9be Fix enum_name_uses_string_view to RETENTION_RUNTIME
RETENTION_SOURCE options are stripped for code generators.

PiperOrigin-RevId: 776726195
2025-06-27 14:54:05 -07:00
chrisse74
ec704dc53f Fix unused parameter warnings (#21038)
This pull request fixes some unused parameter warnings.

Closes #21038

PiperOrigin-RevId: 754022058
2025-05-02 09:01:45 -07:00
chrisse74
b07567f281 C++: Fix readability-uppercase-literal-suffix clang-tidy warning (#21066)
Fixes the readability-uppercase-literal-suffix clang-tidy warning in the c++ sources produces by protoc as discussed in #21029 with @zhangskz

Closes #21066

PiperOrigin-RevId: 752486171
2025-04-28 16:24:50 -07:00
Tony Liao
16254ede43 Refactor GenerateFieldEntries to use Emit.
This change tries to make it easier to reason about generated outputs from
protoc from visual inspection.

PiperOrigin-RevId: 751535329
2025-04-25 13:21:24 -07:00
Jason Lunn
452984bf81 Updating version.json and repo version numbers to: 32.0-dev (#21351)
NOTE: This should be reviewed and imported via Copybara per the normal PR review process.

Closes #21351

PiperOrigin-RevId: 751446098
2025-04-25 09:22:00 -07:00
Mike Kruskal
d8964801b1 Add weak attribute to GetClassData to speed up clang builds.
This results in roughly a 2x speedup and memory reduction, which recovers a big chunk of the 4x regression observed in Chromium after some of our refactorings over the last few years.

PiperOrigin-RevId: 746158016
2025-04-10 13:46:28 -07:00
Protobuf Team Bot
c8f2994bc4 Fully qualify std/absl names in codegen to avoid invalid name resolution when the
user scope has those names defined.

PiperOrigin-RevId: 745232154
2025-04-08 11:56:08 -07:00
Protobuf Team Bot
d34249b4df Improve the ABI of the enum range validator for the table-driven parser.
Store int32_t instead of 16-bits, as that won't increase the size of the aux
entry and will serve for more enums.
Store a closed range instead of start+length. Makes it easier to use.

PiperOrigin-RevId: 740906393
2025-03-26 14:36:51 -07:00