Conversation
Adda0
marked this pull request as ready for review
August 20, 2026 11:29
Specializing std::hash for std::set<A>/std::vector<A> with an arbitrary (possibly built-in) A is undefined behavior: the standard only allows program-defined specializations of standard templates when at least one template argument is program-defined. It also means users can transparently observe mata's hasher through e.g. std::hash<std::set<unsigned>>, even without touching mata types. Replace the std::set/std::vector specializations with mata::utils::SetHash and mata::utils::VectorHash, usable as the explicit Hash template argument of unordered containers, and update the two internal call sites (OrdVector's own std::hash specialization, and a local unordered_map in Nft::lookahead) accordingly. std::hash<std::pair<A, B>> is left as-is for now: it backs the Hash argument of several public API std::unordered_map<std::pair<State, State>, State> parameters (product maps), so removing it would require changing those public signatures. Refs #628.
Specializing std::hash for std::pair<A, B> with arbitrary (possibly built-in) A/B is undefined behavior for the same reason as std::set/ std::vector: the standard only allows program-defined specializations of standard templates when at least one template argument is program-defined. Replace the std::pair specialization with mata::utils::PairHash, usable as the explicit Hash template argument of unordered containers, and update the public API std::unordered_map<std::pair<State, State>, State> parameters (product maps) and their internal call sites accordingly. Refs #628.
…ed product maps The Cython .pxd/.pyx declarations for intersection()/plumbing::intersection() still declared product-map parameters as umap[pair[State, State], State], which no longer matches the C++ signatures after mata::utils::PairHash<State, State> became an explicit template argument. This made the generated C++ fail to compile (mismatched pointer types, and the pair key falling back to the now-removed std::hash<std::pair<A, B>> specialization). Expose mata::utils::PairHash as CPairHash in utils.pxd and pass it as the explicit Hash argument everywhere a product map crosses the Cython/C++ boundary.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Specializing
std::hashforstd::set<A>/std::vector<A>with an arbitrary (possibly built-in)Ais undefined behavior: the standard only allows program-defined specializations of standard templates when at least one template argument is program-defined. It also means users can transparently observe mata's hasher through e.g.std::hash<std::set<unsigned>>, even without touching mata types.Replaces the
std::set/std::vectorspecializations withmata::utils::SetHashandmata::utils::VectorHash, usable as the explicit Hash template argument of unordered containers, and updates the two internal call sites (OrdVector's ownstd::hashspecialization, and a local unordered_map inNft::lookahead) accordingly.std::hash<std::pair<A, B>>is left as-is for now: it backs the Hash argument of several public APIstd::unordered_map<std::pair<State, State>, State>parameters (product maps), so removing it would require changing those public signatures.Refs #628.