They should ignore presence and always process key and value.
Remove codegen for methods in MapEntry and use the ones from Message.
Delete dead code in MapTypeHandler.
PiperOrigin-RevId: 588826780
This change implements maps with keys and values of type string e.g. Map<ProtoStr, i32> and Map<ProtoStr, ProtoStr>.
Implementing the Map type for ProtoStr has been different from scalar types because ProtoStr is an unsized type i.e. its size is not known at compile time. The existing Map implementation assumed sized types in many places. To make unsized types fit into the existing code architecture I have added an associated type 'Value' to the MapWith*KeyOps traits. The associated type needs to be sized and is the type returned by the Map::get(self, key) method e.g. for aProtoStr, the `type Value = &ProtoStr`.
PiperOrigin-RevId: 588783751
Before this CL, we weren't generating view accessors for messages with depth > 1.
We weren't getting to message::GetterForViewOrMut because we were detecting FieldDescriptor::TYPE_MESSAGE and bailing out.
That check has now been expunged, and we now properly emit the right view, even for messages embedded within messages.
Added tests for:
- another level of submsg access depth
- accessing a message declared outside of the current message (that is, not a direct nested message within the same message)
- accessing the accessor of the accessor of the accessor of a recursively defined message
PiperOrigin-RevId: 588460599
Collect all static initializers in a single expression at the end of the file.
This reduces code bloat, and provides a way to customize the
registration for weak descriptor messages.
PiperOrigin-RevId: 588127128
This will allow us to support editions without adding support for proto2 concepts such as closed enums, required fields, and groups. The generator will now only ban unsupported features, meaning that some types of proto2 files will be allowed. The PHP runtime does not yet support editions.
PiperOrigin-RevId: 588091790
This feature allows for tree shaking within a single .proto file, dropping
unused types while still allowing reflection to work for them via the generated
DescriptorPool.
PiperOrigin-RevId: 587066283
When unknown fields are discarded using reflection in reflection_ops.cc, unnecessary switching of the internal map representation is triggered.
A map<int,int> field cannot have unknown fields. However, in the current code the check used is
if (field->IsMap() && IsMapValueMessageTyped(field)) {
// Discard map field
} else {
// Discard repeated message field
}
This means that the code proceeds discarding unknown fields for each mapentry using the RepeatedPtrField of MapEntry representation of the map. Causing unnecessary work and unnecessary, potentially big, memory allocation. This PR fixes this.
See also issue https://github.com/protocolbuffers/protobuf/issues/13222
This is also a bug fix. When a map<int, MyProto> is in a dirty state, previously it would be skipped. After this change it will correctly use the repeated path to clean the MyProto sub-entries
Closes#14879
COPYBARA_INTEGRATE_REVIEW=https://github.com/protocolbuffers/protobuf/pull/14879 from gerben-stavenga:patch_discardunknown fb0749ab8d
PiperOrigin-RevId: 586820137
It's up to the user how to set up the threads, but this will allow them to dispatch any recursive work during the descriptor builds to separate threads with their own stack limit.
PiperOrigin-RevId: 586774613
This is similar to what we did for built-in generators, and gives us the ability to create a new edition without subtley breaking generators that don't support it yet.
PiperOrigin-RevId: 586756816
- Remove _Internal accessors. They only have one caller and it's better to inline it.
- Remove redundant has bit setting. MergeFrom does it globally instead of per field.
- Reuse existing arena object. Avoids redundant calls to `GetArena()`.
- Use rhs object instead of weak instance for calling `New()`.
- Change repeated fields to use the generic MergeFrom instead of Arena::CopyConstruct.
PiperOrigin-RevId: 586680126
This is functionally equivalent, but avoids a codegen change under editions where the inherited value of utf8_validation can change for non-string maps.
PiperOrigin-RevId: 586493296
Unlike Arena::CreateMessage, Arena::Create creates only the top level object
from arena even if it is arena constructalble; e.g. messages, RepeatedPtrField,
etc. This renders arenas less effective.
Instead of asking users to be aware of such nuances to use the right API for
the right type, this CL makes Arena::Create recognizes and fully supports arena
constructable types.
While extremly rare, some users try to emulate Arena::CreateMessage with
Arena::Create by passing arena parameter twice. For example,
```
auto foo = Arena::Create<Foo>(&arena, &arena); // bad
```
This pattern is not supported and will break after this change. The following
is recommended instead.
```
auto foo = Arena::CreateMessage<Foo>(&arena); // recommended
auto foo = Arena::Create<Foo>(&arena); // after this change
```
PiperOrigin-RevId: 585709990
- Avoid redundant calls to `GetArena()`.
- Only do a single call to `xxx_clear()` if needed.
- Set the oneof_case once, if needed.
- Use CopyConstruct for new objects, like we do for non-oneof Merge.
- Avoid the _Internal::mutable_xxx functions, as they are not needed anymore.
PiperOrigin-RevId: 585705944
This change names the lifetime of Mut<'a, T> and requires that T outlives 'a. The motivation for this change came up while implementing `Map<K, ProtoStr>`. The Map implementation makes it so that `V` needs to implement the `MapWithKeyOps` trait which has an associated type with a lifetime (`Value<'a>`. The lifetime bound on `T` ensures that e.g. for `MapWithKeyOps<Value<'b>=&'b ProtoStr>` `'a` outlives `'b`.
PiperOrigin-RevId: 585657154