-
Notifications
You must be signed in to change notification settings - Fork 157
Add support for C++ modules #578
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
base: main
Are you sure you want to change the base?
Conversation
Summary of ChangesHello @mikomikotaishi, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request adds support for C++20 modules, which is a significant and welcome improvement for modern C++ projects. The overall approach of using a primary module interface file with partitions for different serialization formats is sound. I've identified a few issues, including some critical syntax errors in the module files that will prevent compilation, a bug in the CMake configuration, and a couple of other areas for improvement regarding code correctness and maintainability. My detailed comments are below.
| export namespace std { | ||
| using std::hash; | ||
| using std::swap; | ||
|
|
||
| #ifdef REFLECTCPP_USE_STD_EXPECTED | ||
| using std::bad_expected_access; | ||
| #endif | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exporting declarations into the std namespace (as done with export namespace std) results in undefined behavior according to the C++ standard. While this might work on some compilers, it is not portable and should be avoided. Consumers of your module should be responsible for bringing std symbols into scope, for example by importing the std module. Please remove this block.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is necessary as otherwise the std::* specialisations won't be accessible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't really find a source for this being UB. Maybe specializations can be exported explicitly though?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't even actually "undefined behaviour", compiler vendors do this to export the std module. My guess is the AI assumed I was adding additional non-standard symbols into namespace std, but these are official symbols. I think this is necessary to export specialisations/overloads, anyway
3b0d675 to
9137f57
Compare
|
@mikomikotaishi awesome PR. Thank you so |
|
@mikomikotaishi , this looks great. There is one minor comment regarding your rfl module file. Also, we need automated tests for this and should update the Github Actions pipeline accordingly. Do you know how to do it or should I do it? |
|
If I'm allowed to give some input as a user, it appears to be that the module |
|
@liuzicheng1987 Did you leave a comment somewhere in the review? If so, I haven't been able to find it. @GregTheMadMonk If I am understanding correctly, the module itself is built only by including the headers but is compiled, I chose to bundle the serialisation formats into the module in full because I think this offers the simplest API for users. If you have an alternate idea, I am happy to hear it but generally want to keep |
|
I did...I said that most of your includes in the rfl modules are redundant, because they are included in rfl.hpp anyway. |
|
Apologies, I couldn't find it. Anyway, when I was originally writing the library my IDE couldn't detect the symbols until I explicitly added those |
|
@mikomikotaishi the problem is that with the current approach the users still have to install header dependencies for all formats instead just the ones they use. This is quite tedious, and some libraries aren't very pleasant to manage as dependencies. As a user, I'd expect that IMO a good compromise would be to have |
|
That works for me, I was thinking of that. Also, @liuzicheng1987, any thoughts on prefixing the module name with the organisation (i.e. Java-style), and making the module name something like |
|
@mikomikotaishi we shouldn't use Java style. The names of the modules should align with namespaces. |
|
@mikomikotaishi , and by the way I agree with @GregTheMadMonk 's suggestion: There should be a way to only compile what you actually want. Some dependencies can be a bit tedious and forcing people to go through this even though it's completely unnecessary for what they actually want is a problem. So I like the solution you came up with. |
|
@liuzicheng1987 This would require fine-tuned configuration, because CMake has to know ahead of time which modules need to be built. Are there already such things existing in the library? |
|
@mikomikotaishi , yes, there are flags for that in the CMake: |
|
Thanks, this is perfect. |
|
I've decided that I think the best way is just to keep one module, |
|
@mikomikotaishi, sure that works as well. |
|
@liuzicheng1987 I've applied these changes now |
This PR adds support for C++ modules, enabled using
REFLECTCPP_BUILD_MODULES. The main library is part ofrfl, while each serialisation format is a partition of the module (rfl:*).