All of lore.kernel.org
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: Anton Nefedov <anton.nefedov@virtuozzo.com>
Cc: Eric Blake <eblake@redhat.com>,
	qemu-devel@nongnu.org, mdroth@linux.vnet.ibm.com
Subject: Re: [Qemu-devel] [PATCH 1/2] qapi: allow flat unions with empty branches
Date: Thu, 17 May 2018 10:05:59 +0200	[thread overview]
Message-ID: <87fu2qogew.fsf@dusky.pond.sub.org> (raw)
In-Reply-To: <419b57a2-157e-b18c-944e-96ecdb391711@virtuozzo.com> (Anton Nefedov's message of "Wed, 16 May 2018 18:05:13 +0300")

Anton Nefedov <anton.nefedov@virtuozzo.com> writes:

> On 15/5/2018 8:40 PM, Markus Armbruster wrote:
>> Eric Blake <eblake@redhat.com> writes:
>>
>>> On 05/15/2018 02:01 AM, Markus Armbruster wrote:
>>>
>>>>>> QAPI language design alternatives:
>>>>>>
>>>>>> 1. Having unions cover all discriminator values explicitly is useful.
>>>
>>>>>> 2. Having unions repeat all the discriminator values explicitly is not
>>>>>> useful.  All we need is replacing the code enforcing that by code
>>>>>> defaulting missing ones to the empty type.
>>>>>>
>>>>>> 3. We can't decide, so we do both (this patch).
>>>>>>
>>>
>>>> I'd prefer a more opinionated design here.
>>>>
>>>> Either we opine making people repeat the tag values is an overall win.
>>>> Then make them repeat them always, don't give them the option to not
>>>> repeat them.  Drop this patch.  To reduce verbosity, we can add a
>>>> suitable way to denote a predefined empty type.
>>>>
>>>> Or we opine it's not.  Then let them not repeat them, don't give them
>>>> the option to make themselves repeat them.  Evolve this patch into one
>>>> that makes flat union variants optional and default to empty.  If we
>>>> later find we still want a way to denote a predefined empty type, we can
>>>> add it then.
>>>>
>>>> My personal opinion is it's not.
>>>
>>> I followed the arguments up to the last sentence, but then I got lost
>>> on whether you meant:
>>>
>>> This patch is not an overall win, so let's drop it and keep status quo
>>> and/or implement a way to write 'branch':{} (option 1 above)
>>>
>>> or
>>>
>>> Forcing repetition is not an overall win, so let's drop that
>>> requirement by using something similar to this patch (option 2 above)
>>> but without adding a 'partial-data' key.
>>
>> Sorry about that.  I meant the latter.
>>
>>> But you've convinced me that option 3 (supporting a compact branch
>>> representation AND supporting missing branches as defaulting to an
>>> empty type) is more of a maintenance burden (any time there is more
>>> than one way to write something, it requires more testing that both
>>> ways continue to work) and thus not worth doing without strong
>>> evidence that we need both ways (which we do not currently have).
>
> I agree that neither option 3 nor this patch are the best way to handle
> this, so it's 1 or 2.
>
> (2) sure brings some prettiness into jsons; I wonder when it might harm;
> e.g. a person adds another block driver: it would be difficult to get
> round BlockdevOptionsFoo, and what can be missed is something
> optional like BlockdevStatsFoo, which is harmless if left empty and
> probably would be made an empty branch anyway. The difference is that
> an empty branch is something one might notice during a review and
> object.

Yes, forcing reviewer attention is the one real advantage of 1. I can
see.  I agree with you that reviewers missing the "main" union (such as
BlockdevOptions) is unlikely.  Missing "secondary" unions is more
plausible.  Let's see how many of unions sharing a tag enumeration type
we have.  A quick hack to introspect.py coughs up:

    Flat union type                  Tag enum type
    --------------------------------------------------------------
    BlockdevCreateOptions            BlockdevDriver
    BlockdevOptions                  BlockdevDriver
    BlockdevQcow2Encryption          BlockdevQcow2EncryptionFormat
    ImageInfoSpecificQCow2Encryption BlockdevQcow2EncryptionFormat
    BlockdevQcowEncryption           BlockdevQcowEncryptionFormat
    CpuInfo                          CpuInfoArch
    GuestPanicInformation            GuestPanicInformationType
    QCryptoBlockCreateOptions        QCryptoBlockFormat
    SchemaInfo                       SchemaMetaType
    SheepdogRedundancy               SheepdogRedundancyType
    SocketAddress                    SocketAddressType
    SshHostKeyCheck                  SshHostKeyCheckMode
    CpuInfoFast                      SysEmuTarget
    UsernetConnection                UsernetType

Two pairs.  We'll live.

> I think I'd vote for 2 (never enforce all-branches coverage) as well.

Eric, what do you think?

One more thought: if we ever get around to provide more convenient flat
union syntax so users don't have to enumerate the variant names twice,
we'll need a way to say "empty branch".  Let's worry about that problem
when we have it.

  reply	other threads:[~2018-05-17  8:06 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-11  9:05 [Qemu-devel] [PATCH 0/2] qapi: allow flat unions with empty branches Anton Nefedov
2018-05-11  9:05 ` [Qemu-devel] [PATCH 1/2] " Anton Nefedov
2018-05-14 18:08   ` Markus Armbruster
2018-05-14 19:34     ` Eric Blake
2018-05-15  7:01       ` Markus Armbruster
2018-05-15 15:20         ` Eric Blake
2018-05-15 17:40           ` Markus Armbruster
2018-05-16 15:05             ` Anton Nefedov
2018-05-17  8:05               ` Markus Armbruster [this message]
2018-05-17 13:21                 ` Eric Blake
2018-05-18  6:45                   ` Markus Armbruster
2018-05-18  8:16                     ` Anton Nefedov
2018-05-11  9:05 ` [Qemu-devel] [PATCH 2/2] qapi: avoid empty CpuInfoOther type Anton Nefedov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87fu2qogew.fsf@dusky.pond.sub.org \
    --to=armbru@redhat.com \
    --cc=anton.nefedov@virtuozzo.com \
    --cc=eblake@redhat.com \
    --cc=mdroth@linux.vnet.ibm.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.