Commit graph

23923 commits

Author SHA1 Message Date
Protobuf Team Bot
7b091ee68e Auto-generate files after cl/970967137
Some checks failed
Tests / Bazel (push) Has been skipped
Auto-generate stale checked-in files / Refresh stale files (push) Failing after 0s
Tests / Apply Safe for Tests Label (push) Failing after 0s
Tests / Validate YAML (push) Has been skipped
Scorecard supply-chain security / Scorecard analysis (push) Failing after 4s
Tests / C++ (push) Has been skipped
Tests / Java (push) Has been skipped
Tests / Python (push) Has been skipped
Tests / Ruby (push) Has been skipped
Tests / PHP (push) Has been skipped
Tests / Remove safety tag (push) Failing after 0s
Tests / PHP Extension (push) Has been skipped
Tests / C# (push) Has been skipped
Tests / Objective-C (push) Has been skipped
Tests / Rust (push) Has been skipped
Tests / μpb (push) Has been skipped
Tests / hpb (push) Has been skipped
Tests / Staleness (push) Has been cancelled
Tests / All Blocking Tests (push) Has been cancelled
2026-08-26 03:24:01 +00:00
Protobuf Team Bot
6a21212800 Hopefully final batch of return value checks before UPB_NODISCARD enforcement
PiperOrigin-RevId: 970967137
2026-08-25 20:13:17 -07:00
Protobuf Team Bot
b6ca8b9fb1 Support non-canonical extensions in Python upb unknown fields.
PiperOrigin-RevId: 970866648
2026-08-25 16:19:50 -07:00
Protobuf Team Bot
67322442bd Auto-generate files after cl/970851165 2026-08-25 23:08:01 +00:00
Protobuf Team Bot
d43953b4b9 Add upb_Message_NextWireFormatUnknown to iterate over unknown fields in wire format.
PiperOrigin-RevId: 970851165
2026-08-25 15:56:43 -07:00
Protobuf Team Bot
b8ce5dceea Auto-generate files after cl/970834999 2026-08-25 22:41:40 +00:00
Joshua Haberman
f1c23cb216 Prepare Protobuf for a future version of Bazel which will lack the proto fragment
The ultimate effect of this change will be that both the native flags and Starlark flags will continue to work with future versions of Bazel that lack the proto fragment, until such time as we deprecate or remove the flags in a Protobuf release.  This decouples Bazel releases from Protobuf behavior changes.

1. Builds on the Bazel 8-compatible abstraction layer we submitted in cl/955468205 by setting `HAS_NATIVE_PROTO_FLAGS` properly in Bazel.  We do this by adding a `rules.has_proto_fragment` setting to the `proto_bazel_features.bzl` mechanism: we know that the fragment no longer needs to be read in Bazel 9+, because we can use `flag_alias()` instead.
2. Adds `flag_alias()` declarations in MODULE.bazel for all compat layer flags.  This will work in Bazel 9, but is ignored in Bazel 8.

This leads to a slight inconsistency.  Consider the following set of flags set by a user:

```
--@protobuf//bazel/flags:protocopt=foo --protocopt=bar
```

In Bazel 9+, where the flag alias is respected, the final value of the flag will be `bar`.  In Bazel 8, where we emulate `flag_alias()` by reconciling the two different values at analysis time, we always prefer the Starlark version (and cannot tell the relative order), so the final value of the flag will be `foo`.

To avoid this, prefer setting the Starlark version of the flag whenever possible.

PiperOrigin-RevId: 970834999
2026-08-25 15:30:42 -07:00
corpagent-eng-adazhang
ea0f2968ed Internal change
PiperOrigin-RevId: 970808467
2026-08-25 14:46:43 -07:00
Protobuf Team Bot
ff9440f2ee Auto-generate files after cl/970790688 2026-08-25 21:29:46 +00:00
Joshua Haberman
734819d9dc Delete com_google_protobuf_previous_release and associated breaking tests
When trying to land https://github.com/protocolbuffers/protobuf/pull/28957, I ran into problems with the `@com_google_protobuf_previous_release` repo.  The root cause of these problems was that this repo combines a previous version of all of our `.bzl` files (like `proto_library.bzl`) with the *current* version of our `MODULE.bazel` file.

This is a combination that no user will actually encounter, and when skew between the two causes issues, it is very difficult to debug and fix.

If we want to re-introduce these breaking change tests in the future, an alternative approach that would cause fewer problems is to use the examples module at https://github.com/protocolbuffers/protobuf/tree/main/examples.  That module could include previous versions of the `.proto` files, as well as the breaking change tests to compare against the protos in `@com_google_protobuf`.

