From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55632) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ya4Lv-0007YJ-B8 for qemu-devel@nongnu.org; Mon, 23 Mar 2015 11:33:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Ya4Lq-0001JG-Rx for qemu-devel@nongnu.org; Mon, 23 Mar 2015 11:33:19 -0400 Received: from mx1.redhat.com ([209.132.183.28]:44517) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ya4Lq-0001J7-La for qemu-devel@nongnu.org; Mon, 23 Mar 2015 11:33:14 -0400 Message-ID: <55103236.20708@redhat.com> Date: Mon, 23 Mar 2015 09:33:10 -0600 From: Eric Blake MIME-Version: 1.0 References: <1411165504-18198-1-git-send-email-eblake@redhat.com> <1411165504-18198-13-git-send-email-eblake@redhat.com> <87h9zw9mqy.fsf@blackfin.pond.sub.org> <87y4t85dlc.fsf@blackfin.pond.sub.org> <54241FFB.2000104@redhat.com> <87fvffwu3v.fsf@blackfin.pond.sub.org> In-Reply-To: <87fvffwu3v.fsf@blackfin.pond.sub.org> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="rt0ULT965W6eUU9w8P1P1v492XQwt5rFB" Subject: [Qemu-devel] RFC: 'alternate' qapi top-level expression [was: [PATCH v4 12/19] qapi: Add some type check tests] List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Markus Armbruster Cc: Luiz Capitulino , Fam Zheng , qemu-devel@nongnu.org, wenchaoqemu@gmail.com This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --rt0ULT965W6eUU9w8P1P1v492XQwt5rFB Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable [revisiting this series, finally!] On 09/25/2014 10:19 AM, Markus Armbruster wrote: >> Return of an anon union isn't used yet, but _might_ make sense (as the= >> only feasible way of changing existing commands that return an array o= r >> primitive extensible to instead return a dict) -=20 >=20 > Good point. >=20 >> except that back-comp= at >> demands that we can't return a dict in place of a primitive unless the= >> arguments of the command are also enhanced (that is, older callers are= >> not expecting a dict, so we can't return a dict unless the caller >> witnesses they are new enough by explicitly asking for a dict return).= >=20 > I think we can keep things simple for now and reject anonymous unions. > We can always relax the check when we run into a use. In trying to code up what it would take to easily reject anonymous unions from a return type, I'm realizing that it would be smarter to quit mixing anonymous unions in with other unions. Refresher course: on the wire, both a regular union: QAPI: { 'type': 'Type1', 'data': { 'value': 'int' } } { 'union': 'Foo', 'data': { 'a': 'Type1', 'b': 'Type2' } } { 'command': 'bar', 'data': 'Foo' } Wire: { "execute": "bar", "arguments": { "type": "a", "data": { "value": 1 } } } and a flat union: QAPI: { 'type': 'Type1', 'data': { 'value': 'int' } } { 'enum': 'Enum', 'data': [ 'a', 'b' ] } { 'type': 'Base', { 'switch': 'Enum' } } { 'union': 'Foo', 'base': 'Base', 'discriminator': 'switch', 'data': { 'a': 'Type1', 'b': 'Type2' } } { 'command': 'bar', 'data': 'Foo' } Wire: { "execute": "bar", "arguments": { "switch": "a", "value": 1 } } happen to guarantee a top-level dictionary (plain unions always have a two-element dictionary, flat unions are required to have a base type which is itself a dictionary). But an anonymous union is explicitly allowing a multi-type variable, where the determination of which branch of the union is made by the type of the variable. Furthermore, we do not allow two branches to have the same type, so at least one branch must be a non-dictionary; but as _all_ QMP commands currently take a dictionary for the "arguments" key, we do not want to allow: QAPI: { 'type': 'Type1', 'data': { 'value': 'int' } } { 'union': 'Foo', 'discriminator': {}, 'data': { 'a': 'Type1', 'b': 'int' } } { 'command': 'bar', 'data': 'Foo' } Wire: { "execute": "bar", "arguments": 1 } Tracking all three qapi expressions as union types is making the generator code a bit verbose, especially since the code generation for all three is so distinct. Proposal: I am proposing that we convert to an alternate syntax for what we now term as anonymous unions. It will not have any impact to the wire representation of QMP, only to the qapi code generators. The proposal is simple: instead of using "'union':'Name', 'discriminator':{}", we instead use "'alternate': 'Foo'" when declaring a type as an anonymous union (which, for obvious reasons, I would then update the documentation to call an "alternate" instead of an "anonymous union"). I'll go ahead and propose the patches (I've already done the bulk of the conversion work, to prove that not many files were affected). --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --rt0ULT965W6eUU9w8P1P1v492XQwt5rFB Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJVEDI2AAoJEKeha0olJ0Nqn/QH/2jfU1L5JHSiPQUNUzUJmt+S XPvujq7p7oDQjHdlVPAvT4nKaUfd+k9CpPAKgsDUy1GF2MGwnw4XWhxnB6UTOm4E zE3lXt8oForVe/UKj0o5ramAGcTEgNPpJI1mIRpUQlbFzKEV6/DShXeNobJv2dU7 MRvcmWYJAOhsxmLklH1rgG5qwwFgH9X/+/NzydFfuMSRm/Nr0vPogYbceDMjaqMg BJ7cxMINHMQxqvrt2RgmYnfJglc+Lk6D7txPKLkBeWHPXOSUoov55jUhyNRjBp2h QnaoR/ECh150CaENCBTiXKvfta6OVJbwi2fDc6fQ4c4APUmTYFT6T0h4E66Af1I= =6kiA -----END PGP SIGNATURE----- --rt0ULT965W6eUU9w8P1P1v492XQwt5rFB--