From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34184) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z5tit-0008D6-P0 for qemu-devel@nongnu.org; Fri, 19 Jun 2015 06:40:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Z5tio-0005gU-PV for qemu-devel@nongnu.org; Fri, 19 Jun 2015 06:40:35 -0400 Received: from mail-wi0-x232.google.com ([2a00:1450:400c:c05::232]:37322) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z5tio-0005fY-Ik for qemu-devel@nongnu.org; Fri, 19 Jun 2015 06:40:30 -0400 Received: by wicgi11 with SMTP id gi11so14654567wic.0 for ; Fri, 19 Jun 2015 03:40:29 -0700 (PDT) Sender: Paolo Bonzini Message-ID: <5583F19B.2010709@redhat.com> Date: Fri, 19 Jun 2015 12:40:27 +0200 From: Paolo Bonzini MIME-Version: 1.0 References: <20150605095004.GB2139@work-vm> <5571965F.7040502@redhat.com> <20150605140043.GD2139@work-vm> <87eglmgyc3.fsf@blackfin.pond.sub.org> <20150608145750.GG2217@work-vm> <87fv61w9vn.fsf_-_@blackfin.pond.sub.org> In-Reply-To: <87fv61w9vn.fsf_-_@blackfin.pond.sub.org> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] qapi: What does "'gen': false" actually do, and when should I use it? List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Markus Armbruster , "Dr. David Alan Gilbert" Cc: amit.shah@redhat.com, qemu-devel@nongnu.org, quintela@redhat.com On 09/06/2015 10:42, Markus Armbruster wrote: > Part 2: When to use it? > > We use 'gen': false when we can't (be bothered to) specify the exact > type of an argument or result. > > Bad example: netdev_add > > We have arguments 'type': 'str' and '*props': '**'. > > We should have a union tagged by network backend type. For each > type, the union holds the type's properties (if any). The problem with this is that netdev_add was not type safe, because it uses qemu_opts_from_qdict and QemuOpts is exclusively string-based. So you could write 'port': '123' or 'port': 123, and both would work, the conversion to integer is done by the QemuOptsVisitor. Note that device_add would have the same problem. Paolo > Better example: device_add (but that's not even QAPIfied, yet) > > If QAPIfied, we'd have arguments like 'driver': 'str' and '*props': > '**'. > > Looks just like netdev_add. The difference is that network backends > and their properties are defined in one place, but device models and > their properties aren't. They get collected at run time. As long > as the schema is fixed at compile-time, it can't express the > resulting tagged union. > > Another good example: qom-get > > We have a return value '**'. > > The run time type is the type of the property identified by the > arguments. Therefore, the compile time type can only be the union > of all property types, which effectively boils down to "anything". > > The only way to say "anything" right now is '**'. Requires 'gen': > false. I figure we could extend the generators to support '**' in a > few places, which may let us avoid 'gen': false here. > > Drawback of '**': introspection knows nothing. > > Introspection knowing nothing about netdev_add's and device_add's > acceptable properties is a big, painful gap. > > Please don't invent new reasons for 'gen': false without a very > compelling use case. If you think you have one, we need to talk to make > sure use of 'gen': false really beats the alternatives. Alternatives > may include extending the generators. > >