12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667openstructmoduleA=Trace_core.Internal_.Atomic_endmoduleList_with_len=structtype+'at=|Nil|Consofint*'a*'atletempty:_t=Nillet[@inline]len=function|Nil->0|Cons(i,_,_)->ilet[@inline]consxself=Cons(lenself+1,x,self)endtype'at={max_size:int;create:unit->'a;clear:'a->unit;cached:'aList_with_len.tA.t;}letcreate~max_size~create~clear():_t={max_size;create;clear;cached=A.makeList_with_len.empty}letalloc(typea)(self:at):a=letmoduleM=structexceptionFoundofaendintrywhilematchA.getself.cachedwith|Nil->false|Cons(_,x,tl)asold->ifA.compare_and_setself.cachedoldtlthenraise_notrace(M.Foundx)elsetruedo()done;self.create()withM.Foundx->xletrecycle(self:'at)(x:'a):unit=self.clearx;whilematchA.getself.cachedwith|Cons(i,_,_)wheni>=self.max_size->false(* drop buf *)|old->not(A.compare_and_setself.cachedold(List_with_len.consxold))do()doneletwith_(self:'at)f=letx=allocselfintryletres=fxinrecycleselfx;reswithe->letbt=Printexc.get_raw_backtrace()inrecycleselfx;Printexc.raise_with_backtraceebt