Commit Graph

609 Commits

Author SHA1 Message Date
Nicolas Hillegeer
87fded5d2a internal/impl: ensure proto.HasExtension does not allocate
Extensions are unmarshaled lazily if protolegacy is true. The current
implementation of proto.HasExtension forces this unmarshaling to happen.
Change that.

Lazy message extensions are unmarshaled on first access, see
(*ExtensionField).Value. This leads to an (expensive) unmarshal
operation even if the user only wanted to know whether the extension is
present.

Granted, in most cases a HasExtension returning true will be followed by
a GetExtension. Due to memoization (see (*ExtensionField).lazyInit), the
cost will just shift from HasExtension to GetExtension. But, this CL
allows building cheaper functionality that only needs to know about
extension existence.

Why can this validation be removed?

 - All tests pass.
 - This check was added in CL 229558. The author (Joe Tsai) noted:

> Technically this shouldn't be needed, but I couldn't adequately reason
> whether a nil message value would ever be set through non-reflection
> means.

Like the author, I believe it's not needed:

 - `proto.SetExtension` does not allow setting invalid messages (see
   proto/extension.go).
 - Likewise, (*extensionMap).Set panics when attempting to set an
   invalid value.
 - Unmarshaling does not produce submessages for which `IsValid` is
   false.

The added test fails without the fix:

    $ go test -tags=protolegacy -test.v -test.run=TestHasExtensionNoAlloc proto/extension_test.go
    === RUN   TestHasExtensionNoAlloc
    === RUN   TestHasExtensionNoAlloc/Nil
    === RUN   TestHasExtensionNoAlloc/Eager
    === RUN   TestHasExtensionNoAlloc/Lazy
        extension_test.go:156: proto.HasExtension should not allocate, but allocated 3.00B per run
    --- FAIL: TestHasExtensionNoAlloc (0.00s)
        --- PASS: TestHasExtensionNoAlloc/Nil (0.00s)
        --- PASS: TestHasExtensionNoAlloc/Eager (0.00s)
        --- FAIL: TestHasExtensionNoAlloc/Lazy (0.00s)
    FAIL
    FAIL    command-line-arguments  0.018s

The tests are disabled in race mode because the race instrumentation for
closures et al. always allocates. The protolegacy tests were previously
only run in race mode. I added a non-race variant in
integration_test.go.

Change-Id: Idbc67c1cf0aea8833a2735ca7bfc8d2466ceaf44
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/575035
Reviewed-by: Nicolas Hillegeer <aktau@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Damien Neil <dneil@google.com>
Reviewed-by: Lasse Folger <lassefolger@google.com>
Auto-Submit: Nicolas Hillegeer <aktau@google.com>
2024-03-28 16:31:28 +00:00
Lasse Folger
3ebf7dd8a5 proto: fix HasPresence for extensions and missing plugin response
Change-Id: I9ee81f7a88cf91f3041e89936cb03511bd224603
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/574375
Auto-Submit: Lasse Folger <lassefolger@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Stapelberg <stapelberg@google.com>
2024-03-26 09:28:59 +00:00
Lasse Folger
dea00b5e2a all: enable editions support
Change-Id: I30e08a1610e11187a7632a409bd001f3bff1ba4a
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/573355
Auto-Submit: Lasse Folger <lassefolger@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Stapelberg <stapelberg@google.com>
2024-03-22 09:09:14 +00:00
Lasse Folger
59034d830f reflect/protodesc: restore edition in protodesc.ToDescriptorProto
I have choosen to implement this via interace assertion so that
other implementers of protoreflect.FileDescriptor can implement
this as well.

Change-Id: Ib907895044e89bdba1009cc09129d3dd1224561f
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/573055
Reviewed-by: Michael Stapelberg <stapelberg@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-03-21 13:45:49 +00:00
Lasse Folger
3039476726 all: implement proto2/proto3 as editions [2/2]
This change removes the remaining usages of Syntax() from Go Protobuf
and uses edition features instead.

It also adds a new function to the EnumDescriptor interface checking if
the enum is using a Closed semantics.

All of these changes were tested on the Google corpus.

