Capability and Region Types for Typed Memory Management
Prerequisites. Direct starred prerequisites: none. No later core chapter depends on this route.
Let a source computation bind one integer that it never returns: 𝗅𝖾𝗍𝑥=1𝗂𝗇2𝖾𝗇𝖽. Region inference may place the dead binding in a fresh local region while placing the returned integer in an outer region. Three static facts are distinct: the result must not mention the local region, the body may access it only while it is live, and explicit deallocation requires unique authority. Tofte–Talpin region inference proves the first two [TT97]; the Walker–Crary–Morrisett capability calculus proves the third [WCM00].
Tofte–Talpin region inference
Write 𝜌 for a region variable, 𝜖 for an effect variable, and 𝜙 for a finite region effect: a set of effect variables and actions 𝗀𝖾𝗍(𝜌) and 𝗉𝗎𝗍(𝜌). A type with place is a pair 𝜇=(𝜏,𝜌); an arrow type carries the arrow effect𝜖.𝜙, the pair of a handle 𝜖 and a latent effect 𝜙. The exact source and target cores are 𝜏::=𝗂𝗇𝗍∣𝛼∣𝜇1𝜖.𝜙←←←←←←→𝜇2,𝜇::=(𝜏,𝜌),𝑒::=𝑐∣𝑥∣𝜆𝑥.𝑒∣𝑒1𝑒2∣𝗅𝖾𝗍𝑥=𝑒1𝗂𝗇𝑒2𝖾𝗇𝖽∣𝗅𝖾𝗍𝗋𝖾𝖼𝑓(𝑥)=𝑒1𝗂𝗇𝑒2𝖾𝗇𝖽,𝑒′::=𝑐𝖺𝗍𝜌∣𝑥∣𝑓[𝜌1,…,𝜌𝑘]𝖺𝗍𝜌∣𝜆𝑥.𝑒′𝖺𝗍𝜌∣𝑒′1𝑒′2∣𝗅𝖾𝗍𝑥=𝑒′1𝗂𝗇𝑒′2𝖾𝗇𝖽∣𝗅𝖾𝗍𝗋𝖾𝖼𝑓[⃗𝜌](𝑥)𝖺𝗍𝜌=𝑒′1𝗂𝗇𝑒′2𝖾𝗇𝖽∣𝗅𝖾𝗍𝗋𝖾𝗀𝗂𝗈𝗇𝜌𝗂𝗇𝑒′𝖾𝗇𝖽. The full type grammar adds region- and effect-polymorphic schemes. A type environment TE assigns those schemes to source variables. Write frv(𝑋) for the free region variables of the displayed object or tuple of objects 𝑋. The inference judgment TE⊢𝑒⇝𝑒′:𝜇,𝜙 means that source term 𝑒 translates to annotated term 𝑒′, has type with place 𝜇, and may perform the region actions in 𝜙.
Rules 20, 21, 25, and 27 suffice for the opening calculation:
TE⊢𝑐⇝𝑐𝖺𝗍𝜌:(𝗂𝗇𝗍,𝜌),{𝗉𝗎𝗍(𝜌)}
RI-Const
TE(𝑥)=(𝜏,𝜌)
TE⊢𝑥⇝𝑥:(𝜏,𝜌),∅
RI-Var
TE⊢𝑒1⇝𝑒′1:(𝜏1,𝜌1),𝜙1TE,𝑥:(𝜏1,𝜌1)⊢𝑒2⇝𝑒′2:𝜇,𝜙2TE⊢𝗅𝖾𝗍𝑥=𝑒1𝗂𝗇𝑒2𝖾𝗇𝖽⇝𝗅𝖾𝗍𝑥=𝑒′1𝗂𝗇𝑒′2𝖾𝗇𝖽:𝜇,𝜙1∪𝜙2RI−Let Rule 27 is the scope boundary: TE⊢𝑒⇝𝑒′:𝜇,𝜙𝜌∉frv(TE,𝜇)TE⊢𝑒⇝𝗅𝖾𝗍𝗋𝖾𝗀𝗂𝗈𝗇𝜌𝗂𝗇𝑒′𝖾𝗇𝖽:𝜇,𝜙∖{𝗀𝖾𝗍(𝜌),𝗉𝗎𝗍(𝜌)}RI−Letregion There is no premise forbidding 𝜌 in the body effect. The rule exists precisely to discharge those local effects. Freshness concerns the surrounding type environment and the result type-with-place.
Take an outer region 𝜌0 for the returned integer and a fresh local region 𝜌 for the dead binding. The inferred target is 𝗅𝖾𝗍𝗋𝖾𝗀𝗂𝗈𝗇𝜌𝗂𝗇𝗅𝖾𝗍𝑥=1𝖺𝗍𝜌𝗂𝗇2𝖺𝗍𝜌0𝖾𝗇𝖽𝖾𝗇𝖽, and its effect calculation is 𝜙body={𝗉𝗎𝗍(𝜌),𝗉𝗎𝗍(𝜌0)},𝜙whole=𝜙body∖{𝗀𝖾𝗍(𝜌),𝗉𝗎𝗍(𝜌)}={𝗉𝗎𝗍(𝜌0)}. The result type with place is (𝗂𝗇𝗍,𝜌0), so 𝜌∉frv(𝜇); the empty initial TE discharges the other freshness premise.
★☆☆ Reconstruct this derivation. Mark the premise discharged by freshness and the one body effect removed by RI-Letregion; explain why 𝗉𝗎𝗍(𝜌0) remains.
Let P map types, type schemes, and environments to their Milner counterparts by erasing places, region variables, and effects. Fixing 𝜌0 and 𝜖0, let R relate Milner objects to region objects by choosing 𝜌0 at every place and the arrow effect 𝜖0.{𝗀𝖾𝗍(𝜌0),𝗉𝗎𝗍(𝜌0),𝜖0} at every arrow; its clauses for simple and compound schemes preserve their distinct quantifier shapes. These are the projection and relation of Tofte–Talpin Section 5.3.
Proof of Theorem 50.1 — Region inference refines Milner typing
Proof. Part 1 is Tofte–Talpin Lemma 5.1, by induction on the region derivation. Part 2 is Lemma 5.2. The displayed R is a relation rather than a function because simple and compound type schemes have different shapes. The variable case selects the appropriate scheme rule; the lambda case uses the effect-enlargement premise. Lemma 5.3 gives simultaneous type, region, and effect substitution. Neither direction claims principal effects or optimal placement. ◻
Semantic correspondence
The ordinary semantics evaluates 𝐸⊢𝑒⇓𝑣 in source environment 𝐸. The region semantics evaluates 𝑠,𝑉𝐸,𝑅⊢𝑒′⇓𝑣′,𝑠′, where 𝑅 maps region variables to concrete region names and 𝑠 is a region-indexed store. Tofte and Talpin’s coinductive relation C(𝑅,TE,𝐸,𝑠,𝑉𝐸)𝗐.𝗋.𝗍.𝜙∪𝜙′ relates configurations. A region environment 𝑅connects an effect 𝜙 to 𝑠 when frv(𝜙)⊆dom(𝑅) and 𝑅(𝜌)∈dom(𝑠) for every 𝜌∈frv(𝜙); 𝑅≡𝜙𝑅′ means agreement on frv(𝜙).
Assume TE⊢𝑒⇝𝑒′:𝜇,𝜙,𝐸⊢𝑒⇓𝑣,C(𝑅,TE,𝐸,𝑠,𝑉𝐸)𝗐.𝗋.𝗍.𝜙∪𝜙′,𝑅connects𝜙∪𝜙′to𝑠,𝑅′≡𝜙∪𝜙′𝑅,frv(𝑒′)⊆dom(𝑅′). Then some 𝑠′,𝑣′ satisfy 𝑠,𝑉𝐸,𝑅′⊢𝑒′⇓𝑣′,𝑠′andC(𝑅′,𝜇,𝑣,𝑠′,𝑣′)𝗐.𝗋.𝗍.𝜙′.
Proof of Theorem 50.2 — Tofte–Talpin semantic correspondence
Proof. This is Theorem 6.1 of Tofte and Talpin. Section 7 defines consistency; Section 8 proves its closure and store-extension properties. Section 9 uses an outer induction on the source-evaluation derivation and, in each case, an inner induction on the region-inference derivation. In the region case, Lemma 5.3 permits choosing 𝜌∉frv(𝜙′) in addition to RI-Letregion’s freshness for TE and 𝜇. Allocate a fresh concrete region, invoke the induction hypothesis, and remove it; the two freshness facts separately protect the result and continuation. This chapter imports that complete proof for the exact source and target cores displayed above. ◻
Effects approximate future region use, whereas tracing collection follows reachability; neither approximation contains the other. The later ML Kit work turns constraints into spreading and fixed-point computations. The historical and engineering account belongs to the region-memory retrospective [TBEH04], not to Theorem 6.1.
The capability machine
Walker, Crary, and Morrisett use region variables 𝜌, concrete region names 𝜈, and regions 𝑟::=𝜌∣𝜈. The runtime value 𝗁𝖺𝗇𝖽𝗅𝖾(𝜈), a region handle, is distinct from the compile-time name 𝜈. Selected syntax is 𝐶::=𝜀∣∅∣{𝑟𝜑}∣𝐶1⊕𝐶2∣――𝐶,𝜑::=1∣+,Δ::=⋅∣Δ,𝜌:𝖱𝗀𝗇∣Δ,𝜀≤𝐶,𝑣::=𝑥∣𝑖∣𝜈.ℓ∣𝗁𝖺𝗇𝖽𝗅𝖾(𝑟)∣⋯,ℎ::=⟨𝑣0,…,𝑣𝑛−1⟩∣𝖿𝗂𝗑𝑓[Δ](𝐶,⃗𝑥:⃗𝜏).𝑒∣⋯,𝑑::=𝑥=𝑣∣𝑥=ℎ𝖺𝗍𝑣∣𝑥=𝜋𝑖𝑣∣𝗇𝖾𝗐𝗋𝗀𝗇𝜌,𝑥∣𝖿𝗋𝖾𝖾𝗋𝗀𝗇𝑣,𝑒::=𝗅𝖾𝗍𝑑𝗂𝗇𝑒∣𝗂𝖿𝟢𝑣𝗍𝗁𝖾𝗇𝑒𝖾𝗅𝗌𝖾𝑒∣𝑣(⃗𝑣)∣𝗁𝖺𝗅𝗍𝑣. The capability variable𝜀 ranges over unknown authority. The duplicable authority{𝑟+} permits shared access; the unique authority{𝑟1} permits destruction. The stripping operation――𝐶 changes unique flags to duplicable ones, distributes over ⊕, and is idempotent. In particular, ∅⊕𝐶=𝐶,―――{𝑟1}={𝑟+},―――――𝐶1⊕𝐶2=―――𝐶1⊕―――𝐶2,――――𝐶=――𝐶. The judgment Δ⊢𝐶1=𝖢𝖺𝗉𝐶2 is the congruence generated by these equations, associativity, commutativity, and the bounded variables in Δ. Write Δ⊢𝐶1≤𝖢𝖺𝗉𝐶2 when some 𝐶3 satisfies Δ⊢𝐶1=𝖢𝖺𝗉𝐶2⊕𝐶3. Stripped authority is idempotent; {𝑟1}⊕{𝑟1} is not satisfiable. Subcapability admits {𝑟1}≤{𝑟+}, not the converse.
A memory𝑀 maps 𝜈 to finite region heaps. A memory typeΨ maps each 𝜈 to a region typeΥ, which maps allocated labels to their heap-value types. The judgment ⊢𝑀:Ψ checks the same region names and gives every allocated label the heap-value type recorded by Υ. The declaration judgment Ψ;Δ;Γ;𝐶⊢𝑑⇒Δ′;Γ′;𝐶′ threads authority. The expression rules connecting it to programs are
Ψ;Δ;Γ;𝐶⊢𝑑⇒Δ′;Γ′;𝐶′Ψ;Δ′;Γ′;𝐶′⊢𝑒
Ψ;Δ;Γ;𝐶⊢𝗅𝖾𝗍𝑑𝗂𝗇𝑒
Cap-LetDec
Ψ;Δ;Γ⊢𝑣:𝗂𝗇𝗍Δ⊢𝐶=𝖢𝖺𝗉∅
Ψ;Δ;Γ;𝐶⊢𝗁𝖺𝗅𝗍𝑣
Cap-Halt
Four declaration rules expose the resource boundary: 𝜌∉dom(Δ)𝑥∉dom(Γ)Ψ;Δ;Γ;𝐶⊢𝗇𝖾𝗐𝗋𝗀𝗇𝜌,𝑥⇒Δ,𝜌:𝖱𝗀𝗇;Γ,𝑥:𝜌𝗁𝖺𝗇𝖽𝗅𝖾;𝐶⊕{𝜌1}Cap−NewΨ;Δ;Γ⊢𝑣:𝑟𝗁𝖺𝗇𝖽𝗅𝖾Ψ;Δ;Γ⊢ℎ𝖺𝗍𝑟:𝜏Δ⊢𝐶≤𝖢𝖺𝗉𝐶′⊕{𝑟+}Ψ;Δ;Γ;𝐶⊢𝑥=ℎ𝖺𝗍𝑣⇒Δ;Γ,𝑥:𝜏;𝐶Cap−AllocΨ;Δ;Γ⊢𝑣:⟨𝜏0,…,𝜏𝑛−1⟩𝖺𝗍𝑟Δ⊢𝐶≤𝖢𝖺𝗉𝐶′⊕{𝑟+}0≤𝑖<𝑛Ψ;Δ;Γ;𝐶⊢𝑥=𝜋𝑖𝑣⇒Δ;Γ,𝑥:𝜏𝑖;𝐶Cap−ProjectΨ;Δ;Γ⊢𝑣:𝑟𝗁𝖺𝗇𝖽𝗅𝖾Δ⊢𝐶=𝖢𝖺𝗉𝐶′⊕{𝑟1}Ψ;Δ;Γ;𝐶⊢𝖿𝗋𝖾𝖾𝗋𝗀𝗇𝑣⇒Δ;Γ;𝐶′Cap−Free For example, Cap-New followed by Cap-Alloc derives allocation under {𝜌1}, since unique authority is a subcapability of duplicable access authority. Cap-Free then consumes exactly the unique occurrence.
The machine dynamics has the same phase distinction: (𝑀,𝗅𝖾𝗍𝗇𝖾𝗐𝗋𝗀𝗇𝜌,𝑥𝗂𝗇𝑒)⟶(𝑀[𝜈↦∅],𝑒[𝜈,𝗁𝖺𝗇𝖽𝗅𝖾(𝜈)/𝜌,𝑥]),(𝑀,𝗅𝖾𝗍𝑥=ℎ𝖺𝗍𝗁𝖺𝗇𝖽𝗅𝖾(𝜈)𝗂𝗇𝑒)⟶(𝑀[𝜈.ℓ↦ℎ],𝑒[𝜈.ℓ/𝑥]),(𝑀,𝗅𝖾𝗍𝑥=𝜋𝑖(𝜈.ℓ)𝗂𝗇𝑒)⟶(𝑀,𝑒[𝑣𝑖/𝑥]),(𝑀,𝗅𝖾𝗍𝖿𝗋𝖾𝖾𝗋𝗀𝗇𝗁𝖺𝗇𝖽𝗅𝖾(𝜈)𝗂𝗇𝑒)⟶(𝑀∖𝜈,𝑒), where 𝜈∉dom(𝑀) in the first line; 𝜈∈dom(𝑀) and ℓ is fresh in its heap in the second; and 𝑀(𝜈.ℓ)=⟨𝑣0,…,𝑣𝑛−1⟩ with 0≤𝑖<𝑛 in the third. The free rule likewise requires 𝜈∈dom(𝑀).
If Ψ={𝜈1:Υ1,…,𝜈𝑛:Υ𝑛}, then Ψ⊧𝐶 holds exactly when the 𝜈𝑖 are distinct and ⋅⊢𝐶=𝖢𝖺𝗉{𝜈𝜑11}⊕⋯⊕{𝜈𝜑𝑛𝑛}. A closed state is well typed by the program rule ⊢𝑀:ΨΨ⊧𝐶Ψ;⋅;⋅;𝐶⊢𝑒⊢(𝑀,𝑒)Cap−Program The constructor and term contexts are empty; otherwise an open stuck term could pass for a program.
If Ψ⊧𝐶, then 𝜈∈dom(Ψ) exactly when 𝐶 contains authority for 𝜈. Equality and subcapability preserve this set, and removing a unique {𝜈1} preserves satisfiability for Ψ∖𝜈.
Proof of Lemma 50.4 — Capability–memory correspondence
Proof. Invert the single satisfiability rule. The normal form lists exactly the distinct names in Ψ. Capability-equality cardinality preservation keeps unique occurrences unique; stripping may change 1 to + but does not change the name set. Removing the unique singleton and the matching memory-type entry yields the final clause. These are the report’s CECP lemma and Lemmas 34–35. ◻
Proof of Theorem 50.5 — Capability preservation and progress
Proof. These are technical-report Lemmas 36–37. Preservation uses substitution, memory-type extension, and memory garbage collection. In the free case, Cap-Free exposes a unique singleton and lemma 50.4 removes it together with its region. Progress inverts Cap-Program; canonical memory typing turns every typed address into an allocated label, while satisfiability turns every required region authority into a live concrete region. Thus allocation, projection, and free have matching dynamic rules. ◻
Proof. A terminating run ends in a well-typed halt by preservation and progress. Invert Cap-Halt. By lemma 50.4, satisfiability under empty authority forces Ψ={}. Inversion of memory typing forces 𝑀={}. This is technical-report Theorem 40. ◻
A separate region calculus and its CPS translation
The source of the Walker–Crary–Morrisett translation is not the inference language above. It is a second, explicitly typed region calculus: 𝜓::=𝛼∣∅∣{𝑟}∣𝜓1∪𝜓2,𝑒𝑅::=⋯∣⟨𝑒1,…,𝑒𝑛⟩𝖺𝗍𝑒ℎ∣𝜋𝑖𝑒∣𝗅𝖾𝗍𝗋𝖾𝗀𝗂𝗈𝗇𝜌,𝑥𝜌𝗂𝗇𝑒. Its effects record region access without distinguishing 𝗀𝖾𝗍 from 𝗉𝗎𝗍. Its delimiter binds both a compile-time region variable and the runtime handle. The projection and delimiter rules are Δ;Γ⊢𝑅𝑒:⟨𝜏0,…,𝜏𝑛−1⟩𝖺𝗍𝑟,𝜓0≤𝑖<𝑛Δ;Γ⊢𝑅𝜋𝑖𝑒:𝜏𝑖,𝜓∪{𝑟}R−Project and Δ,𝜌:𝖱𝗀𝗇;Γ,𝑥𝜌:𝜌𝗁𝖺𝗇𝖽𝗅𝖾⊢𝑅𝑒:𝜏,𝜓𝜌∉ftv(𝜏)∪dom(Δ)𝑥𝜌∉dom(Γ)Δ;Γ⊢𝑅𝗅𝖾𝗍𝗋𝖾𝗀𝗂𝗈𝗇𝜌,𝑥𝜌𝗂𝗇𝑒:𝜏,𝜓∖{𝜌}R−Letregion Again the body may mention 𝜌; the conclusion discharges it.
The running region-calculus term is 𝑒𝗉𝖺𝗂𝗋𝖥𝗂𝗋𝗌𝗍=𝗅𝖾𝗍𝗋𝖾𝗀𝗂𝗈𝗇𝜌,𝑥𝜌𝗂𝗇𝜋0(⟨1,2⟩𝖺𝗍𝑥𝜌). Allocation gives the pair type ⟨𝗂𝗇𝗍,𝗂𝗇𝗍⟩𝖺𝗍𝜌; R-Project returns an integer while retaining effect {𝜌}, and R-Letregion discharges that effect because the result type contains no free 𝜌.
The named effect-to-capability translation is total on that grammar: 𝖢𝖺𝗉𝖮𝖿(𝛼)=𝛼,𝖢𝖺𝗉𝖮𝖿(∅)=∅,𝖢𝖺𝗉𝖮𝖿({𝑟})={𝑟+},𝖢𝖺𝗉𝖮𝖿(𝜓1∪𝜓2)=𝖢𝖺𝗉𝖮𝖿(𝜓1)⊕𝖢𝖺𝗉𝖮𝖿(𝜓2). Every translated arrow effect is stripped, hence duplicable; equality of such capabilities is therefore set equality. Terms use the context- and continuation-indexed translation 𝖢𝖯𝖲Δ;Γ;Θ(𝑒;𝑘). The delimiter uses a WCM meta-level continuation, written 𝑘=⟨𝑥𝑘;𝑒𝑘⟩. Its application is the target term 𝖺𝗉𝗉𝗅𝗒(𝑘,𝑣)=𝗅𝖾𝗍𝑥𝑘=𝑣𝗂𝗇𝑒𝑘. The delimiter clause is 𝖢𝖯𝖲Δ;Γ;Θ(𝗅𝖾𝗍𝗋𝖾𝗀𝗂𝗈𝗇𝜌,𝑥𝜌𝗂𝗇𝑒;𝑘)=𝗅𝖾𝗍𝗇𝖾𝗐𝗋𝗀𝗇𝜌,𝑥𝜌𝗂𝗇𝖢𝖯𝖲Δ,𝜌:𝖱𝗀𝗇;Γ,𝑥𝜌:𝜌𝗁𝖺𝗇𝖽𝗅𝖾;Θ′(𝑒;⟨𝑥′;𝗅𝖾𝗍𝖿𝗋𝖾𝖾𝗋𝗀𝗇𝑥𝜌𝗂𝗇𝖺𝗉𝗉𝗅𝗒(𝑘,𝑥′)⟩), where Θ′ extends both the current capability 𝐶Θ and its bound 𝐵Θ by {𝜌1}. No object-level lambda is introduced.
If the closed region-calculus term 𝑒 has type 𝗂𝗇𝗍 and empty effect, then its CPS translation applied to a fresh halting continuation is well typed under empty memory, constructor, term, and capability contexts.
Proof of Theorem 50.8 — Region-to-capability CPS type preservation
Proof. This is technical-report Theorem 52. Its strengthened induction carries a translation environment Θ, current capability 𝐶Θ, and bound 𝐵Θ satisfying 𝐵Θ=𝐵Θ⊕𝖢𝖺𝗉𝖮𝖿(𝜓). Lemmas 43–48 preserve well-formedness, substitution, equality, and effect inclusion. In the R-Letregion case both 𝐶Θ and the bound grow by {𝜌1}, the translated body runs while 𝜌 is live, and the continuation is typed by Cap-Free. Instantiating the strengthened result with empty contexts yields the theorem. ◻
For 𝑒𝗉𝖺𝗂𝗋𝖥𝗂𝗋𝗌𝗍, dynamics chooses a concrete 𝜈. The authority calculation is ∅𝐶𝑎𝑝−𝑁𝑒𝑤←←←←←←←←←←←←←←←→{𝜈1}𝐶𝑎𝑝−𝐴𝑙𝑙𝑜𝑐,𝐶𝑎𝑝−𝑃𝑟𝑜𝑗𝑒𝑐𝑡←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←→{𝜈1}𝐶𝑎𝑝−𝐹𝑟𝑒𝑒𝗁𝖺𝗇𝖽𝗅𝖾(𝜈)←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←→∅. After the last arrow, both 𝑀(𝜈) and authority for 𝜈 are absent.
★☆☆ Starting from empty 𝑀,Ψ,𝐶, write all three after Cap-New, Cap-Alloc, Cap-Project, and Cap-Free. Cite the premise that forbids projection after free.
Cyclone combines explicit handles, lexically scoped regions, effects, local inference, and region subtyping in a C-like language [GMJ^+02]. Let 𝛾⊢𝑟long⪰𝑟short mean that the region-order context 𝛾 proves the first region outlives the second. A pointer into the longer-lived region may be used where the shorter guarantee is expected: 𝛾⊢𝑟long⪰𝑟shortΔ;𝛾⊢𝗉𝗍𝗋(𝜏,𝑟long)≤𝗉𝗍𝗋(𝜏,𝑟short)Cyc−Region−Sub The reverse coercion is not derivable.
Cyclone’s right-expression judgment has the form Δ;Γ;𝛾;𝜖⊢𝗋𝗁𝗌𝑒:𝜏. Here Δ binds type and region names, Γ binds values, 𝛾 records outlives constraints, and the live-region effect𝜖 is a set of regions—not a set of 𝗀𝖾𝗍/𝗉𝗎𝗍 actions. For a live lexical region 𝑟, the two relevant judgments are Δ;Γ,ℎ𝑟:𝑟𝗁𝖺𝗇𝖽𝗅𝖾;𝛾;{𝑟}⊢𝗋𝗁𝗌𝖺𝗅𝗅𝗈𝖼(ℎ𝑟,7):𝗉𝗍𝗋(𝗂𝗇𝗍,𝑟),Δ;Γ,ℎ𝑟:𝑟𝗁𝖺𝗇𝖽𝗅𝖾,𝑝:𝗉𝗍𝗋(𝗂𝗇𝗍,𝑟);𝛾;{𝑟}⊢𝗋𝗁𝗌𝗋𝖾𝖺𝖽(𝑝):𝗂𝗇𝗍,eval(𝗋𝖾𝗀𝗂𝗈𝗇𝑟𝗂𝗇(𝖺𝗅𝗅𝗈𝖼;𝗋𝖾𝖺𝖽))=(7,region𝑟deallocated). The first two lines expose the core context discipline; the last is a bounded execution schematic, not executable Cyclone code. The cited technical report proves type soundness [GMJ^+01]. The PLDI paper summarizes the design. Neither document proves correspondence for a particular compiler revision.
An L3 configuration is (𝜎,𝑒). The linear type 𝖢𝖺𝗉𝜌𝜏 owns the store fact that abstract location 𝜌 contains a 𝜏. The type 𝖯𝗍𝗋𝜌 is also linear; only !𝖯𝗍𝗋𝜌 is duplicable. The three source rules are
Δ;Γ⊢𝑒:𝜏
Δ;Γ⊢𝗇𝖾𝗐𝑒:∃𝜌.(𝖢𝖺𝗉𝜌𝜏⊗!𝖯𝗍𝗋𝜌)
L3-New
Δ;Γ⊢𝑒:∃𝜌.(𝖢𝖺𝗉𝜌𝜏⊗!𝖯𝗍𝗋𝜌)
Δ;Γ⊢𝖿𝗋𝖾𝖾𝑒:∃𝜌.𝜏
L3-Free
Δ;Γ1⊢𝑒1:𝖢𝖺𝗉𝜌𝜏1Δ;Γ2⊢𝑒2:𝖯𝗍𝗋𝜌Δ;Γ3⊢𝑒3:𝜏3Δ;Γ1,Γ2,Γ3⊢𝗌𝗐𝖺𝗉𝑒1𝑒2𝑒3:𝖢𝖺𝗉𝜌𝜏3⊗𝜏1L3−Swap Thus swap consumes its pointer and returns only the updated capability and the old content. Its root dynamics, together with allocation and deallocation, is (𝜎,𝗇𝖾𝗐𝑣)⟶𝖫𝟥(𝜎[ℓ↦𝑣],⟨ℓ,⟨𝖼𝖺𝗉,!𝗉𝗍𝗋(ℓ)⟩⟩),(𝜎[ℓ↦𝑣],𝖿𝗋𝖾𝖾⟨ℓ,⟨𝖼𝖺𝗉,!𝗉𝗍𝗋(ℓ)⟩⟩)⟶𝖫𝟥(𝜎,⟨ℓ,𝑣⟩),(𝜎[ℓ↦𝑣1],𝗌𝗐𝖺𝗉𝖼𝖺𝗉(𝗉𝗍𝗋(ℓ))𝑣2)⟶𝖫𝟥(𝜎[ℓ↦𝑣2],⟨𝖼𝖺𝗉,𝑣1⟩).
If Δ;Γ⊢𝑒:𝜏, then that judgment belongs to the source’s semantic interpretation. Hence a closed well-typed term terminates at a final configuration in the value interpretation of 𝜏.
Proof. This is Theorem 3.1 and Corollary 3.1 of [AFM07]. Their logical relation interprets 𝖢𝖺𝗉ℓ𝜏 by a singleton owned store fragment and 𝖯𝗍𝗋ℓ by an empty fragment; the fundamental induction therefore validates the three rules and frames every disjoint store fragment. ◻
For a cell initially containing 7, swapping in a pair transforms before:𝖢𝖺𝗉𝜌𝗂𝗇𝗍,after:𝖢𝖺𝗉𝜌(𝗂𝗇𝗍×𝗂𝗇𝗍). An unrestricted reference calculus must keep one fixed content type; it cannot validate this strong update without an additional exclusivity argument.
In 𝜆𝑈𝐿𝗋𝗀𝗇, a configuration (𝜓,𝑒) pairs a region store with a term; 𝜓(𝜈) is the heap for concrete region 𝜈. Suppressing the source’s explicit (U/L) wrappers, the two management interfaces have the shapes 𝗇𝖾𝗐𝗋𝗀𝗇:1⊸∃𝜌.(𝖼𝖺𝗉𝜌⊗𝗁𝗇𝖽𝜌),𝖿𝗋𝖾𝖾𝗋𝗀𝗇:∀𝜌.(𝖼𝖺𝗉𝜌⊗𝗁𝗇𝖽𝜌)⊸1. A linear region capability is threaded through 𝗇𝖾𝗐, 𝗋𝖾𝖺𝖽, and 𝗐𝗋𝗂𝗍𝖾; the handle is unrestricted, but it cannot justify destruction without the matching linear capability. The root allocation and deallocation steps have the shape (𝜓,𝗇𝖾𝗐𝗋𝗀𝗇∗)⟶𝗅𝗋(𝜓[𝜈↦{}],𝗉𝖺𝖼𝗄𝜈⟨𝖼𝖺𝗉,𝗁𝗇𝖽(𝜈)⟩),(𝜓[𝜈↦𝐻],𝖿𝗋𝖾𝖾𝗋𝗀𝗇𝜈⟨𝖼𝖺𝗉,𝗁𝗇𝖽(𝜈)⟩)⟶𝗅𝗋(𝜓,∗).
Proof. This is Theorem 1 of [FMA06]. The paper reports a Twelf verification for a richer target. The displayed theorem is only target safety; its lexical-region, first-class-region, and unique-pointer encodings are sketches rather than separately stated preservation theorems. ◻
For the paper’s FRGN translation, a stack of regions becomes a nested linear tuple of capabilities. The 𝗅𝖾𝗍𝖱𝗀𝗇 clause allocates a fresh capability, pairs it onto that tuple, translates the body, then projects the same capability and feeds it to 𝖿𝗋𝖾𝖾𝗋𝗀𝗇. Consequently the one-step interface calculation is 𝑆⟼𝖥𝖱𝖦𝖭𝑆⊗𝖼𝖺𝗉𝜌⟼𝖥𝖱𝖦𝖭𝑆⊗𝖼𝖺𝗉𝜌⟼𝖥𝖱𝖦𝖭𝑆. The first and last arrows are the displayed allocation and deallocation steps; the middle arrow summarizes accesses that thread the capability. This is a representation calculation at the paper’s translation signature, not a separate theorem for the sketched Cyclone encodings.
The monadic region interface has the rank-2 delimiter 𝗋𝗎𝗇𝖱𝖦𝖭:∀𝛼.(∀𝛾.𝖱𝖦𝖭𝖧𝖺𝗇𝖽𝗅𝖾𝛾→𝖱𝖦𝖭𝛾𝛼)→𝛼. Store-tower typing records live stacks and regions; command evaluation threads the selected region store, and leaving 𝗋𝗎𝗇𝖱𝖦𝖭 removes the hidden region. If 𝑠,𝑟 are fresh, its root evaluation extends a tower 𝑇 by an empty one-region stack, evaluates the command there, and then substitutes dead stack and region markers in the result: 𝑇;𝗋𝗎𝗇𝖱𝖦𝖭[𝜏]𝑣⇓𝑣′[∘/𝑠][∙/𝑟],afterevaluationunder𝑇,𝑠↦(⋅,𝑟↦{}).
Every closed well-typed FRGN expression either diverges or evaluates to a value of the same type. The SEC-to-FRGN translation preserves semantics and is correct for closed programs.
Proof. Preservation, progress, and soundness are Theorems 3.1–3.3; translation preservation and closed-program correctness are Theorems 5.1–5.2 of [FM06]. The source proofs carry tower-domain typing through fresh-stack extension and substitute the dead markers on exit. ◻
Parametricity prevents a result of 𝗋𝗎𝗇𝖱𝖦𝖭 from exposing 𝛾. An existential package could hide a name but still permit the package to escape; the rank-2 interface instead scopes every client of the handle under the quantifier. A one-cell run allocates, reads, and removes its store before returning the integer: 𝗋𝗎𝗇𝖱𝖦𝖭(Λ𝛾.𝜆ℎ.𝗇𝖾𝗐ℎ7≫=𝖥𝖱𝖦𝖭𝜆𝑟.𝗋𝖾𝖺𝖽𝑟)⇓7.
Affe combines ML inference with affine kinds and scoped shared or exclusive borrows [RST20]. It is a useful modern comparison, but its borrow regions are not a theorem-preserving presentation of either the Tofte–Talpin or WCM calculus.
Sources.
Tofte–Talpin Sections 5.2–5.4 own inference, Milner refinement, and substitution; Sections 7–9 own Theorem 6.1 [TT97]. Walker–Crary–Morrisett Sections 2–3 and technical-report Appendices A–B own capability safety, complete collection, and CPS preservation [WCM00]. The four later designs retain their own signatures and theorem boundaries.
★★☆ For each card, write the store typing and authority across its displayed allocation/deallocation example. For L3, also change one cell from an integer to a pair with L3-Swap. State the exact theorem boundary for each card: which owns strong update, and which owns lifetime hiding?
★★★Practical project.region-capability-trace-auditor Implement absent, unique, shared, and freed states in Kappa. Maintain the invariant that access has live authority, free has unique authority, and halt has no live region. Accept the chapter’s allocate–access–free trace; reject access after free, shared free, double free, and live-region halt. Mutate free to accept shared authority: the mutant must check and audit cleanly but fail its named negative oracle. State explicitly that this finite machine does not prove theorem 50.5.