Skip to content

Conversation

cosmith-nvidia
Copy link

If native_type is specified on a table:

  • No object API struct type is generated.
  • The object API refers to the table by its native_type.
  • UnPack and Create methods are declared but not defined; as they
    must be user-provided.

Addresses #4969

@github-actions github-actions bot added c++ codegen Involving generating code from schema documentation Documentation labels Aug 13, 2025
@aardappel
Copy link
Collaborator

This generally looks good, wonder if this does what people on the original issue wanted it for @buster3 @iceboy233 @sketch34 @lp35 @meniku

@cosmith-nvidia cosmith-nvidia force-pushed the table-native-type branch 2 times, most recently from 969d890 to c112473 Compare August 19, 2025 04:32
@github-actions github-actions bot removed c++ codegen Involving generating code from schema labels Aug 19, 2025
If native_type is specified on a table:
- No object API struct type is generated.
- The object API refers to the table by its native_type.
- UnPack and Create<TableName> methods are declared but not defined; as they
  must be user-provided.
@github-actions github-actions bot added c++ codegen Involving generating code from schema labels Aug 19, 2025
@iceboy233
Copy link
Contributor

Can you turn on --gen-compare and fix the generated code?

@cosmith-nvidia cosmith-nvidia force-pushed the table-native-type branch 2 times, most recently from 0216f18 to db1df79 Compare August 19, 2025 18:22
Per the definition of --gen-compare: only generate comparators for object API
generated structs. Tables and structs annoated with native_type must define
their own comparators if `--gen-compare` is enabled.
@cosmith-nvidia
Copy link
Author

Can you turn on --gen-compare and fix the generated code?

Added. This was not working at main prior to this change.

I'm also not sure the behavior for structs was correct: when a flatbuffer struct was annotated with native_type, it was generating a comparator for the flatbuffer struct.

I think the desired behavior would be to only generate comparators for the object API generated types (suffixed with T), and not generate comparators for structs/tables with native_types (which need to define the comparators themselves). Let me know if this interpretation is correct (per the flatc description: Generate operator== for object-based API types.).

@iceboy233
Copy link
Contributor

This was not working at main prior to this change.

I'm also not sure the behavior for structs was correct

Maybe it can be a separate change as it's not working prior.

Is it feasible/align with existing code to allow user to implement the member Pack instead of Create, which looks more symmetrical. Or should Native suffix be appended to the create function (CreateMatrixNative) as the code base seems not doing same name function overload (CreateMatrixDirect)? I haven't used flatbuffers for a long time so not sure. @aardappel

@cosmith-nvidia
Copy link
Author

Maybe it can be a separate change as it's not working prior.

Sounds good. Mailed #8681 for this.

Is it feasible/align with existing code to allow user to implement the member Pack instead of Create

Happy to do whatever you and @aardappel suggest. Let me try to draft. I think this will just reverse some of the current dependencies of autogenerated Pack() -> Create(), and require rewriting some of the autogenerated object API type code to use Pack instead of Create.

@aardappel
Copy link
Collaborator

@dbaileychess opinion?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ codegen Involving generating code from schema documentation Documentation python
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants