From: Markus Armbruster <armbru@redhat.com>
To: John Snow <jsnow@redhat.com>
Cc: qemu-devel@nongnu.org, "Michael Roth" <michael.roth@amd.com>,
"Eric Blake" <eblake@redhat.com>,
"Marc-André Lureau" <marcandre.lureau@redhat.com>,
"Richard Henderson" <richard.henderson@linaro.org>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Mauro Carvalho Chehab" <mchehab+huawei@kernel.org>,
"Michael S. Tsirkin" <mst@redhat.com>,
"Peter Maydell" <peter.maydell@linaro.org>,
"Pierrick Bouvier" <pierrick.bouvier@oss.qualcomm.com>,
"Igor Mammedov" <imammedo@redhat.com>,
"Gerd Hoffmann" <kraxel@redhat.com>,
"Ani Sinha" <anisinha@redhat.com>,
"Philippe Mathieu-Daudé" <philmd@linaro.org>
Subject: Re: [PATCH v2 05/13] qapi/docs: adjust stub member insertion algorithm
Date: Tue, 05 May 2026 15:54:46 +0200 [thread overview]
Message-ID: <87o6iu2c7t.fsf@pond.sub.org> (raw)
In-Reply-To: <CAFn=p-btJTG9NPzRi3ai+Ac1v1bMqeiYX0HZKKGGX8m3wo+cUg@mail.gmail.com> (John Snow's message of "Mon, 4 May 2026 14:30:10 -0400")
John Snow <jsnow@redhat.com> writes:
> On Mon, May 4, 2026 at 7:20 AM Markus Armbruster <armbru@redhat.com> wrote:
>>
>> I'm feeling dense again. Please be patient with me.
>
> It's okay, this is a complex one. This is part of the reason for
> pursuing strict ordering to begin with: the insertion algorithm is
> complex and ugly.
>
>>
>> John Snow <jsnow@redhat.com> writes:
>>
>> > A forthcoming patch removes the implicit PLAIN section that always
>> > starts a QAPIDoc section list. Further future changes begin converting
>> > "PLAIN" sections to "INTRO" sections. To accommodate this, the insertion
>> > algorithm that places stub and dummy members must be adjusted to cope.
>>
>> What are the stub and dummy members?
>
> "stub" - undocumented members.
> "dummy" - placeholder section named q_dummy that causes "The members
> of ..." references to be printed in the rendered documentation.
Got it, thanks.
I figure synthesized "Returns:" can also be effected.
>> > This algorithm can handle zero-or-more PLAIN *or* INTRO sections at the
>> > beginning of a QAPIDoc object.
>>
>> The revised algorithm, I presume.
>>
>> What's the structure of its valid input before and after this patch?
>
> Before: Plain EverythingElse?
> After: (Plain* | Intro*) EverythingElse?
>
> Where EverythingElse may never start with "Intro", and may contain
> "Plain" but not as the first token when following a Plain section from
> the prior production. (Because contiguous plain sections are merged by
> the parser into one section.)
>
> This is to allow a gradual conversion. Once everything is fully
> converted, and especially after "details" is introduced and the strict
> ordering is enforced, this is tightened down considerably to: Intro?
> EverythingElse?
>
> where EverythingElse may no longer contain Plain (It is removed), may
> never contain Intro, and may only contain one Details section in the
> appropriate position (Near the end, before Since.)
>
> More or less: this patch removes the assumption that every QAPIDoc
> starts with exactly one Plain section and allows it to cope with any
> number of Intro/Plain sections at the beginning, but makes no change
> to what the parser actually produces or accepts. In effect, we go
> from:
>
> Plain EverythingElse
>
> to, in the next patch:
>
> Plain? EverythingElse
>
> then as the conversion continues, one of these two:
>
> Intro Plain? EverythingElse? (Without converted intro)
> Intro EverythingElse? (With converted intro)
>
> ... This entire insertion algorithm gets to be removed once we enforce
> strict ordering, because we can insert directly to the correct
> position in the list thereafter. So, it is only a temporary complexity
> that exists for the sake of gradual conversion and piecemeal list
> review of each QAPI module.
Would working this into the commit message make sense?
>> > Since we have three places that need to insert stub members, take the
>> > opportunity to unify and deduplicate this code.
>>
>> Three? I can only see two: Transmogrifier.visit_sections() and
>> QAPIDoc.connect_member().
>
> Bad wording on my part again. ensure_returns also inserts stub
> *sections*, not "members", sorry.
>
>>
>> >
>> > Signed-off-by: John Snow <jsnow@redhat.com>
>> > ---
>> > docs/sphinx/qapidoc.py | 36 ++++++++---------
>> > scripts/qapi/parser.py | 90 +++++++++++++++++++++++++++---------------
>> > 2 files changed, 75 insertions(+), 51 deletions(-)
>> >
>> > diff --git a/docs/sphinx/qapidoc.py b/docs/sphinx/qapidoc.py
>> > index 1f7c15b7075..70ab9cdc214 100644
>> > --- a/docs/sphinx/qapidoc.py
>> > +++ b/docs/sphinx/qapidoc.py
>> > @@ -349,30 +349,32 @@ def _get_target(
>> > )
>> >
>> > def visit_sections(self, ent: QAPISchemaDefinition) -> None:
>> > + # Generate a placeholder right after the member section(s) which
>> > + # will be used to generate documentation for "The members of..."
>> > + # pointers in the rendered document.
>> > + # This is a temporary hack until the inliner is merged.
>> > + if ent.doc:
>> > + ent.doc.append_member_stub(
>> > + QAPIDoc.ArgSection(
>> > + ent.doc.info, QAPIDoc.Kind.MEMBER, "q_dummy"
>> > + )
>> > + )
>> > +
>>
>> This hack is of the nastier sort: passing a QAPISchema to the doc
>> generator modifies it.
>>
>> Would it be possible to add this dummy always in QAPISchema? Any
>> drawbacks?
>
> Well...
>
> I didn't like the idea of generating "q_dummy" stubs inside the
> parser, as it is an implementation detail of qapidoc. Though as you
> note, this leaks it back out anyway.
>
> Here's my argument: the entire "q_dummy" thing goes away with the
> inliner anyway, which is what I am actively working towards, and this
> ugliness goes away entirely either way: we do not need q_dummy, we do
> not need member pointer stubs, we will not need to modify the caller's
> section list.
>
> I found this easier to do, despite the ugliness. Also consider that in
> this case, we are building an isolated schema directly inside of the
> Sphinx process anyway, so we are spiritually already "modifying our
> own copy" - i.e. there's no chance that this stuff leaks out into
> other users of the Schema. I think that's actually quite appropriate
> and unlikely to cause unintended consequences.
I think this is really a QAPIDoc defect.
The doc parser knows where the (empty) arguments are.
QAPIDoc also knows, but makes it hard to retrieve.
The old code searches QAPIDoc.all_sections to rediscover the spot.
Moderately ugly, relies on the well-known possible sequence of sections
in all_sections.
Your patch factors out the search, runs it once, and hacks up
.all_sections to store the result.
If we want the result stored in .all_sections (or anywhere in QAPIDoc,
really), why not simply store it when we know it?
Sometimes I wish QAPIDoc had a structure more useful than flat list of
sections...
>> [Remainder left for later...]
>>
next prev parent reply other threads:[~2026-05-05 13:55 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-29 19:25 [PATCH v2 00/13] qapi: add formal "intro" section John Snow
2026-04-29 19:25 ` [PATCH v2 01/13] tests/qapi: generate output in source order John Snow
2026-05-04 9:50 ` Markus Armbruster
2026-05-04 17:55 ` John Snow
2026-04-29 19:26 ` [PATCH v2 02/13] qapi/docs: remove unused QAPIDoc subsection members John Snow
2026-05-04 9:51 ` Markus Armbruster
2026-04-29 19:26 ` [PATCH v2 03/13] qapi/docs: make remaining subsection members "private" John Snow
2026-05-04 9:54 ` Markus Armbruster
2026-05-04 18:07 ` John Snow
2026-04-29 19:26 ` [PATCH v2 04/13] qapi/docs: add "Intro" section John Snow
2026-04-29 19:26 ` [PATCH v2 05/13] qapi/docs: adjust stub member insertion algorithm John Snow
2026-05-04 11:20 ` Markus Armbruster
2026-05-04 18:30 ` John Snow
2026-05-05 13:54 ` Markus Armbruster [this message]
2026-05-04 18:33 ` John Snow
2026-04-29 19:26 ` [PATCH v2 06/13] qapi/docs: remove implicit Plain section John Snow
2026-04-29 19:26 ` [PATCH v2 07/13] qapi/docs: add "Intro" section parsing John Snow
2026-05-04 11:57 ` Markus Armbruster
2026-05-04 18:44 ` John Snow
2026-05-05 13:30 ` Markus Armbruster
2026-04-29 19:26 ` [PATCH v2 08/13] qapi/docs: Add rendering for INTRO sections John Snow
2026-05-04 12:05 ` Markus Armbruster
2026-05-12 21:13 ` John Snow
2026-05-13 6:25 ` Markus Armbruster
2026-04-29 19:26 ` [PATCH v2 09/13] qapi: convert intro sections for accelerator.json John Snow
2026-04-29 19:26 ` [PATCH v2 10/13] qapi: convert intro sections for acpi-hest.json John Snow
2026-04-29 19:26 ` [PATCH v2 11/13] qapi: convert intro sections for acpi.json John Snow
2026-04-29 19:26 ` [PATCH v2 12/13] qapi: convert intro sections for audio.json John Snow
2026-04-29 19:26 ` [PATCH v2 13/13] rfc: intro starts on next line John Snow
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=87o6iu2c7t.fsf@pond.sub.org \
--to=armbru@redhat.com \
--cc=anisinha@redhat.com \
--cc=eblake@redhat.com \
--cc=imammedo@redhat.com \
--cc=jsnow@redhat.com \
--cc=kraxel@redhat.com \
--cc=marcandre.lureau@redhat.com \
--cc=mchehab+huawei@kernel.org \
--cc=michael.roth@amd.com \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=philmd@linaro.org \
--cc=pierrick.bouvier@oss.qualcomm.com \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.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