CPS Translation of Dependent Types Amal Ahmed Northeastern University Work in progress, with Nick Rioux and William Bowman
Compiling Dependent Types • Much recent focus on verified compilation of dependently typed languages: Coqonut, CertiCoq • Our goal: type-preserving , compositional verified compilation of Coq/Agda • Types at target level can be used to provide protection from target contexts/attackers (fully abstract compilation)
CPS Translation of Dependent Types Prior work • CPS Translations and Applications: The Cube and Beyond [ Barthe, Hatcliff, Sorenson HOSC’99 ] • [ Barthe & Uustalu PEPM’02 ] - Good news: “CPS translations… generalize for dependently typed calculi” - Bad news: “No translation is possible along the same lines for small -types and sum types with dependent case” Σ
CPS Translation of Dependent Types Prior work • CPS Translations and Applications: The Cube and Beyond [ Barthe, Hatcliff, Sorenson HOSC’99 ] • [ Barthe & Uustalu PEPM’02 ] - Good news: “CPS translations… generalize for dependently typed calculi” - Bad news: “No translation is possible along the same lines for small -types and sum types with dependent case” Σ
CPS Translation of Dependent Types Prior work • CPS Translations and Applications: The Cube and Beyond [ Barthe, Hatcliff, Sorenson HOSC’99 ] • [ Barthe & Uustalu PEPM’02 ] - Good news: “CPS translations… generalize for dependently typed calculi” - Bad news: “No translation is possible along the same lines for small -types and sum types with dependent case” Σ
This Talk: CPS-ing CoC with Σ ∗ | Π x : X. κ | Π α : κ 1 . κ 2 Kinds κ ::= α | Π x : X. Y | Π α : κ . X | Σ x : X. Y | A, X Types ::= λ x : X. A | A e | λ α : κ . A | A B | e 1 = X e 2 x | λ x : X. e | λ α : κ . e | e 1 e 2 | e A | e Terms ::= ⟨ e 1 , e 2 ⟩ | fst e | snd e | refl x | λ x : X. e | ⟨ e 1 , e 2 ⟩ | refl v Values ::= · | Γ , x : X | Γ , α : κ Environments Γ ::=
This Talk: CPS-ing CoC with Σ ∗ | Π x : X. κ | Π α : κ 1 . κ 2 Kinds κ ::= α | Π x : X. Y | Π α : κ . X | Σ x : X. Y | A, X Types ::= λ x : X. A | A e | λ α : κ . A | A B | e 1 = X e 2 x | λ x : X. e | λ α : κ . e | e 1 e 2 | e A | e Terms ::= ⟨ e 1 , e 2 ⟩ | fst e | snd e | refl x | λ x : X. e | ⟨ e 1 , e 2 ⟩ | refl v Values ::= · | Γ , x : X | Γ , α : κ Environments Γ ::= denote types of kind X,Y ∗
Typed CPS: STLC (call by name) Computation translation τ ÷ τ ÷ = ( τ + → ⊥ ) → ⊥ Value translation τ + bool + = bool ( τ 1 → τ 2 ) + τ ÷ 1 → τ ÷ = 2
Typed CPS: STLC (call by name) Computation translation τ ÷ τ ÷ = ( τ + → ⊥ ) → ⊥ Value translation τ + bool + = bool ( τ 1 → τ 2 ) + τ ÷ 1 → τ ÷ = 2 1 → ( τ + τ ÷ 2 → ⊥ ) → ⊥
Typed CPS: Dependent Types (cbn) Computation translation X ÷ X ÷ = ( X + → ⊥ ) → ⊥ Value translation X + α + = α ( Π x : X. Y ) + = Π x : X ÷ . Y ÷ ( Σ x : X. Y ) + = Σ x : X ÷ . Y ÷ . . .
Typed CPS: Dependent Types (cbn) Computation translation ÷ X ÷ � X ′ Γ ⊢ X : ∗ X ÷ = ( X + → ⊥ ) → ⊥ Value translation X + α + = α ( Π x : X. Y ) + = Π x : X ÷ . Y ÷ ( Σ x : X. Y ) + = Σ x : X ÷ . Y ÷ . . .
Typed CPS: Dependent Types (cbn) Computation translation ÷ X ÷ � X ′ Γ ⊢ X : ∗ X ÷ = ( X + → ⊥ ) → ⊥ + Value translation X + � A ′ Γ ⊢ A : κ α + = α ( Π x : X. Y ) + = Π x : X ÷ . Y ÷ ( Σ x : X. Y ) + = Σ x : X ÷ . Y ÷ . . .
Typed CPS: pair … warm up ÷ ÷ � e ÷ � e ÷ : Y ÷ [ e ÷ : X ÷ Γ ⊢ e 1 : X Γ ⊢ e 2 : Y [ e 1 /x ] 1 /x ] 1 2 ÷ � λ k : ( Σ x : X ÷ . Y ÷ ) → ⊥ . Γ ⊢ ⟨ e 1 , e 2 ⟩ : Σ x : X. Y � � e ÷ 1 , e ÷ k 2
Typed CPS: pair … warm up ÷ ÷ � e ÷ � e ÷ : Y ÷ [ e ÷ : X ÷ Γ ⊢ e 1 : X Γ ⊢ e 2 : Y [ e 1 /x ] 1 /x ] 1 2 ÷ � λ k : ( Σ x : X ÷ . Y ÷ ) → ⊥ . Γ ⊢ ⟨ e 1 , e 2 ⟩ : Σ x : X. Y � � e ÷ 1 , e ÷ k 2
Typed CPS: pair … warm up ÷ ÷ � e ÷ � e ÷ : Y ÷ [ e ÷ : X ÷ Γ ⊢ e 1 : X Γ ⊢ e 2 : Y [ e 1 /x ] 1 /x ] 1 2 ÷ � λ k : ( Σ x : X ÷ . Y ÷ ) → ⊥ . Γ ⊢ ⟨ e 1 , e 2 ⟩ : Σ x : X. Y � � e ÷ 1 , e ÷ k 2
Typed CPS: pair … warm up ÷ ÷ � e ÷ � e ÷ : Y ÷ [ e ÷ : X ÷ Γ ⊢ e 1 : X Γ ⊢ e 2 : Y [ e 1 /x ] 1 /x ] 1 2 ÷ � λ k : ( Σ x : X ÷ . Y ÷ ) → ⊥ . Γ ⊢ ⟨ e 1 , e 2 ⟩ : Σ x : X. Y � � e ÷ 1 , e ÷ k 2
Typed CPS: pair … warm up ÷ ÷ � e ÷ � e ÷ : Y ÷ [ e ÷ : X ÷ Γ ⊢ e 1 : X Γ ⊢ e 2 : Y [ e 1 /x ] 1 /x ] 1 2 ÷ � λ k : ( Σ x : X ÷ . Y ÷ ) → ⊥ . Γ ⊢ ⟨ e 1 , e 2 ⟩ : Σ x : X. Y � � e ÷ 1 , e ÷ k 2
Typed CPS: pair … warm up ÷ ÷ � e ÷ � e ÷ : Y ÷ [ e ÷ : X ÷ Γ ⊢ e 1 : X Γ ⊢ e 2 : Y [ e 1 /x ] 1 /x ] 1 2 ÷ � λ k : ( Σ x : X ÷ . Y ÷ ) → ⊥ . Γ ⊢ ⟨ e 1 , e 2 ⟩ : Σ x : X. Y � � e ÷ 1 , e ÷ k 2
Typed CPS: fst … all’s well : ( Σ x : X ÷ . Y ÷ → ⊥ ) → ⊥ ÷ � e ÷ Γ ⊢ e : Σ x : X. Y � λ k : X + → ⊥ . ÷ Γ ⊢ fst e : X e ÷ ( λ p : ( Σ x : X ÷ . Y ÷ ) . let z = fst p in z k )
Typed CPS: fst … all’s well : ( Σ x : X ÷ . Y ÷ → ⊥ ) → ⊥ ÷ � e ÷ Γ ⊢ e : Σ x : X. Y � λ k : X + → ⊥ . ÷ Γ ⊢ fst e : X e ÷ ( λ p : ( Σ x : X ÷ . Y ÷ ) . let z = fst p in z k )
Typed CPS: fst … all’s well : ( Σ x : X ÷ . Y ÷ → ⊥ ) → ⊥ ÷ � e ÷ Γ ⊢ e : Σ x : X. Y � λ k : X + → ⊥ . ÷ Γ ⊢ fst e : X e ÷ ( λ p : ( Σ x : X ÷ . Y ÷ ) . let z = fst p in z k )
Typed CPS: fst … all’s well : ( Σ x : X ÷ . Y ÷ → ⊥ ) → ⊥ ÷ � e ÷ Γ ⊢ e : Σ x : X. Y � λ k : X + → ⊥ . ÷ Γ ⊢ fst e : X e ÷ ( λ p : ( Σ x : X ÷ . Y ÷ ) . let z = fst p in z k )
Typed CPS: snd … the evil case! : ( Σ x : X ÷ . Y ÷ → ⊥ ) → ⊥ ÷ � e ÷ Γ ⊢ e : Σ x : X. Y � λ k : ( Y [ fst e/x ]) + → ⊥ . ÷ Γ ⊢ snd e : Y [ fst e/x ] e ÷ ( λ p : ( Σ x : X ÷ . Y ÷ ) . let y = snd p in y k )
Typed CPS: snd … the evil case! : ( Σ x : X ÷ . Y ÷ → ⊥ ) → ⊥ ÷ � e ÷ Γ ⊢ e : Σ x : X. Y � λ k : ( Y [ fst e/x ]) + → ⊥ . ÷ Γ ⊢ snd e : Y [ fst e/x ] e ÷ ( λ p : ( Σ x : X ÷ . Y ÷ ) . let y = snd p in y k )
Typed CPS: snd … the evil case! : ( Σ x : X ÷ . Y ÷ → ⊥ ) → ⊥ ÷ � e ÷ Γ ⊢ e : Σ x : X. Y � λ k : ( Y [ fst e/x ]) + → ⊥ . ÷ Γ ⊢ snd e : Y [ fst e/x ] e ÷ ( λ p : ( Σ x : X ÷ . Y ÷ ) . let y = snd p in y k )
Typed CPS: snd … the evil case! : ( Σ x : X ÷ . Y ÷ → ⊥ ) → ⊥ ÷ � e ÷ Γ ⊢ e : Σ x : X. Y � λ k : ( Y [ fst e/x ]) + → ⊥ . ÷ Γ ⊢ snd e : Y [ fst e/x ] e ÷ ( λ p : ( Σ x : X ÷ . Y ÷ ) . let y = snd p in y k ) Y + [( fst e ) ÷ /x ] → ⊥ Y ÷ [ fst p/x ]
Typed CPS: snd … the evil case! : ( Σ x : X ÷ . Y ÷ → ⊥ ) → ⊥ ÷ � e ÷ Γ ⊢ e : Σ x : X. Y � λ k : ( Y [ fst e/x ]) + → ⊥ . ÷ Γ ⊢ snd e : Y [ fst e/x ] e ÷ ( λ p : ( Σ x : X ÷ . Y ÷ ) . let y = snd p in y k ) Y + [( fst e ) ÷ /x ] → ⊥ ( Y + [ fst p/x ] → ⊥ ) → ⊥
Typed CPS: snd … the evil case! : ( Σ x : X ÷ . Y ÷ → ⊥ ) → ⊥ ÷ � e ÷ Γ ⊢ e : Σ x : X. Y � λ k : ( Y [ fst e/x ]) + → ⊥ . ÷ Γ ⊢ snd e : Y [ fst e/x ] e ÷ ( λ p : ( Σ x : X ÷ . Y ÷ ) . let y = snd p in y k ) Y + [( fst e ) ÷ /x ] → ⊥ ( Y + [ fst p/x ] → ⊥ ) → ⊥
Reasoning about value passed to cont. e : ( X + → ⊥ ) → ⊥ Want to extract the content of type inside X + e Idea: change the type translation e : Π α : ∗ . ( X + → α ) → α e X + id Now, we can extract via: X ÷ = Π α : ∗ . ( X + → α ) → α
Reasoning about value passed to cont. e : ( X + → ⊥ ) → ⊥ Want to extract the content of type inside X + e Idea: change the type translation e : Π α : ∗ . ( X + → α ) → α e X + id Now, we can extract via: X ÷ = Π α : ∗ . ( X + → α ) → α
Reasoning about value passed to cont. e : ( X + → ⊥ ) → ⊥ Want to extract the content of type inside X + e Idea: change the type translation e : Π α : ∗ . ( X + → α ) → α e X + id Now, we can extract via: X ÷ = Π α : ∗ . ( X + → α ) → α
Reasoning about value passed to cont. e : ( X + → ⊥ ) → ⊥ Want to extract the content of type inside X + e Idea: change the type translation e : Π α : ∗ . ( X + → α ) → α e X + id Now, we can extract via: X ÷ = Π α : ∗ . ( X + → α ) → α
Typed CPS: snd again ÷ � e ÷ Γ ⊢ e : Σ x : X. Y � λ α : ∗ . λ k : ( Y [ fst e/x ]) + → α . ÷ Γ ⊢ snd e : Y [ fst e/x ] e ÷ α ( λ p : ( Σ x : X ÷ . Y ÷ ) . let y = snd p in y α k )
Typed CPS: snd again ÷ � e ÷ Γ ⊢ e : Σ x : X. Y � λ α : ∗ . λ k : ( Y [ fst e/x ]) + → α . ÷ Γ ⊢ snd e : Y [ fst e/x ] e ÷ α ( λ p : ( Σ x : X ÷ . Y ÷ ) . let y = snd p in y α k ) e ÷ ( Σ x : X ÷ . Y ÷ ) id
Recommend
More recommend