Change-Id: I7a8110f6f3b6ed24bf7ece500b4942371302c56c
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/572695
Reviewed-by: Michael Stapelberg <stapelberg@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-03-19 12:54:36 +00:00
Lasse Folger
7259b46773 all: implement proto2/proto3 as editions [1/2]
This change removes most usages of Syntax() from the repository and uses
edition features for instead. The appropriate edition feature defaults are
loaded for proto2/proto3 when the initialization of the descriptors
start.

All of these changes were tested on the Google corpus.

Change-Id: Ieca076a2b38ca8e50e084cd32e725b7b3dcb4171
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/572435
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Stapelberg <stapelberg@google.com>
2024-03-19 09:40:08 +00:00
Damien Neil
e216807546 all: start v1.33.0-devel
Change-Id: I56d6444809d27fd3f0c1dd633ce8b9bb3555523e
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/569358
Reviewed-by: Roland Shoemaker <roland@golang.org>
TryBot-Bypass: Damien Neil <dneil@google.com>
Commit-Queue: Damien Neil <dneil@google.com>
2024-03-05 19:00:36 +00:00
Damien Neil
ec47fd138f all: release v1.33.0
Change-Id: Idcadb6ae9ae24489ce613c0783ae2a8aeddffa17
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/569357
TryBot-Bypass: Damien Neil <dneil@google.com>
Commit-Queue: Damien Neil <dneil@google.com>
Reviewed-by: Roland Shoemaker <roland@golang.org>
2024-03-05 19:00:20 +00:00
Damien Neil
f01a588e58 encoding/protojson, internal/encoding/json: handle missing object values
In internal/encoding/json, report an error when encountering a }
when we are expecting an object field value. For example, the input
`{"":}` now correctly results in an error at the closing } token.

In encoding/protojson, check for an unexpected EOF token in
skipJSONValue. This is redundant with the check in internal/encoding/json,
but adds a bit more defense against any other similar bugs that
might exist.

Fixes CVE-2024-24786

Change-Id: I03d52512acb5091c8549e31ca74541d57e56c99d
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/569356
TryBot-Bypass: Damien Neil <dneil@google.com>
Reviewed-by: Roland Shoemaker <roland@golang.org>
Commit-Queue: Damien Neil <dneil@google.com>
2024-03-05 19:00:02 +00:00
Lasse Folger
fe89159266 internal/filedesc: make descriptor initialization goroutine-safe
Before this change there was a data race if you initialized the
descriptor of a message in parallel to the descriptor of any extension of
that message because the extendees feature set is read during the
initialization of the extension.

Change-Id: Id896b9fbf848209fce7dae8a7f40e2d61a3b2825
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/568695
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Stapelberg <stapelberg@google.com>
2024-03-04 08:49:27 +00:00
Lasse Folger
02e13d2dc7 internal/filedesc: align editions and non-editions HasPresence()
Change-Id: I1a581d82133b1684d81425fa91c4dc4057d92900
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/566399
Reviewed-by: Michael Stapelberg <stapelberg@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Lasse Folger <lassefolger@google.com>
2024-02-27 10:26:08 +00:00
Lasse Folger
416d517afa internal/conformance: make conformance tests work with editions
In scope of this change, I had to fix the `IsPacked()` implementation
for field descriptors because it was not returning the correct values
for edition protos.

Change-Id: Ic1ba9d0b3552ddf16360a80336c14632f2ce6f16
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/566039
Auto-Submit: Lasse Folger <lassefolger@google.com>
Reviewed-by: Michael Stapelberg <stapelberg@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-02-26 08:14:29 +00:00
Lasse Folger
055c812a4f encoding/prototext: add proto editions and fuzz tests
Change-Id: I2afc5ae83bf68600def3568e1d3ad51ef00e7671
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/566395
Auto-Submit: Lasse Folger <lassefolger@google.com>
Reviewed-by: Michael Stapelberg <stapelberg@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-02-23 12:14:08 +00:00
Lasse Folger
2caa6b02a2 all: format all .proto files
Change-Id: Ied684945de38ab1895c3ce8afaa1d84cda1e24f9
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/566037
Auto-Submit: Lasse Folger <lassefolger@google.com>
Reviewed-by: Michael Stapelberg <stapelberg@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-02-23 09:30:28 +00:00
Lasse Folger
f2cb7f136e encoding/protojson: add protojson editions tests including fuzztests
Change-Id: I478bf6a945cb2c86c71fd20b64dedb4b2e585f1d
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/566035
Reviewed-by: Michael Stapelberg <stapelberg@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Lasse Folger <lassefolger@google.com>
2024-02-23 08:35:31 +00:00
Lasse Folger
da0e6634fb proto: add editions tests for invalid messages
Change-Id: I97dff474afa7465ffbf1ac554cad8127bd4717bf
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/565975
Reviewed-by: Michael Stapelberg <stapelberg@google.com>
Auto-Submit: Lasse Folger <lassefolger@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-02-22 08:59:49 +00:00
Lasse Folger
f9eb6c71e7 go_features.proto: move .proto file next to generated .pb.go file
Change-Id: Ia24ca1ad2186bcc95681081d2719ee834b385728
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/565955
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Lasse Folger <lassefolger@google.com>
Reviewed-by: Michael Stapelberg <stapelberg@google.com>
2024-02-22 08:56:15 +00:00
Lasse Folger
11de0a6409 all: add editions support for extensions
Before this change the implementation would ignore editions options set on
extension declarations.
This change also add much more coverage for valid messages.

