Received: from eggs.gnu.org ([2001:4830:134:3::10]:57175) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aVzCx-0007oa-EI for qemu-devel@nongnu.org; Wed, 17 Feb 2016 05:19:44 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aVzCu-00071X-7B for qemu-devel@nongnu.org; Wed, 17 Feb 2016 05:19:43 -0500 Received: from mx1.redhat.com ([209.132.183.28]:48263) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aVzCt-00071T-VS for qemu-devel@nongnu.org; Wed, 17 Feb 2016 05:19:40 -0500 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (Postfix) with ESMTPS id 1CB357EBAE for ; Wed, 17 Feb 2016 10:19:39 +0000 (UTC) From: Markus Armbruster References: <20160216173540.GG11370@redhat.com> <56C36037.5070702@redhat.com> Date: Wed, 17 Feb 2016 11:19:36 +0100 In-Reply-To: <56C36037.5070702@redhat.com> (Eric Blake's message of "Tue, 16 Feb 2016 10:45:27 -0700") Message-ID: <87r3gbiqpz.fsf@blackfin.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] Problem with discriminated unions with enum prefixes List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Eric Blake Cc: qemu-devel@nongnu.org Eric Blake writes: > On 02/16/2016 10:35 AM, Daniel P. Berrange wrote: >> In my LUKS encryption series, I have a discriminated union for >> storing options for different encryption formats. See qapi/crypto.json >> in this file: >>=20 >> https://lists.gnu.org/archive/html/qemu-devel/2016-02/msg03187.html >>=20 >> You'll notice I have the 'prefix' line for the enum commented out. When >> I uncomment this, I discovered that the discriminated union visitor does >> not deal with prefixes. >>=20 > >> Apply that and then try to build and it'll fail with: >>=20 >> qapi-visit.c: In function =E2=80=98visit_type_QDemo=E2=80=99: >> qapi-visit.c:7596:10: error: =E2=80=98Q_DEMO_TYPE_FOO=E2=80=99 undeclare= d (first use in this function) >> case Q_DEMO_TYPE_FOO: >> ^ >> qapi-visit.c:7596:10: note: each undeclared identifier is reported only = once for each function it appears in >> qapi-visit.c:7599:10: error: =E2=80=98Q_DEMO_TYPE_BAR=E2=80=99 undeclare= d (first use in this function) >> case Q_DEMO_TYPE_BAR: >> ^ >>=20 >> The issue is that we used the 'QDEMO_TYPE' custom prefix for generating = the >> enum, but we didn't use the prefix in the union visitor. > > Should be a quick fix, if we want to keep prefixes. I'll go ahead and > post it, at least for discussion purposes. > >>=20 >> I know we had had previous discussions with Markus strongly wanting to k= ill >> off the support for enum prefixes. So before I waste time trying to fix >> this union visitor code to handle prefixes, I figure we should decide if >> we actually want to fix it, or go with Markus' plan to kill custom prefi= xes >> on enums. > > I'm still on the fence which way to go; we've definitely improved the > code base so that inadvertent collisions due to odd heuristics are less > likely to occur, but every special case we have to carry (custom prefix > being one of them) results in more code to maintain and test. Yes. As so many things, QAPI started out relatively simple & stupid, if saddled with a certain amount of accidental complexity due to hasty design and implementation. Then features got bolted on left and right. That's normal; useful software expands to fill available space. We've been working hard on reducing the accidental complexity. I believe we should also try to control the complexity due to features. Features need to earn their keep. >> Per previous discussions, I think the ability to have custom prefixes is >> quite desirable, to get more natural enum constant names. At the end of >> the day though, the default enum naming is far from the worst bit of >> QEMU, so I'm not ultimately too bothered either way. We either make >> custom enum prefixes work everything they need to, or remove them. Keeping an unloved feature half-broken while we deliberate whether to keep it is the worst of all worlds. Since the fix is a one-liner (plus tests), let's just apply it to unblock Dan as soon as possible.