Bugfix: do not tree shake map entry messages.

Since maps have a different in-memory representation than repeated messages, it is not safe to tree shake map entry messages.

Specifically, map fields use `kUpb_FieldMode_Map` instead of `kUpb_FieldMode_Array`, and there is no easy way to get the linker to rewrite this when the map entry is dropped.

However it is safe to tree shake message typed map values, since these use `kUpb_FieldMode_Scalar`, which remains valid even after the type is tree shaken.

PiperOrigin-RevId: 646199050
pull/17215/head
Joshua Haberman 5 months ago committed by Copybara-Service
parent 6429885156
commit 69a1888fd5
  1. 2
      upb_generator/protoc-gen-upb_minitable.cc

@ -364,7 +364,7 @@ void WriteMessage(upb::MessageDefPtr message, const DefPoolPair& pools,
auto pair = subs.emplace(index, GetSub(field, false));
ABSL_CHECK(pair.second);
if (options.one_output_per_message && field.IsSubMessage() &&
IsCrossFile(field)) {
IsCrossFile(field) && !upb_MiniTableField_IsMap(f)) {
if (seen.insert(pools.GetMiniTable64(field.message_type())).second) {
output(
"__attribute__((weak)) const upb_MiniTable* $0 ="

Loading…
Cancel
Save