Since the examples module does not contain a copy of all our `.bzl` files, this design would avoid the `.bzl` skew that causes problems in the current setup.

PiperOrigin-RevId: 970790688
2026-08-25 14:21:28 -07:00
Protobuf Team Bot
2d75af0868 Auto-generate files after cl/970750490 2026-08-25 20:36:15 +00:00
Samuel Benzaquen
1cf5e73656 Remove version pin from the script.
Let it get the one from .bazeliskrc

This fixes the autoupdater robot.

PiperOrigin-RevId: 970750490
2026-08-25 13:25:37 -07:00
Tony Liao
6836552e25 Allow later enum aliases to overwrite in C# custom JSON enum mapping.
When constructing the custom JSON enum name map in C# JsonParser, remove the
ContainsKey check so that subsequent aliased enum values overwrite earlier ones,
aligning with the "last match wins" semantics used across C++, Java, PHP, and Python.

PiperOrigin-RevId: 970656172
2026-08-25 10:50:27 -07:00
Samuel Benzaquen
b445fe13b1 Continue cleaning up after the GLOBALS experiment.
Change registration APIs to take ClassData* instead of prototypes.

PiperOrigin-RevId: 970649058
2026-08-25 10:41:13 -07:00
Jason Lunn
3df019d491 Forward-port Rust crate swap (#29397)
Cherrypick crate fixes from 36.x to main

Closes #29397

COPYBARA_INTEGRATE_REVIEW=https://github.com/protocolbuffers/protobuf/pull/29397 from protocolbuffers:forward_port_crate_swap 2b5bb9fe65
PiperOrigin-RevId: 970589358
2026-08-25 09:08:44 -07:00
Protobuf Team Bot
d17cf67434 Use monomorphic static dispatch for Java Protobuf submessage parsing
PiperOrigin-RevId: 970550003
2026-08-25 07:51:15 -07:00
Samuel Benzaquen
d3daee4c68 Continue cleaning up after the GLOBALS experiment.
Remove branching for MessageGlobalsBase and the trait.

PiperOrigin-RevId: 970537151
2026-08-25 07:25:40 -07:00
Tony Liao
9d98477ca9 Optimize pure Python parse path for custom JSON enum names.
This implementation is similar to our Java idea in cl/949670944,
basically the idea is that we will have a local map (dictionary) that
will be populated the very first time we try to parse into an enum
field. The lifetime of this dictionary will be tied to the Parser
instance, similar to the Java implementation.

BENCHMARKS (baseline stats are recorded at cl/952170250):

Python:
```
[BENCHMARK] ParseJsonDefault:                med 10.06 us/op | p99 11.22 us/op | mean 10.10 ± 0.20 us/op
[BENCHMARK] ParseJsonCustom:                 med 20.33 us/op | p99 22.23 us/op | mean 20.40 ± 0.34 us/op
[BENCHMARK] ParseJsonUnknownIgnored:         med 24.21 us/op | p99 26.25 us/op | mean 24.31 ± 0.44 us/op
[BENCHMARK] ParseRepeatedJsonDefault:        med 1.94 us/item | p99 2.05 us/item | mean 1.95 ± 0.03 us/item
[BENCHMARK] ParseRepeatedJsonCustom:         med 2.26 us/item | p99 2.45 us/item | mean 2.27 ± 0.03 us/item
[BENCHMARK] ParseRepeatedJsonUnknownIgnored: med 5.31 us/item | p99 5.52 us/item | mean 5.32 ± 0.05 us/item
```

Cpp:
```
[BENCHMARK] ParseJsonDefault:                med 8.66 us/op | p99 9.21 us/op | mean 8.70 ± 0.13 us/op
[BENCHMARK] ParseJsonCustom:                 med 26.33 us/op | p99 29.71 us/op | mean 26.44 ± 0.69 us/op
[BENCHMARK] ParseJsonUnknownIgnored:         med 28.46 us/op | p99 31.80 us/op | mean 28.59 ± 0.67 us/op
[BENCHMARK] ParseRepeatedJsonDefault:        med 1.72 us/item | p99 2.19 us/item | mean 1.74 ± 0.06 us/item
[BENCHMARK] ParseRepeatedJsonCustom:         med 2.12 us/item | p99 2.38 us/item | mean 2.13 ± 0.04 us/item
[BENCHMARK] ParseRepeatedJsonUnknownIgnored: med 4.61 us/item | p99 4.92 us/item | mean 4.62 ± 0.07 us/item
```

UPB:
```
[BENCHMARK] ParseJsonDefault:                med 11.22 us/op | p99 12.29 us/op | mean 11.27 ± 0.21 us/op
[BENCHMARK] ParseJsonCustom:                 med 37.54 us/op | p99 39.25 us/op | mean 37.65 ± 0.46 us/op
[BENCHMARK] ParseJsonUnknownIgnored:         med 41.18 us/op | p99 48.45 us/op | mean 41.30 ± 0.89 us/op
[BENCHMARK] ParseRepeatedJsonDefault:        med 2.10 us/item | p99 2.19 us/item | mean 2.10 ± 0.02 us/item
[BENCHMARK] ParseRepeatedJsonCustom:         med 2.58 us/item | p99 2.73 us/item | mean 2.59 ± 0.03 us/item
[BENCHMARK] ParseRepeatedJsonUnknownIgnored: med 5.70 us/item | p99 5.90 us/item | mean 5.71 ± 0.04 us/item
```

Seeing these benchmarks, we can see a very noticeable improvement in
`ParseRepeatedJsonCustom` and `ParseRepeatedJsonUnknownIgnored` cases --
which correspond to the pathological cases that we are worried about.
Singular fields are taking longer to parse in our microbenchmark because
the cache that we've added is tied to each Parser instance and must be
re-instantiated across every `Parse` call.

PiperOrigin-RevId: 970528683
2026-08-25 07:09:41 -07:00
Protobuf Team Bot
7f86060aae Avoid unchecked cast warnings in TextFormat.parse
Use Class.cast instead of unchecked casts to eliminate @SuppressWarnings("unchecked") in TextFormat.parse overloads.

Shouldn't be a performance problem - this is only available in full runtime (not android) where hotspot has a class.cast intrinsic (and text proto parsing is relatively slow anyway, this won't be the bottleneck).

