-
Notifications
You must be signed in to change notification settings - Fork 65
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
c++17 concepts with CPP_template for engine/idTable/ files #1746
c++17 concepts with CPP_template for engine/idTable/ files #1746
Conversation
c317040
to
dbf0b40
Compare
Signed-off-by: Johannes Kalmbach <[email protected]>
Hello @sebastian-wieczorek
As already said, I have consistently applied points 1-3 and pushed your branch, the rest seems to work, but I will perform a separate review. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #1746 +/- ##
==========================================
+ Coverage 89.95% 90.03% +0.07%
==========================================
Files 395 395
Lines 37651 37922 +271
Branches 4234 4264 +30
==========================================
+ Hits 33869 34142 +273
+ Misses 2487 2484 -3
- Partials 1295 1296 +1 ☔ View full report in Codecov by Sentry. |
Signed-off-by: Johannes Kalmbach <[email protected]>
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.
Thank you very much, I have addressed two of your TODOs myself (the solution was straightforward) , and left another one + some cleanup suggestions for you.
Please let me know if you have further questions of if I can be of assistance.
Best regards
Johannes
src/engine/idTable/IdTable.h
Outdated
// TODO: <ccoecontrol> what about these? template cannot be defaulted | ||
// possible solution: implement defaulted ones by hand |
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.
Thanks for pointing that out, In fact there seems to be no really simple + good C++-17 solution.
The manual implementation is rather error-prone, especially for the assignment.
I would suggest putting this whole block in its original form behind a #ifndef
So
#ifdef QLEVER_CPP_17
IdTable(const IdTable&) = default;
IdTable& operator= (const IdTable&) = default;
#else
// The original code with the requires
#endif
```
as soon as we compile in C++20 mode we will detect all the illegal copies.
And additionally write a comment tha4t there is no simple way to formulate this in C++17 .
(For completeness: We could add a separate layer of wrapper classes that only handles the viewness, but that would be overkill for now).
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.
default put behind a macro here
@@ -346,7 +365,8 @@ class IdTable { | |||
// Get a reference to the `i`-th row. The returned proxy objects can be | |||
// implicitly and trivially converted to `row_reference`. For the design | |||
// rationale behind those proxy types see above for their definition. | |||
row_reference_restricted operator[](size_t index) requires(!isView) { | |||
CPP_template(typename = void)(requires(!isView)) row_reference_restricted |
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 pattern happens very often, maybe wriite two macros at the beginning of this fiile
define REQUIRES_VIEW CPP_template(typename = void) (requires isView)
And the same for REQUIRES_NOT_VIEW
, then you can write
REQUIRES_NOT_VIEW row_reference_restricted operator[](size_t index)
here (similar in the other places),
whiich is nicer and uses less space.
Don't forget to undefine the macros again at the end of the header file to not clutter the global namespace.
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.
my guess is that this will be more common that just this file, what about enhancing concepts.h with some macro like:
CPP_parameterless_template(...) CPP_template(__VA_ARGS__)
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.
Something like that could work, I will look into it, as I have discovered some additional macros to be missing.
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.
For this PR (to get it merged) we will leave the typename = void
defaults,
But if I have time I will add some additional macros.
src/engine/idTable/IdTable.h
Outdated
// TODO: <ccoecontrol> what with this one? | ||
// reimplementing it with CPP_template macro causes template redefinition | ||
// errors |
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'll first have a look at the remainder, and then think of something.
src/engine/idTable/IdTable.h
Outdated
CPP_template(typename = void)( | ||
requires(isCloneable)) auto moveOrClone() const& { | ||
return clone(); | ||
} | ||
CPP_template(typename = void)( | ||
requires(isCloneable)) IdTable&& moveOrClone() && { |
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 could just be rewritten. Probably when trying out you misplaced some of the many &&
s here or something else went wrong.
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.
yeah, I tried this with gcc13 and this was just showing errors from other parts of the code when compiled with backports on
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.
here is gcc13 fix related to CPP_template usage for overloads or specializations, please share if you think is is needed.
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.
That fix is definitely needed, I also have it in some open PRs... GCC11 didn't complain about this, but Clang16 (where I treid it) and obviously GCC13 (from what you say) correctly reject that code. It is time that we merge it in.
Signed-off-by: Johannes Kalmbach <[email protected]>
Signed-off-by: Johannes Kalmbach <[email protected]>
Signed-off-by: Johannes Kalmbach <[email protected]>
Signed-off-by: Johannes Kalmbach <[email protected]>
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.
We can leave this as is for now,
We have learned something for the next iteration.
I think for member functions that are constrained on the template arguments of the outer template, the better alternative to CPP_template<typename = void>
is
using the CPP_member
macro in combination with CPP_ret
as it yields the best code for both C++17 and C++20. I have incorporated those into some of the places.
Conformance check passed ✅No test result changes. |
|
Backport C++20 concepts in the
src/engine/idTable
directory back to C++17 using macros fromrange-v3