-
-
Notifications
You must be signed in to change notification settings - Fork 555
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
Fix compile error when compiling boost graphs with recent clang #39526
base: develop
Are you sure you want to change the base?
Conversation
this fixes an underlying type confusion in our wrapper that has lead to warnings before but now produces an actual error, see sagemath#39249
public: | ||
adjacency_list graph; | ||
std::vector<vertex_descriptor> vertices; | ||
vertex_to_int_map index; | ||
|
||
public: |
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 is not necessary to fix the warning. But since these fields are not part of the Cython interface, they can as well be private (would have helped me to understand things more quickly.
Documentation preview for this PR (built with commit 395ca33; changes) is ready! 🎉 |
typedef int v_index; | ||
typedef long e_index; | ||
typedef unsigned long v_index; | ||
typedef unsigned long e_index; |
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 don't think this change is necessary. I think you got confused when the programmer lies to cython or something
https://cython-guidelines.readthedocs.io/en/latest/articles/lie.html
similar to #39098 (comment)
In other words: even though in the pxd the declaration is
ctypedef unsigned long v_index
ctypedef unsigned long e_index
in compiled code it should still use int
. (before the change)
Or so I think.
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 don't understand why the programmer would want to lie to Cython here? So, e_index
should be the type that num_edges
returns. That's boost::graph_traits<G>::edges_size_type
. I don't think I can reference that type directly from a pxd (but maybe there is a way, then I should probably use it.) Let me put a static assert into the code to check that this is actually unsigned long. Similarly, v_index
is vertex_index_t
andsize_t
and vertices_size_type
. I guess they are all just unsigned long
but I'll add a static assert to be sure.
This is not terribly clean. If we end up building on a platform where this is not true, then we might have to stop identifying these types but I think it's just the same type on all platforms anyway.
Maybe I'll put in the extra work and actually separate these types but I think in Cython I'll just set them all to unsigned long
.
I am not sure I really understood your objection here though. Maybe you can rephrase what you had in mind?
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 see now what you meant with the v_index
. It's the type used in the definition of adjacency_list
. So if I change it to an unsigned type, this actually changes something.
Anyway I think the problem is why is in the original code
the tl;dr while the two places changing |
Thanks for your thoughts, I'll try to make the code be a bit more careful with the types. |
I think |
Okay, maybe I misunderstood. But anyway, the "morally correct" typedef is to make
belong to, right? (which is Or is that too much of a breaking API change and we should just cast it to Edit: because of
then Edit: turns out it's because #include <boost/graph/adjacency_list.hpp>
#include <boost/property_map/property_map.hpp>
#include <boost/type_traits/is_same.hpp>
#include <type_traits>
#include <vector>
// type aliases remain unchanged
typedef int v_index;
typedef long e_index;
typedef boost::adjacency_list<
boost::vecS, // OutEdgeList
boost::vecS, // VertexList
boost::undirectedS, // DirectedS
boost::property<boost::vertex_index_t, v_index>, // Vertex property.
boost::no_property, // Edge property (can be enhanced if needed).
boost::no_property, // Graph property.
boost::vecS // EdgeList
> Graph;
typedef boost::property_map<Graph, boost::vertex_index_t>::type vertex_to_int_map;
static_assert(std::is_same_v<typename vertex_to_int_map::value_type, v_index>,
"The vertex property map's value type must be v_index"); when Not sure if this is intended. I decide to open an issue on boost graph boostorg/graph#420 to see whether it is. |
I think it makes sense to split this into two separate issues. One that just fixes the compile error but keeps the status quo. And a second one that fixes all the confusion with the types that seems to be happening in the three .cpp .pxd and .pyx files that are involved here. |
At https://github.com/sagemath/sage/pull/38872/files#diff-5787682a0554d08f4dc34e60e792af0bbf764ecae08c8c941865e2573edf50f0, I have a more "minimal" fix. I'm lacking the background to see which one is "better". v_index source = index[boost::source(*ei, graph)];
v_index target = index[boost::target(*ei, graph)];
double weight = boost::get(boost::edge_weight, graph, *ei);
to_return.push_back({source, {target, weight}}); |
I think we can just do this (which means performing an explicit casting at the use site, possibly adding a note explaining why the casting is needed) (which is what the more minimal fix does.) |
Setting this to CI Fix to resolve the macos build errors on macos. |
this fixes an underlying type confusion in our wrapper that has lead to warnings before but now produces an actual error, see #39249