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

[QoL][IR] Provide std::hash and std::equal_to for IR Variable types #16909

Merged
merged 2 commits into from
May 13, 2024

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
19 checks passed
@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