This is the equivalent of CL 638495, but for the Opaque API.
While the behavior is the same for non-synthetic oneofs between
the Open Struct API and Opaque API, the behavior for synthetic oneofs
is not the same: Because the Opaque API uses a bitfield to store
presence, we need to use the Opaque presence check in WhichOneof().
This CL extends the testproto generator to use the protoc
command-line flag for the test3 testproto (which specifies
syntax = "proto3";), as the in-file api_level is only available
in .proto files using editions (but editions does not use synthetic
oneofs for optional fields, only proto3 does).
For golang/protobuf#1659
Change-Id: I0a1fd6e5fc6f96eeab043f966728ce2a14dbd446
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/638515
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Chressie Himpel <chressie@google.com>
This reverts change https://go.dev/cl/632735, in which
I misunderstood what the Protobuf documentation wanted to convey:
The quoted docs in CL 632735 refer to reflection for proto3 optional
fields, not to reflection for proto3 synthetic oneofs.
Synthetic oneofs should remain visible through reflection.
For the Open API, this change restores the old behavior.
For the Opaque API, another fix is needed and will be sent
in a separate, follow-up CL (follow golang/protobuf#1659).
For golang/protobuf#1659
Thanks to Joshua Humphries for the report and reproducer!
Change-Id: I3a924eed6d2425581adc65651395a68fc1576f4d
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/638495
Reviewed-by: Chressie Himpel <chressie@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
While godoc does not render comments within interface definitions,
using the [] syntax regardless helps with the replacement rules
we use to import Go Protobuf back into Google.
Change-Id: I0287ec3df5ba74261f563ce1117ab1e1be1fc270
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/635138
Reviewed-by: Cassondra Foesch <cfoesch@gmail.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Damien Neil <dneil@google.com>
For golang/protobuf#1657
In order to change the default API level, one can now specify:
protoc […] --go_opt=default_api_level=API_HYBRID
To override the default API level for a specific file, use
the apilevelM mapping flag (similar to the M flag for import paths):
protoc […] --go_opt=apilevelMhello.proto=API_HYBRID
(Similar to the M option.)
Change-Id: I44590e9aa4c034a5bb9c93ae32f4b11188e684a0
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/634818
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Damien Neil <dneil@google.com>
For golang/protobuf#1657
Change-Id: I7b2b0c30506706015ce278e6054439c9ad9ef727
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/634815
TryBot-Bypass: Michael Stapelberg <stapelberg@google.com>
Reviewed-by: Joseph Tsai <joetsai@digital-static.net>
Reviewed-by: Damien Neil <dneil@google.com>
This updates all generated code to match the contents of the latest
v29.1 release of Protobuf. The main significant change is that
SourceCodeInfo is now extendable (though in a very limited way).
This release of Protobuf includes new conformance tests that do not
pass with the latest version of this protobuf-go module. These have
been added to the list of known-failing tests. However all of them
are marked "required" in the conformance suite so should be likely
be addressed as soon as possible. (This change makes no attempt to
fix any of them.)
Change-Id: Ib554d393d7742b7a616af998eeab84a080a85e0e
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/634015
Reviewed-by: Chressie Himpel <chressie@google.com>
Reviewed-by: Michael Stapelberg <stapelberg@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Calling WhichOneof should not be possible for synthetic oneofs;
on the reflection level, these fields should work as if they
were regular fields, not as if they were oneofs:
> Reflection for proto3 optional fields should work properly. For example, a
> method like Reflection::HasField() should know to look for the hasbit for a
> proto3 optional field. It should not be fooled by the synthetic oneof into
> thinking that there is a case member for the oneof.
From the Protobuf docs at:
https://github.com/protocolbuffers/protobuf/blob/main/docs/implementing_proto3_presence.md#updating-reflection
This change was tested Google-internally as CL 701866153.
Change-Id: Id9500d4aa492acf4ebc6d2d84be07ed81201d2aa
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/632735
Reviewed-by: Chressie Himpel <chressie@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This test was accidentally migrated from proto.GetExtension to
proto.HasExtension in a semi-automated change and nobody noticed.
proto.HasExtension does not actually trigger lazy extension decoding.
I verified this using the dlv debugger:
% go test -tags protolegacy -c -gcflags "all=-N -l"
% dlv exec ./impl.test
Type 'help' for list of commands.
(dlv) r -test.run=TestMarshalMessageSetLazyRace -test.v
Process restarted with PID 3586699
(dlv) b TestMarshalMessageSetLazyRace
Breakpoint 1 set at 0xac9bf6 for google.golang.org/protobuf/internal/impl_test.TestMarshalMessageSetLazyRace() ./lazy_test.go:500
(dlv) c
=== RUN TestMarshalMessageSetLazyRace
> [Breakpoint 1] google.golang.org/protobuf/internal/impl_test.TestMarshalMessageSetLazyRace() ./lazy_test.go:500 (hits goroutine(32):1 total:1) (PC: 0xac9bf6)
=> 500: func TestMarshalMessageSetLazyRace(t *testing.T) {
(dlv) b ExtensionField.lazyInit
Breakpoint 2 set at 0x8da076 for google.golang.org/protobuf/internal/impl.(*ExtensionField).lazyInit() ./codec_extension.go:123
(dlv) c
--- PASS: TestMarshalMessageSetLazyRace (4.07s)
PASS
Process 3586699 has exited with status 0
(dlv) exit
Note how breakpoint 2 is unexpectedly not hit!
Here is how the output changes with my fix:
% go test -tags protolegacy -c -gcflags "all=-N -l"
% dlv --check-go-version=false exec ./impl.test
Type 'help' for list of commands.
(dlv) r -test.run=TestMarshalMessageSetLazyRace -test.v
Process restarted with PID 3587344
(dlv) b TestMarshalMessageSetLazyRace
Breakpoint 1 set at 0xac9bf6 for google.golang.org/protobuf/internal/impl_test.TestMarshalMessageSetLazyRace() ./lazy_test.go:500
(dlv) c
=== RUN TestMarshalMessageSetLazyRace
> [Breakpoint 1] google.golang.org/protobuf/internal/impl_test.TestMarshalMessageSetLazyRace() ./lazy_test.go:500 (hits goroutine(28):1 total:1) (PC: 0xac9bf6)
=> 500: func TestMarshalMessageSetLazyRace(t *testing.T) {
(dlv) b ExtensionField.lazyInit
Breakpoint 2 set at 0x8da076 for google.golang.org/protobuf/internal/impl.(*ExtensionField).lazyInit() ./codec_extension.go:123
(dlv) c
> [Breakpoint 2] google.golang.org/protobuf/internal/impl.(*ExtensionField).lazyInit() ./codec_extension.go:123 (hits goroutine(68):1 total:4) (PC: 0x8da076)
> [Breakpoint 2] google.golang.org/protobuf/internal/impl.(*ExtensionField).lazyInit() ./codec_extension.go:123 (hits goroutine(70):1 total:4) (PC: 0x8da076)
> [Breakpoint 2] google.golang.org/protobuf/internal/impl.(*ExtensionField).lazyInit() ./codec_extension.go:123 (hits goroutine(58):1 total:4) (PC: 0x8da076)
> [Breakpoint 2] google.golang.org/protobuf/internal/impl.(*ExtensionField).lazyInit() ./codec_extension.go:123 (hits goroutine(54):1 total:4) (PC: 0x8da076)
=> 123: func (f *ExtensionField) lazyInit() {
(dlv) bt
0 0x00000000008da076 in google.golang.org/protobuf/internal/impl.(*ExtensionField).lazyInit
at ./codec_extension.go:123
1 0x00000000008dac3e in google.golang.org/protobuf/internal/impl.(*ExtensionField).Value
at ./codec_extension.go:180
2 0x000000000094e5d9 in google.golang.org/protobuf/internal/impl.(*extensionMap).Get
at ./message_reflect.go:276
3 0x000000000095a2ee in google.golang.org/protobuf/internal/impl.(*messageState).Get
at ./message_reflect_gen.go:90
4 0x0000000000890099 in google.golang.org/protobuf/proto.GetExtension
at /usr/local/google/home/stapelberg/protobuf/proto/extension.go:90
5 0x0000000000aca7d4 in google.golang.org/protobuf/internal/impl_test.TestMarshalMessageSetLazyRace.func2.1
at ./lazy_test.go:545
6 0x0000000000aca625 in google.golang.org/protobuf/internal/impl_test.TestMarshalMessageSetLazyRace.func2
at ./lazy_test.go:550
7 0x00000000006001c1 in runtime.goexit
at /usr/lib/google-golang/src/runtime/asm_amd64.s:1700
Change-Id: Ie7a8621064af412a1db7efb3ad6b8473f9db58e8
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/624416
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Chressie Himpel <chressie@google.com>
This required renaming the extension fields to have distinct names, as
makeMessages() uses the protobuild package, which works with field names.
The makeMessages() function can be centrally extended with other variants of
testprotos (e.g. editions).
Change-Id: I68ef28baee674c6b53da8629c5ff7b2e1b92d4ff
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/624415
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Chressie Himpel <chressie@google.com>
This will be useful for a few different upcoming tests,
to be submitted in a follow-up CL.
Change-Id: I1fde9f4567b149141737a74c8448c2ee14946ae4
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/623117
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Chressie Himpel <chressie@google.com>
With this change, we establish a similar mechanism in encoding/prototext as
already exists in the proto package: a testmessages_test.go which serves as an
extension point where one can inject more variants into the corpus of test
messages.
Change-Id: I9f83735a44e5fd2e4736f888aaca428e4cc8ed42
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/623116
Reviewed-by: Chressie Himpel <chressie@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This is important for test coverage: the makeMessages() function is where we
declare the various different test message types. Using this central function is
better than explicitly having to spell out all the various cases in the test
table.
This CL is roughly neutral in terms of lines changed, but actually increases
coverage: in the existing table, not every group of tests had coverage for all
cases (proto2, proto3, editions). This was difficult to spot previously, but now
the different test message types are now clearly spelled out (allTypesNoProto3).
Also, the test now prints the description and message types as subtest name.
This makes it easy to verify coverage by just reading the test output.
Change-Id: I08f541548d087233cbb4686785c456674371c2a3
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/623115
Reviewed-by: Chressie Himpel <chressie@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This change required updating editions_defaults.binpb with
--edition_defaults_maximum=2024 so that we can use edition 2024 in our
testdata/enumprefix.proto test file.
For end users, this feature will only be available once:
1. protoc declares support for edition 2024 (expected early 2025).
2. protoc-gen-go declares support for edition 2024.
related to golang/protobuf#513
Change-Id: Ib8daeecae39ef32eff942279707d256c312f2a53
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/618979
Reviewed-by: Lasse Folger <lassefolger@google.com>
Reviewed-by: Mike Kruskal <mkruskal@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Damien Neil <dneil@google.com>
Some other implementations do not send the value field when encoding
an Any representing a message of the Empty Well-Known-Type.
Fixesgolang/protobuf#1620
Change-Id: I89bffd5f92656ba3ac462c0b6365ed4b49e6189d
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/618395
Reviewed-by: Damien Neil <dneil@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Stapelberg <stapelberg@google.com>
Also adds better benchmark cases for large message where some fields are
actually populated.
This change was previously done in Google internal cl/660848520.
Change-Id: I682aae0c9c2850bfe7638de29ab743ad7d7b119a
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/609035
Reviewed-by: Christian Höppner <hoeppi@google.com>
Reviewed-by: Cassondra Foesch <cfoesch@gmail.com>
Reviewed-by: Michael Stapelberg <stapelberg@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Most of our imports already comply with the style, but this change makes it
consistent across the entire repository.
I suspect that these unnecessary imports are left-overs from differences between
Google-internal (where many imports are renamed) and Open Source.
Change-Id: Id5f6eabd22bcc72dd4e36dd018b6cc5138df7696
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/609875
Reviewed-by: Christian Höppner <hoeppi@google.com>
Auto-Submit: Michael Stapelberg <stapelberg@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This change was originally done by Mike Kruskal in Google-internal cl/520045664.
(Undeclared extensions are no longer accepted Google-internally.)
Change-Id: I24d24ff2c7dc85920bd5dbe86724186d98783a18
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/609555
Reviewed-by: Christian Höppner <hoeppi@google.com>
Auto-Submit: Michael Stapelberg <stapelberg@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This change was originally done by Patrik Nyblom in Google-internal cl/308876443
(The corresponding test is TestDecodeFastCheckInitialized in methods_test.go.)
Change-Id: I312dff53db4d6f87decf152eb20ec4dd280f03c3
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/608256
Reviewed-by: Christian Höppner <hoeppi@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Document the type mapping and the recommended pattern for working with
extensions. This documentation was Google-internal (cl/335451491), presumably
because of the reference to static analysis tools that don’t exist outside.
Compared to the internal version, this CL uses “should” instead of “must”.
Change-Id: I9293c10b2f6f91c9546d145c94b52e84f3a7a9c9
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/607995
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Damien Neil <dneil@google.com>
Reviewed-by: Christian Höppner <hoeppi@google.com>
Go 1.23 was released a few weeks ago.
Change-Id: Ied9daddbe57b5f57993a31fd09fe1c8c47a42878
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/608316
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Michael Stapelberg <stapelberg@google.com>
Reviewed-by: Christian Höppner <hoeppi@google.com>
This change was originally done in Google-internal cl/512993970.
Change-Id: I66ea95cd975b160892ed9f931312f1767cbc9fc9
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/608315
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Michael Stapelberg <stapelberg@google.com>
Reviewed-by: Christian Höppner <hoeppi@google.com>
This test was accidentally duplicated in CL 569356.
Change-Id: I0e2f81fbebe9b4c37bf6d28615e0bf51d28cfc4c
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/607777
Auto-Submit: Michael Stapelberg <stapelberg@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Christian Höppner <hoeppi@google.com>
This should have been part of CL 606755.
related to golang/protobuf#1640
Change-Id: Iae1bfb9e3bd440f879047d3a78e1bba364d7568c
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/607775
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Christian Höppner <hoeppi@google.com>
This flag is used by the (Google-internal) editions codegen test.
Having the functionality in the open source repository reduces
our maintenance burden (fewer/smaller patches).
Change-Id: Idb9c95e9b2cb8922584bcb7ca13a8ddef4347af0
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/606735
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Lasse Folger <lassefolger@google.com>
This change was originally done by Mike Kruskal in Google-internal cl/515091827.
Change-Id: I5d1588193663249964cf8bc9b9fe9f61d29c98a6
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/606756
Reviewed-by: Christian Höppner <hoeppi@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This cleanup was done in June 2020 by Dan Scales,
but never upstreamed to the open source Go Protobuf repository.
Change-Id: I175d9588b5bb536fa276133f8fe6073278e6d3b0
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/605895
Reviewed-by: Christian Höppner <hoeppi@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Add support for additional primitive types such as int8, int16, uint8, uint16,
and the json.Number type in the conversion logic of the NewValue function.
This change ensures that the generated code can handle a wider range of Go types
when converting them to protobuf Value types, improving compatibility with JSON
data formats.
fixesgolang/protobuf#1463
Change-Id: I6ea7b8f644f6c3dbe5e6c17e744be40c56846328
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/601775
Reviewed-by: Michael Stapelberg <stapelberg@google.com>
Reviewed-by: Lasse Folger <lassefolger@google.com>
Reviewed-by: Funda Secgin <fundasecgin32@gmail.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Before this commit, message-level Go editions features were not parsed
correctly.
Change-Id: I94ead5428fadae5fd70ed991fa405ce9388e9660
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/603015
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Michael Stapelberg <stapelberg@google.com>
Reviewed-by: Lasse Folger <lassefolger@google.com>
go_features.proto apparently lived in package google.protobuf,
but was later moved to package pb, without updating generate-protos.
This change fixes the oversight and re-generates go_features_gen.go.
Change-Id: I6fd68fdb7b146f32dd610c0bad6ecf5ec940ae78
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/602055
Reviewed-by: Lasse Folger <lassefolger@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
The IsLazy() method is intentionally not added to the
protoreflect.FieldDescriptor interface because users should not need it.
The Go Protobuf runtime will use type assertion to dynamically call the method.
There is no change in behavior, this is preparation only.
Change-Id: I4500c17f5edd1bdc40447eb89bff115b4e8eab06
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/596539
Reviewed-by: Chressie Himpel <chressie@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>