Remove tag in Hc
commit745a1884bb4de1bca4300078bf1873a35c454610
authorJake Bailey (Hacklang) <jakebailey@fb.com>
Wed, 26 Jan 2022 00:14:05 +0000 (25 16:14 -0800)
committerFacebook GitHub Bot <facebook-github-bot@users.noreply.github.com>
Wed, 26 Jan 2022 00:24:34 +0000 (25 16:24 -0800)
tree3b54c0a28711c7a313a68bbae2f7565888e54e1e
parentb8b53cec3ca306c076dab08034d2dacdf97df5d2
Remove tag in Hc

Summary:
Each hash-consed value is associated with a unique tag, so that we can test for equality between values just by comparing the tags. This strategy is described in [this paper](https://www.lri.fr/~filliatr/ftp/publis/hash-consing2.pdf) and implemented in [this Rust library](https://docs.rs/hashconsing/1.3.0/hashconsing/index.html), which may have inspired our own hcons implementation. The paper notes that a tag must be used rather than pointer values because of the garbage collector. While the GC shouldn't be a problem for testing equality (there will still be only one copy of each hash-consed value, and all pointers to it will be equal to one another), the paper describes building balanced-tree datastructures using tags as the key. Using pointers as keys for those data structures wouldn't be suitable, since a hashconsed value may be moved after it is inserted into the container.

This isn't a concern for us: we don't currently have data structures for hash-consed terms which key off the tag or pointer-value, and even if we did, there is no GC to move our ref-counted values. I think we could just use pointer-values rather than tags. This should help performance: when performing an equality test, there's no need to dereference the pointer to get the tag.

Additionally, since there's no longer a need for an HcImpl struct to store the tag, we can more easily hash-cons unsized types like `str`. A later diff in the stack switches the representation of `Symbol` from `Hc<Box<str>>` to `Hc<str>` now that this is possible.

Differential Revision: D33698453

fbshipit-source-id: 7817151c45489cb19bbb78b8d32972ae5245a65f
hphp/hack/src/rupro/lib/hcons/mod.rs