-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[ADT] Fix llvm::concat_iterator for ValueT == common_base_class *
#144744
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1032,13 +1032,17 @@ class concat_iterator | |
|
||
static constexpr bool ReturnsByValue = | ||
!(std::is_reference_v<decltype(*std::declval<IterTs>())> && ...); | ||
static constexpr bool ReturnsConvertiblePointer = | ||
std::is_pointer_v<ValueT> && | ||
(std::is_convertible_v<decltype(*std::declval<IterTs>()), ValueT> && ...); | ||
|
||
using reference_type = | ||
typename std::conditional_t<ReturnsByValue, ValueT, ValueT &>; | ||
typename std::conditional_t<ReturnsByValue || ReturnsConvertiblePointer, | ||
ValueT, ValueT &>; | ||
|
||
using handle_type = | ||
typename std::conditional_t<ReturnsByValue, std::optional<ValueT>, | ||
ValueT *>; | ||
using handle_type = typename std::conditional_t< | ||
ReturnsConvertiblePointer, ValueT, | ||
std::conditional_t<ReturnsByValue, std::optional<ValueT>, ValueT *>>; | ||
Comment on lines
+1035
to
+1045
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is getting complicated with the need for a nested condition -- could we move this to a new type trait struct or find some other way to simplify the code? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On second thoughts, I cannot see an obvious way to simplify this conditional type; unfortunately, defining a type trait struct would span over more lines (and I don't think it pays off given that this type is only used by a couple of private member functions). I am not sure it is much clearer, but if it helps, it can be trivially split as using wrap_type =
typename std::conditional_t<ReturnsByValue, std::optional<ValueT>, ValueT *>;
using handle_type = typename std::conditional_t<ReturnsConvertiblePointer, ValueT, wrap_type>; Any preference? Other than that, I think the PR is ready; build passing 👍. |
||
|
||
/// We store both the current and end iterators for each concatenated | ||
/// sequence in a tuple of pairs. | ||
|
@@ -1088,7 +1092,7 @@ class concat_iterator | |
if (Begin == End) | ||
return {}; | ||
|
||
if constexpr (ReturnsByValue) | ||
if constexpr (ReturnsByValue || ReturnsConvertiblePointer) | ||
return *Begin; | ||
else | ||
return &*Begin; | ||
|
@@ -1105,8 +1109,12 @@ class concat_iterator | |
|
||
// Loop over them, and return the first result we find. | ||
for (auto &GetHelperFn : GetHelperFns) | ||
if (auto P = (this->*GetHelperFn)()) | ||
return *P; | ||
if (auto P = (this->*GetHelperFn)()) { | ||
if constexpr (ReturnsConvertiblePointer) | ||
return P; | ||
else | ||
return *P; | ||
} | ||
|
||
llvm_unreachable("Attempted to get a pointer from an end concat iterator!"); | ||
} | ||
|
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.
Doesn't this change the reference type in the case where all pointer types are the same? Prior to this PR, the
reference_type
used to beT *&
, now it will becomeT *
.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.
Similar for
handle_type
, doesn't this change the type fromT **
toT *
?