Skip to content

Conversation

@Lunderberg
Copy link
Contributor

For most IR types, neither std::hash nor std::equal_to are provided, as it would be ambiguous whether comparisons should be performed with reference equality or structural equality. While this avoids ambiguity in the general case of nested structures, IR variables follow reference equality and are frequently used as lookup keys.

This commit implements a specialization of std::hash and std::equal_to for tvm::GlobalVar, tvm::tir::Var, and tvm::relax::Var. This allows them to be used as lookup keys for std::unordered_set and std::unordered_map without explicitly specifying explicit ObjectPtrHash and ObjectPtrEqual.

For most IR types, neither `std::hash` nor `std::equal_to` are
provided, as it would be ambiguous whether comparisons should be
performed with reference equality or structural equality.  While this
avoids ambiguity in the general case of nested structures, IR
variables follow reference equality and are frequently used as lookup
keys.

This commit implements a specialization of `std::hash` and
`std::equal_to` for `tvm::GlobalVar`, `tvm::tir::Var`, and
`tvm::relax::Var`.  This allows them to be used as lookup keys for
`std::unordered_set` and `std::unordered_map` without explicitly
specifying explicit `ObjectPtrHash` and `ObjectPtrEqual`.
@masahi masahi merged commit 5b5f8d0 into apache:main May 13, 2024
@Lunderberg Lunderberg deleted the qol_std_hash_and_equalto_for_variables branch May 13, 2024 20:18
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.

2 participants