-
Notifications
You must be signed in to change notification settings - Fork 22
feat: add visit type support #94
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
Signed-off-by: Junwang Zhao <[email protected]>
Signed-off-by: Junwang Zhao <[email protected]>
Signed-off-by: Junwang Zhao <[email protected]>
/// Unlike VisitTypeInline which calls `visitor.Visit`, here `visitor` | ||
/// itself is called. | ||
/// `visitor` must support a `const Type&` argument as a fallback, | ||
/// in addition to concrete type classes. | ||
/// | ||
/// The intent is for this to be called on a generic lambda | ||
/// that may internally use `if constexpr` or similar constructs. | ||
template <typename VISITOR, typename... ARGS> | ||
inline auto VisitType(const Type& type, VISITOR&& visitor, ARGS&&... args) | ||
-> decltype(std::forward<VISITOR>(visitor)(type, args...)) { | ||
switch (type.type_id()) { | ||
ICEBERG_GENERATE_FOR_ALL_TYPES(TYPE_VISIT_INLINE); | ||
default: | ||
internal::Unreachable("Type not implemented"); |
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.
The docstring says a fallback is called but the body aborts in the default case?
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.
TBH I have no idea what that sentence actually means, I don't think these words does any help to understand the template, so I'd rather delete that, or do you have any suggestions?
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.
So this was copied from Arrow? It may be worth noting that in the header just for reference.
Looking at it again, I think what it means is that because the visitor here does not inherit from a base class that has all cases defined, you must make sure to handle all cases. So I guess the implementation is OK. But the wording could be improved.
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.
So this was copied from Arrow? It may be worth noting that in the header just for reference.
Yeah, it's adapted from arrow, I'll add the note.
Looking at it again, I think what it means is that because the visitor here does not inherit from a base class that has all cases defined, you must make sure to handle all cases. So I guess the implementation is OK. But the wording could be improved.
How about we keep this as is for now, and revisit it later, either improve the wording ourselves or sync with Arrow if they update their version.
The visit type infrastructure is adapted from apache arrow. Add a reference note per @lidavidm's suggestion. Signed-off-by: Junwang Zhao <[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.
Thanks for adding this! I was thinking of the same thing.
|
||
namespace iceberg::internal { | ||
|
||
[[noreturn]] ICEBERG_EXPORT void Unreachable( |
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.
Why not directly use std::unreachable
?
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 did a quick search and found that std::unreachable was introduced in C++23 [1]. And it doesn't support passing a custom message, which I think might be useful for logging purposes.
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.
Ah my bad. Please ignore this comment.
* under the License. | ||
*/ | ||
|
||
#pragma once |
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.
nit: add the \file
docstring and mention that it is adapted from Apache Arrow.
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.
Will add later today, thanks for the suggestion.
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.
If we take big pieces from other projects, then we also want to add that to the LICENSE
:
For example in PyIceberg: https://github.com/apache/iceberg-python/blob/260ef54e3920d435ae3b2ccda090e66f9c1ac015/LICENSE#L206-L213
Add a
TypeId
field to each concrete type to enable macro-based type visitor support.