iddqd, or the hardest kind of unsafe Rust

75 points by sunshowers


mqudsi

If I’m understanding this correctly (on my phone and on the go), this is solvable via a wrapper type and using HashSet/BTreeSet instead of HashMap/BTreeMap. (You don’t even need a wrapper type, but it’s a good call for safety/posterity).

All you need is a zero-size wrapper around the object that has a custom PartialEq/Hash impl that only looks at the field you care about. You can create a second type impl’ing AsRef for the value type to perform searches without a full value.

That’s to reuse the existing HashSet/BTreeSet interface as-is with no unsafe. Instead of wrapping the value/key type you can instead create a new HashSet/BtreeSet wrapper that does that for you.

rjzak

Oxide Computers seems like a pretty cool company, I've been following along for some time. I also greatly appreciate Doom references.

coxley

I'm not that well-versed in the Rust ecosystem, but @sunshowers posts are always a fun read regardless. :) And now I'm thinking on all the times that iddqd would have been really handy.

typesanitizer

To formally verify iddqd, one’s first thought would be to use a model checker like Kani to establish that the maps don’t violate internal invariants. But iddqd is unfortunately a bit too complicated for Kani to handle, and the required proofs blow up beyond what is feasible for the tool.

Could you share more details about this? Is the point the computational complexity in the algorithms used degenerates into worst-case behavior?

This is an interesting case study overall for formal methods, I'm glad you covered that. One might naively think that existing formal verification tools would be able to at least prove the correctness of data structures (given successes at other large-scale projects), but turns out, not all data structures are equal, and doing proofs even in Rust (which I think is considered to be more amenable to proofs compared to languages which allow for unrestricted aliasing), is actually not that easy in practice.


Bit off-topic but I'm curious, how did you make the diagrams? Did you script something one-off? Seems like something special purpose to match the design of the Oxide blog/website, not something more generic.