Re: [PATCH v2 10/16] scripts/qapi: add QAPISchemaType.is_predefined

Paolo Bonzini
2026-02-25T08:01:34Z

On 2/25/26 08:33, Markus Armbruster wrote:
> Paolo Bonzini <pbonzini@redhat.com> writes:
>
>> It is impossible to call is_implicit on an enum type from the visitor, because
>> the QAPISchemaEnumType has already been exploded into its costituent fields.
>
> constituent
>
> Passing selected attributes instead of the entire object to its visitor
> method limits what the visitor can do. This is both good and bad.
> We've run into "bad" a couple of times. It's never been bad enough to
> change the interface, though.
>
> Thoughts?

I think that applies here, is_predefined() is a reasonable addition.

>> The Rust backend is also not modular (yet?) so it is not possible to filter
>> out the builtin module;
>
> Really?
>
> The visitors are all based on QAPISchemaVisitor. Protocol:
>
> .visit_begin()
> for all modules:
> .visit_module()
> for all entities:
> if .visit_needed():
> .visit_FOO()
> .visit_end()
>
> QAPISchemaModularCVisitor implements .visit_module() to generate code
> per module. Its .write() skips builtin modules unless opt_builtins.

... because its .write() already builds multiple QAPIGen{C,H,Trace}, one
per module. Here instead there is just one QAPIGenRs.

Using multiple QAPIGenRs instances, one per module, would be hackish.
I'd rather just go modular instead of that. I can take a look, since
this series will be (early) 11.1 material anyway.

Paolo

> QAPISchemaMonolithicCVisitor is oblivious of modules: it doesn't
> implement .visit_module(), and writes out everything. This is fine,
> because we use it only to generate qapi-features.[ch] and
> qapi-introspect.[ch]. Generating the former has no need for recognizing
> the built-ins because there are no built-in features. Generating the
> latter has no need because it treats built-in stuff exactly like
> user-defined stuff.
>
> QAPISchemaRsVisitor [PATCH 12] also doesn't implement .visit_module().
> It uses QAPISchema.is_predefined(), defined in this patch, to skip
> built-in. Could it rely on .visit_module() instead?
>
>> add a way to query for implicit type names without
>> having the object itself.
>>
>> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
>> ---
>> scripts/qapi/schema.py | 11 +++++++++++
>> 1 file changed, 11 insertions(+)
>>
>> diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py
>> index 848a7401251..15f5d97418f 100644
>> --- a/scripts/qapi/schema.py
>> +++ b/scripts/qapi/schema.py
>> @@ -1243,6 +1243,17 @@ def _def_builtin_type(
>> # schema.
>> self._make_array_type(name, None)
>>
>> + def is_predefined(self, name: str) -> bool:
>> + # See QAPISchema._def_predefineds()
>> + entity = self._entity_dict[name]
>> + if isinstance(entity, QAPISchemaBuiltinType):
>> + return True
>> + if entity is self.the_empty_object_type:
>> + return True
>> + if name == 'QType':
>> + return True
>> + return False
>> +
>> def _def_predefineds(self) -> None:
>> for t in [('str', 'string', 'char' + POINTER_SUFFIX),
>> ('number', 'number', 'double'),
>
>
>