dropbox / djinni

A tool for generating cross-language type declarations and interface bindings.
Apache License 2.0
2.88k stars 488 forks source link

Circular Dependencies for Record? #440

Closed codingrhythm closed 5 years ago

codingrhythm commented 5 years ago

I have something similar to this

record_a = record {
  value: list<record_b>;
}

record_b = record {
  value: record_a;
}

and the generated code failed to build for cpp and Objective-C because of the circular dependencies. Any ideas? for interface, Djinni uses forward declarations to break circular dependencies. Can we support this for record as well? Thanks

artwyman commented 5 years ago

No, records contain their fields "by value", meaning that a circularly-defined type would be of infinite size. If you need recursive types you need to implement them using custom interfaces, or come up with some other data format to pass them across the language boundary.

For your specific case, I think the list does indeed keep it from being infinite size at run-time, but at build time you can't define the C++ structs circularly, even with forward-declarations, since vector<T> requires the full definition of T. A record representation which could break that dependency would have to use an extra layer of indirection via pointers or type-erasure, which isn't something intended by Djinni.