qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: Markus Armbruster <armbru@redhat.com>
Cc: marcandre.lureau@redhat.com, qemu-devel@nongnu.org,
	ehabkost@redhat.com, Michael Roth <mdroth@linux.vnet.ibm.com>
Subject: Re: [Qemu-devel] [PATCH v6 06/12] qapi: Track owner of each object member
Date: Fri, 2 Oct 2015 08:48:07 -0600	[thread overview]
Message-ID: <560E9927.5060102@redhat.com> (raw)
In-Reply-To: <871tddfvjx.fsf@blackfin.pond.sub.org>

[-- Attachment #1: Type: text/plain, Size: 4934 bytes --]

On 10/02/2015 03:50 AM, Markus Armbruster wrote:
> Eric Blake <eblake@redhat.com> writes:
> 
>> Future commits will migrate semantic checking away from parsing
>> and over to the various QAPISchema*.check() methods.  But to
>> report an error message about an incorrect semantic use of a
>> member of an object type, we need to know which type, command,
>> or event owns the member.  Rather than making all the check()
>> methods have to pass around additional information, it is easier
>> to have each member track who owns it in the first place.
>>
>> The source information is intended for human consumption in
>> error messages, and a new describe() method is added to access
>> the resulting information.  For example, given the qapi:
>>  { 'command': 'foo', 'data': { 'string': 'str' } }
>> an implementation of visit_command() that calls
>>  arg_type.members[0].describe()
>> will see "'string' (member of foo arguments)".
> 
> Peeking ahead a bit, I see two describe(), one for ordinary members
> returning
> 
>     "'%s' (member of %s)" % (self.name, self._owner)
> 
> and one for variant members returning
> 
>     "'%s' (branch of %s)" % (self.name, self._owner)
> 
> The name _owner makes me expect it's the owning types name, but that's
> not always the case, as we shall see.  How is it related to info and to
> the owning type's name then?
> 
> In your example (implicit arguments type):
> 
>     arg_type.members[0]._owner is 'foo arguments'.
> 
>     arg_type.members[0] has no info.

Well, none of the members have info - they are not subclassed from
QAPISchemaEntity.

> 
>     arg_type.name is ':obj-foo-arg'
> 
>     arg_type.info is something like
> 
>         info {'line': 10, 'parent': None, 'file': 'example-schema.json'}
> 
>     pointing to the definition of command 'foo'.  It's actually the
>     command's info, inherited by its implicit argument type.
> 
> Here, _owner is merely a variation of the owning type's name geared for
> human readers.

Oh, I think I see where you are going with this - why is 'owner' a
string, rather than the actual QAPISchemaType python object?  And is it
worth following the pattern used in other classes, where __init__ gets a
string naming the type, and then check() resolves that name to the
actual type?  At which point, we could do member.owner.info to access
the info of the type that owns the member?

But there's a chicken-and-egg situation - we don't know what the type
will be named until we call _make_implicit_object_type(), but that
function requires that we have already pre-constructed the
QAPISchemaObjectTypeMembers array (which means we can't pre-construct
the members with the type name embedded).

We'd have to refactor things to generate the type name, then construct
the members, then construct the type (doable, but probably involves
splitting this patch for ease of review).

> 
> Example of explicit arguments type:
> 
>     { 'struct': 'BarArgs', 'data': { 'string': 'str' } }
>     { 'command': 'bar', 'data': 'BarArgs' }
> 
> Here, we get:
> 
>     arg_type.members[0]._owner is 'BarArgs'.
> 
>     arg_type.members[0] has no info.

Again, because NO members have info.

> 
>     arg_type.name is 'BarArgs'
> 
>     arg_type.info is something like
> 
>         info {'line': 12, 'parent': None, 'file': 'example-schema.json'}
> 
>     pointing to the definition of command 'bar.  Again, it's the
>     command's info, inherited by its implicit argument type.
> 
> Here, _owner *is* the owning type's name.
> 
> So, _owner is a more readable name we make up when the other name for
> the same thing isn't readable.  However, we make up that other name,
> too!  Begs the question why we don't simply make it readable right away.
> 
> Naturally, we still need to make up names collision-free.  But as far as
> I can tell, nothing stops us from picking ':obj-foo arguments' instead
> of ':obj-foo-arg', and when we talk to users strip off the common prefix
> ':obj-' we prepend to avoid collisions.

Might be doable, but then we'd have to generate the implicit object name
prior to creating its Member objects (thus splitting
_make_implicit_object_type() into two parts).

> 
>> Where implicit types are involved, the code intentionally tries
>> to pick the name of the owner of that implicit type, rather than
>> the type name itself (a user reading the error message should be
>> able to grep for the problem in their original file, but will not
>> be able to locate a generated implicit name).
>>
>> No change to generated code.
>>
>> Signed-off-by: Eric Blake <eblake@redhat.com>
> 
> Let's discuss the above before I review the actual patch closely.

What do you think - would that refactoring be worth it?

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


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

  reply	other threads:[~2015-10-02 14:48 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-02  4:31 [Qemu-devel] [PATCH v6 00/12] post-introspection cleanups, subset B Eric Blake
2015-10-02  4:31 ` [Qemu-devel] [PATCH v6 01/12] qapi: Use predicate callback to determine visit filtering Eric Blake
2015-10-02  6:47   ` Markus Armbruster
2015-10-02 12:16     ` Eric Blake
2015-10-02  4:31 ` [Qemu-devel] [PATCH v6 02/12] qapi: Don't use info as witness of implicit object type Eric Blake
2015-10-02  7:02   ` Markus Armbruster
2015-10-02 12:54     ` Eric Blake
2015-10-02 14:12       ` Markus Armbruster
2015-10-02 14:33         ` Eric Blake
2015-10-02 16:48           ` Markus Armbruster
2015-10-02 16:57             ` Eric Blake
2015-10-02 22:40               ` Eric Blake
2015-10-06  8:32               ` Markus Armbruster
2015-10-06 11:56                 ` Eric Blake
2015-10-06 13:31                   ` Markus Armbruster
2015-10-02  4:31 ` [Qemu-devel] [PATCH v6 03/12] qapi: Lazy creation of array types Eric Blake
2015-10-02  8:06   ` Markus Armbruster
2015-10-02 13:05     ` Eric Blake
2015-10-06  8:35       ` Markus Armbruster
2015-10-02  4:31 ` [Qemu-devel] [PATCH v6 04/12] qapi: Create simple union type member earlier Eric Blake
2015-10-02  8:34   ` Markus Armbruster
2015-10-02 13:08     ` Eric Blake
2015-10-02  4:31 ` [Qemu-devel] [PATCH v6 05/12] qapi: Track location that created an implicit type Eric Blake
2015-10-02  8:54   ` Markus Armbruster
2015-10-02 14:07     ` Eric Blake
2015-10-02 16:07       ` Markus Armbruster
2015-10-02 16:13         ` Eric Blake
2015-10-02  4:31 ` [Qemu-devel] [PATCH v6 06/12] qapi: Track owner of each object member Eric Blake
2015-10-02  9:50   ` Markus Armbruster
2015-10-02 14:48     ` Eric Blake [this message]
2015-10-02 17:05       ` Markus Armbruster
2015-10-02 22:35         ` Eric Blake
2015-10-02  4:31 ` [Qemu-devel] [PATCH v6 07/12] qapi: Detect collisions in C member names Eric Blake
2015-10-02 13:19   ` Markus Armbruster
2015-10-02 15:12     ` Eric Blake
2015-10-02 17:11       ` Markus Armbruster
2015-10-03  1:01         ` Eric Blake
2015-10-06  8:41           ` Markus Armbruster
2015-10-02  4:31 ` [Qemu-devel] [PATCH v6 08/12] qapi: Defer duplicate member checks to schema check() Eric Blake
2015-10-02 14:00   ` Markus Armbruster
2015-10-02 15:52     ` Eric Blake
2015-10-02  4:31 ` [Qemu-devel] [PATCH v6 09/12] qapi: Defer duplicate enum value " Eric Blake
2015-10-02  4:31 ` [Qemu-devel] [PATCH v6 10/12] qapi: Correct error for union branch 'kind' clash Eric Blake
2015-10-03 17:56   ` Eric Blake
2015-10-02  4:31 ` [Qemu-devel] [PATCH v6 11/12] qapi: Detect base class loops Eric Blake
2015-10-02  4:31 ` [Qemu-devel] [PATCH v6 12/12] RFC: qapi: Hide _info member Eric Blake

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=560E9927.5060102@redhat.com \
    --to=eblake@redhat.com \
    --cc=armbru@redhat.com \
    --cc=ehabkost@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).