1. The interface perennial matches

perennial@0.1.0Updated 4 min readView as markdown

Reference: im-rc 15.1.0 and im 15.1.0 (identical API apart from the pointer kind), with the additions of imbl 7.0.2 where they do not conflict. The behaviour of every item is specified in docs/spec/ (clean room); docs/COMPAT.md maps every public item to "same" or "differs, and how".

Crate ↔ target

Target perennial crate Pointer Migration
im-rc 15.1.0 perennial-rc Rc im-rc = { package = "perennial-rc", version = "0.1" }
im 15.1.0 perennial Arc im = { package = "perennial", version = "0.1" }
imbl 7.0.2 perennial generic imbl = { package = "perennial", version = "0.1" }, for code using the shared API

Both crates expose the same paths: the five collections at the root, the modules hashmap, hashset, ordmap, ordset, vector, iter, shared_ptr, the macros hashmap!, hashset!, ordmap!, ordset!, vector!, get_in!, update_in!, and the optional modules proptest and the pool types (feature pool).

Shape decisions

  • Bounds follow im 15.1: Borrow-based lookups (BK: Hash + Eq + ?Sized, K: Borrow<BK>), with_hasher accepting anything Into<Ptr<S>>, hasher() returning &Ptr<S>.
  • Generic types as in imbl: GenericHashMap<K, V, S, P>, GenericHashSet<A, S, P>, GenericOrdMap<K, V, P>, GenericOrdSet<A, P>, GenericVector<A, P> with P: shared_ptr::SharedPointerKind (our own trait, implemented by RcK and ArcK; DefaultSharedPtr is ArcK in perennial and RcK in perennial-rc). The public names are aliases. Unlike imbl's alias, HashMap<K, V, S = RandomState> keeps the hasher parameter, as im's does.
  • imbl additions kept: get_key_value_mut, OrdSet::get, insert_ord_by, insert_ord_by_key, From<[A; N]>, IntoIterator for &mut Vector, Clone for iterators, double-ended exact-size OrdSet consuming iterator, PartialEq across hasher types.
  • Pools (feature pool, im-rc only upstream): the types and with_pool/pool methods exist for compile compatibility; a pool is a size-only handle and allocation is unchanged.

Behaviour decisions where the references disagree or are defective

Item im 15.1 imbl 7.0.2 perennial Why
union value priority (maps) larger map wins, self on a tie self wins self wins matches both crates' documentation; size-dependent priority is a defect
difference alias of symmetric_difference same, deprecated same, deprecated keep the name's meaning so no caller changes behaviour silently
Hash for HashMap/HashSet iteration-order dependent removed kept, order-independent (equal collections hash equally) compiles for im users and fixes the contract
PartialOrd/Ord for HashMap/HashSet iteration-order dependent removed kept, compares the sorted contents (the bounds already require Ord) as above
OrdMap::range len()/size_hint whole-map length (0, Some(n)) exact a wrong ExactSizeIterator is a defect
Vector::sort / sort_by unstable unstable stable a stable order is a valid unstable order; no caller can tell, except by getting the better one
Vector::skip(n > len), truncate(n > len), Focus::split_at(len) panic empty / no-op as imbl matches Vec and slices
panic texts listed in docs/spec listed im's text where both exist drop-in for im-rc callers that match on panic payloads (rare)
ptr_eq of two fresh empty collections false true (maps/sets) true for maps and sets, false for Vector empty collections share no allocation
OrdSet == PartialEq of elements Ord PartialEq Eq is the documented contract of ==

Every row is a differential-test exception with its own named test.

Items decided after the first COMPAT pass

Item Decision
Vector::dot, bincode impls, features bincode, small-chunks, triomphe, ArcTK, shared_ptr::SharedPointer (imbl only) not provided in 0.1: niche, and not part of im's API
Debug for ordmap::RangedIter provided
OrdMap::range / OrdSet::range return type im's shape (ordmap::Iter / ordset::Iter) with an exact len(); RangedIter exists as a type alias of the same iterator so imbl-shaped code compiles
leaked ordmap::NodeDiffIter / NodeDiffItem not provided: internal types that appear in im's docs only by accident
HashSet: From<BTreeSet<A>> by value provided, alongside the by-reference form
imbl's looser bounds (Debug, generic get_prev/get_next over a borrowed key, FusedIterator on ordset::DiffIter) adopted: they accept every program im's bounds accept
OrdSet::diff follows PartialEq, like ==
HashMap/HashSet union result hasher self's, as self's values win
pool sizes pool_size() and the *_pool_size() accessors return the size passed at construction, 0 for a collection made without a pool; feature refpool exists as an alias of pool
features serde, arbitrary, quickcheck, proptest, debug both crates; rayon only in perennial (Rc is not Send)
Vector inline storage (is_inline, ptr_eq of a small vector and its clone) no inline storage: is_inline is true only when empty; a non-empty vector and its unmodified clone are ptr_eq, small ones included. Keeping elements in the struct would make clone O(n) for small vectors and buy nothing measurable
Focus::narrow / FocusMut::narrow with an empty range accepted, giving an empty focus, as slices and imbl do; only ranges outside the view panic (im's text)
a panicking Clone while sorting a shared Vector the panic propagates and the sorted handle is left empty; no element is dropped twice and the other handles keep their elements. Restoring the handle would need a second copy of every element
variance of the type parameters invariant in every parameter: the node pointer is the generic associated type P::Pointer<T>, which Rust treats as invariant. im and imbl are covariant, so code that coerces Vector<&'static T> to Vector<&'a T> must name the shorter lifetime up front