[enhancement?] Avoid comparing or hashing `Node*`
- Dominant language
- C++
- Stars
- 1.9k
- Forks
- 283
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 135
Description
XLS uses `Node*` heavily to reference Nodes, including checking if `Node*`s are equal and using them as keys for hash tables & sets. This works well for many cases... but leads to a lot of ergonomic issues, and due to potential reuse if the underlying Node is deleted, storing `Node*` while Nodes might be deleted is risky. (For example, see: https://github.com/google/xls/pull/2233)
If we can avoid comparing or hashing `Node*` without losing performance, it seems worth doing so.
To make this possible, we could replace almost all uses of `Node*` with `NodeRef`, as introduced in https://github.com/google/xls/pull/2233. By capturing both the `Node*` for each reference and the node's ID (which is intended to be forever-unique at the Package scope), comparison & hashing are both as cheap as comparing two `int64_t`'s, and accessing the features of the `Node*` still uses the same syntax.
Things get less convenient if we're storing a pointer to a subclass of `Node` (e.g., `StateRead*`), but we could also create a templated version of `NodeRef` for this purpose.
Contributor guide
Assessment
This issue has not been assessed yet.