qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: John Snow <jsnow@redhat.com>
Cc: qemu-devel@nongnu.org, "Peter Xu" <peterx@redhat.com>,
	"Marcel Apfelbaum" <marcel.apfelbaum@gmail.com>,
	"Gerd Hoffmann" <kraxel@redhat.com>,
	"Fabiano Rosas" <farosas@suse.de>,
	"Pavel Dovgalyuk" <pavel.dovgaluk@ispras.ru>,
	"Ani Sinha" <anisinha@redhat.com>,
	"Michael Roth" <michael.roth@amd.com>,
	"Kevin Wolf" <kwolf@redhat.com>, "Jiri Pirko" <jiri@resnulli.us>,
	"Mads Ynddal" <mads@ynddal.dk>,
	"Jason Wang" <jasowang@redhat.com>,
	"Igor Mammedov" <imammedo@redhat.com>,
	"Peter Maydell" <peter.maydell@linaro.org>,
	"Philippe Mathieu-Daudé" <philmd@linaro.org>,
	"Marc-André Lureau" <marcandre.lureau@redhat.com>,
	"Stefan Hajnoczi" <stefanha@redhat.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Eduardo Habkost" <eduardo@habkost.net>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	qemu-block@nongnu.org,
	"Stefan Berger" <stefanb@linux.vnet.ibm.com>,
	"Victor Toso de Carvalho" <victortoso@redhat.com>,
	"Eric Blake" <eblake@redhat.com>,
	"Daniel P. Berrangé" <berrange@redhat.com>,
	"Konstantin Kostiuk" <kkostiuk@redhat.com>,
	"Lukas Straub" <lukasstraub2@web.de>,
	"Yanan Wang" <wangyanan55@huawei.com>,
	"Hanna Reitz" <hreitz@redhat.com>
