Blame for All Amal Ahmed, Indiana University Robert Bruce Findler, - - PowerPoint PPT Presentation

blame for all
SMART_READER_LITE
LIVE PREVIEW

Blame for All Amal Ahmed, Indiana University Robert Bruce Findler, - - PowerPoint PPT Presentation

Blame for All Amal Ahmed, Indiana University Robert Bruce Findler, Northwestern University Jacob Matthews, Google Philip Wadler, University of Edinburgh A repeated theme Henglein (1994): Dynamic typing Findler and Felleisen (2002):


slide-1
SLIDE 1

Blame for All

Amal Ahmed, Indiana University Robert Bruce Findler, Northwestern University Jacob Matthews, Google Philip Wadler, University of Edinburgh

slide-2
SLIDE 2
slide-3
SLIDE 3
slide-4
SLIDE 4

A repeated theme

Henglein (1994): Dynamic typing Findler and Felleisen (2002): Contracts Siek and Taha (2006): Gradual types Tobin-Hochstadt and Felleisen (2006): Migratory types Flanagan (2006): Hybrid types

slide-5
SLIDE 5

A repeated theme

Javascript 4.0 Perl 6.0 C# 4.0 Visual Basic 9.0

slide-6
SLIDE 6

Part I

Blame

slide-7
SLIDE 7

Syntax

base type B type S, T ::= B | S → T | * cast C, D ::= B | C → D | * ground G, H ::= B | * → * blame label p, q term s, t, u ::= x | λx : S. t | t s | D ⇐ Cp s

slide-8
SLIDE 8

Typing

Γ ⊢ t : T Γ ⊢ s : S S ∼ T Γ ⊢ T ⇐ Sp s : T

Compatibility

S ∼ T S ∼ * * ∼ T B ∼ B S ∼ S′ T ∼ T ′ S → T ∼ S′ → T ′

slide-9
SLIDE 9

Typing

Γ ⊢ t : T Γ ⊢ s : |C| C ✁ D Γ ⊢ D ⇐ Cp s : |D|

Compatibility

C ✁ D C ✁ * * ✁ D B ✁ B C′ ✁ C D ✁ D′ C → D ✁ C′ → D′

Erasure

|C| = T |B| = B |C → D| = |C| → |D| |*| = *

slide-10
SLIDE 10

Syntax

ground G, H ::= B | * → * value v, w ::= λx. t | * ⇐ Gp v

Reductions

s − → t (λx. t) v − → t[x := v] C′→D′ ⇐ C→Dp v − → λx. D′ ⇐ Dp v (C ⇐ C′¯

p x)

* ⇐ *p v − → v B ⇐ Bp v − → v * ⇐ C→Dp v − → * ⇐ *→*p *→* ⇐ C→Dp v C→D ⇐ *p v − → C→D ⇐ *→*p *→* ⇐ *p v G ⇐ *q* ⇐ Gp v − → v H ⇐ *q* ⇐ Gp v − → blame q, if G = H

slide-11
SLIDE 11

Part II

Blame for all

slide-12
SLIDE 12

Syntax

base type B type S, T ::= B | S → T | * | X | ∀X. T cast C, D ::= B | C → D | * | X | ∀X. C | k(T) ground G, H ::= B | * → * | k(T) term s, t, u ::= x | λx : S. t | t s | D ⇐ Cp s λX. t | t S | s isp G

slide-13
SLIDE 13

Typing

Γ ⊢ t : T Γ ⊢ s : |C| C ✁ D Γ ⊢ D ⇐ Cp s : |D|

Compatibility

C ✁ D X ✁ X k(T) ✁ k(T) C[X := *] ✁ D ∀X. C ✁ D C ✁ D X ∈ C C ✁ ∀X. D

Erasure

|C| = T |X| = X |∀X. C| = ∀X. |C| |k(T)| = T

slide-14
SLIDE 14

Compatibility is reflexive C ✁ D C[X := *] ✁ D ∀X. C ✁ D X ∈ ∀X. C ∀X. C ✁ ∀X. D

slide-15
SLIDE 15

Reduction K; s − → t; K′ K; (ΛX. t) S − → t[X := k(S)]; K ∪ {k}, if k ∈ K D ⇐ ∀X. Cp v − → D ⇐ C[X := *]p (v *) ∀X. D ⇐ Cp v − → ΛX. D ⇐ Cp v, if X ∈ C, v

slide-16
SLIDE 16

Reduction, continued (* ⇐ Gp v) isq G − → true, if G = k(T) (* ⇐ Gp v) isq H − → false, if G = H, k(T) (* ⇐ k(T)p v) isq H − → blame q

slide-17
SLIDE 17

Part III

Subtyping

slide-18
SLIDE 18