PiperOrigin-RevId: 970171466
2026-08-24 17:04:58 -07:00
Protobuf Team Bot
44baf91cc1 Improve type safety in ProtobufList.concatenate
Use Collection<?> for the sizing check to eliminate unchecked cast warning and narrow @SuppressWarnings("unchecked") to the specific ProtobufList fast-path assignment.

PiperOrigin-RevId: 970165037
2026-08-24 16:54:42 -07:00
Protobuf Team Bot
11117398dd Update CodedInputStream Javadoc regarding exception handling and isAtEnd behavior.
PiperOrigin-RevId: 970118591
2026-08-24 15:32:21 -07:00
Protobuf Team Bot
0258a65743 Internal change
PiperOrigin-RevId: 970105512
2026-08-24 15:09:41 -07:00
Protobuf Team Bot
205d45b629 Migrate Java(Lite|Mutable|)ProtoLibraryTest.testEmptySrcsForJavaApi to Starlark-based analysis test.
PiperOrigin-RevId: 970099350
2026-08-24 14:58:47 -07:00
Protobuf Team Bot
4d20214ca8 Internal change.
PiperOrigin-RevId: 970073736
2026-08-24 14:21:14 -07:00
Protobuf Team Bot
dee117a787 Avoid empty byte array allocations in Proto Lite toByteArray().
In AbstractMessageLite.toByteArray(), check if getSerializedSize() == 0 and return Internal.EMPTY_BYTE_ARRAY directly instead of allocating a new 0-byte array and CodedOutputStream wrappers.

PiperOrigin-RevId: 970010400
2026-08-24 12:44:01 -07:00
Protobuf Team Bot
672eda6f1f Fasttable: Fix overly strict assert.
PiperOrigin-RevId: 969873676
2026-08-24 08:43:17 -07:00
Protobuf Team Bot
f1a2ca97f8 Avoid unchecked cast warning in Internal.getDefaultInstance
Use Class.cast instead of an unchecked generic cast to avoid compiler warnings and ensure runtime type safety.

Not a big deal but a nice opportunity to remove a warning.

This is only used in the full runtime AFAIK, where hotspot has an intrinsic for Class.cast so shouldn't be a performance issue.

PiperOrigin-RevId: 969794451
2026-08-24 05:40:20 -07:00
Protobuf Team Bot
a55c302e3f Automated Code Change
PiperOrigin-RevId: 969413413
2026-08-23 09:06:54 -07:00
Protobuf Team Bot
407b27d8da Automated Code Change
PiperOrigin-RevId: 969393499
2026-08-23 07:56:27 -07:00
Ada Zhang
e712d276bc Add upb_Message_NextSerializableField and unify field presence checks.
PiperOrigin-RevId: 968809631
2026-08-21 18:42:09 -07:00
Sandy Zhang
718a3e58b4 Document context and Java runtime guidance on feature extension restriction.
PiperOrigin-RevId: 968759632
2026-08-21 16:33:49 -07:00
Protobuf Team Bot
2901ce6db3 Handle refcount issues on allocation failure in python
PiperOrigin-RevId: 968724072
2026-08-21 15:34:04 -07:00
Protobuf Team Bot
bf50167a85 Allow disabling lazy parsing in individual ExtensionRegistryLite which will signal the parsing whether should parse extension fields lazily.
PiperOrigin-RevId: 968674119
2026-08-21 13:57:24 -07:00
Samuel Benzaquen
39882988a9 Remove tc_table from MessageInfo.
This reduces the size of ExtensionInfo.

