According to https://protobuf.dev/support/cross-version-runtime-guarantee/#cpp, since there's no guarantees for cross-version support even for the micro/patch versions, we shouldn't allow range of versions that could be backward-compatible with, either, and should detach the corresponding version verifications.
PiperOrigin-RevId: 583056663
Before this change we would generate nested unsafe blocks that led to compiler warnings. This change minimizes each unsafe block and thereby avoids the nesting and compiler warnings. It's generally a best practice to keep unsafe blocks minimal to avoid the situation where a currently safe function is marked unsafe at a later point and all existing callsides don't need to be updated.
PiperOrigin-RevId: 582993146
This bug has been found by the TSAN sanitizer as part of cl/582814210. Before this change we were incorrectly returning an immutable Message instance for mutable accessors. This bug has been detected by TSAN because for embedded message fields the C++ runtime returns a static message instance if a field has not been set. In cl/582814210 this bug led to two separate unit tests read and write from/to the same object without any synchronization. Thus TSAN found a data race.
Tests for this change will be added as part of cl/582814210. At this state of the source we don't have any mutation functions available to trigger the TSAN error.
PiperOrigin-RevId: 582978261
Before this change the runtimes export a Map and MapInner. This change merges the Map and MapInner types into a single MapInner type, removing the Map type from the runtime (upb.rs, cpp.rs).
The motivation for this change is twofold:
1) A separate Map type is not strictly needed by the runtime. I hope this reduces some complexity.
2) After this change we can introduce a runtime-agnostic protobuf::Map type that implements Proxied.
PiperOrigin-RevId: 582978008
As a prerequisite of enabling go/protobuf-weak-speed-messages downcasts using built-in cast operations need to be changed to cast functions recommended by protobuf team (go/protobuf-downcast-recommendation)
**More information**: go/protobuf-stripping-lsc
#codehealth
PiperOrigin-RevId: 582977861
This CL implements Maps for scalar types for the C++ runtime. It's orthogonal to cl/580453646. This CL is constrained by having to force template instantiation of proto2::Map<K, V>. Put differently, a Rust protobuf::Map<K, V> implementation needs to call 'extern "C"' functions with both key and value type in the function name (e.g. __pb_rust_Map_i32_f64_get()). We use macros to generate a Map implementation for every (K,V)-pair. An alternative would have been to use vtables.
Luckily a key in a protobuf map can only be integer types, bool and string. So the number of key types is bounded by the specification, while the number of value types is not i.e. any protobuf message can be a value in a map. Given these constraints we introduce one 'MapKeyOps' trait per key type e.g. MapKeyBOOLOps or MapKeyI32Ops. These traits need to be implemented for every value type e.g. 'impl MapKeyBOOLOps for i32' will implement 'Map::<bool, i32>'. In particular the MapKeyOps traits can also be implemented for generated messages without violating the orphan rule.
This CL also contains significant changes to the UPB runtime so that both upb.rs and cpp.rs export a similar interface to simplify the implementation in map.rs and the generated code.
This CL does not yet implement the Proxied trait.
PiperOrigin-RevId: 582951914
Methods without options have three ways of ending their definition: {}, ;, and {};. This tracks this choice in metadata and restores it when writing.
PiperOrigin-RevId: 582903253
msg.submsg().x() and msg.submsg().x_mut() should now be callable for strings and bytes. Main idea here was to return &[u8] for bytes (vs [u8]) and &ProtoStr instead of &str or &[u8] for strings.
This CL also expunges IsSimpleScalar.
PiperOrigin-RevId: 582809307
- Reduce the minimum capacity to avoid waste on small tables.
- Increase max load factor of small tables to 1.0.
- Return the memory to the arena during growth. This avoids the 2x memory
usage of the backing array. This was already implemented for RepeatedField in
the past.
We also update the bucket calculation to do more bit mixing to ensure proper non-determinism on small tables now that the minimum is lower.
PiperOrigin-RevId: 582765057
We've had access to views for submessages for a while:
If you hit some_message.submsg().some_int(), you'll get a view for that int.
Until now, there hasn't been a way to get some_message.submsg_mut(), so we introduce the mutational pathway here.
We haven't added fully-functioning mutation, but this is a step towards that goal.
subview was inaccurate, so I've refactored and renamed: { accessor_fns_for_views, accessor_fns_for_muts }.
PiperOrigin-RevId: 581984371
`upb_Array_Append` and `upb_Array_Insert` will resize the array and then immediately overwrite the new values. These methods currently use `upb_Array_Resize` to do the array resizing, however this does extra unnecessary work by initializing those new values. This changes these insertion methods to use `_upb_Array_ResizeUninitialized` instead, which will perform the resize without the extra unnecessary initialization.
PiperOrigin-RevId: 581980280
This also fixes a few minor bugs in the editions implementation that were caught in python/conformance tests, and adds a new SetFeatureSetDefaults API to the def pool for consistency with C++ and other python implementations.
PiperOrigin-RevId: 581384108
This was already fully implemented in C++, but we need to expose features methods to the Python runtime to fully enable it. This also enables conformance and unit-testing for C++.
PiperOrigin-RevId: 581364355