Proof of concept: Template functions#2650
Draft
Danacus wants to merge 3 commits intorust-lang:mainfrom
Draft
Conversation
Collaborator
|
☔ The latest upstream changes (possibly #3365) made this pull request unmergeable. Please resolve the merge conflicts. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hi, I wanted to explore if bindgen could support template functions and methods if some explicit instantiations are given in the header file, as explained in #492 (implicit instantiations also work just fine, clang doesn't seem to make a large distinction anyway).
As I mentioned in this issue, I believe this is currently not possible due to a limitation of libclang, so I decided to patch libclang such that instantiations of a template function are visited (patch based on LLVM 16):
With this patch, bindgen can support template functions with just 3 additional lines of code (e8efccb).
I then tried the same thing for template methods, which was a bit more difficult in bindgen, and this solution is very much a proof of concept, not final code to be merged.
Here is an example of this proof of concept:
C++ header:
Generated Rust bindings:
Would it be useful/interesting/worthwhile to open a PR on the LLVM repository to propose these changes, such that support for template functions can be implemented in bindgen? Or is there anything I have overlooked that might make things more complicated than they appear to be at first glance?