It turns out that we have an implementation of WeakHashSet in a compiler:
However, it's semantics are very fishy. I noticed two problems:
1. The WeakReferenceWithEquals caches hashCode. Now imagine that two WeakReferenceWithEquals point at different objects so they store different hashCodes. Later on the underlaying objects get GCed so now equals return true (because null == null) but hashCode would be still different. That breaks the basic contract between equals and hashCode.
2. We do not register a ReferenceQueue so WeakReferenceWithEquals instances themselves are never GC'ed and they block slots in has table. Check implementation of Java's WeakHashmap for inspiration how pruning of slots should be done.