From: Markus Armbruster <armbru@redhat.com>
To: Eric Blake <eblake@redhat.com>
Cc: Kevin Wolf <kwolf@redhat.com>,
Michael Roth <mdroth@linux.vnet.ibm.com>,
qemu-devel@nongnu.org, 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: Thu, 21 Nov 2019 20:46:59 +0100 [thread overview]
Message-ID: <871ru1811o.fsf@dusky.pond.sub.org> (raw)
In-Reply-To: <0214e73e-062e-a9c8-16c9-e99354c07277@redhat.com> (Eric Blake's message of "Thu, 21 Nov 2019 09:24:44 -0600")
Eric Blake <eblake@redhat.com> writes:
> On 11/21/19 9:07 AM, Markus Armbruster wrote:
>> Max Reitz <mreitz@redhat.com> writes:
>>
>>> With this change, it is possible to give default values for struct
>>> members, as follows:
>>>
>>> What you had to do so far:
>>>
>>> # @member: Some description, defaults to 42.
>>> { 'struct': 'Foo',
>>> 'data': { '*member': 'int' } }
>>>
>>> What you can do now:
>>>
>>> { 'struct': 'Foo',
>>> 'data': { '*member': { 'type': 'int', 'default': 42 } }
>>
>> The '*' is redundant in this form.
>>
>> Can anyone think of reasons for keeping it anyway? Against?
>
> Is there ever a reason to allow an optional member but without a
> 'default' value? Or can we just blindly state that if 'default' is
> not present, that is the same as 'default':0/'default':null?
>
> Or, applying your statement further,
>
> 'data': { '*a':'int', '*b':'str' }
>
> is shorthand for:
>
> 'data': { 'a': { 'type':'int', 'default':0 },
> 'b': { 'type':'str', 'default':null } }
You propose to default 'default' to a type-specific value.
I don't think that's a good idea.
Quoting myself on v3:
In many programming languages, absent optional arguments / members
default to a default value specified in the declaration. Simple.
In others, 'absent' is effectively an additional value. The code
consuming the argument / member can interpret 'absent' however it wants.
It may eliminate the additional value by mapping it to a default value,
but it can also interpret 'absent' unlike any value. If there's more
than one consumer, their interpretations need not be consistent. The
declaration provides no clue on semantics of 'absent'.
QAPI is in the latter camp. I trust you can already sense how much I
like that.
[...]
If I could go back in time, I'd flip QAPI to "'absent' defaults to a
default value". Lacking a time machine, we're stuck with cases of
"'absent' means something you can't express with a value" and "'absent'
means different things in different contexts" that have been enshrined
in external interfaces. Is there anything we could do to improve
matters for saner cases?
I think there is: we could provide for an *optional* default value. If
the schema specifies it, that's what 'absent' means. If it doesn't, all
bets are off, just like they are now.
This patch implements this idea.
When an absent member behaves just like it was present with a certain
value DFLT, we want to be able to say in the schema 'default': DFLT.
But the schema language also needs to let us say "absent member behaves
unlike any value".
If we define 'default' to default to a value, then that value must have
this special meaning.
Where that value is also a valid value, the schema language cannot
express "absent member behaves like it was present with that value".
I think this makes 0 a poor default value for 'default': "behaves like
member was present with value 0" is fairly common, I think.
Defaulting 'default' to null regardless of member type could work.
null is a valid value of the 'null' type and of alternate types with a
member of type 'null'. For optional members of such types, the schema
language then can't express ""absent member behaves like it was present
with value null". I think the need to say that is much less common than
the needs to say "like value 0".
Checking... *sigh*: there are a few optional members that can take null
values, e.g. MigrateSetParameters member @tls-creds. I read its doc
comment twice, and I have to admit I can't make heads or tails of it.
Can't say for sure whether absent behaves like null, or some other
value, or unlike any value.
QAPI/QMP introspection already specifies null to have exactly this
special meaning.
> So I could live with permitting '*' only in the shorthand form, and
> declaring that it is incompatible with longhand form because the
> existence of a 'default' key in longhand form is evidence that the
> member is therefore optional.
Noted.
More opinions?
next prev parent reply other threads:[~2019-11-21 19:49 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 [this message]
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
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=871ru1811o.fsf@dusky.pond.sub.org \
--to=armbru@redhat.com \
--cc=eblake@redhat.com \
--cc=kwolf@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 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.