The extern "C" block in messages is now:
- Cpp kernel: All of the message/accessor/oneof externs
- Upb kernel: Only the upb_MiniTable extern
PiperOrigin-RevId: 668518308
instantiate objects if permitted by the compiler.
We can use memset for zero initialized objects, and memcpy for ones cloned from
the prototype.
This permits creating objects from the parser without calling virtual
functions.
For the cases where the efficient implementation can't be used, we generate a
"placement new" style function to offload the memory allocation out of the code
generation. This reduces code bloat even when we can't use the more efficient
implementation.
Migrate many callers of `New` and similar to the new functionality. In
particular, the parsing paths will use this.
Finally, make `New` non-virtual now that `MessageLite` can handle it directly.
It reduces binary size.
PiperOrigin-RevId: 668077355
`unsafe trait` means that the _implementation_ has constraints they need to meet for the behavior to be safe (which is the intent here, namely that it should always return the same value and always be a safe to deref value), unsafe on the fn means that the _caller_ of that fn has some constraints they need to meet for it to be safe (of which there are none in this case).
PiperOrigin-RevId: 668028628
This unifies the duplicated logic that we had for each different non-repeated field to emit these same 3 methods for each of the different field types, and moves the has/clear off of upb-accessors-C-codegen and onto the upb-C-API for all cases (matching the singular scalars case which moved in a previous change).
PiperOrigin-RevId: 667953223
These types are effectively two ways to spell the same type, but MapView/MapMut is more terse, especially where the unnamed lifetime was used which can now be implied (`View<'_, Map<K, V>>` can just be `MapView<K,V>`)
PiperOrigin-RevId: 667636945
`absl::string_view`.
This is a modernization of the API and performance improvement for all callers.
Currently gated behind opt-in macro
`PROTOBUF_TEMPORARY_ENABLE_STRING_VIEW_RETURN_TYPE` for users to test and prevent
issues when the breaking change happens.
PiperOrigin-RevId: 667616632
These are very old unit-tests that appear to have been written to provide some conformance and fuzzing capabilities before we had more comprehensive solutions. Today, they should be already covered by our conformance tests and fuzz tests and create unnecessary noise.
The goal of this change is to remove the checked-in binary golden data that we no longer know how to regenerate. There is a lot of nearby code that could likely also be cleaned up in a follow-up
PiperOrigin-RevId: 667604310
We were really inconsistent on where we put Private or not and this tries to make a sensible consistent state of:
- For types that are exposed to application code, any pub methods which are only pub so they can be used by gencode (which is mostly anything that has any internal/runtime type anywhere on the parameters or return type list), have those methods have both a `Private` arg and doc(hidden)
- For structs that are only inside __runtime / __internal to begin with, put doc(hidden) on the types, and don't put Private on any of their methods since callers can't reach those types regardless.
Note that for exposed functions which also _accept_ another internal/runtime type in a parameter, the additional `Private` arg is superfluous since application code shouldn't ever be able to reach one of those internal types to be able to pass one in, but this keeps the pattern of keeping Private on it in those cases as well (the `Private` would still be the only guard on methods which only _return_ an internal type).
PiperOrigin-RevId: 667547566
Putting it into BUILD files unintentionally forces it on all our downstream users. Instead, we just want to enable this during testing and let them choose for themselves in their builds.
Note, that this expands the scope of -Werror to our entire repo for CI, so a bunch of fixes and opt-outs had to be applied to get this change passing.
Closed#14714
PiperOrigin-RevId: 666903224
This is useful/necessary when the caller wants to tie the View to a lifetime other than a stack frame, including 'static.
The documentation is clarified that the preexisting one should be preferred in most situations, and only use the new one where tying the View lifetime to a stack frame isn't suitable.
PiperOrigin-RevId: 666396427
This should get use feedback so we know if usage, the intent is to
be able to remove the different generation code in the future if
folks don't need these.
PiperOrigin-RevId: 666318474
Protobuf enums in C++ always have `int` as their backing type, so for the
purpose of use as a map value, we can just treat enums as 32-bit ints. This
allows us to delete the enum-specific generated C++ thunks.
PiperOrigin-RevId: 666043376
This change adds delete, clear, serialize, parse, copy_from, and merge_from
operations to the runtime. Since these operations can all be implemented easily
on the `MessageLite` interface, we can use a common implementation in the
runtime instead of generating per-message thunks for all of these.
I suspect this will also make it possible to remove some of our generated trait
implementations and replace them with blanket implementations, but I will leave
that for a future change.
PiperOrigin-RevId: 665910927
We can use memset for zero initialized objects, and memcpy for ones cloned from the prototype.
This permits creating objects from the parser without calling virtual functions.
For the cases where the efficient implementation can't be used, we generate a "placement new" style function to offload the memory allocation out of the code generation. This reduces code bloat even when we can't use the more efficient implementation.
Migrate many callers of `New` and similar to the new functionality. In particular, the parsing paths will use this.
Finally, make `New` non-virtual now that `MessageLite` can handle it directly. It reduces binary size.
PiperOrigin-RevId: 665411723
Our bootstrapping setup compiles multiple versions of the generated code for `descriptor.proto` and `plugin.proto`, one for each stage of the bootstrap. For source files (`.c`), we can always select the correct version of the file in the BUILD rules, but for header files we need to make sure the correct stage's file is always selected via `#include`.
Previously we used `cc_library(includes=[])` to make it appear as though our bootstrapped headers had the same names as the "real" headers. This allowed a lot of the code to be agnostic to whether a bootstrap header was being used, which simplified things because we did not have to change the code performing the `#include`.
Unfortunately, due to build system limitations, this sometimes led to the incorrect header getting included. This should not have been possible, because we had a clean BUILD graph that should have removed all ambiguity about which header should be available. But in non-sandboxed builds, the compiler was able to find headers that were not actually in `deps=[]`, and worse it preferred those headers over the headers that actually were in `deps=[]`. This led to unintended results and errors about layering check violations.
This CL fixes the problem by removing all use of `includes=[]`. We now spell a full pathname to all bootstrap headers, so this class of errors is no longer possible. Unfortunately this adds some complexity, as we have to hard-code these full paths in several places.
A nice improvement in this CL is that `bootstrap_upb_proto_library()` can now only be used for bootstrapping; it only exposes the `descriptor_bootstrap.h` / `plugin_bootstrap.h` files. Anyone wanting to use the normal `net/proto2/proto/descriptor.upb.h` file should depend on `//net/proto2/proto:descriptor_upb_c_proto` target instead.
PiperOrigin-RevId: 664953196
Using `field.full_name()` instead of constructing a thunk name based on the containing_type makes little difference for normal fields, but it will actually be unique for extension fields, whereas the prior approach would break if an extension field name and a regular field collided (or if 2 extensions for the same message had field names that collided).
PiperOrigin-RevId: 664910530