145. @cache fields (2026-11-21)
- Decision. A struct field marked
@cachemay be written by the struct's own methods through a readself. Nolendsresult or projection may borrow it.Dsu.find,DsuOf.findandCombuse it. - Why. Logically-read methods (path compression, lazy tables, lazy
tag pushes) otherwise force
varand block calls during walks. 19.10 gaveCombinterior mutability as a stdlib privilege; this makes it a general power. Sound because no outside lend can point into the field. - Rule.
@cacheand@laware promises, notunsafe: a broken one gives wrong answers, never undefined behaviour, so codegen never optimizes on a promise (no__restrictfrom adisjointlaw). - Invariants. Compiler: no lend of the field escapes, only own
methods write it, a cache write is a
mutaccess inside the struct, no unknown calls while the field is lent, derived==/hash/Ord/printskip 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, andcpl explainlists every site. - Reverse. Drop
@cache;findreturns tomut self.