compiling dependent types
play

Compiling Dependent Types Much recent focus on verified compilation - PowerPoint PPT Presentation

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


  1. CPS Translation of Dependent Types Amal Ahmed Northeastern University Work in progress, with Nick Rioux and William Bowman

  2. 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)

  3. 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” Σ

  4. 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” Σ

  5. 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” Σ

  6. 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 Γ ::=

  7. 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 ∗

  8. Typed CPS: STLC (call by name) Computation translation τ ÷ τ ÷ = ( τ + → ⊥ ) → ⊥ Value translation τ + bool + = bool ( τ 1 → τ 2 ) + τ ÷ 1 → τ ÷ = 2

  9. Typed CPS: STLC (call by name) Computation translation τ ÷ τ ÷ = ( τ + → ⊥ ) → ⊥ Value translation τ + bool + = bool ( τ 1 → τ 2 ) + τ ÷ 1 → τ ÷ = 2 1 → ( τ + τ ÷ 2 → ⊥ ) → ⊥

  10. 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 ÷ . . .

  11. 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 ÷ . . .

  12. 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 ÷ . . .

  13. 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

  14. 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

  15. 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

  16. 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

  17. 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

  18. 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

  19. 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 )

  20. 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 )

  21. 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 )

  22. 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 )

  23. 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 )

  24. 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 )

  25. 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 )

  26. 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 ]

  27. 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 ] → ⊥ ) → ⊥

  28. 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 ] → ⊥ ) → ⊥

  29. 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 + → α ) → α

  30. 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 + → α ) → α

  31. 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 + → α ) → α

  32. 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 + → α ) → α

  33. 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 )

  34. 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