Change-Id: I0e7029b1430a39859cdd4a93667ac20c7e0ff20e
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/565396
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Stapelberg <stapelberg@google.com>
Auto-Submit: Lasse Folger <lassefolger@google.com>
2024-02-22 08:53:07 +00:00
Lasse Folger
7d98b0e8ab all: implement features.field_presence = LEGACY_REQUIRED support
Change-Id: Iaba3f4b81ac1b73f7542397a479642d081152c39
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/565656
Auto-Submit: Lasse Folger <lassefolger@google.com>
Reviewed-by: Michael Stapelberg <stapelberg@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-02-21 14:39:44 +00:00
Lasse Folger
6e0d73fd79 proto: add extension tests for editions protos
Change-Id: Ib3a00d8bf6fbf4841959ad9099fdc7b0d59ee0d3
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/565655
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Lasse Folger <lassefolger@google.com>
Reviewed-by: Michael Stapelberg <stapelberg@google.com>
2024-02-21 09:19:43 +00:00
Lasse Folger
194457763e proto: add more editions tests for proto.Size and proto.Equal
Change-Id: I8c7065d413b3a8d90ef25a2f5b9b9868c18906ec
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/565395
Auto-Submit: Lasse Folger <lassefolger@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Stapelberg <stapelberg@google.com>
2024-02-21 08:36:29 +00:00
Lasse Folger
5e8da94149 proto: add decoding fuzz test for proto3 to editions conversion
Change-Id: Ic2536373eeb5c814059ddf5c7c0d675d0e06153c
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/564817
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Stapelberg <stapelberg@google.com>
Auto-Submit: Lasse Folger <lassefolger@google.com>
2024-02-20 10:20:29 +00:00
Lasse Folger
8f6a6615d6 proto: add fuzztest for proto2 and equivalent editions proto
This fixes more minor issue when constructing the descriptor in that
delimited encoded message fields are not considered properly as groups.

Change-Id: I714a227a0f8d256fa7430c526844e8e94acdda33
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/564816
Reviewed-by: Michael Stapelberg <stapelberg@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Lasse Folger <lassefolger@google.com>
2024-02-20 09:18:14 +00:00
Lasse Folger
997075a7f5 reflect/protodesc: add editions support
Change-Id: Ie7fee936bdb480802cbaca34cf63c0dad34590b8
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/564815
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Stapelberg <stapelberg@google.com>
2024-02-19 07:03:53 +00:00
Lasse Folger
f102ec6532 all: add more test for editions and fix some bugs in the implementation
There are several minor fixes:
* fix the unmarshaler for the field options (it used the wrong field numbers).
* fix the unmarshaler to always initialize the file options with the appropriate defaults.
* fix the coder selection to work properly for fields with implicit presence tracking (they used the coders for explicit tracking).
* fix the dynamic message created from a descriptor for an editions using proto to use HasPresence instead of a syntax check for proto3

Change-Id: Ic13bc22a71aa9f93b476e5edd650d4d2ab5dcb98
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/564455
Auto-Submit: Michael Stapelberg <stapelberg@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Stapelberg <stapelberg@google.com>
2024-02-16 14:47:55 +00:00
Lasse Folger
020ec10f7b internal/filedesc: implement runtime editions support
This change add parsing editions specific descriptor parts to
internal/filedesc which makes it possible to load file descriptors of
protos using editions at runtime.

