qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: Markus Armbruster <armbru@redhat.com>, qemu-devel@nongnu.org
Cc: marcandre.lureau@redhat.com, mdroth@linux.vnet.ibm.com
Subject: Re: [PATCH 16/25] qapi: Move context-sensitive checking to the proper place
Date: Tue, 24 Sep 2019 12:49:34 -0500	[thread overview]
Message-ID: <15b817d6-afa5-53c0-1fdd-2af4ad2a0bd8@redhat.com> (raw)
In-Reply-To: <20190924132830.15835-17-armbru@redhat.com>


[-- Attachment #1.1: Type: text/plain, Size: 5025 bytes --]

On 9/24/19 8:28 AM, Markus Armbruster wrote:
> When we introduced the QAPISchema intermediate representation (commit
> ac88219a6c7), we took a shortcut: we left check_exprs() & friends
> alone instead of moving semantic checks into the
> QAPISchemaFOO.check().  The .check() assert check_exprs() did its job.
> 
> Time to finish the conversion job.  Move exactly the context-sensitive
> checks to the .check().  They replace assertions there.  Context-free
> checks stay put.
> 
> Fixes the misleading optional tag error demonstrated by test
> flat-union-optional-discriminator.
> 
> A few other error message improve.
> 
> Signed-off-by: Markus Armbruster <armbru@redhat.com>
> ---

> diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py
> index f5599559ac..ac4c898e51 100644
> --- a/scripts/qapi/common.py

Thankfully, our large coverage of tests goes a long way to show that the
conversion is correct.  I didn't notice anything obvious that might have
been overlooked (we may still find things down the road, but I'm not
going to hold up this patch trying to find those things).  Meanwhile,
the conversion from assert to conditionals inside .check() looks complete.


> +++ b/tests/qapi-schema/args-union.err
> @@ -1,2 +1,2 @@
>  tests/qapi-schema/args-union.json: In command 'oops':
> -tests/qapi-schema/args-union.json:3: 'data' for command 'oops' cannot use union type 'Uni'
> +tests/qapi-schema/args-union.json:3: command's 'data' can take union type 'Uni' only with 'boxed': true

This one is definitely nicer.

> +++ b/tests/qapi-schema/flat-union-discriminator-bad-name.err
> @@ -1,2 +1,2 @@
>  tests/qapi-schema/flat-union-discriminator-bad-name.json: In union 'MyUnion':
> -tests/qapi-schema/flat-union-discriminator-bad-name.json:7: discriminator of flat union 'MyUnion' uses invalid name '*switch'
> +tests/qapi-schema/flat-union-discriminator-bad-name.json:6: discriminator '*switch' is not a member of 'base'
> diff --git a/tests/qapi-schema/flat-union-discriminator-bad-name.json b/tests/qapi-schema/flat-union-discriminator-bad-name.json
> index ea84b75cac..3ae8c06a89 100644
> --- a/tests/qapi-schema/flat-union-discriminator-bad-name.json
> +++ b/tests/qapi-schema/flat-union-discriminator-bad-name.json
> @@ -1,5 +1,4 @@
>  # discriminator '*switch' isn't a member of base, 'switch' is
> -# reports "uses invalid name", which is good enough
>  { 'enum': 'Enum', 'data': [ 'one', 'two' ] }
>  { 'struct': 'Base',
>    'data': { '*switch': 'Enum' } }

I find this one to be borderline in quality (if we have '*switch' in the
base, claiming that '*switch' is not a member of base is confusing until
you realize that base actually has an optional member named 'switch') -
but anyone that actually stumbles into this one will probably quickly
figure out their problem, and we may be revisiting it later anyways when
we finally include patches for a default discriminator.

> +++ b/tests/qapi-schema/flat-union-optional-discriminator.err
> @@ -1,2 +1,2 @@
>  tests/qapi-schema/flat-union-optional-discriminator.json: In union 'MyUnion':
> -tests/qapi-schema/flat-union-optional-discriminator.json:7: discriminator 'switch' is not a member of 'base'
> +tests/qapi-schema/flat-union-optional-discriminator.json:6: discriminator member 'switch' of base type 'Base' must not be optional
> diff --git a/tests/qapi-schema/flat-union-optional-discriminator.json b/tests/qapi-schema/flat-union-optional-discriminator.json
> index 143ab23a0d..2e7f766f60 100644
> --- a/tests/qapi-schema/flat-union-optional-discriminator.json
> +++ b/tests/qapi-schema/flat-union-optional-discriminator.json
> @@ -1,5 +1,4 @@
>  # we require the discriminator to be non-optional
> -# FIXME reports "discriminator 'switch' is not a member of base struct 'Base'"
>  { 'enum': 'Enum', 'data': [ 'one', 'two' ] }
>  { 'struct': 'Base',
>    'data': { '*switch': 'Enum' } }

And while the other one is borderline, I agree that this one is better.

> +++ b/tests/qapi-schema/union-unknown.err
> @@ -1,2 +1,2 @@
>  tests/qapi-schema/union-unknown.json: In union 'Union':
> -tests/qapi-schema/union-unknown.json:2: member 'unknown' of union 'Union' uses unknown type 'MissingType'
> +tests/qapi-schema/union-unknown.json:2: union uses unknown type 'MissingType'
> diff --git a/tests/qapi-schema/union-unknown.json b/tests/qapi-schema/union-unknown.json
> index aa7e8143d8..64d3666176 100644
> --- a/tests/qapi-schema/union-unknown.json
> +++ b/tests/qapi-schema/union-unknown.json
> @@ -1,3 +1,3 @@
>  # we reject a union with unknown type in branch
>  { 'union': 'Union',
> -  'data': { 'unknown': 'MissingType' } }
> +  'data': { 'unknown': ['MissingType'] } }
> 

