Effect capabilities, explicit labels, and tunnelling
appendix sectionrules
Effect capabilities, explicit labels, and tunnelling
This appendix freezes the three independent calculi used by chapter 32. Identical letters in different cards do not identify judgments across cards.
System 𝖷𝗂
The selected source and runtime syntax is 𝜏::=𝖨𝗇𝗍∣𝖡𝗈𝗈𝗅∣1,𝜎::=(¯𝜏,¯𝜎)→𝜏,𝑒::=𝑥∣𝑣,𝑣::=()∣𝑛∣𝗍𝗋𝗎𝖾∣𝖿𝖺𝗅𝗌𝖾,𝑏::=𝑓∣𝑢,𝑢::=𝑤∣𝖼𝖺𝗉ℓ{(𝑥,𝑘)⇒𝑠},𝑤::={(¯𝑥:¯𝜏,¯𝑓:¯𝜎)⇒𝑠},𝑠::=𝑒∣𝗏𝖺𝗅𝑥=𝑠;𝑠∣𝖽𝖾𝖿𝑓=𝑏;𝑠∣𝑏(¯𝑒,¯𝑏)∣𝗁𝖺𝗇𝖽𝗅𝖾{𝐹⇒𝑠}𝗐𝗂𝗍𝗁{(𝑥,𝑘)⇒𝑠}∣#ℓ{𝑠}. The contexts and judgments are Γ::=∅∣Γ,𝑥:𝜏,Δ::=∅∣Δ,𝑓:𝜎,Ξ::=∅∣Ξ,ℓ:𝜏,Γ⊢𝑒:𝜏,Γ∣Δ∣Ξ⊢𝑏:𝜎,Γ∣Δ∣Ξ⊢𝑠:𝜏. All judgments are relative to a fixed operation signature Ω, with Ω(𝐹)=𝜏1→𝜏0. This arrow abbreviates the single-value, no-block-parameter type ((𝜏1),())→𝜏0; block-context lookup is rightmost. The selected pure fragment contains exactly unit, integer and Boolean constants and variables; its constant signature is C(())=1, C(𝑛)=𝖨𝗇𝗍, and C(𝗍𝗋𝗎𝖾)=C(𝖿𝖺𝗅𝗌𝖾)=𝖡𝗈𝗈𝗅. Value types contain no block type. Expressions contain no block variable or block abstraction. This syntactic separation is the second-class restriction.
The complete selected typing rules are
𝑥:𝜏∈Γ
Γ⊢𝑥:𝜏
X-Var
C(𝑣)=𝜏
Γ⊢𝑣:𝜏
X-Const
Δ(𝑓)=𝜎
Γ∣Δ∣Ξ⊢𝑓:𝜎
X-BVar
Γ,¯𝑥:¯𝜏∣Δ,¯𝑓:¯𝜎∣Ξ⊢𝑠:𝜏
Γ∣Δ∣Ξ⊢{(¯𝑥:¯𝜏,¯𝑓:¯𝜎)⇒𝑠}:(¯𝜏,¯𝜎)→𝜏
X-Block
Γ⊢𝑒:𝜏
Γ∣Δ∣Ξ⊢𝑒:𝜏
X-Expr
Γ∣Δ∣Ξ⊢𝑠0:𝜏0Γ,𝑥:𝜏0∣Δ∣Ξ⊢𝑠1:𝜏1
Γ∣Δ∣Ξ⊢𝗏𝖺𝗅𝑥=𝑠0;𝑠1:𝜏1
X-Val
Γ∣Δ∣Ξ⊢𝑏:𝜎Γ∣Δ,𝑓:𝜎∣Ξ⊢𝑠:𝜏
Γ∣Δ∣Ξ⊢𝖽𝖾𝖿𝑓=𝑏;𝑠:𝜏
X-Def
Γ∣Δ∣Ξ⊢𝑏:(¯𝜏,¯𝜎)→𝜏0(Γ⊢𝑒𝑖:𝜏𝑖)𝑖(Γ∣Δ∣Ξ⊢𝑏𝑗:𝜎𝑗)𝑗
Γ∣Δ∣Ξ⊢𝑏(¯𝑒,¯𝑏):𝜏0
X-Call
Ω(𝐹)=𝜏1→𝜏0Γ∣Δ,𝐹:𝜏1→𝜏0∣Ξ⊢𝑠:𝜏Γ,𝑥:𝜏1∣Δ,𝑘:𝜏0→𝜏∣Ξ⊢𝑠ℎ:𝜏
Γ∣Δ∣Ξ⊢𝗁𝖺𝗇𝖽𝗅𝖾{𝐹⇒𝑠}𝗐𝗂𝗍𝗁{(𝑥,𝑘)⇒𝑠ℎ}:𝜏
X-Handle
Ξ=Ξ0,ℓ:𝜏,Ξ+Γ,𝑥:𝜏1∣Δ,𝑘:𝜏0→𝜏∣Ξ0⊢𝑠ℎ:𝜏
Γ∣Δ∣Ξ⊢𝖼𝖺𝗉ℓ{(𝑥,𝑘)⇒𝑠ℎ}:𝜏1→𝜏0
X-Cap
ℓ∉dom(Ξ)Γ∣Δ∣Ξ,ℓ:𝜏⊢𝑠:𝜏
Γ∣Δ∣Ξ⊢#ℓ{𝑠}:𝜏
X-Delim
The ordered label context records allocation origin. In Ξ0,ℓ:𝜏,Ξ+, the stored handler body is typed in the birth prefix Ξ0; Ξ+ contains only delimiters allocated after ℓ. This exact prefix premise, rather than deletion from an unordered set, is what preserves the clause type when a request crosses intervening delimiters.
Evaluation contexts and contexts not binding ℓ are 𝐻::=[]∣𝗏𝖺𝗅𝑥=𝐻;𝑠∣#ℓ{𝐻},𝐻ℓ::=[]∣𝗏𝖺𝗅𝑥=𝐻ℓ;𝑠∣#ℓ′{𝐻ℓ}(ℓ′≠ℓ). Reduction is compatible closure under 𝐻 of 𝗏𝖺𝗅𝑥=𝑣;𝑠⇝0𝑠[𝑣/𝑥]𝑋−𝑉𝑎𝑙−𝑏𝑒𝑡𝑎,𝖽𝖾𝖿𝑓=𝑢;𝑠⇝0𝑠[𝑢/𝑓]𝑋−𝐷𝑒𝑓−𝑏𝑒𝑡𝑎,{(¯𝑥,¯𝑓)⇒𝑠}(¯𝑣,¯𝑢)⇝0𝑠[¯𝑣/¯𝑥][¯𝑢/¯𝑓]𝑋−𝐵𝑙𝑜𝑐𝑘−𝑏𝑒𝑡𝑎,#ℓ{𝑣}⇝0𝑣𝑋−𝐷𝑒𝑙𝑖𝑚−𝑟𝑒𝑡. Handler allocation is 𝗁𝖺𝗇𝖽𝗅𝖾{𝐹⇒𝑠}𝗐𝗂𝗍𝗁{(𝑥,𝑘)⇒𝑠ℎ}⇝0#ℓ{𝑠[𝖼𝖺𝗉ℓ{(𝑥,𝑘)⇒𝑠ℎ}/𝐹]}𝑋−𝐻𝑎𝑛𝑑𝑙𝑒−𝑏𝑒𝑡𝑎. The remaining root contraction captures the delimited context: #ℓ{𝐻ℓ[𝖼𝖺𝗉ℓ{(𝑥,𝑘)⇒𝑠ℎ}(𝑣)]}⇝0𝑠ℎ[𝑣/𝑥,{(𝑦:𝜏0)⇒#ℓ{𝐻ℓ[𝑦]}}/𝑘]𝑋−𝐶𝑎𝑝−𝑏𝑒𝑡𝑎. The label chosen by X-Handle-beta is fresh. Source terms contain no labels; runtime typing extends Ξ only through X-Delim.
Effekt
The selected Effekt source is 𝜏::=𝖨𝗇𝗍∣𝖡𝗈𝗈𝗅∣1,𝜎::=(¯𝜏,¯𝜎)→𝜏/𝜀,𝜀::={𝐹1,…,𝐹𝑛},𝑣::=()∣𝑛∣𝗍𝗋𝗎𝖾∣𝖿𝖺𝗅𝗌𝖾,𝑒::=𝑥∣𝑣,𝑠::=𝑒∣𝗏𝖺𝗅𝑥=𝑠;𝑠∣𝖽𝖾𝖿𝑓(¯𝑥:¯𝜏,¯𝑔:¯𝜎):𝜏/𝜀=𝑠;𝑠∣𝑓(¯𝑒,¯𝑔)∣𝖾𝖿𝖿𝖾𝖼𝗍𝐹(𝑥:𝜏1):𝜏0;𝑠∣𝖽𝗈𝐹(𝑒)∣𝗍𝗋𝗒{𝑠}𝗐𝗂𝗍𝗁𝐹{(𝑥:𝜏1)⇒𝑠ℎ}. The judgments are Γ⊢𝑒:𝜏 and Γ∣Δ∣Σ⊢𝑠:𝜏∣𝜀, where Σ(𝐹)=𝜏1→𝜏0. Value variables, ordinary block variables, and operation names are pairwise disjoint syntactic classes; binders are alpha-renamed before extension. Expressions use X-Var and X-Const. The complete statement rules are
Effekt has no separate direct reduction relation in this chapter. Its semantics is the named syntax translation of Appendix D followed by System 𝖷𝗂 reduction.
The tunnelling calculus
The selected syntax is 𝑒::=𝛼∣ℓ∣ℎ.𝗅𝖻𝗅,𝑇,𝑆::=1∣𝖨𝗇𝗍∣𝑆→[𝑇]¯𝑒∣∀𝛼.𝑇∣Πℎ:𝖥.[𝑇]¯𝑒,ℎ,𝑔::=ℎ𝗏∣𝐻ℓ,𝐻::=𝗁𝖺𝗇𝖽𝗅𝖾𝗋𝖥𝑥𝑘.𝑡,𝑡::=()∣𝑛∣𝑥∣𝜆𝑥:𝑇.𝑡∣𝑡𝑡∣𝗅𝖾𝗍𝑥:𝑇=𝑡𝗂𝗇𝑡∣Λ𝛼.𝑡∣𝑡[¯𝑒]∣𝜆ℎ:𝖥.𝑡∣𝑡ℎ∣⇑ℎ∣⇓ℓ[𝑇]¯𝑒𝑡. Here ℎ𝗏 is an atomic handler variable; binders use ℎ as its metavariable. This repairs the self-referential production printed in the source. The source core has only unit; this book adds 𝖨𝗇𝗍, integer literals, and the three formation rules below for the chapter’s observable examples. Contexts are Δ for effect variables, 𝑃 for handler variables, Γ for term variables, and Ξ for labels. The four judgments are Δ∣𝑃∣Ξ⊢𝑇𝗍𝗒𝗉𝖾,Δ∣𝑃∣Ξ⊢¯𝑒𝖾𝖿𝖿𝖾𝖼𝗍𝗌,Δ∣𝑃∣Γ∣Ξ⊢𝑡:[𝑇]¯𝑒,Δ∣𝑃∣Γ∣Ξ⊢ℎ:𝖥∣𝑒. They are relative to a fixed interface signature O; the premise 𝗈𝗉(𝖥)=𝑇→𝑆 abbreviates O(𝖥)=𝑇→𝑆, and 𝑇→𝑆 abbreviates 𝑇→[𝑆]∅. Effect sequences are identified up to permutation, duplicate removal, and flattening under effect substitution. The four characteristic rules are printed in Figure 10 of the source paper. The formation, ordinary typing, subtyping, and effect-inclusion rules below are the exact closure printed in Appendix A.1 of Cornell technical report 1813/60202. In particular, application and let assign one common effect to their premises; union-effect forms are derived with T-Sub, not substituted for the published rules. The complete table begins with well-formedness:
Δ∣𝑃∣Ξ⊢∅𝖾𝖿𝖿𝖾𝖼𝗍𝗌
WF-Emp
𝛼∈Δ
Δ∣𝑃∣Ξ⊢𝛼𝖾𝖿𝖿𝖾𝖼𝗍𝗌
WF-EVar
ℓ∈dom(Ξ)
Δ∣𝑃∣Ξ⊢ℓ𝖾𝖿𝖿𝖾𝖼𝗍𝗌
WF-Label
𝑃(ℎ)=𝖥
Δ∣𝑃∣Ξ⊢ℎ.𝗅𝖻𝗅𝖾𝖿𝖿𝖾𝖼𝗍𝗌
WF-HLabel
Δ∣𝑃∣Ξ⊢¯𝑒1𝖾𝖿𝖿𝖾𝖼𝗍𝗌Δ∣𝑃∣Ξ⊢¯𝑒2𝖾𝖿𝖿𝖾𝖼𝗍𝗌
Δ∣𝑃∣Ξ⊢¯𝑒1,¯𝑒2𝖾𝖿𝖿𝖾𝖼𝗍𝗌
WF-ESeq
Δ∣𝑃∣Ξ⊢1𝗍𝗒𝗉𝖾
WF-Unit
Δ∣𝑃∣Ξ⊢𝖨𝗇𝗍𝗍𝗒𝗉𝖾
WF-Int
Δ∣𝑃∣Ξ⊢𝑆𝗍𝗒𝗉𝖾Δ∣𝑃∣Ξ⊢𝑇𝗍𝗒𝗉𝖾Δ∣𝑃∣Ξ⊢¯𝑒𝖾𝖿𝖿𝖾𝖼𝗍𝗌
Δ∣𝑃∣Ξ⊢𝑆→[𝑇]¯𝑒𝗍𝗒𝗉𝖾
WF-Fun
Δ,𝛼∣𝑃∣Ξ⊢𝑇𝗍𝗒𝗉𝖾
Δ∣𝑃∣Ξ⊢∀𝛼.𝑇𝗍𝗒𝗉𝖾
WF-EAll
Δ∣𝑃,ℎ:𝖥∣Ξ⊢𝑇𝗍𝗒𝗉𝖾Δ∣𝑃,ℎ:𝖥∣Ξ⊢¯𝑒𝖾𝖿𝖿𝖾𝖼𝗍𝗌
Δ∣𝑃∣Ξ⊢Πℎ:𝖥.[𝑇]¯𝑒𝗍𝗒𝗉𝖾
WF-HAll
The term and handler rules are
Δ∣𝑃∣Γ∣Ξ⊢():[1]∅
T-Unit
Δ∣𝑃∣Γ∣Ξ⊢𝑛:[𝖨𝗇𝗍]∅
T-Int
𝑥:𝑇∈Γ
Δ∣𝑃∣Γ∣Ξ⊢𝑥:[𝑇]∅
T-Var
Δ∣𝑃∣Ξ⊢𝑆𝗍𝗒𝗉𝖾Δ∣𝑃∣Γ,𝑥:𝑆∣Ξ⊢𝑡:[𝑇]¯𝑒
Δ∣𝑃∣Γ∣Ξ⊢𝜆𝑥:𝑆.𝑡:[𝑆→[𝑇]¯𝑒]∅
T-Lam
Δ∣𝑃∣Γ∣Ξ⊢𝑡1:[𝑆→[𝑇]¯𝑒]¯𝑒Δ∣𝑃∣Γ∣Ξ⊢𝑡2:[𝑆]¯𝑒
Δ∣𝑃∣Γ∣Ξ⊢𝑡1𝑡2:[𝑇]¯𝑒
T-App
Δ∣𝑃∣Ξ⊢𝑆𝗍𝗒𝗉𝖾Δ∣𝑃∣Γ∣Ξ⊢𝑡1:[𝑆]¯𝑒Δ∣𝑃∣Γ,𝑥:𝑆∣Ξ⊢𝑡2:[𝑇]¯𝑒
Δ∣𝑃∣Γ∣Ξ⊢𝗅𝖾𝗍𝑥:𝑆=𝑡1𝗂𝗇𝑡2:[𝑇]¯𝑒
T-Let
Type subtyping is the least transitive relation generated by
Δ∣𝑃∣Ξ⊢1≤1
S-Unit
Δ∣𝑃∣Ξ⊢𝖨𝗇𝗍≤𝖨𝗇𝗍
S-Int
Δ∣𝑃∣Ξ⊢𝑇2≤𝑇1Δ∣𝑃∣Ξ⊢𝑆1≤𝑆2Δ∣𝑃∣Ξ⊢¯𝑒1≤¯𝑒2
Δ∣𝑃∣Ξ⊢𝑇1→[𝑆1]¯𝑒1≤𝑇2→[𝑆2]¯𝑒2
S-Fun
Δ,𝛼∣𝑃∣Ξ⊢𝑇1≤𝑇2
Δ∣𝑃∣Ξ⊢∀𝛼.𝑇1≤∀𝛼.𝑇2
S-AllE
Δ∣𝑃,ℎ:𝖥∣Ξ⊢𝑇1≤𝑇2Δ∣𝑃,ℎ:𝖥∣Ξ⊢¯𝑒1≤¯𝑒2
Δ∣𝑃∣Ξ⊢Πℎ:𝖥.[𝑇1]¯𝑒1≤Πℎ:𝖥.[𝑇2]¯𝑒2
S-AllH
Δ∣𝑃∣Ξ⊢𝑇1≤𝑇2Δ∣𝑃∣Ξ⊢𝑇2≤𝑇3
Δ∣𝑃∣Ξ⊢𝑇1≤𝑇3
S-Trans
Effect inclusion and term subsumption are
(∀𝑗)(∃𝑖).𝑒1𝑗=𝑒2𝑖(Δ∣𝑃∣Ξ⊢𝑒2𝑖𝖾𝖿𝖿𝖾𝖼𝗍𝗌)𝑖
Δ∣𝑃∣Ξ⊢¯𝑒1≤¯𝑒2
Eff-Sub
Δ∣𝑃∣Γ∣Ξ⊢𝑡:[𝑇1]¯𝑒1Δ∣𝑃∣Ξ⊢𝑇1≤𝑇2Δ∣𝑃∣Ξ⊢¯𝑒1≤¯𝑒2
Δ∣𝑃∣Γ∣Ξ⊢𝑡:[𝑇2]¯𝑒2
T-Sub
The usual union-effect application and sequencing rules are admissible by subsuming their premises to a common finite join before applying T-App or T-Let.
Here 𝑇[ℎ] and ¯𝑒[ℎ] replace the bound handler variable by its argument and replace ℎ.𝗅𝖻𝗅 by the argument label. Every context extension in this card binds a fresh name; the explicit first premise of T-Down records the delimiter-label instance of that convention. Since the type and effect well-formedness premises are checked before the fresh label is added, WF-Label derives ℓ∉fl(𝑇,¯𝑒); this is not an independent hypothesis.
Values and evaluation contexts are 𝑣::=()∣𝜆𝑥:𝑇.𝑡∣Λ𝛼.𝑡∣𝜆ℎ:𝖥.𝑡∣⇑𝐻ℓ,𝐾::=[]∣𝐾𝑡∣𝑣𝐾∣𝐾[¯ℓ]∣𝐾𝐻ℓ∣𝗅𝖾𝗍𝑥:𝑇=𝐾𝗂𝗇𝑡∣⇓ℓ𝐾. Contextual refinement quantifies over the larger program-context grammar 𝐶::=[]∣𝐶[𝜆𝑥:𝑇.[]]∣𝐶[[]𝑡]∣𝐶[𝑡[]]∣𝐶[𝗅𝖾𝗍𝑥:𝑇=[]𝗂𝗇𝑡]∣𝐶[𝗅𝖾𝗍𝑥:𝑇=𝑡𝗂𝗇[]]∣𝐶[Λ𝛼.[]]∣𝐶[[][¯𝑒]]∣𝐶[𝜆ℎ:𝖥.[]]∣𝐶[[]ℎ]∣𝐶[𝑡(𝗁𝖺𝗇𝖽𝗅𝖾𝗋𝖥𝑥𝑘.[])ℓ]∣𝐶[(𝗁𝖺𝗇𝖽𝗅𝖾𝗋𝖥𝑥𝑘.[])ℓ]∣𝐶[⇓ℓ[𝑇]¯𝑒[]]. Its well-formedness judgment is ⊢𝐶:Δ∣𝑃∣Γ∣Ξ∣[𝑇]¯𝑒⟹𝑇′. These are not the evaluation contexts 𝐾. Reduction is compatible closure under 𝐾 of (𝜆𝑥:𝑇.𝑡)𝑣⇝0𝑡[𝑣/𝑥]𝑇𝑢𝑛−𝐴𝑝𝑝−𝑏𝑒𝑡𝑎,(Λ𝛼.𝑡)[¯ℓ]⇝0𝑡[¯ℓ/𝛼]𝑇𝑢𝑛−𝐸𝑓𝑓−𝑏𝑒𝑡𝑎,(𝜆ℎ:𝖥.𝑡)𝐻ℓ⇝0𝑡[𝐻ℓ/ℎ]𝑇𝑢𝑛−𝐻𝑎𝑛𝑑𝑙𝑒𝑟−𝑏𝑒𝑡𝑎,𝗅𝖾𝗍𝑥:𝑇=𝑣𝗂𝗇𝑡⇝0𝑡[𝑣/𝑥]𝑇𝑢𝑛−𝐿𝑒𝑡−𝑏𝑒𝑡𝑎,⇓ℓ𝑣⇝0𝑣𝑇𝑢𝑛−𝐷𝑜𝑤𝑛−𝑣𝑎𝑙. The tunneled request contraction is ⇓ℓ𝐾[⇑𝐻ℓ𝑣]⇝0𝑡[𝑣/𝑥,(𝜆𝑦:𝑇2.⇓ℓ𝐾[𝑦])/𝑘]𝑇𝑢𝑛−𝐷𝑜𝑤𝑛−𝑢𝑝. where 𝐻=𝗁𝖺𝗇𝖽𝗅𝖾𝗋𝖥𝑥𝑘.𝑡, 𝗈𝗉(𝖥)=𝑇1→𝑇2, and 𝐾 does not bind ℓ.
Source-bounded finer cards
Control-flow linearity uses the comparison predicate 𝗎𝗌𝖾𝗌(𝑟,𝑀)≤𝑞, 𝑞∈{1,𝜔}, from section 32.5; no rule of the source calculus is imported.
The Olaf source boundary uses the typing judgment Δ∣Θ∣Γ∣Ξ⊢𝑡:[𝜏]𝑐 and configuration transition 𝐿;𝑡⟶𝐿′;𝑡′. Its operation signatures, continuation types, lifetime effects, fixpoint handlers, and rules belong to the source calculus of [ZSM20]; section 32.5 records its theorem boundary. No Olaf rule is imported into System 𝖷𝗂, Effekt, or the tunnelling calculus.
The locality source card distinguishes ordinary bindings Γ;𝑥:𝜏 from global bindings Γ;𝑥:◻𝜏 and restricts contexts by ∅/◻=∅,(Γ;𝑥:𝜏)/◻=Γ/◻,(Γ;𝑥:◻𝜏)/◻=(Γ/◻);𝑥:◻𝜏. Its characteristic introduction rule is
Γ/◻⊢𝖵𝑣:𝜏
Γ⊢𝖵𝖻𝗈𝗑𝑣:◻𝜏
Loc-Box
The effect-reflection card uses 𝑦(Σ), 𝑊Σ(𝜏), 𝗋𝖾𝖿𝗅𝖾𝖼𝗍, and 𝗋𝖾𝗂𝖿𝗒Σ with
Γ⊢𝖵𝑣1:𝑦(Σ)𝗈𝗉:𝜏1⇝𝜏2∈ΣΓ⊢𝖵𝑣2:◻𝜏1Γ;𝑥:◻𝜏2⊢𝖢𝑐:𝜏3
Γ⊢𝖢𝗋𝖾𝖿𝗅𝖾𝖼𝗍(𝑣1(𝗈𝗉))(𝑣2,𝑥.𝑐):𝜏3
Refl-Up
Γ;𝑥:𝑦(Σ)⊢𝖢𝑐:◻𝜏
Γ⊢𝖢𝗋𝖾𝗂𝖿𝗒Σ(𝑥.𝑐):𝑊Σ(◻𝜏)
Refl-Down
These two cards belong to [Whi26]; they supply no rule to the three principal calculi of this appendix section.