Change-Id: I7a0c23303acddd2cff115859d4cf82bf0102b14c
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/563615
Reviewed-by: Michael Stapelberg <stapelberg@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-02-13 12:20:49 +00:00
Lasse Folger
f387b036d8 editions: add some test protos for editions
I'll add the runtime implementations and tests in a followup change to
make it easier to review.

Change-Id: I2917e0d40a99e81799d89a66584a680ed7e8dbf7
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/561939
Auto-Submit: Lasse Folger <lassefolger@google.com>
Reviewed-by: Michael Stapelberg <stapelberg@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-02-12 14:14:45 +00:00
Lasse Folger
2040e8671b all: implement Go-specific GenerateLegacyUnmarshalJSON
This change adds the first Go specific editions feature and the
associated proto. The feature is used to control if the legacy
UnmarshalJSON method should be generated for enums. This change only
affects protos using editions.

More tests will be added in a followup change.

Change-Id: Ifb62454d7568bd6d90d0b93f8953adcfe46c45fd
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/561938
Reviewed-by: Michael Stapelberg <stapelberg@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Lasse Folger <lassefolger@google.com>
2024-02-12 13:54:51 +00:00
Lasse Folger
99e193e5dd all: update to protobuf-26.0-rc2 to implement go edition features
Change-Id: I190b1550e3e2e630392fed155716af9d651c74bc
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/562615
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Stapelberg <stapelberg@google.com>
Auto-Submit: Lasse Folger <lassefolger@google.com>
2024-02-08 09:23:48 +00:00
Josh Humphries
82c6b3ad29 protoreflect: remove unnecessary cache so extension types can be GC'ed
Resolves golang/protobuf#1521

In the internal/impl package, a helper computes metadata used for
serialization and deserialization of extension values. It features a
package var of type sync.Map that is used as cache. This ostensibly
was for performance, however it has never worked, because the code
that updates the cache inserts entries into the wrong map. (These
erroneous entries do not cause any issues because they are keys that
never conflict with those used in valid queries.)

Instead of a one-line fix to have this code update the correct cache,
this change removes the cache altogether. The existence of the cache
means that once a protoreflect.ExtensionType is used to serialize or
deserialize a message, it can *never* be garbage collected. Workloads
that are long-lived servers using dynamic messages and extensions
based on user requests will exhibit unbounded growth in memory usage
as the cache only gets larger and larger.

Since the cache has never worked, any advantages it ostensibly
conferred have not been missed. So this fixes the unbounded memory
growth instead.

Change-Id: I15957fd8521852f9f7f9f89db7ebfd7170d85202
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/560095
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Damien Neil <dneil@google.com>
Reviewed-by: Michael Stapelberg <stapelberg@google.com>
Reviewed-by: Lasse Folger <lassefolger@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
2024-02-01 19:49:10 +00:00
Lasse Folger
b70f02be53 editions: minor fix to resolve editions features correctly
+ The previous commit forgot to resolve the LegacyRequired feature

Change-Id: I05a2847be3d52277c65df004363ea3c87944364e
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/555976
Reviewed-by: Michael Stapelberg <stapelberg@google.com>
Auto-Submit: Lasse Folger <lassefolger@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-01-16 15:43:50 +00:00
Lasse Folger
9e454d6514 internal/filedesc: refactor editions feature resolution
Before this CL we only used features where they were applicable, e.g.
file features were only set on the file descriptor and field features
only on the fields descriptor. After this CL all descriptors (file,
message and field) contain always all features and when initializing
either of them we merge the features specified by options with the
features of the parent descriptor and use the result as the effective
feature. This way we initialize all the descriptors the same way and the
proto spec can change on which level features can be specified without
us having to change the code (at the moment most features can only be
specified on file or field level, in the future message might also be
possible).

Change-Id: I822202bf6a2bba5167bf9622c91a65c4523e78f9
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/555975
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Stapelberg <stapelberg@google.com>
2024-01-16 12:12:51 +00:00
Jeff Hodges
7b7814916b internal/impl: correct reflect.ValueError use
The composites x/tools/analysis pass errors on this use of
reflect.ValueError with:

```
internal/impl/message_reflect_field.go:541:10: reflect.ValueError struct literal uses unkeyed fields (composites)
```

This patch adds the missing field names.

