From: Markus Armbruster <armbru@redhat.com>
To: John Snow <jsnow@redhat.com>
Cc: qemu-devel@nongnu.org, "Zhao Liu" <zhao1.liu@intel.com>,
"Peter Xu" <peterx@redhat.com>,
"Philippe Mathieu-Daudé" <philmd@mailo.com>,
"Philippe Mathieu-Daudé" <philmd@oss.qualcomm.com>,
"Jonathan Cameron" <jic23@kernel.org>,
"Eric Blake" <eblake@redhat.com>,
"Fabiano Rosas" <farosas@suse.de>,
"Kevin Wolf" <kwolf@redhat.com>,
"Michael Roth" <michael.roth@amd.com>,
linux-cxl@vger.kernel.org, qemu-block@nongnu.org,
"Junjie Cao" <junjie.cao@intel.com>,
"Lukas Straub" <lukasstraub2@web.de>,
"Hanna Reitz" <hreitz@redhat.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Jason Wang" <jasowangio@gmail.com>
Subject: Re: [PATCH v4 5/7] qapi/parser: fix intermediate "intro" detection
Date: Thu, 17 Sep 2026 20:49:02 +0200 [thread overview]
Message-ID: <87pkybr9wh.fsf@pond.sub.org> (raw)
In-Reply-To: <CAFn=p-YAVahwz2-MmWkwO10RxrDaJDKNp_2-eqEAyzjqbneW3g@mail.gmail.com> (John Snow's message of "Thu, 17 Sep 2026 13:57:28 -0400")
John Snow <jsnow@redhat.com> writes:
> On Thu, Sep 17, 2026 at 1:13 AM Markus Armbruster <armbru@redhat.com> wrote:
>>
>> John Snow <jsnow@redhat.com> writes:
>>
>> > In 43e7ad1a3fa5, I adjusted the insertion algorithm for inserting
>> > something after the "introduction" to cope with both the old and new
>> > syntax while we converted QAPI to the new syntax. There's a bug in
>> > that code that only shows up in a handful of cases and only when using
>> > the new syntax while this affordance/flex code is still enabled.
>> >
>> > In the case that we do actually have a real bona-fide intro section,
>> > we want to insert directly after that real-deal intro section, not
>> > after any plaintext sections that may follow it. This code adjusts the
>> > temporary code to strongly prefer inserting after the actual intro
>> > section if it exists.
>> >
>> > Once again: once conversion is done, you will be delighted by how much
>> > of this ugly code goes away.
>> >
>> > Signed-off-by: John Snow <jsnow@redhat.com>
>> > ---
>> > scripts/qapi/parser.py | 8 ++++++++
>> > 1 file changed, 8 insertions(+)
>> >
>> > diff --git a/scripts/qapi/parser.py b/scripts/qapi/parser.py
>> > index 9e14c2f7921..6a9a5589c14 100644
>> > --- a/scripts/qapi/parser.py
>> > +++ b/scripts/qapi/parser.py
>> > @@ -845,6 +845,14 @@ def _insert_after_intro(
>> > needed and ``_insert_near_kind(QAPIDoc.Kind.INTRO, ...)`` will
>> > be sufficient.
>> > """
>> > + first = self.all_sections[0]
>> > + if first.text and first.kind == QAPIDoc.Kind.INTRO:
>> > + # First section is introduction and is non-empty: insert here.
>> > + # Rest assured all of this ugliness will very soon go away.
>> > + # Pinkie-swear.
>> > + self._insert_near_kind(QAPIDoc.Kind.INTRO, section, after=True)
>>
>> Isn't this a roundabout way to do
>>
>> self.all_sections.insert(1, section)
>>
>> ?
>
> Yes O:-)
>
> ... but it's the more semantically abstracted version that does not
> rely on the specific location of the section. By the end of the
> next-next series, all of this goes away anyway. I think I was
> preferring to avoid using insert in more than the two helpers we
> already use it in. (But since I intend to delete it all, I don't
> really care about fighting for purity in isolating this call.)
>
> Specifically:
>
> _insert_near_kind(), _insert_after_intro() both go away.
> append_member_stub() also goes away. ensure_returns() stays but
> becomes something like two lines.
>
> *all* section modification in the next-next series happens exclusively
> through a method named `_append()` which Does The Right Thing In All
> Cases.
>
> --js
What caught my eye was the dissonance between self._insert_near_kind()
above and self.all_sections.insert() below.
Then I looked at ._insert_near_kind(). It inserts before or after the
last section of a certain kind. Here, it inserts after the last INTRO.
Since we always have exactly INTRO, and it always comes first, it
inserts after the first section. Just what the comment says. Good.
But why not just do what the comment says in the most straightforward
way possible? Am I missing something? Thus my question.
>>
>> > + return
>> > +
>> > index = 0
>> > for index, ref_section in enumerate(self.all_sections):
>> > if ref_section.kind.name in ("PLAIN", "INTRO"):
>> continue
>> break
>> else:
>> index += 1
>>
>> self.all_sections.insert(index, section)
>>
next prev parent reply other threads:[~2026-09-17 18:49 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-16 13:58 [PATCH v4 0/7] qapi: convert remaining "simple" intro sections John Snow
2026-09-16 13:58 ` [PATCH v4 1/7] qapi: convert remaining simple intros for block-export.json John Snow
2026-09-16 13:58 ` [PATCH v4 2/7] qapi: convert remaining simple intros for cxl.json John Snow
2026-09-16 13:58 ` [PATCH v4 3/7] qapi: convert remaining simple intros for machine.json John Snow
2026-09-16 13:58 ` [PATCH v4 4/7] qapi: convert remaining simple intros for block-core.json John Snow
2026-09-16 13:58 ` [PATCH v4 5/7] qapi/parser: fix intermediate "intro" detection John Snow
2026-09-17 5:12 ` Markus Armbruster
2026-09-17 17:57 ` John Snow
2026-09-17 18:49 ` Markus Armbruster [this message]
2026-09-16 13:58 ` [PATCH v4 6/7] qapi: convert intro sections with "TODO" markers John Snow
2026-09-16 13:58 ` [PATCH v4 7/7] qapi: convert intro sections followed by notes/examples John Snow
2026-09-16 18:12 ` Markus Armbruster
2026-09-17 17:50 ` John Snow
2026-09-17 18:51 ` 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=87pkybr9wh.fsf@pond.sub.org \
--to=armbru@redhat.com \
--cc=eblake@redhat.com \
--cc=farosas@suse.de \
--cc=hreitz@redhat.com \
--cc=jasowangio@gmail.com \
--cc=jic23@kernel.org \
--cc=jsnow@redhat.com \
--cc=junjie.cao@intel.com \
--cc=kwolf@redhat.com \
--cc=linux-cxl@vger.kernel.org \
--cc=lukasstraub2@web.de \
--cc=michael.roth@amd.com \
--cc=pbonzini@redhat.com \
--cc=peterx@redhat.com \
--cc=philmd@mailo.com \
--cc=philmd@oss.qualcomm.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=zhao1.liu@intel.com \
/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