google / google/xls

[enhancement?] Avoid comparing or hashing `Node*`

Open
#2,235 0 comments 0 reactions 0 assignees View on GitHub
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.