SIGN IN SIGN UP

Protocol Buffers - Google's data interchange format

0 0 35 C++

Update Rust generator to output minidescriptors instead of C minitables

With this change, we no longer emit any C generated code for the Rust upb
implementation. Instead, we output minidescriptors in the Rust generated code,
and use these to construct the minitables at run time. Each message's
`AssociatedMiniTable::mini_table()` method will lazily build the minitable on
first use.

We need a place to put the minidescriptor and lazily-built minitable for enums,
so I added a new `AssociatedMiniTableEnum` trait for this purpose. This is
only necessary for closed enums.

There are a couple of things that were somewhat difficult about building the
minitables at runtime:
 - Each map entry is represented as its own implicit message type and needs a
   minitable. To facilitate this, I updated the generator to output a
   visibility-controlled struct to represent each map entry. This way we can
   implement `AssociatedMiniTable` on it and treat it like any other message
   for the purpose of building minitables.
 - The naive way of recursively building minitables is vulnerable to deadlock
   in the case of cycles in the message graph. Such cycles are allowed within a
   single .proto file, so we need to be able to handle this. My change handles
   this problem by treating each strongly-connected component (SCC) as its own
   unit, and then the graph of SCCs has no cycles. Each SCC has an arbitrariliy
   chosen representative responsible for linking all messages in the SCC.

PiperOrigin-RevId: 761654774
A
Adam Cozzette committed
1b4b5fc1ff28bf642b51008a413c2a65046b2aa1
Parent: 49d9e2d
Committed by Copybara-Service <copybara-worker@google.com> on 5/21/2025, 8:53:12 PM