Subtype C <: D C <: G C <: * * <: * B <: B C′ <: C D <: D′ C → D <: C′ → D′ Positive subtype C <:+ D C <:+ * B <:+ B C′ <:− C D <:+ D′ C → D <:+ C′ → D′ Negative subtype C <:− D C <:− G C <:− D * <:− D B <:− B C′ <:+ C D <:− D′ C → D <:− C′ → D′ Naive subtype C <:n D C <:n * B <:n B C <:n C′ D <:n D′ C → D <:n C′ → D′

slide-19
SLIDE 19

Examples * → I <: I → * I → I <:n * → *

slide-20
SLIDE 20

Tangram theorems C <: D iff C <:+ D and C <:− D C <:n D iff C <:+ D and D <:− C

slide-21
SLIDE 21

Safety

C <:+ D s sf p D ⇐ Cp s sf p C <:− D s sf p D ⇐ C¯

p s sf p

q = p, ¯ p s sf p D ⇐ Cq s sf p x sf p t sf p λx. t sf p t sf p s sf p t s sf p

slide-22
SLIDE 22

Blame theorem

Preservation If s sf p and s − → t then t sf p Progress If t sf p then t − → blame p

slide-23
SLIDE 23

Part IV

Subtyping for all

slide-24
SLIDE 24

Subtype C <: D X <: X k(T) <: k(T) Positive subtype C <:+ D X <:+ X k(T) <:+ k(T) Negative subtype C <:− D X <:− X k(T) <:− k(T) Naive subtype C <:n D X <:n X k(T) <:n k(T)

slide-25
SLIDE 25

Subtype C <: D C[X := *] <: D ∀X. C <: D C <: D X ∈ C C <: ∀X. D Positive subtype C <:+ D C[X := *] <:+ D ∀X. C <:+ D C <:+ D X ∈ C C <:+ ∀X. D Negative subtype C <:− D C[X := *] <:− D ∀X. C <:− D C <:− D X ∈ C C <:− ∀X. D Naive subtype C <:n D C[X := *] <:n D ∀X. C <:n D C <:n D X ∈ C C <:n ∀X. D

slide-26
SLIDE 26

Subtyping is not reflexive

C <: D incorrect! C[X := *] <: D ∀X. C <: D X ∈ ∀X. C ∀X. C <: ∀X. D

slide-27
SLIDE 27

Blame theorem still holds

Preservation If s sf p and s − → t then t sf p Progress If t sf p then t − → blame p

slide-28
SLIDE 28

Tangram theorems still hold C <: D iff C <:+ D and C <:− D C <:n D iff C <:+ D and D <:− C

slide-29
SLIDE 29

Second Tangram Theorem requires two lemmas

Lemma 1: Assume X ∈ D D <:− C[X := *] iff D <:− C C[X := *] <:+ D iff C <:+ D Lemma 2: C <:+ D and X ∈ C implies X ∈ D C <:− D and X ∈ D implies X ∈ C

slide-30
SLIDE 30

Better subtyping

C <:′ D C <:′ G C <:′ * * <:′ * B <:′ B C′ <:′ C D <:′ D′ C → D <:′ C′ → D′ X <:′ X k(T) <:′ k(T) C[X := T] <:′ D ∀X. C <:′ D C <:′ D X ∈ C C <:′ ∀X. D Maybe ordinary subtyping is of some use after all ...

slide-31
SLIDE 31

The end

slide-32
SLIDE 32

Bonus material

slide-33
SLIDE 33

Counterexample

It is tempting to take C[X := T] <:+ D ∀X. C <:+ D but that would be wrong, since * <:− I I <:+ I I → I <:+ * → I ∀X. X → X <:+ * → I

slide-34
SLIDE 34

and (* → I ⇐ ∀X. X → Xp id) true − → (* → I ⇐ * → *p id *) true − → I ⇐ *p id * (* ⇐ *¯

p true)

− → I ⇐ *p true − → blame p

slide-35
SLIDE 35

Proof of tangram theorem (one case)

Assume X ∈ D ∀X. C <:n D iff (def’n subtyping, inversion) C[X := *] <:n D iff (inductive hypothesis) C[X := *] <:+ D and D <:− C[X := *] iff (Lemma 1) C[X := *] <:+ D and D <:− C iff (def’n subtyping, inversion) ∀X. C <:+ D and D <:− ∀X. C

slide-36
SLIDE 36

Proof of tangram theorem (another case)

Assume X ∈ C C <:n ∀X. D iff (def’n subtyping, inversion) C <:n D iff (inductive hypothesis) C <:+ D and D <:− C iff (Lemma 2, X ∈ D implies D = D[X := *]) C <:+ D and D[X := *] <:− C iff (def’n subtyping, inversion) C <:+ ∀X. D and ∀X. D <:− C