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

Add an static_assert for the GenericParameters and remove the EnableIf #676

Merged
merged 7 commits into from
Sep 18, 2024

Conversation

jmcarcell
Copy link
Member

@jmcarcell jmcarcell commented Sep 17, 2024

This was discussed in key4hep/k4FWCore#223 (comment).

BEGINRELEASENOTES

  • Remove EnableIf for GenericParameters and add static_assert in its place to make errors easier to read and debug.

ENDRELEASENOTES

Copy link
Collaborator

@tmadlener tmadlener left a comment

Choose a reason for hiding this comment

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

I think the overload with std::vector<std::string> also needs some changes, because without SFINAE, putParameter("somekey", {"an", "initializer_list", "of", "string", "literals"}), will hit the one with std::initializer_list<T>, which will trigger a compilation error once it gets to the underlying GenericParameters.

@tmadlener
Copy link
Collaborator

Also similar changes should be put in place for getParameter. However, there it should be much more straight forward.

@tmadlener
Copy link
Collaborator

CI failure seems to be due to an issue in EDM4hep.

@tmadlener
Copy link
Collaborator

CI for edm4hep workflows should start to work again with #677

@@ -264,7 +264,7 @@ def put_parameter(self, key, value, as_type=None):
cpp_types = _get_cpp_types(as_type)
if len(cpp_types) == 0:
raise ValueError(f"Cannot put a parameter of type {as_type} into a Frame")
self._frame.putParameter[cpp_types[0]](key, value)
self._frame.putParameter[cpp_types[0][0]](key, value)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is this change necessary? Was this a pre-existing bug?

Copy link
Member Author

Choose a reason for hiding this comment

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

cpp_types will be a list of tuples so the first [0] gets the first tuple. Before since there were two template arguments (one of them being the EnableIf) it was possible to pass this tuple, now it is not, and the second [0] gets the actual C++ type. So not exactly a bug. While having a look at this I also tried to simplify this part a bit but in the end I left it as it is with only a couple of lines in a more pythonic way.

Copy link
Collaborator

@tmadlener tmadlener left a comment

Choose a reason for hiding this comment

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

I found another one at getParameterKeys. And the set with the initializer_list could also be changed to a static_assert, I think.

@jmcarcell
Copy link
Member Author

I think I got all of them now.

I found another one at getParameterKeys. And the set with the initializer_list could also be changed to a static_assert, I think.

This one actually has to remain, because otherwise the initializer_list<const char*> will give an error since the elements won't be converted to std::string.

inline void putParameter(const std::string& key, T value) {
static_assert(podio::isSupportedGenericDataType<T>, "The type is not supported by the GenericParameters");
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
static_assert(podio::isSupportedGenericDataType<T>, "The type is not supported by the GenericParameters");
static_assert(podio::isSupportedGenericDataType<T>, "T is not a supported parameter type");

I think GenericParameters is too much of an implementation detail here, especially if users get this message from their algorithms, they will not know what it is and where to look. I would change this message at least for the cases in Frame. Not sure if we should also put the supported types in, because this message is likely to become outdated if we have to add more types.

Copy link
Member Author

Choose a reason for hiding this comment

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

For the same reason T doesn't tell you much where to look or what to do. But showing the type isn't completely trivial 🤷

Copy link
Collaborator

Choose a reason for hiding this comment

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

We need to have documentation where we state the supported datatypes (not sure if we already have). I think we could also drop the T from the message. In the end the compiler error will contain the type they tried to use in some form.

Copy link
Contributor

Choose a reason for hiding this comment

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

The docs mention int, float, strong and vectors of those https://github.com/AIDASoft/podio/blob/master/doc/frame.md#usage-for-parameters

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah right, I knew it was somewhere :D. But it's missing a double 🙈

@tmadlener tmadlener merged commit 4615421 into AIDASoft:master Sep 18, 2024
18 checks passed
jmcarcell added a commit to jmcarcell/podio that referenced this pull request Sep 18, 2024
…o std::string

when trying to put a parameter that can be converted to std::string, therefore
it will fail with the static_assert when compiling.
tmadlener pushed a commit that referenced this pull request Sep 18, 2024
…tring (#680)

when trying to put a parameter that can be converted to std::string, therefore
it will fail with the static_assert when compiling.

Co-authored-by: jmcarcell <jmcarcell@users.noreply.github.com>
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.

3 participants