TimelyDataflow / differential-dataflow

An implementation of differential dataflow using timely dataflow on Rust.
MIT License
2.53k stars 182 forks source link

Arrangement GATs #438

Closed frankmcsherry closed 8 months ago

frankmcsherry commented 8 months ago

This PR introduces support for Generic Associated Types for arrangement Key and Val associated types. The types are generic in a lifetime 'storage that corresponds to the shared read-only storage from which they are read. Conventionally these types would be &'a Key and &'a Val for some standard key and value types, like String. By allowing them to vary with lifetimes, we can introduce new types that serve a smart pointers to the corresponding content. This allows for example encoded data returned with a shared codebook, or returning pairs of references rather than a reference to a pair (allowing more columnar support).

The changes are pervasive, but everywhere the theme is that ::Key turns to ::Key<'a> and ::Val turns to ::Val<'a>. More traits also now have an associated KeyOwned and ValOwned type; these are lifetime-less types that each of the lifetimed traits can be converted into. There is a helpful trait MyTrait (better name pending) which describes something like a generalization of ToOwned, without requiring a Borrow implementation, and some convenience methods.

The only "harm" I've found so far is that lifetime GATs can force some 'static bound introductions where they didn't exist before. These are e.g. when you write type Val<'a> = &'a T, then T will need to be outlive all of the Val<'a> up to and including Val<'static>.