And here you covered one more code path by going through an array type.

Overall looks good.

Reviewed-by: Eric Blake <eblake@redhat.com>

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

  reply	other threads:[~2019-09-24 17:50 UTC|newest]

Thread overview: 63+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-24 13:28 [PATCH 00/25] qapi: Pay back some frontend technical debt Markus Armbruster
2019-09-24 13:28 ` [PATCH 01/25] qapi: Tighten QAPISchemaFOO.check() assertions Markus Armbruster
2019-09-24 14:39   ` Eric Blake
2019-09-24 20:18     ` Markus Armbruster
2019-09-24 13:28 ` [PATCH 02/25] qapi: Rename .owner to .defined_in Markus Armbruster
2019-09-24 14:41   ` Eric Blake
2019-09-24 13:28 ` [PATCH 03/25] qapi: New QAPISourceInfo, replacing dict Markus Armbruster
2019-09-24 14:51   ` Eric Blake
2019-09-24 20:18     ` Markus Armbruster
2019-09-24 19:12   ` Eric Blake
2019-09-25  6:40     ` Markus Armbruster
2019-09-24 13:28 ` [PATCH 04/25] qapi: Prefix frontend errors with an "in definition" line Markus Armbruster
2019-09-24 14:58   ` Eric Blake
2019-09-24 13:28 ` [PATCH 05/25] qapi: Clean up member name case checking Markus Armbruster
2019-09-24 15:07   ` Eric Blake
2019-09-24 20:20     ` Markus Armbruster
2019-09-24 13:28 ` [PATCH 06/25] qapi: Change frontend error messages to start with lower case Markus Armbruster
2019-09-24 15:17   ` Eric Blake
2019-09-24 20:35     ` Markus Armbruster
2019-09-24 13:28 ` [PATCH 07/25] qapi: Improve reporting of member name clashes Markus Armbruster
2019-09-24 15:38   ` Eric Blake
2019-09-24 13:28 ` [PATCH 08/25] qapi: Reorder check_FOO() parameters for consistency Markus Armbruster
2019-09-24 15:41   ` Eric Blake
2019-09-24 13:28 ` [PATCH 09/25] qapi: Improve reporting of invalid name errors Markus Armbruster
2019-09-24 15:48   ` Eric Blake
2019-09-24 13:28 ` [PATCH 10/25] qapi: Use check_name_str() where it suffices Markus Armbruster
2019-09-24 15:50   ` Eric Blake
2019-09-24 13:28 ` [PATCH 11/25] qapi: Report invalid '*' prefix like any other invalid name Markus Armbruster
2019-09-24 15:52   ` Eric Blake
2019-09-24 13:28 ` [PATCH 12/25] qapi: Move check for reserved names out of add_name() Markus Armbruster
2019-09-24 15:56   ` Eric Blake
2019-09-24 13:28 ` [PATCH 13/25] qapi: Make check_type()'s array case a bit more obvious Markus Armbruster
2019-09-24 15:57   ` Eric Blake
2019-09-24 13:28 ` [PATCH 14/25] qapi: Plumb info to the QAPISchemaMember Markus Armbruster
2019-09-24 16:01   ` Eric Blake
2019-09-24 13:28 ` [PATCH 15/25] qapi: Inline check_name() into check_union() Markus Armbruster
2019-09-24 16:39   ` Eric Blake
2019-09-24 13:28 ` [PATCH 16/25] qapi: Move context-sensitive checking to the proper place Markus Armbruster
2019-09-24 17:49   ` Eric Blake [this message]
2019-09-24 20:41     ` Markus Armbruster
2019-09-24 13:28 ` [PATCH 17/25] qapi: Move context-free " Markus Armbruster
2019-09-24 17:59   ` Eric Blake
2019-09-24 13:28 ` [PATCH 18/25] qapi: Improve reporting of invalid 'if' errors Markus Armbruster
2019-09-24 18:01   ` Eric Blake
2019-09-24 13:28 ` [PATCH 19/25] qapi: Improve reporting of invalid flags Markus Armbruster
2019-09-24 18:07   ` Eric Blake
2019-09-24 20:43     ` Markus Armbruster
2019-09-25  6:13       ` Markus Armbruster
2019-09-24 13:28 ` [PATCH 20/25] qapi: Improve reporting of missing / unknown definition keys Markus Armbruster
2019-09-24 18:13   ` Eric Blake
2019-09-24 20:46     ` Markus Armbruster
2019-09-24 13:28 ` [PATCH 21/25] qapi: Avoid redundant definition references in error messages Markus Armbruster
2019-09-24 18:46   ` Eric Blake
2019-09-24 20:59     ` Markus Armbruster
2019-09-24 13:28 ` [PATCH 22/25] qapi: Eliminate check_keys(), rename check_known_keys() Markus Armbruster
2019-09-24 18:49   ` Eric Blake
2019-09-24 13:28 ` [PATCH 23/25] qapi: Improve reporting of missing documentation comment Markus Armbruster
2019-09-24 19:44   ` Eric Blake
2019-09-24 13:28 ` [PATCH 24/25] qapi: Improve reporting of redefinition Markus Armbruster
2019-09-24 19:53   ` Eric Blake
2019-09-24 13:28 ` [PATCH 25/25] qapi: Improve source file read error handling Markus Armbruster
2019-09-24 19:57   ` Eric Blake
2019-09-24 20:59     ` 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=15b817d6-afa5-53c0-1fdd-2af4ad2a0bd8@redhat.com \
    --to=eblake@redhat.com \
    --cc=armbru@redhat.com \
    --cc=marcandre.lureau@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 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).