From: Markus Armbruster <armbru@redhat.com>
To: Max Reitz <mreitz@redhat.com>
Cc: qemu-block@nongnu.org, Kevin Wolf <kwolf@redhat.com>,
qemu-devel@nongnu.org, Michael Roth <mdroth@linux.vnet.ibm.com>,
Markus Armbruster <armbru@redhat.com>
Subject: Re: [Qemu-devel] [PATCH v2 01/10] qapi: Add default-variant for flat unions
Date: Tue, 12 Jun 2018 17:25:14 +0200 [thread overview]
Message-ID: <87efhct4bp.fsf@dusky.pond.sub.org> (raw)
In-Reply-To: <20180611205203.2624-2-mreitz@redhat.com> (Max Reitz's message of "Mon, 11 Jun 2018 22:51:54 +0200")
Max Reitz <mreitz@redhat.com> writes:
> This patch allows specifying a discriminator that is an optional member
> of the base struct. In such a case, a default value must be provided
> that is used when no value is given.
Hmm. Can you explain why you need this feature?
> Signed-off-by: Max Reitz <mreitz@redhat.com>
> ---
> qapi/introspect.json | 8 +++++
> scripts/qapi/common.py | 57 ++++++++++++++++++++++++++++------
> scripts/qapi/doc.py | 8 +++--
> scripts/qapi/introspect.py | 10 ++++--
> scripts/qapi/visit.py | 13 ++++++++
> tests/qapi-schema/test-qapi.py | 2 ++
> 6 files changed, 83 insertions(+), 15 deletions(-)
The documentation update is in the next patch, and tests are in the
patch after next. I'd squash all three.
>
> diff --git a/qapi/introspect.json b/qapi/introspect.json
> index 80a0a3e656..b43c87fe8d 100644
> --- a/qapi/introspect.json
> +++ b/qapi/introspect.json
> @@ -168,6 +168,13 @@
> # @tag: the name of the member serving as type tag.
> # An element of @members with this name must exist.
> #
> +# @default-variant: if the @tag element of @members is optional, this
> +# is the default value for choosing a variant. Its
> +# value will be a valid value for @tag.
> +# Present exactly when @tag is present and the
> +# associated element of @members is optional.
> +# (Since: 3.0)
> +#
> # @variants: variant members, i.e. additional members that
> # depend on the type tag's value. Present exactly when
> # @tag is present. The variants are in no particular order,
> @@ -181,6 +188,7 @@
> { 'struct': 'SchemaInfoObject',
> 'data': { 'members': [ 'SchemaInfoObjectMember' ],
> '*tag': 'str',
> + '*default-variant': 'str',
> '*variants': [ 'SchemaInfoObjectVariant' ] } }
>
> ##
Until now, the QAPI schema doesn't let you specify default values.
Instead, code sees "absent", and does whatever needs to be done.
Sometimes, it supplies a default value. "Absent" is shorthand for this
value then. Sometimes, it behaves differently than for any value.
"Absent" is a distinct additional case then. I'm not too fond of the
latter case, but it's what we have, and it's not going away.
We've discussed extending the QAPI schema to let you specify default
values. Two advantages: the default value is *specified* rather than
just documented (or not, when documentation sucks), and we can supply
the default value in generated code. The introspection schema is even
prepared for 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
##
The idea was to turn
'*name': 'type'
into sugar for
'name': { 'type': 'type', 'optional': true }
then extend it to
'name': { 'type': 'type', 'optional': true, 'default': JSON-VALUE }
where JSON-VALUE null means behavior for "absent" is not specified.
Your patch adds default values in a different way, and for just for
union tags. For the QAPI language, that's not necessarily a deal
breaker, as we don't need to maintain backward compatibility there. But
for the introspection schema, we do. Once we add @default-variant,
we're stuck with it. Even though it's redundant with
SchemaInfoObjectMember's @default.
I'm skipping review of the implementation for now.
next prev parent reply other threads:[~2018-06-12 15:25 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-11 20:51 [Qemu-devel] [PATCH v2 00/10] block: Try to create well typed json:{} filenames Max Reitz
2018-06-11 20:51 ` [Qemu-devel] [PATCH v2 01/10] qapi: Add default-variant for flat unions Max Reitz
2018-06-12 15:25 ` Markus Armbruster [this message]
2018-06-13 14:05 ` Max Reitz
2018-06-11 20:51 ` [Qemu-devel] [PATCH v2 02/10] docs/qapi: Document optional discriminators Max Reitz
2018-06-11 20:51 ` [Qemu-devel] [PATCH v2 03/10] tests: Add QAPI optional discriminator tests Max Reitz
2018-06-11 20:51 ` [Qemu-devel] [PATCH v2 04/10] qapi: Formalize qcow2 encryption probing Max Reitz
2018-06-11 21:02 ` Eric Blake
2018-06-11 21:05 ` Max Reitz
2018-06-12 8:06 ` Daniel P. Berrangé
2018-06-11 20:51 ` [Qemu-devel] [PATCH v2 05/10] qapi: Formalize qcow " Max Reitz
2018-06-11 21:02 ` Eric Blake
2018-06-12 8:06 ` Daniel P. Berrangé
2018-06-11 20:51 ` [Qemu-devel] [PATCH v2 06/10] qdict: Make qdict_flatten() shallow-clone-friendly Max Reitz
2018-06-12 13:34 ` Markus Armbruster
2018-06-11 20:52 ` [Qemu-devel] [PATCH v2 07/10] tests: Add QDict clone-flatten test Max Reitz
2018-06-12 13:35 ` Markus Armbruster
2018-06-11 20:52 ` [Qemu-devel] [PATCH v2 08/10] block: Try to create well typed json:{} filenames Max Reitz
2018-06-11 20:52 ` [Qemu-devel] [PATCH v2 09/10] iotests: Test internal option typing Max Reitz
2018-06-11 20:52 ` [Qemu-devel] [PATCH v2 10/10] iotests: qcow2's encrypt.format is now optional Max Reitz
2018-06-12 8:07 ` Daniel P. Berrangé
2018-06-19 6:05 ` [Qemu-devel] [PATCH v2 00/10] block: Try to create well typed json:{} filenames 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=87efhct4bp.fsf@dusky.pond.sub.org \
--to=armbru@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.