From: Kevin Wolf <kwolf@redhat.com>
To: Markus Armbruster <armbru@redhat.com>
Cc: qemu-devel@nongnu.org, Michael Roth <mdroth@linux.vnet.ibm.com>,
qemu-block@nongnu.org, Max Reitz <mreitz@redhat.com>
Subject: Re: [Qemu-devel] [PATCH v4 03/14] qapi: Introduce default values for struct members
Date: Fri, 22 Nov 2019 17:12:15 +0100 [thread overview]
Message-ID: <20191122161215.GD4433@linux.fritz.box> (raw)
In-Reply-To: <87k17sq8im.fsf@dusky.pond.sub.org>
Am 22.11.2019 um 15:40 hat Markus Armbruster geschrieben:
> Kevin Wolf <kwolf@redhat.com> writes:
>
> > Am 22.11.2019 um 08:29 hat Markus Armbruster geschrieben:
> >> > At any rate, your counterpoint is taken - whatever we pick, we'll want
> >> > to make sure that introspection can expose semantics, and whether we
> >> > can make '*' redundant with some other form of longhand in the qapi
> >> > language is in part determined by whether we also reflect that through
> >> > introspection.
> >>
> >> Introspection has the true member name, without the '*' prefix.
> >>
> >> We'll also want to avoid unnecessary compromises on QAPI schema
> >> expressiveness. If we use null to mean "schema does not specify
> >> behavior when member is absent", we can't use it to mean "absent member
> >> behaves like the value null". A bit of a blemish, but I think it's a
> >> tolerable one.
> >
> > If you want an example for an option that defaults to null, take the
> > backing option of BlockdevOptionsGenericCOWFormat.
> >
> > What is the reason for even considering limiting the expressiveness? Do
> > you think that an additional 'optional' bool, at least for those options
> > that don't have a default, would be so bad in the longhand form? Or
> > keeping '*' even in the longhand form, as suggested below.
>
> Well, one reason is this:
>
> ##
> # @SchemaInfoObjectMember:
> #
> # An object member.
> #
> # @name: the member's name, as defined in the QAPI schema.
> #
> # @type: the name of the member's type.
> #
> # @default: default when used as command parameter.
> # If absent, the parameter is mandatory.
> # If present, the value must be null. The parameter is
> # optional, and behavior when it's missing is not specified
> # here.
> # Future extension: if present and non-null, the parameter
> # is optional, and defaults to this value.
> #
> # Since: 2.5
> ##
>
> If we want to be able to express the difference between "behavior when
> absent is not specified here" and "absent behaves like value null", then
> we need to somehow add that bit of information here.
>
> Could use a feature. Features are not yet implemented for members, but
> we need them anyway.
That definition wasn't a great idea, I'm afraid. :-(
But "default is QNull" is still acceptable behaviour for "not
specified" if the client doesn't need to know what the default is.
> >> > If that means that keeping '*' in the longhand form of
> >> > optional members (whether or not those members have a default value),
> >> > then so be it.
> >>
> >> I believe both
> >>
> >> '*KEY': { 'type': ARG': 'default': null }
> >>
> >> and
> >>
> >> 'KEY': { 'type': ARG': 'default': null }
> >>
> >> are viable longhand forms for '*KEY': 'ARG'.
> >>
> >> I prefer the latter, but I'm open to arguments.
> >
> > If you go for the former, then you certainly want to use absent
> > 'default' to indicate no default, and allow a QNull default with
> > 'default': null.
> >
> > The only reason to abuse 'default': null for no default is that you
> > can't distinguish optional and non-optional if you use 'KEY' for both
> > instead of 'KEY' for mandatory and '*KEY' for optional.
> >
> > So while I understand and to some degree share your dislike for the '*'
> > prefix, I think I cast my pragmatic vote for:
> >
> > mandatory: 'KEY': { 'type': 'ARG' }
> > optional without a default: '*KEY': { 'type': 'ARG' }
> > optional with QNull default: '*KEY': { 'type': 'ARG', 'default': null }
>
> The last one could also be 'KEY': { 'type': 'ARG', 'default': null }
> without loss of expressiveness.
>
> Differently ugly.
Not loss of expressiveness, but loss of consistency.
> Here's yet another idea. For the "absent is not specified here" case,
> use
>
> 'KEY': { 'type': 'ARG', optional: true }
> '*KEY': 'ARG'
>
> For the "absent defaults to DEFVAL" case, use
>
> 'KEY': { 'type': 'ARG', optional: true, 'default': DEFVAL }
> 'KEY': { 'type': 'ARG', 'default': DEFVAL }
I assume this means: 'optional' defaults to true if 'default' is
present, and to false if 'default' is absent. (It's an example of a
default that can't be expressed in the schema.)
Works for me.
Kevin
next prev parent reply other threads:[~2019-11-22 16:14 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-06-24 17:39 [Qemu-devel] [PATCH v4 00/14] block: Try to create well-typed json:{} filenames Max Reitz
2019-06-24 17:39 ` [Qemu-devel] [PATCH v4 01/14] qapi: Parse numeric values Max Reitz
2019-11-14 9:15 ` Markus Armbruster
2019-11-14 9:50 ` Max Reitz
2019-11-14 12:01 ` Markus Armbruster
2019-06-24 17:39 ` [Qemu-devel] [PATCH v4 02/14] qapi: Move to_c_string() to common.py Max Reitz
2019-11-14 9:20 ` Markus Armbruster
2019-11-14 9:58 ` Max Reitz
2019-06-24 17:39 ` [Qemu-devel] [PATCH v4 03/14] qapi: Introduce default values for struct members Max Reitz
2019-11-14 15:53 ` Markus Armbruster
2019-11-21 15:07 ` Markus Armbruster
2019-11-21 15:24 ` Eric Blake
2019-11-21 19:46 ` Markus Armbruster
2019-11-21 19:56 ` Eric Blake
2019-11-22 7:29 ` Markus Armbruster
2019-11-22 10:25 ` Kevin Wolf
2019-11-22 14:40 ` Markus Armbruster
2019-11-22 16:12 ` Kevin Wolf [this message]
2019-06-24 17:39 ` [Qemu-devel] [PATCH v4 04/14] qapi: Allow optional discriminators Max Reitz
2019-11-21 15:13 ` Markus Armbruster
2019-06-24 17:39 ` [Qemu-devel] [PATCH v4 05/14] qapi: Document default values for struct members Max Reitz
2019-06-24 17:39 ` [Qemu-devel] [PATCH v4 06/14] test-qapi: Print struct members' default values Max Reitz
2019-06-24 17:39 ` [Qemu-devel] [PATCH v4 07/14] tests: Test QAPI default values for struct members Max Reitz
2019-06-24 17:39 ` [Qemu-devel] [PATCH v4 08/14] tests: Add QAPI optional discriminator tests Max Reitz
2019-06-24 17:39 ` [Qemu-devel] [PATCH v4 09/14] qapi: Formalize qcow2 encryption probing Max Reitz
2019-06-24 17:39 ` [Qemu-devel] [PATCH v4 10/14] qapi: Formalize qcow " Max Reitz
2019-06-24 17:39 ` [Qemu-devel] [PATCH v4 11/14] block: Try to create well typed json:{} filenames Max Reitz
2019-06-24 20:06 ` Max Reitz
2019-06-24 17:39 ` [Qemu-devel] [PATCH v4 12/14] iotests: Test internal option typing Max Reitz
2019-06-24 17:39 ` [Qemu-devel] [PATCH v4 13/14] iotests: qcow2's encrypt.format is now optional Max Reitz
2019-06-24 17:39 ` [Qemu-devel] [PATCH v4 14/14] block: Make use of QAPI defaults Max Reitz
2019-06-24 18:35 ` [Qemu-devel] [PATCH v4 00/14] block: Try to create well-typed json:{} filenames no-reply
2019-06-24 19:04 ` Max Reitz
2019-06-24 19:06 ` Max Reitz
2019-06-24 19:00 ` no-reply
2019-06-24 20:06 ` Max Reitz
2019-08-19 16:49 ` Max Reitz
2019-09-13 11:49 ` Max Reitz
2019-11-06 13:01 ` Max Reitz
2019-11-14 8:54 ` Markus Armbruster
2019-11-21 15:17 ` Markus Armbruster
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=20191122161215.GD4433@linux.fritz.box \
--to=kwolf@redhat.com \
--cc=armbru@redhat.com \
--cc=mdroth@linux.vnet.ibm.com \
--cc=mreitz@redhat.com \
--cc=qemu-block@nongnu.org \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).