PiperOrigin-RevId: 968562757
2026-08-21 10:17:44 -07:00
Samuel Benzaquen
035554bd86 Continue cleaning up after the GLOBALS experiment.
Remove TcParser::GetTable and migrate callers to MessageTraits.

PiperOrigin-RevId: 968547835
2026-08-21 09:52:47 -07:00
Protobuf Team Bot
e29507ff0d Migrate upb_Message_NextUnknown to upb_Message_NextUnknown2 in _cel_UnknownFields_FromMessage to support non-canonical extensions.
PiperOrigin-RevId: 968134008
2026-08-20 16:51:29 -07:00
Clayton Knittel
12d69dbd9f Automated rollback of commit 6b336e7038.
PiperOrigin-RevId: 968043364
2026-08-20 14:07:43 -07:00
Protobuf Team Bot
5957f0ecdb Enable FastTable for non-opt builds.
PiperOrigin-RevId: 968007366
2026-08-20 13:10:05 -07:00
Samuel Benzaquen
50c6c24a2b Remove table prefetching experiment.
It didn't pan out and was never turned on.

PiperOrigin-RevId: 967969922
2026-08-20 12:09:14 -07:00
Clayton Knittel
60a6b5f352 Move generated methods specialized by simple bases to Helpers_.
PiperOrigin-RevId: 967928105
2026-08-20 11:02:19 -07:00
Protobuf Team Bot
03e410d5f7 Migrate JavaProtoLibraryTest.testJavaProtosExposesJavaProvider and lite / mutable counterparts JavaLiteProtoLibraryTest and JavaMutableProtoLibraryTest to Starlark-based analysis test.
PiperOrigin-RevId: 967869339
2026-08-20 09:30:04 -07:00
Protobuf Team Bot
f6cd30a44e Enable FastTable for non-opt builds.
PiperOrigin-RevId: 967807696
2026-08-20 07:25:36 -07:00
Ada Zhang
a972dac424 Support printing non-canonical extensions in the text encoder.
PiperOrigin-RevId: 967565448
2026-08-19 21:20:45 -07:00
Clayton Knittel
bca6336df1 Move internal message helper functions into the Helpers_ struct.
This change moves internal helper methods (PlacementNew_, InternalNewImpl_, and InternalGenerateClassData_) from the main message class into a nested `Helpers_` struct.

PiperOrigin-RevId: 967513868
2026-08-19 18:28:39 -07:00
Protobuf Team Bot
8917ad8c48 Fix unused return value warnings in upb call sites and tests.
Several functions in upb marked with UPB_NODISCARD had their return values ignored in test and wrapper call sites.

Check and assert the return values of upb_Message_SetString, upb_Message_SetInt32, upb_ExtensionRegistry_AddArray, _upb_Message_AddUnknown, upb_Array_New, and _upb_Array_ResizeUninitialized across upb and protobuf tests and wrappers.

PiperOrigin-RevId: 967461770
2026-08-19 16:15:36 -07:00
Protobuf Team Bot
9996b547f7 Fasttable: fix gaps in malformed tag guarding.
PiperOrigin-RevId: 967454749
2026-08-19 16:04:34 -07:00
Protobuf Team Bot
229a528948 Handle more allocation failures
PiperOrigin-RevId: 967454374
2026-08-19 15:59:03 -07:00
Protobuf Team Bot
2de70d7105 Add allocation failure tests for unknowns and defbuilder
PiperOrigin-RevId: 967386997
2026-08-19 13:46:43 -07:00
Clayton Knittel
bdf71ccdd1 Move InternalGenerateParseTable_ to .pb.cc.
This moves `InternalGenerateParseTable_` to the nested `_Internals` class, which is only defined in `.pb.cc`, and renames it to `GenerateParseTable` (now that the `Internal` would be redundant).

PiperOrigin-RevId: 967383875
2026-08-19 13:41:28 -07:00
Samuel Benzaquen
676d7209c3 Internal change
PiperOrigin-RevId: 967359668
2026-08-19 12:55:58 -07:00