Change-Id: I1a175aad6e9724c27f2469adc1f3a9b1e8c61e85
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/553915
Reviewed-by: Christian Höppner <hoeppi@google.com>
Reviewed-by: Michael Stapelberg <stapelberg@google.com>
Auto-Submit: Michael Stapelberg <stapelberg@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-01-04 13:14:07 +00:00
Michael Stapelberg
9f73929456 all: start v1.32.0-devel
Change-Id: I8533c876a60538f6bf81531dfbec0f4d61c6d78e
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/552416
Reviewed-by: Christian Höppner <hoeppi@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2023-12-22 09:30:39 +00:00
Michael Stapelberg
3068604084 all: release v1.32.0
Change-Id: I6565e6142e40254abac10063ce12041ade3258e0
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/552415
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Stapelberg <stapelberg@google.com>
Reviewed-by: Olena Synenka <olenasynenka@google.com>
Reviewed-by: Christian Höppner <hoeppi@google.com>
2023-12-22 09:30:25 +00:00
Lasse Folger
e8baad6b6c reflect/protodesc: support editions feature resolution
This is the first of multiple changes to add protobuf editions support
to the Go implementation.
This change includes the feature resolutions for protobuf editions.
The plugin does not yet report editions support and protoc would fail
if it invoked this plugin with a proto that uses editions.

Change-Id: I7d31909366c3433b21abab74ec92263e08145434
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/547315
Auto-Submit: Lasse Folger <lassefolger@google.com>
Reviewed-by: Michael Stapelberg <stapelberg@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Commit-Queue: Lasse Folger <lassefolger@google.com>
Reviewed-by: Lasse Folger <lassefolger@google.com>
2023-12-08 13:18:14 +00:00
Michael Stapelberg
2b71f26c99 all: fix go generate (needs protolegacy build tag for weak fields)
Prior to this change, one could either use go generate or
./test.bash -regenerate to re-generate the files — but only
the latter way would work.

With this change, we make ./test.bash -regenerate call go generate
so that the two ways cannot diverge again.

Change-Id: I940df66ebc6a4200847cf751929b3611309b67bc
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/547256
Reviewed-by: Lasse Folger <lassefolger@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2023-12-05 15:20:58 +00:00
David Chase
2087447a6b internal/strs: use go1.20 unsafe interface for strings
This is slightly more efficient and removes explicit dependence
on string layout and alignment.  Build tags control use.

Because of what is arguably a bug in go 1.20's treatment of build tags,
is build-tagged to go1.21, not go1.20.  (1.20 sees that it matches the
build tag and tries to compile the file, but then demands that it only use
language features from the version mentioned in go.mod. Go 1.21 and 1.22
behave more sensibly.)

Change-Id: I0cfc3b2e5651595edd3a82d9071d918700f961cd
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/545195
Reviewed-by: Cassondra Foesch <cfoesch@gmail.com>
Run-TryBot: David Chase <drchase@google.com>
Reviewed-by: Lasse Folger <lassefolger@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2023-11-28 09:45:19 +00:00
Michael Stapelberg
9492118ab1 internal/benchmarks: make download_benchdata print an error
Currently, the script fails, and not with a good error message.

related to https://github.com/golang/protobuf/issues/1524

Change-Id: Ia27a895a7ae2f6349bb1262936e4428fa485bb92
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/538955
Reviewed-by: Damien Neil <dneil@google.com>
Reviewed-by: Lasse Folger <lassefolger@google.com>
2023-11-03 08:27:41 +00:00
Josh Humphries
f4a6c1f6e5 types/descriptorpb: regenerate using latest protobuf v25.0-rc2 release candidate
This updates all generated code to match the contents of the latest
v25.0-rc2 release candidate of Protobuf. This provides access to the
various new fields and types defined in google/protobuf/descriptor.proto.

Change-Id: I209f8509f2d3e9a0ac7d9e134caef38c48a0d16b
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/538075
Reviewed-by: Lasse Folger <lassefolger@google.com>
Reviewed-by: Michael Stapelberg <stapelberg@google.com>
2023-10-27 08:25:48 +00:00
Vanja Pejovic
86bdc4705a internal/impl: preallocate memory when unmarshalling packed repeated fields
This improves wall time and allocated memory. I haven't found any
case (0 values, few values, many values) where this change is a
consistent regression. For fields with thousands of values, this
reduces memory usage by 50% and wall time by 20%.

