-
Notifications
You must be signed in to change notification settings - Fork 5
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
Simplify parameter type signatures #2
Labels
rust
wRPC Rust support
Comments
rvolosatovs
pushed a commit
that referenced
this issue
Apr 4, 2024
* Refactor generation of types in C This commit is an attempt to redo how types are generated and modeled in the C bindings generator. There are a number of existing issues around the C generator related to resources for example, but there are other issues historically that plague the C generator. This refactoring effectively entirely refactors the generation of types in C. Previously C worked by generating types throughout the bindings process and generating lots of bits at the end of the bindings generation process. This doesn't work for resources because the same resource imported and exported needs different bindings, unlike the one set of bindings generated prior. The new scheme of generating types looks like: * All work is now done immediately when a type is visited. This means that helper functions, destructors, etc, are all generated at type generation time. Nothing is deferred until the end of the bindings generation process. * The split between anonymous and public types in the C generator is removed. Lots of weird infrastructure was present to manage this and the only benefit was that a few types would be omitted from the public header file because they didn't need to be there. Instead this commit takes the strategy of generating all the types all the time, and if they're not used that's no skin off anyone's back. * When types are generated they now assume that all their dependencies have previously been generated. This makes generation of a reference to a type much easier because it's a simple "that name must be in this map" assertion. This is done by using `LiveTypes` to visit all types for a unit of generation. This topological sorting is then iterated over to emit all types. * Resources now generate `own` and `borrow` handle types immediately when they're visited. These serve as the canonical versions of these types and then all other references to these handles are done via `typedef`s to ensure that the types all stay the same. * Anonymous types such as tuples are now duplicated across interfaces. Previously the generator attempted to deduplicate everything into the world namespace but this doesn't work for resources which needs some means of duplicating in some cases. To solve this I went ahead and generated all anonymous types all the time which means that if a WIT files has `tuple<u32, u32>` in two interfaces that'll generate two types despite only needing one. Overall the generated C bindings are a bit more verbose than before but the generation process is vastly simpler. My hope is that this'll make the C generator less buggy without losing any functionality. Closes #629 Closes #723 Closes #727 Closes #735 Closes #749 * test(C): test all generated C header files for C++ compatibility, too Closes #691 * Fix C++ compatibility in tests Remove some empty types and additionally don't generate an empty `union` for a `result` type. * Disable Go runtime tests temporarily * Ignore more Go tests * Fix duplicate types for exports not being generated * fix: use root as module name for imported types and functions drop func (#2) * fix: use root as module name for imported types and functions drop func Signed-off-by: Jiaxiao Zhou (Mossaka) <[email protected]> * fix again Signed-off-by: Jiaxiao Zhou (Mossaka) <[email protected]> --------- Signed-off-by: Jiaxiao Zhou (Mossaka) <[email protected]> --------- Signed-off-by: Jiaxiao Zhou (Mossaka) <[email protected]> Co-authored-by: Till Schneidereit <[email protected]> Co-authored-by: Jiaxiao Zhou <[email protected]>
rvolosatovs
pushed a commit
that referenced
this issue
May 23, 2024
* Refactor generation of types in C This commit is an attempt to redo how types are generated and modeled in the C bindings generator. There are a number of existing issues around the C generator related to resources for example, but there are other issues historically that plague the C generator. This refactoring effectively entirely refactors the generation of types in C. Previously C worked by generating types throughout the bindings process and generating lots of bits at the end of the bindings generation process. This doesn't work for resources because the same resource imported and exported needs different bindings, unlike the one set of bindings generated prior. The new scheme of generating types looks like: * All work is now done immediately when a type is visited. This means that helper functions, destructors, etc, are all generated at type generation time. Nothing is deferred until the end of the bindings generation process. * The split between anonymous and public types in the C generator is removed. Lots of weird infrastructure was present to manage this and the only benefit was that a few types would be omitted from the public header file because they didn't need to be there. Instead this commit takes the strategy of generating all the types all the time, and if they're not used that's no skin off anyone's back. * When types are generated they now assume that all their dependencies have previously been generated. This makes generation of a reference to a type much easier because it's a simple "that name must be in this map" assertion. This is done by using `LiveTypes` to visit all types for a unit of generation. This topological sorting is then iterated over to emit all types. * Resources now generate `own` and `borrow` handle types immediately when they're visited. These serve as the canonical versions of these types and then all other references to these handles are done via `typedef`s to ensure that the types all stay the same. * Anonymous types such as tuples are now duplicated across interfaces. Previously the generator attempted to deduplicate everything into the world namespace but this doesn't work for resources which needs some means of duplicating in some cases. To solve this I went ahead and generated all anonymous types all the time which means that if a WIT files has `tuple<u32, u32>` in two interfaces that'll generate two types despite only needing one. Overall the generated C bindings are a bit more verbose than before but the generation process is vastly simpler. My hope is that this'll make the C generator less buggy without losing any functionality. Closes #629 Closes #723 Closes #727 Closes #735 Closes #749 * test(C): test all generated C header files for C++ compatibility, too Closes #691 * Fix C++ compatibility in tests Remove some empty types and additionally don't generate an empty `union` for a `result` type. * Disable Go runtime tests temporarily * Ignore more Go tests * Fix duplicate types for exports not being generated * fix: use root as module name for imported types and functions drop func (#2) * fix: use root as module name for imported types and functions drop func Signed-off-by: Jiaxiao Zhou (Mossaka) <[email protected]> * fix again Signed-off-by: Jiaxiao Zhou (Mossaka) <[email protected]> --------- Signed-off-by: Jiaxiao Zhou (Mossaka) <[email protected]> --------- Signed-off-by: Jiaxiao Zhou (Mossaka) <[email protected]> Co-authored-by: Till Schneidereit <[email protected]> Co-authored-by: Jiaxiao Zhou <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Currently there is some additional level of indirection added to trait parameter type signatures to work around latest Rust compiler reaching deadlock and/or recursion limit with recursive data structures. There should be a way to make this nicer post-MVP
The text was updated successfully, but these errors were encountered: