Skip to content
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

DM-29563: replace std::variant, fix clang compilation #581

Merged
merged 1 commit into from May 5, 2021

Conversation

mwittgen
Copy link
Contributor

No description provided.

@mwittgen mwittgen force-pushed the tickets/DM-29563 branch 3 times, most recently from eb8a749 to abeb6e4 Compare April 21, 2021 18:09
Copy link
Member

@kfindeisen kfindeisen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm surprised that reference_wrapper's implicit conversions to and from references don't help here. Unfortunately, I don't have any good insights into how to deal with that.

include/lsst/afw/typehandling/GenericMap.h Show resolved Hide resolved
include/lsst/afw/typehandling/GenericMap.h Show resolved Hide resolved
include/lsst/afw/typehandling/GenericMap.h Show resolved Hide resolved
return boost::get<T const&>(foo);
} catch (boost::bad_get const&) {
return std::get<std::reference_wrapper<T const>>(foo);
} catch (std::bad_variant_access const&) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still need to use exceptions at all, now that we have holds_alternative?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd guess not; just something that didn't occur to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change to use holds_alternative.

@@ -434,7 +433,7 @@ class GenericMap {
message << "Key " << key << " not found, but a key labeled " << key.getId() << " is present.";
throw LSST_EXCEPT(pex::exceptions::OutOfRangeError, message.str());
}
} catch (boost::bad_get const&) {
} catch (std::bad_variant_access const&) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider replacing with holds_alternative.

F _func;
public:

explicit refwrap_visitor(F && func) : _func(std::move(func)) {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be std::forward?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably, and even more probably with C++17's adjustments to construction that allows class template constructors to behave more like function templates. But I would need to get my head back into this much more than I have right now to be certain.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change to std::forward?

python/lsst/afw/typehandling/_GenericMap.cc Show resolved Hide resolved
Comment on lines 75 to 76
// Generic case: unwrap the reference_wrapper, then copy-construct and
// cast to Python.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redundant comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove.

include/lsst/afw/typehandling/detail/refwrap_utils.h Outdated Show resolved Hide resolved
include/lsst/afw/fits.h Outdated Show resolved Hide resolved
src/image/Image.cc Outdated Show resolved Hide resolved
src/image/Image.cc Outdated Show resolved Hide resolved
Copy link
Member

@TallJimbo TallJimbo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry it took me so long to get to this.

But I started looking at the clang-tidy changes, and almost every one I've seen is actually undesirable for one reason or another (or at least questionable) - usually it's a case where our code is doing something that isn't exactly best practice, but fixing it naively (as clang-tidy has done) is simply incorrect.

The only exceptions so far are the changes from iterator-based to range-based for; those do look okay.

I think it might be best to remove those clang-tidy commits from this ticket entirely, and perhaps run it much more carefully (or at least less aggressively) on a future ticket. Were any of them needed to get the variant and filesystem changes compiling at all?

include/lsst/afw/fits.h Outdated Show resolved Hide resolved
include/lsst/afw/image/Image.h Outdated Show resolved Hide resolved
include/lsst/afw/image/ImageBase.h Outdated Show resolved Hide resolved
include/lsst/afw/image/ImageBase.h Outdated Show resolved Hide resolved
@mwittgen
Copy link
Contributor Author

@TallJimbo removed all the clang-tidy stuff and also the cherry-pick for arm-osx compilation for now as is changes the compile flag -D_LIBCPP_DISABLE_AVAILABILITY=1 for all platforms and all the arm osx stuff should go into a proper ticket.

Copy link
Member

@TallJimbo TallJimbo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've responded to @kfindeisen 's comments on the code that I wrote. But I wouldn't be able to actually get to addressing them in the code myself for at least a few weeks, I'm afraid, so I'm hoping @mwittgen can take that on.

The code that I didn't originally write (just adding std:: to nullptr_t, now, I think) is approved.

@mwittgen , did you review the std::variant changes in afw::table? It doesn't look like @kfindeisen did, from where his comments are.

include/lsst/afw/typehandling/GenericMap.h Show resolved Hide resolved
return boost::get<T const&>(foo);
} catch (boost::bad_get const&) {
return std::get<std::reference_wrapper<T const>>(foo);
} catch (std::bad_variant_access const&) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd guess not; just something that didn't occur to me.

include/lsst/afw/typehandling/GenericMap.h Show resolved Hide resolved
F _func;
public:

explicit refwrap_visitor(F && func) : _func(std::move(func)) {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably, and even more probably with C++17's adjustments to construction that allows class template constructors to behave more like function templates. But I would need to get my head back into this much more than I have right now to be certain.

python/lsst/afw/typehandling/_GenericMap.cc Show resolved Hide resolved
template <typename ...E> struct TypeList {};

/// A compile-time list of scalar field types.
using ScalarFieldTypes = TypeList<AFW_TABLE_SCALAR_FIELD_TYPES>;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ScalarFieldTypes is never used.

@mwittgen mwittgen requested a review from TallJimbo May 4, 2021 20:47
Copy link
Member

@TallJimbo TallJimbo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Only remaining comment is a tiny style one; feel free to merge after that's addressed (assuming Jenkins is green, etc.).

try {
auto foo = unsafeLookup(key.getId());
auto foo = unsafeLookup(key.getId());
if(std::holds_alternative<std::reference_wrapper<T const>>(foo)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our style has a space between if and (.

Switch from boost::variant to std::variant in afw::table.
fix clang compilation
@mwittgen mwittgen merged commit 2bc2b1e into master May 5, 2021
@mwittgen mwittgen deleted the tickets/DM-29563 branch May 5, 2021 05:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants