blame and coercion together again for the first time pldi
play

Blame and coercion: together again for the first time (PLDI 2015) - PowerPoint PPT Presentation

Blame and coercion: together again for the first time (PLDI 2015) Jeremy Siek (Indiana) Peter Thiemann (Freiburg) Philip Wadler (Edinburgh) WG 2.8, Keffalonia, 2529 May 2015 Part I Conclusion Three calcluli B Blame calculus


  1. Blame and coercion: together again for the first time (PLDI 2015) Jeremy Siek (Indiana) Peter Thiemann (Freiburg) Philip Wadler (Edinburgh) WG 2.8, Keffalonia, 25–29 May 2015

  2. Part I Conclusion

  3. Three calcluli • λ B Blame calculus Findler and Felleisen (2002) Wadler and Findler (2009) • λ C Coercion calculus Henglein (1994) • λ S Space-efficient coercion calculus Hermann, Tomb, Flanagan (2007) Siek and Wadler (2010) Garcia (2013)

  4. Full abstraction Strong correctness property: Full abstraction ctx ctx if and only if | M | BC = C | N | BC • M = B N ctx ctx if and only if | M | CS = T | N | CS • M = C N Equivalences in λ B and λ C easily proved in λ S Key lemma Fundamental property of casts < : + < : < : − < : n Four subtyping relations: Translation between λ B and λ C explains < : + and < : −

  5. Part II The Blame Calculus ( λ B )

  6. Types and ground types Base types ι ι | A → B | ⋆ ::= Types A, B, C ι | ⋆ → ⋆ G, H ::= Ground types ι + ( ⋆ → ⋆ ) = ⋆

  7. Compatibility Γ ⊢ M : A A ∼ B p Γ ⊢ ( M : A = ⇒ B ) : B A ′ ∼ A B ∼ B ′ A → B ∼ A ′ → B ′ ι ∼ ι A ∼ ⋆ ⋆ ∼ A Lemma 1. If A � = ⋆ then there is a unique G such that A ∼ G . Lemma 2. ∼ is reflexive and symmetric but not transitive.

  8. Reductions p E [ V : ι ⇒ ι ] − → E [ V ] = ⇒ A ′ → B ′ ) W ] − p E [( V : A → B → = p p E [( V ( W : A ′ ⇒ A )) : B ⇒ B ′ ] = = p E [ V : ⋆ = ⇒ ⋆ ] − → E [ V ] p p p E [ V : A ⇒ ⋆ ] − → E [ V : A ⇒ G ⇒ ⋆ ] = = = if A � = ⋆, A � = G, A ∼ G p p p E [ V : ⋆ ⇒ A ] − → E [ V : ⋆ ⇒ G ⇒ A ] = = = if A � = ⋆, A � = G, A ∼ G p q E [ V : G ⇒ ⋆ ⇒ G ] − → E [ V ] = = p q E [ V : G ⇒ ⋆ ⇒ H ] − → blame q if G � = H = =

  9. Part III The Coercion Calculus ( λ C )

  10. Coercions and typing ⇒ A id A : A = ? p G : ⋆ = G ! : G = ⇒ ⋆ ⇒ G c : A ′ = ⇒ A d : B = ⇒ B ′ ⇒ A ′ → B ′ c → d : A → B = ⇒ B ⇒ C c : A = d : B = c ; d : A = ⇒ C A � = ⋆ A ∼ G G � = H ⊥ GpH : A = ⇒ B

  11. Failure A � = ⋆ A ∼ G G � = H ⊥ GpH : A = ⇒ B ⊥ GpH : A = ⇒ B corresponds to p • • • M : A = ⇒ G = ⇒ ⋆ = ⇒ H = ⇒ B Lemma 3. (Failure) If A � = ⋆ and A ∼ G and G � = H then p 1 p 2 p 3 p 4 M : A = ⇒ G = ⇒ ⋆ = ⇒ H = ⇒ B − → blame p 3 .

  12. Reductions E [ V � id A � ] − → E [ V ] E [( V � c → d � ) W ] − → E [( V ( W � c � )) � d � ] E [ V � G ! �� ? p G � ] − → E [ V ] E [ V � G ! �� ? p H � ] − → blame p if G � = H E [ V � c ; d � ] − → E [ V � c �� d � ] E [ V � ⊥ GpH � ] − → blame p

  13. Part IV Space-efficient Blame Calculus ( λ S )

  14. Coercions in normal form id ⋆ | ? p G ; i | i ::= Space-efficient coercions s, t g ; G ! | g | ⊥ GpH i ::= Intermediate coercions id ι | s → t g, h ::= Ground coercions Lemma 4. • If i : A = ⇒ B then A � = ⋆ . • If g : A = ⇒ B then A � = ⋆ and B � = ⋆ , and there is a unique G such that A ∼ G and B ∼ G .

  15. Space-efficient composition id ι � id ι = id ι ( s → t ) � ( s ′ → t ′ ) = ( s ′ � s ) → ( t � t ′ ) id ⋆ � t = t ( g ; G ! ) � id ⋆ = g ; G ! ( ? p G ; i ) � t = ? p G ; ( i � t ) g � ( h ; H ! ) = ( g � h ) ; H ! ( g ; G ! ) � ( ? p G ; i ) = g � i ( g ; G ! ) � ( ? p H ; i ) = ⊥ GpH if G � = H ⊥ GpH � s = ⊥ GpH g � ⊥ GpH = ⊥ GpH

  16. Reductions F [ U � id ι � ] − → F [ U ] E [( U � s → t � ) W ] − → E [( U ( W � s � )) � t � ] F [ U � id ⋆ � ] − → F [ U ] F [ M � s �� t � ] − → F [ M � s � t � ] F [ U � ⊥ GpH � ] − → blame p

  17. Compare: Herman, Tomb, and Flanagan (2007) F [ M � c �� d � ] − → F [ M � c ; d � ] ( c ; d ) ; e = c ; ( d ; e ) id A ; c = c c ; id A = c ( c → d ) ; ( c ′ → d ′ ) = ( c ′ ; c ) → ( d ; d ′ ) G ! ; ? G = id G G ! ; ? H = ⊥ if G � = H ⊥ ; c = ⊥ c ; ⊥ = ⊥

  18. Compare: Siek and Wadler (2010) ι l � ι m = ι l ( P → l Q ) � ( P ′ → m Q ′ ) = ( P ′ � P ) → l ( Q � Q ′ ) ⋆ � P = P P � ⋆ = P P G m � Q H p = ⊥ pG m if G � = H ⊥ pG m � Q = ⊥ pG m P G l � ⊥ pG m = ⊥ pG l P G l � ⊥ pH q = ⊥ qG l if G � = H

  19. Compare: Siek and Wadler (2010) P G l means P ∼ G and the top-level blame label in P is l . If there is no top-level blame label in P , then l is ǫ . ι ǫ corresponds to id ι ι p corresponds to ? p ι ; id ι P → ǫ Q corresponds to P → Q P → p Q corresponds to ? p ( ⋆ → ⋆ ) ; ( P → Q ) ⋆ corresponds to id ⋆ ⊥ pG ǫ corresponds to ⊥ GpH ⊥ pG q corresponds to ? q G ; ⊥ GpH

  20. Compare: Garcia (2013) N [ [ id ⋆ ] ] = id ⋆ N [ [ id ι ] ] = id ι [ ⊥ pG ] ] = ⊥ p N [ [ ⊥ pGq ] ] = ? q G ; ⊥ p N [ N [ [ G ! ] ] = G ! [ G ? p ] ] = ? p G N [ [ G ? p ! ] ] = ? p G ; G ! N [ N [ c 1 → ¨ ] = N [ ] → N [ [¨ c 2 ] [¨ c 1 ] [¨ c 2 ] ] N [ c 1 → ! ¨ ] = ( N [ ] → N [ ]) ; ( ⋆ → ⋆ ) ! [¨ c 2 ] [¨ c 1 ] [¨ c 2 ] c 1 ? p → ¨ ] = ? p ( ⋆ → ⋆ ) ; ( N [ N [ ] → N [ [¨ c 2 ] [¨ c 1 ] [¨ c 2 ] ]) c 1 ? p → ! ¨ ] = ? p ( ⋆ → ⋆ ) ; ( N [ N [ ] → N [ ]) ; ( ⋆ → ⋆ ) ! [¨ c 2 ] [¨ c 1 ] [¨ c 2 ]

  21. Part V Full abstraction

  22. Contextual equivalence Definition 5 (Contextual equivalence) . Two terms are contextually ctx = B N , if for any context C , either equivalent, written M 1. both converge to a value, C [ M ] − → ∗ B V and C [ N ] − → ∗ B W , for some values V and W . 2. both allocate blame to the same label, C [ M ] − → ∗ B blame p and C [ N ] − → ∗ B blame p , for some label p , or 3. both diverge, C [ M ] ↑ B and C [ N ] ↑ B . The same definition applies, mutatis mutandis, for λ C and λ S .

  23. Full abstraction The best previous result (Siek and Wadler (2010)): Theorem 6 (Contextual equivalence without the context) . | M | BT ↑ T • M ↑ B if and only if Our result: Theorem 7 (Full abstraction) . ctx ctx | M | BC = C | N | BC • M = B N if and only if ctx ctx | M | CS = T | N | CS • M = C N if and only if

  24. A key lemma Lemma 8 (Equivalences) . The following hold in λ C . ctx 1. M � id � = C M ctx 2. M � c ; d � = C M � c �� d � ctx ctx 3. M � c ; id � = C M � c � = C M � id ; c � 4. M � ( c → d ) ; ( c ′ → d ′ ) � = C M � ( c ′ ; c ) → ( d ; d ′ ) � ctx ctx 5. M � c → d � = C M � ( c → id ) ; ( id → d ) � ctx 6. M � c → d � = C M � ( id → c ) ; ( d → id ) � Proof. Trivial to prove using full abstraction from λ C to λ S . [Tricky to prove otherwise; probably requires a custom bisimulation.]

  25. Fundamental property of casts Lemma 9. If A & B < : n C then ⇒ B | BS = | A p p p ⇒ C | BS � | C ⇒ B | BS | A = = = Proof. Easy induction on A , B , and C . Corollary 10 (Fundamental Property of Casts) . Let M be a term of λ B . If A & B < : n C then p p p ctx ⇒ B ⇒ C ⇒ B M : A = = B M : A = = Proof. Immediate from Lemma 4 and full abstraction for λ C and λ S . [Required a custom bisimulation and six lemmas in Siek and Wadler (2010)!]

  26. Part VI Conclusion

  27. Three calcluli • λ B Blame calculus Findler and Felleisen (2002) Wadler and Findler (2009) • λ C Coercion calculus Henglein (1994) • λ S Space-efficient coercion calculus Hermann, Tomb, Flanagan (2007) Siek and Wadler (2010) Garcia (2013)

  28. Full abstraction Strong correctness property: Full abstraction ctx ctx if and only if | M | BC = C | N | BC • M = B N ctx ctx if and only if | M | CS = T | N | CS • M = C N Equivalences in λ B and λ C easily proved in λ S Key lemma Fundamental property of casts < : + Four subtyping relations ( < : < : − < : n ) Translation between λ B and λ C explains < : + and < : −

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend