Re: [PATCH 21/22] qapi: Drop simple unions

2021-09-13 Thread Markus Armbruster
Eric Blake  writes:

> On Mon, Sep 13, 2021 at 02:39:31PM +0200, Markus Armbruster wrote:
>> Simple unions predate flat unions.  Having both complicates the QAPI
>> schema language and the QAPI generator.  We haven't been using simple
>> unions in new code for a long time, because they are less flexible and
>> somewhat awkward on the wire.
>> 
>> The previous commits eliminated simple union from the tree.  Now drop
>> them from the QAPI schema language entirely, and update mentions of
>> "flat union" to just "union".
>> 
>> Signed-off-by: Markus Armbruster 
>> ---
>>  docs/devel/qapi-code-gen.rst  | 125 --
>>  scripts/qapi/expr.py  |  21 +--
>>  scripts/qapi/schema.py| 101 +++---
>>  .../qapi-schema/flat-union-array-branch.json  |   2 +-
>>  tests/qapi-schema/flat-union-empty.json   |   2 +-
>>  tests/qapi-schema/flat-union-int-branch.json  |   2 +-
>>  tests/qapi-schema/flat-union-no-base.err  |   2 +-
>>  tests/qapi-schema/flat-union-no-base.json |   2 +-
>>  tests/qapi-schema/qapi-schema-test.json   |   2 +-
>>  tests/qapi-schema/reserved-member-u.json  |   2 +-
>>  tests/qapi-schema/union-base-empty.json   |   2 +-
>>  .../union-base-no-discriminator.err   |   2 +-
>>  .../union-base-no-discriminator.json  |   2 +-
>>  13 files changed, 62 insertions(+), 205 deletions(-)
>
> Whee!  What a fun ride!

3-2-1-gone!  And good riddance :)

> Reviewed-by: Eric Blake 

Thank you for your quick review!




Re: [PATCH 21/22] qapi: Drop simple unions

2021-09-13 Thread Eric Blake
On Mon, Sep 13, 2021 at 02:39:31PM +0200, Markus Armbruster wrote:
> Simple unions predate flat unions.  Having both complicates the QAPI
> schema language and the QAPI generator.  We haven't been using simple
> unions in new code for a long time, because they are less flexible and
> somewhat awkward on the wire.
> 
> The previous commits eliminated simple union from the tree.  Now drop
> them from the QAPI schema language entirely, and update mentions of
> "flat union" to just "union".
> 
> Signed-off-by: Markus Armbruster 
> ---
>  docs/devel/qapi-code-gen.rst  | 125 --
>  scripts/qapi/expr.py  |  21 +--
>  scripts/qapi/schema.py| 101 +++---
>  .../qapi-schema/flat-union-array-branch.json  |   2 +-
>  tests/qapi-schema/flat-union-empty.json   |   2 +-
>  tests/qapi-schema/flat-union-int-branch.json  |   2 +-
>  tests/qapi-schema/flat-union-no-base.err  |   2 +-
>  tests/qapi-schema/flat-union-no-base.json |   2 +-
>  tests/qapi-schema/qapi-schema-test.json   |   2 +-
>  tests/qapi-schema/reserved-member-u.json  |   2 +-
>  tests/qapi-schema/union-base-empty.json   |   2 +-
>  .../union-base-no-discriminator.err   |   2 +-
>  .../union-base-no-discriminator.json  |   2 +-
>  13 files changed, 62 insertions(+), 205 deletions(-)

Whee!  What a fun ride!

Reviewed-by: Eric Blake 

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.   +1-919-301-3266
Virtualization:  qemu.org | libvirt.org




[PATCH 21/22] qapi: Drop simple unions

2021-09-13 Thread Markus Armbruster
Simple unions predate flat unions.  Having both complicates the QAPI
schema language and the QAPI generator.  We haven't been using simple
unions in new code for a long time, because they are less flexible and
somewhat awkward on the wire.

The previous commits eliminated simple union from the tree.  Now drop
them from the QAPI schema language entirely, and update mentions of
"flat union" to just "union".