Subject: Re: [PATCH 09/20] qapi/parser: add undocumented stub members to all_sections
Date: Tue, 18 Jun 2024 13:32:56 +0200	[thread overview]
Message-ID: <87msni7afr.fsf@pond.sub.org> (raw)
In-Reply-To: <CAFn=p-YTa=z5Y5p+S+MN__kEuxf_H36K+=QPNNBdh6wEaZBrkw@mail.gmail.com> (John Snow's message of "Mon, 17 Jun 2024 12:54:26 -0400")

John Snow <jsnow@redhat.com> writes:

> On Fri, Jun 14, 2024 at 4:53 AM Markus Armbruster <armbru@redhat.com> wrote:
>
>> John Snow <jsnow@redhat.com> writes:
>>
>> > This helps simplify the doc generator if it doesn't have to check for
>> > undocumented members.
>> >
>> > Signed-off-by: John Snow <jsnow@redhat.com>
>> > ---
>> >  scripts/qapi/parser.py | 20 ++++++++++++++++++--
>> >  1 file changed, 18 insertions(+), 2 deletions(-)
>> >
>> > diff --git a/scripts/qapi/parser.py b/scripts/qapi/parser.py
>> > index b1794f71e12..3cd8e7ee295 100644
>> > --- a/scripts/qapi/parser.py
>> > +++ b/scripts/qapi/parser.py
>> > @@ -740,8 +740,24 @@ def connect_member(self, member: 'QAPISchemaMember') -> None:
>> >                  raise QAPISemError(member.info,
>> >                                     "%s '%s' lacks documentation"
>> >                                     % (member.role, member.name))
>> > -            self.args[member.name] = QAPIDoc.ArgSection(
>> > -                self.info, '@' + member.name, 'member')
>> > +
>> > +            # Insert stub documentation section for missing member docs.
>> > +            section = QAPIDoc.ArgSection(
>> > +                self.info, f"@{member.name}", "member")
>>
>> Although I like f-strings in general, I'd pefer to stick to '@' +
>> member.name here, because it's simpler.
>
> Tomayto, Tomahto. (OK.)

Apropos healthy vegetables: at some time, we might want to mass-convert
to f-strings where they are easier to read.

>> Also, let's not change 'member' to "member".  Existing practice: single
>> quotes for string literals unless double quotes avoid escapes.  Except
>> English prose (like error messages) is always in double quotes.
>>
>
> OK. I realize I'm not consistent in this patch either, but I'll explain
> that my using double quotes here is a black-ism that is sneaking in the
> more I use it to auto-format my patches :)
>
> Maybe time for a flag day when I move scripts/qapi to python/qemu/qapi ...
>
> (Sorry, this type of stuff is ... invisible to me, and I really do rely on
> the linters to make sure I don't do this kind of thing.)
>
>
>>
>> > +            self.args[member.name] = section
>> > +
>> > +            # Determine where to insert stub doc.
>>
>> If we have some member documentation, the member doc stubs clearly must
>> go there.  Inserting them at the end makes sense.
>>
>> Else we want to put them where the parser would accept real member
>> documentation.
>>
>> "The parser" is .get_doc().  This is what it accepts (I'm prepared to
>> explain this in detail if necessary):
>>
>>     One untagged section
>>
>>     Member documentation, if any
>>
>>     Zero ore more tagged or untagged sections
>>
>>     Feature documentation, if any
>>
>>     Zero or more tagged or untagged sections
>>
>> If we there is no member documentation, this is
>>
>>     One untagged section
>>
>>     Zero ore more tagged or untagged sections
>>
>>     Feature documentation, if any
>>
>>     Zero or more tagged or untagged sections
>>
>> Note that we cannot have two adjacent untagged sections (we only create
>> one if the current section isn't untagged; if it is, we extend it
>> instead).  Thus, the second section must be tagged or feature
>> documentation.
>>
>> Therefore, the member doc stubs must go right after the first section.
>>
>> This is also where qapidoc.py inserts member documentation.
>>
>> > +            index = 0
>> > +            for i, sect in enumerate(self.all_sections):
>> > +                # insert after these:
>> > +                if sect.kind in ('intro-paragraph', 'member'):
>> > +                    index = i + 1
>> > +                # but before these:
>> > +                elif sect.kind in ('tagged', 'feature', 'outro-paragraph'):
>> > +                    index = i
>> > +                    break
>>
>> Can you describe what this does in English?  As a specification; simply
>> paraphrasing the code is cheating.  I tried, and gave up.
>>
>
> It inserts after any intro-paragraph or member section it finds, but before
> any tagged, feature, or outro-paragraph it finds.
>
> The loop breaks on the very first instance of tagged/feature/outro, exiting
> immediately and leaving the insertion index set to the first occurrence of
> such a section, so that the insertion will place the member documentation
> prior to that section.
>
> The loop doesn't break when it finds intro-paragraph or members, so it'll
> continue to tick upwards until it reaches the end of the list or it finds
> something disqualifying.
>
>
>>
>> Above, I derived what I believe we need to do.  It's simple enough: if
>> we have member documentation, it starts right after the first (untagged)
>> section, and the stub goes to the end of the member documentation.
>> Else, the stub goes right after the first section.
>>
>> Code:
>>
>>             index = 1;
>>             while self.all_sections[index].kind == 'member':
>>                 index += 1
>>
>
> Wellp, yeah. That's certainly less code :)
>
> I tossed in your algorithm alongside mine and asserted they were always
> equal, and they are, so... yup. I think the only possible concern here is
> if there is precisely one and only one section and 1 is beyond EOL, but
> that's easy to fix. It apparently doesn't happen in practice, but I can't
> presently imagine why it *couldn't* happen.
>
> I'll just write a comment explaining the assumptions that make your algo
> work (intro section always guaranteed even if empty; intro sections always
> collapse into one section, members must start at i:=1 if they exist at all,
> members must be contiguous.)

You could assert the first section exists and is untagged.  And maybe
assert if we have members, the first is at index 1.

>> Of course future patches I haven't seen might change the invariants in
>> ways that break my simple code.  We'll see.
>>
>> > +            self.all_sections.insert(index, section)
>> > +
>> >          self.args[member.name].connect(member)
>> >
>> >      def connect_feature(self, feature: 'QAPISchemaFeature') -> None:
>>
>>
> Now, for a critique of my own patch: this patch makes it difficult to audit
> all of the cases where intro vs outro paragraphs sections may be ambiguous
> because we automatically add members sections, so the warning yap I add
> later on catches less cases.
>
> It's possible we may want to add a warning yap about paragraph ambiguity
> directly to the parser, OR just decide we don't really care and we just
> *assume* and that it's fine.
>
> We can discuss this pointedly on a call next time, and I'll come prepared
> with examples and line numbers.... Or, if you'd prefer, you can get a
> written report so you can take your time reading in silence.

Let's try whatever feels easier for you first.



  reply	other threads:[~2024-06-18 11:33 UTC|newest]

Thread overview: 66+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-14 21:57 [PATCH 00/20] qapi: new sphinx qapi domain pre-requisites John Snow
2024-05-14 21:57 ` [PATCH 01/20] [DO-NOT-MERGE]: Add some ad-hoc linting helpers John Snow
2024-05-14 21:57 ` [PATCH 02/20] qapi: linter fixups John Snow
2024-05-15  9:10   ` Markus Armbruster
2024-05-14 21:57 ` [PATCH 03/20] docs/qapidoc: delint a tiny portion of the module John Snow
2024-05-15  9:16   ` Markus Armbruster
2024-05-15 12:02     ` John Snow
2024-05-15 16:09     ` John Snow
2024-05-15 17:27       ` Markus Armbruster
2024-05-15 17:52         ` John Snow
2024-05-14 21:57 ` [PATCH 04/20] qapi/parser: preserve indentation in QAPIDoc sections John Snow
2024-05-15 11:50   ` Markus Armbruster
2024-05-15 12:24     ` John Snow
2024-05-15 14:17       ` Markus Armbruster
2024-05-15 17:03         ` John Snow
2024-05-14 21:57 ` [PATCH 05/20] qapi/parser: adjust info location for doc body section John Snow
2024-05-16  5:58   ` Markus Armbruster
2024-05-16 14:30     ` John Snow
2024-05-27 11:58       ` Markus Armbruster
2024-06-21 21:18         ` John Snow
2024-05-14 21:57 ` [PATCH 06/20] qapi/parser: fix comment parsing immediately following a doc block John Snow
2024-05-16  6:01   ` Markus Armbruster
2024-05-16 17:32     ` John Snow
2024-06-13 14:32       ` Markus Armbruster
2024-06-17 15:40         ` John Snow
2024-05-14 21:57 ` [PATCH 07/20] qapi/parser: add semantic 'kind' parameter to QAPIDoc.Section John Snow
2024-05-16  6:18   ` Markus Armbruster
2024-05-16 14:46     ` John Snow
2024-06-13 14:45       ` Markus Armbruster
2024-06-17 15:47         ` John Snow
2024-05-14 21:57 ` [PATCH 08/20] qapi/parser: differentiate intro and outro paragraphs John Snow
2024-05-16  9:34   ` Markus Armbruster
2024-05-16 15:06     ` John Snow
2024-05-16 17:43       ` John Snow
2024-05-14 21:57 ` [PATCH 09/20] qapi/parser: add undocumented stub members to all_sections John Snow
2024-06-14  8:52   ` Markus Armbruster
2024-06-17 16:54     ` John Snow
2024-06-18 11:32       ` Markus Armbruster [this message]
2024-05-14 21:57 ` [PATCH 10/20] qapi/schema: add __iter__ method to QAPISchemaVariants John Snow
2024-05-14 21:57 ` [PATCH 11/20] qapi/schema: add doc_visible property to QAPISchemaDefinition John Snow
2024-06-14  9:40   ` Markus Armbruster
2024-06-17 17:33     ` John Snow
2024-05-14 21:57 ` [PATCH 12/20] qapi/source: allow multi-line QAPISourceInfo advancing John Snow
2024-05-14 21:57 ` [PATCH 13/20] docs/qapidoc: fix nested parsing under untagged sections John Snow
2024-06-14  9:45   ` Markus Armbruster
2024-06-17 17:42     ` John Snow
2024-05-14 21:57 ` [PATCH 14/20] qapi: fix non-compliant JSON examples John Snow
2024-06-14 10:55   ` Markus Armbruster
2024-06-17 17:52     ` John Snow
2024-06-18  8:48       ` Markus Armbruster
2024-05-14 21:57 ` [PATCH 15/20] qapi: remove developer factoring comments from QAPI doc blocks John Snow
2024-05-14 21:57 ` [PATCH 16/20] qapi: rewrite StatsFilter comment John Snow
2024-05-14 21:57 ` [PATCH 17/20] qapi: rewrite BlockExportOptions doc block John Snow
2024-05-14 21:57 ` [PATCH 18/20] qapi: ensure all errors sections are uniformly typset John Snow
2024-06-14 11:24   ` Markus Armbruster
2024-06-17 17:56     ` John Snow
2024-06-18  8:52       ` Markus Armbruster
2024-05-14 21:57 ` [PATCH 19/20] qapi: convert "Note" sections to plain rST John Snow
2024-06-14 13:44   ` Markus Armbruster
2024-06-17 19:56     ` John Snow
2024-06-18 11:08       ` Markus Armbruster
2024-05-14 21:57 ` [PATCH 20/20] qapi: convert "Example" sections to rST John Snow
2024-06-14 14:38   ` Markus Armbruster
2024-06-17 21:27     ` John Snow
2024-06-18 11:25       ` Markus Armbruster
2024-05-16 17:56 ` [PATCH 00/20] qapi: new sphinx qapi domain pre-requisites Stefan Hajnoczi

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=87msni7afr.fsf@pond.sub.org \
    --to=armbru@redhat.com \
    --cc=anisinha@redhat.com \
    --cc=berrange@redhat.com \
    --cc=eblake@redhat.com \
    --cc=eduardo@habkost.net \
    --cc=farosas@suse.de \
    --cc=hreitz@redhat.com \
    --cc=imammedo@redhat.com \
    --cc=jasowang@redhat.com \
    --cc=jiri@resnulli.us \
    --cc=jsnow@redhat.com \
    --cc=kkostiuk@redhat.com \
    --cc=kraxel@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=lukasstraub2@web.de \
    --cc=mads@ynddal.dk \
    --cc=marcandre.lureau@redhat.com \
    --cc=marcel.apfelbaum@gmail.com \
    --cc=michael.roth@amd.com \
    --cc=mst@redhat.com \
    --cc=pavel.dovgaluk@ispras.ru \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=peterx@redhat.com \
    --cc=philmd@linaro.org \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanb@linux.vnet.ibm.com \
    --cc=stefanha@redhat.com \
    --cc=victortoso@redhat.com \
    --cc=wangyanan55@huawei.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;
as well as URLs for NNTP newsgroup(s).