Design decisions

145. @cache fields (2026-11-21)

  • Decision. A struct field marked @cache may be written by the struct's own methods through a read self. No lends result or projection may borrow it. Dsu.find, DsuOf.find and Comb use it.
  • Why. Logically-read methods (path compression, lazy tables, lazy tag pushes) otherwise force var and block calls during walks. 19.10 gave Comb interior mutability as a stdlib privilege; this makes it a general power. Sound because no outside lend can point into the field.
  • Rule. @cache and @law are promises, not unsafe: a broken one gives wrong answers, never undefined behaviour, so codegen never optimizes on a promise (no __restrict from a disjoint law).
  • Invariants. Compiler: no lend of the field escapes, only own methods write it, a cache write is a mut access inside the struct, no unknown calls while the field is lent, derived ==/hash/Ord/print skip it. Author: cache writes change no answer; stress runs check this by undoing them at method exit.
  • Tiers. Proved, trap, promise (@cache, @law), unsafe (@trusted:, @cpp). Everything trusted without proof is an @ attribute from that closed list, and cpl explain lists every site.
  • Reverse. Drop @cache; find returns to mut self.