Benchmark results from:
go test bench_test.go testmessages_test.go decode_test.go -run=none -bench=BenchmarkDecode/packed -benchmem -count=6 -timeout=0

goos: linux
goarch: amd64
cpu: Intel(R) Xeon(R) W-2135 CPU @ 3.70GHz
                                  │ base        │ fast
                                  │ sec/op      │ sec/op      vs base
repeated0packedAllTypes         432.9n ± 5%  420.1n ± 11%       ~ p=0.39
repeated0packed3AllTypes        431.2n ± 6%  433.8n ±  3%       ~ p=0.69
repeated0packedAllExt           2.748µ ± 6%  2.845µ ±  2%       ~ p=0.06
repeated0length_packedAllTypes  310.0n ± 0%  307.4n ±  1%  -0.84% p=0.00
repeated0length_packed3AllTypes 309.7n ± 1%  309.1n ±  4%       ~ p=0.41
repeated0length_packedAllExt    1.689µ ± 2%  1.732µ ±  5%       ~ p=0.39
packedPackedTypes               308.6n ± 1%  276.3n ±  1% -10.47% p=0.00
packedPackedExt                 2.727µ ± 2%  2.685µ ±  1%  -1.54% p=0.00
packed0lengthPackedTypes        163.4n ± 1%  160.8n ±  4%       ~ p=0.06
packed0lengthPackedExt          1.676µ ± 1%  1.748µ ±  4%  +4.30% p=0.01
geomean                             673.4n       668.3n        -0.75%

                                  │ base         │ fast
                                  │ B/op         │ B/op       vs base
repeated0packedAllTypes         1.328Ki ± 0%  1.281Ki ± 0% -3.53% p=0.00
repeated0packed3AllTypes        1.328Ki ± 0%  1.281Ki ± 0% -3.53% p=0.00
repeated0packedAllExt           5.364Ki ± 0%  5.364Ki ± 0%      ~ p=1.00
repeated0length_packedAllTypes  1.125Ki ± 0%  1.125Ki ± 0%      ~ p=1.00
repeated0length_packed3AllTypes 1.125Ki ± 0%  1.125Ki ± 0%      ~ p=1.00
repeated0length_packedAllExt    4.208Ki ± 0%  4.208Ki ± 0%      ~ p=1.00
packedPackedTypes                 592.0 ± 0%    544.0 ± 0% -8.11% p=0.00
packedPackedExt                 5.364Ki ± 0%  5.364Ki ± 0%      ~ p=1.00
packed0lengthPackedTypes          384.0 ± 0%    384.0 ± 0%      ~ p=1.00
packed0lengthPackedExt          4.208Ki ± 0%  4.208Ki ± 0%      ~ p=1.00
geomean                             1.735Ki       1.708Ki      -1.55%

                                  │ base       │ fast
                                  │ allocs/op  │ allocs/op   vs base
repeated0packedAllTypes         21.00 ± 0% 15.00 ± 0%  -28.57% p=0.002
repeated0packed3AllTypes        21.00 ± 0% 15.00 ± 0%  -28.57% p=0.002
repeated0packedAllExt           131.0 ± 0% 131.0 ± 0%        ~ p=1.000
repeated0length_packedAllTypes  1.000 ± 0% 1.000 ± 0%        ~ p=1.000
repeated0length_packed3AllTypes 1.000 ± 0% 1.000 ± 0%        ~ p=1.000
repeated0length_packedAllExt    33.00 ± 0% 33.00 ± 0%        ~ p=1.000
packedPackedTypes               21.00 ± 0% 15.00 ± 0%  -28.57% p=0.002
packedPackedExt                 131.0 ± 0% 131.0 ± 0%        ~ p=1.000
packed0lengthPackedTypes        1.000 ± 0% 1.000 ± 0%        ~ p=1.000
packed0lengthPackedExt          33.00 ± 0% 33.00 ± 0%        ~ p=1.000
geomean                             13.30      12.02        -9.60%

Change-Id: I622dd2055c3ca936f948f86ae8434387f42f8d8e
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/534196
Reviewed-by: Michael Stapelberg <stapelberg@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
2023-10-12 06:52:24 +00:00
Michael Stapelberg
322d454415 all: avoid non-const reflect.MethodByName calls
fixes golang/protobuf#1561