Signed-off-by: Markus Armbruster 
---
 docs/devel/qapi-code-gen.rst  | 125 --
 scripts/qapi/expr.py  |  21 +--
 scripts/qapi/schema.py| 101 +++---
 .../qapi-schema/flat-union-array-branch.json  |   2 +-
 tests/qapi-schema/flat-union-empty.json   |   2 +-
 tests/qapi-schema/flat-union-int-branch.json  |   2 +-
 tests/qapi-schema/flat-union-no-base.err  |   2 +-
 tests/qapi-schema/flat-union-no-base.json |   2 +-
 tests/qapi-schema/qapi-schema-test.json   |   2 +-
 tests/qapi-schema/reserved-member-u.json  |   2 +-
 tests/qapi-schema/union-base-empty.json   |   2 +-
 .../union-base-no-discriminator.err   |   2 +-
 .../union-base-no-discriminator.json  |   2 +-
 13 files changed, 62 insertions(+), 205 deletions(-)

diff --git a/docs/devel/qapi-code-gen.rst b/docs/devel/qapi-code-gen.rst
index b154eae82e..b2569de486 100644
--- a/docs/devel/qapi-code-gen.rst
+++ b/docs/devel/qapi-code-gen.rst
@@ -319,13 +319,9 @@ Union types
 Syntax::
 
 UNION = { 'union': STRING,
-  'data': BRANCHES,
-  '*if': COND,
-  '*features': FEATURES }
-  | { 'union': STRING,
-  'data': BRANCHES,
   'base': ( MEMBERS | STRING ),
   'discriminator': STRING,
+  'data': BRANCHES,
   '*if': COND,
   '*features': FEATURES }
 BRANCHES = { BRANCH, ... }
@@ -334,63 +330,30 @@ Syntax::
 
 Member 'union' names the union type.
 
-There are two flavors of union types: simple (no discriminator or
-base), and flat (both discriminator and base).
-
-Each BRANCH of the 'data' object defines a branch of the union.  A
-union must have at least one branch.
-
-The BRANCH's STRING name is the branch name.
-
-The BRANCH's value defines the branch's properties, in particular its
-type.  The form TYPE-REF_ is shorthand for :code:`{ 'type': TYPE-REF }`.
-
-A simple union type defines a mapping from automatic discriminator
-values to data types like in this example::
-
- { 'struct': 'BlockdevOptionsFile', 'data': { 'filename': 'str' } }
- { 'struct': 'BlockdevOptionsQcow2',
-   'data': { 'backing': 'str', '*lazy-refcounts': 'bool' } }
-
- { 'union': 'BlockdevOptionsSimple',
-   'data': { 'file': 'BlockdevOptionsFile',
- 'qcow2': 'BlockdevOptionsQcow2' } }
-
-In the Client JSON Protocol, a simple union is represented by an
-object that contains the 'type' member as a discriminator, and a
-'data' member that is of the specified data type corresponding to the
-discriminator value, as in these examples::
-
- { "type": "file", "data": { "filename": "/some/place/my-image" } }
- { "type": "qcow2", "data": { "backing": "/some/place/my-image",
-  "lazy-refcounts": true } }
-
-The generated C code uses a struct containing a union.  Additionally,
-an implicit C enum 'NameKind' is created, corresponding to the union
-'Name', for accessing the various branches of the union.  The value
-for each branch can be of any type.
-
-Flat unions permit arbitrary common members that occur in all variants
-of the union, not just a discriminator.  Their discriminators need not
-be named 'type'.  They also avoid nesting on the wire.
-
 The 'base' member defines the common members.  If it is a MEMBERS_
 object, it defines common members just like a struct type's 'data'
 member defines struct type members.  If it is a STRING, it names a
 struct type whose members are the common members.
 
-All flat union branches must be `Struct types`_.
+Member 'discriminator' must name a non-optional enum-typed member of
+the base struct.  That member's value selects a branch by its name.
+If no such branch exists, an empty branch is assumed.
 
-In the Client JSON Protocol, a flat union is represented by an object
-with the common members (from the base type) and the selected branch's
-members.  The two sets of member names must be disjoint.  Member
-'discriminator' must name a non-optional enum-typed member of the base
-struct.
+Each BRANCH of the 'data' object defines a branch of the union.  A
+union must have at least one branch.
 
-The following example enhances the above simple union example by
-adding an optional common member 'read-only', renaming the
-discriminator to something more applicable than the simple union's
-default of 'type', and reducing the number of ``{}`` required on the wire::
+The BRANCH's STRING name is the branch name.  It must be a value of
+the discriminator enum type.
+
+The BRANCH's