Open mtreinish opened 1 month ago
I thought about this more overnight, and I think that while specialisation isn't a stable part of Rust, it's hard to make the exact API I sketched above work exactly right, unless we require T: Default
for all Interner
generics - the trick is that Interner::<T>::new
needs to always enforce that the default entry is always created (if T: Default
), and we need specialisation for that to work natively.
I think overall the general scheme works, just the API I roughly sketched in the comment isn't 100% there yet.
I have a change to the interners I want to make once the
DAGCircuit
PR merges that will avoid the need for theVec
here in favour of the static empty slice (which is at least a small saving), but I think the idea of the special "intern key to the 'zero' object" is a good one too. I can see it coming up a lot, and I think it's doable without losing any particular generality in the interners - we can make it likeor something like that, and arrange that the 0 index of
Interner<T: Default>
always corresponds to<T as Default>::default()
._Originally posted by @jakelishman in https://github.com/Qiskit/qiskit/pull/12809#discussion_r1709932633_