Change-Id: Ibf9d7c48c367bdbb241b09acf4563c64d512bce7
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/527896
Reviewed-by: Damien Neil <dneil@google.com>
Reviewed-by: Lasse Folger <lassefolger@google.com>
Reviewed-by: Joseph Tsai <joetsai@digital-static.net>
2023-10-03 07:25:07 +00:00
Singee
70db1e1de2 encoding/protojson: ignore unknown enum name if DiscardUnknown=true
This makes encoding/protojson pass all protobuf conformance tests.

Other Similar CL:
  - https://go-review.googlesource.com/c/protobuf/+/350469
  - https://go-review.googlesource.com/c/protobuf/+/256677

Fixes golang/protobuf#1208

Change-Id: I9f74162b80a3c7ee4750160fc59f0313345046de
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/525535
Reviewed-by: Cassondra Foesch <cfoesch@gmail.com>
Reviewed-by: Michael Stapelberg <stapelberg@google.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2023-09-08 10:59:01 +00:00
Josh Humphries
6d0a5dbd95 types/descriptorpb: regenerate using latest protobuf v24.0-rc2 release candidate
This updates all generated code to match the contents of the latest
v24.0-rc2 release candidate of Protobuf. This provides access to the
various new fields and types defined in google/protobuf/descriptor.proto.

Change-Id: I8ec56b308dd7eed52fb9b17b258a45d0669c47ff
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/512795
Reviewed-by: Lasse Folger <lassefolger@google.com>
Reviewed-by: Michael Stapelberg <stapelberg@google.com>
2023-07-27 12:38:59 +00:00
Lasse Folger
55f120eb3b all: start v1.31.0-devel
Change-Id: Ief1eb5ca950f0382e123ae833a28acc2d76bb8fb
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/506156
Reviewed-by: Michael Stapelberg <stapelberg@google.com>
2023-06-26 11:17:47 +00:00
Lasse Folger
68463f0e96 all: release v1.31.0
Change-Id: Ic67237749015f22a8657b65ad7250a6f95b742b4
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/506155
Reviewed-by: Michael Stapelberg <stapelberg@google.com>
2023-06-26 11:17:38 +00:00
Michael Stapelberg
cc524c9cf1 internal/order: fix sorting of synthetic oneofs to be deterministic
Before this change, synthetic oneofs were ignored in the inOneof() helper
function, but not in the remainder of the LegacyFieldOrder function.

Change-Id: Ia60e5244ae1000e98bbba9dd26f1d1583337fab4
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/497935
Reviewed-by: Damien Neil <dneil@google.com>
Reviewed-by: Lasse Folger <lassefolger@google.com>
Reviewed-by: Cassondra Foesch <cfoesch@gmail.com>
2023-05-25 07:36:46 +00:00
Edward McFarlane
05cbe34333 encoding: add MarshalAppend to protojson and prototext
Adds MarshalAppend methods to allow for byte slices to be reused.
Copies signature from the binary encoding.

Small changes to internal json and text libraries to use strconv
AppendInt and AppendUint for number encoding.

Change-Id: Ife7c8979c1c153a0a0bf9b70b296b8158d38dffc
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/489615
Reviewed-by: Edward McFarlane <emcfarlane000@gmail.com>
Reviewed-by: Joseph Tsai <joetsai@digital-static.net>
Reviewed-by: Lasse Folger <lassefolger@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
2023-05-01 15:10:15 +00:00
Damien Neil
736947c4de all: update protobuf release version to fix macOS tests
Update to a protobuf version that contains a fix for
https://github.com/protocolbuffers/protobuf/issues/12173
(macOS build error).

Set "CC=clang" when building the protobuf repo on macOS,
which fixes build errors on my machine (macOS 13.3.1, M1).

Change-Id: Id8abb054479454b7ccbded5a6fa4d74f3d3c236d
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/489315
Run-TryBot: Damien Neil <dneil@google.com>
Reviewed-by: Joseph Tsai <joetsai@digital-static.net>
Reviewed-by: Lasse Folger <lassefolger@google.com>
2023-04-26 20:34:47 +00:00
Lasse Folger
808c66411f all: start v1.30.0-devel
Change-Id: I36d043a08b60783360dfca21f100b697fe7e3e8d
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/476836
Reviewed-by: Michael Stapelberg <stapelberg@google.com>
2023-03-16 08:33:08 +00:00