Lectures onType Theory
Ownership, borrowing, and affine protocols
appendix sectionrules

Ownership, borrowing, and affine protocols

The finite protocol of chapter 19 has states q::=O(A)DSB(A)Xα¯(A), where B is a nonempty finite set and α¯ a nonempty lifetime stack. The complete state-changing rules are

kdom(Ω)
L;Ω,h:O(A)move h as kL;Ω,h:D,k:O(A)
Move
L;Ω,h:O(A)drop hL;Ω,h:D
Drop
αL
L;Ω,h:O(A)beginSαhLα;Ω,h:S{α}(A)
Share-begin
αL
L;Ω,h:SB(A)beginSαhLα;Ω,h:SB{α}(A)
Share-nest
B{α}
Lα;Ω,h:SB(A)endSαhL;Ω,h:SB{α}(A)
Share-end
B={α}
Lα;Ω,h:SB(A)endSαhL;Ω,h:O(A)
Share-return
αL
L;Ω,h:O(A)beginXαhLα;Ω,h:Xα(A)
Ex-begin
βL
L;Ω,h:Xα¯(A)reborrowXβhLβ;Ω,h:Xα¯β(A)
Ex-reborrow
α¯ϵ
Lβ;Ω,h:Xα¯β(A)endXβhL;Ω,h:Xα¯(A)
Ex-pop
Lα;Ω,h:Xα(A)endXαhL;Ω,h:O(A)
Ex-return

Access and sequencing are

q{O(A),SB(A),Xα¯(A)}
L;Ω,h:qreadhL;Ω,h:q
Read
q{O(A),Xα¯(A)}v:A
L;Ω,h:qwritehvL;Ω,h:q
Write
L;Ωc1L1;Ω1L1;Ω1c2L2;Ω2
L;Ωc1;c2L2;Ω2
Seq

The runtime realization performs the same mode update. Move transfers the payload to the fresh destination, drop removes it, read leaves it unchanged, and write replaces it by the displayed closed value. Agreement is L;RownΩ; it requires equal domains and modes, well-typed live payloads, and every lifetime in a shared set or exclusive stack to occur in L with the stack-induced order.

The affine target representation for the local simulation is R(L;Ω)=Life(L)Caph1(Ω(h1))Caphm(Ω(hm)), where h1,,hm is the ordered domain of Ω. Each primitive protocol derivation contributes an affine constant from the representation of its premise to the representation of its conclusion; sequencing is affine composition. The primitive contracts on the canonical input in one target step.

The selected Affe rules are XCΓ,x:σ=(Γ1,[x:σ]bn)(Γ2,x:σ)Susp,

[x:τx]bnΓCxΓregΓCΓe:τCkind(τ)Ln1
CΓ{|e|}x,bn:τ
Region
&bx:&kσΓCx,τx=inst(Γ,σ)CCxdrop(Γx)
CΓ&bx:&kτx
Borrow

The paper-facing Pure Borrow interface includes runBO:Linearly(α.BOα(Endαa))a,borrow:Linearlya(MutαaLendαa),share:MutαaUr(Shareαa),reclaim:LendαaEndαa. Pure Borrow keeps its two executions distinct. A mutative configuration is (H;μ;x) and steps by m; a denotational configuration is (G;x) and steps by d. Allocation, update, lifetime end, and reclamation respectively mutate global memory in the first semantics and construct a pure reference, update a borrow history, move the history to a dead token, and replay that history in the second. The association judgment is MAD. These signatures do not identify either execution with the finite protocol above.

Search the book

Type to search the local edition.