Eric Blake <ebl...@redhat.com> writes: > Right now, we emit the branches of union types as a boxed pointer, > and it suffices to have a forward declaration of the type. However, > a future patch will swap things to directly use the branch type, > instead of hiding it behind a pointer. For this to work, the > compiler needs the full definition of the type, not just a forward > declaration, prior to the union that is including the branch type. > This patch just adds topological sorting to hoist all types > mentioned in a branch of a union to be fully declared before the > union itself. The sort is always possible, because we do not > allow circular union types that include themselves as a direct > branch
When a patch makes a "can't happen" claim, I normally ask for assertions to make sure we go down in flames should it happen anyway. But in this case, the C compiler will shoot us down then, and that'll do nicely. > (it is, however, still possible to include a branch type > that itself has a pointer to the union, for a type that can > indirectly recursively nest itself - that remains safe, because > that the member of the branch type will remain a pointer, and the > QMP representation of such a type adds another {} for each recurring > layer of the union type). > > Signed-off-by: Eric Blake <ebl...@redhat.com>