Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gate representation in C bindings #14

Open
alecandido opened this issue Apr 15, 2024 · 0 comments
Open

Gate representation in C bindings #14

alecandido opened this issue Apr 15, 2024 · 0 comments

Comments

@alecandido
Copy link
Member

Note

This is mostly a note to myself

There might be an issue if we're going to generate C bindings directly from the current Gate layout.

The reason is the following:

The representation of a repr(C) enum with fields is a repr(C) struct with two fields, also called a "tagged union" in C:

  • a repr(C) version of the enum with all fields removed ("the tag")
  • a repr(C) union of repr(C) structs for the fields of each variant that had them ("the payload")

[...]

Note: unions with non-Copy fields are unstable, see 55149.

https://doc.rust-lang.org/nightly/reference/type-layout.html#reprc-enums-with-fields

Even though the mentioned issue has been closed (still have to read that).

Thus, we should make sure that whatever is in a gate will be Copy, or choose a different scheme for the C API and implement a mapping in the bindings.

Size

Also consider that the size of a union is the size of its biggest field (rounded to the alignment). This means that, even if we limited to store arrays and whatever needed in a Copy-struct, every gate would have the size of an arbitrary Unitary (or the largest gate we have).

This might be irrelevant, but it would certainly blow up the memory consumption.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant