A Kripke Logical Relation for Linear Functions

80
A Kripke Logical Relation for Linear Functions: The Story of a Free Theorem in the Presence of Non-termination Phillip Mates & Amal Ahmed Northeastern University

Transcript of A Kripke Logical Relation for Linear Functions

Page 1: A Kripke Logical Relation for Linear Functions

A Kripke Logical Relation for Linear Functions:

The Story of a Free Theorem in the Presence of Non-termination

Phillip Mates & Amal AhmedNortheastern University

Page 2: A Kripke Logical Relation for Linear Functions

2

Programmers shouldn't have to think about compilers

Page 3: A Kripke Logical Relation for Linear Functions

3

Fully abstract compiler

Source Target

Page 4: A Kripke Logical Relation for Linear Functions

4

Fully abstract compiler

Source Target

preserves equivalence

Page 5: A Kripke Logical Relation for Linear Functions

5

Fully abstract compiler

Source Target

reflects equivalence

preserves equivalence

&

Page 6: A Kripke Logical Relation for Linear Functions

6

Verifying a CPS translation fully abstract

Source

Target

Page 7: A Kripke Logical Relation for Linear Functions

7

Outline

Finding a fully abstract CPS translation w/ • Standard CPS

• Polymorphic CPS ( only in a pure setting)

• Linear + polymorphic CPS

Proving full-abstraction

Towards a semantic model for linearly-treated functions

Page 8: A Kripke Logical Relation for Linear Functions

8

Standard CPS isn't fully abstract

Page 9: A Kripke Logical Relation for Linear Functions

9

Standard CPS isn't fully abstract

Page 10: A Kripke Logical Relation for Linear Functions

10

Standard CPS isn't fully abstract

Page 11: A Kripke Logical Relation for Linear Functions

11

Standard CPS isn't fully abstract

Page 12: A Kripke Logical Relation for Linear Functions

12

Standard CPS isn't fully abstract

Page 13: A Kripke Logical Relation for Linear Functions

13

Standard CPS isn't fully abstract

Page 14: A Kripke Logical Relation for Linear Functions

14

Standard CPS isn't fully abstract

Page 15: A Kripke Logical Relation for Linear Functions

15

Standard CPS isn't fully abstract

Page 16: A Kripke Logical Relation for Linear Functions

16

How can we modify the standardCPS translation to be fully abstract?

Page 17: A Kripke Logical Relation for Linear Functions

17

Standard CPS

Ahmed & Blume's polymorphic CPS

Page 18: A Kripke Logical Relation for Linear Functions

18

What happens when we add non-termination?

Standard CPS

Ahmed & Blume's polymorphic CPS

Page 19: A Kripke Logical Relation for Linear Functions

19

Linear + polymorphic CPS

Standard CPS

Ahmed & Blume's polymorphic CPS

Page 20: A Kripke Logical Relation for Linear Functions

20

Outline

Finding a fully abstract CPS translation w/

Proving full-abstraction• Polymorphic CPS proof

• Scaling to a non-terminating setting using linearity

Towards a semantic model for linearly-treated functions

Page 21: A Kripke Logical Relation for Linear Functions

21

Proving polymorphic CPS fully abstract

Ahmed + Blume's approach relies ona type isomorphism:

Page 22: A Kripke Logical Relation for Linear Functions

22

Proving polymorphic CPS fully abstract

The type isomorphism relies ona parametric condition:

Page 23: A Kripke Logical Relation for Linear Functions

23

Parametric condition fails in the presence of non-termination

Page 24: A Kripke Logical Relation for Linear Functions

24

Parametric condition fails in the presence of non-termination

Page 25: A Kripke Logical Relation for Linear Functions

25

Parametric condition fails in the presence of non-termination

Page 26: A Kripke Logical Relation for Linear Functions

26

Parametric condition fails in the presence of non-termination

Page 27: A Kripke Logical Relation for Linear Functions

27

A step back

Ahmed & Blume's polymorphic CPS

Page 28: A Kripke Logical Relation for Linear Functions

28

A step back

Ahmed & Blume's polymorphic CPS

requires

Page 29: A Kripke Logical Relation for Linear Functions

29

A step back

Ahmed & Blume's polymorphic CPS

requires

Page 30: A Kripke Logical Relation for Linear Functions

30

A step back

Ahmed & Blume's polymorphic CPS

requires

Linear + polymorphic CPS

Page 31: A Kripke Logical Relation for Linear Functions

31

A step back

Ahmed & Blume's polymorphic CPS

requires

Linear + polymorphic CPS

requires

Page 32: A Kripke Logical Relation for Linear Functions

32

A step back

Ahmed & Blume's polymorphic CPS

requires

Linear + polymorphic CPS

requires linear

Page 33: A Kripke Logical Relation for Linear Functions

33

A “linear” parametric conditionin presence of non-termination

linear

Page 34: A Kripke Logical Relation for Linear Functions

34

How do you prove thisnew parametric condition,

which uses continuations linearly?

Page 35: A Kripke Logical Relation for Linear Functions

35

Free theorem: use a logical relation

Page 36: A Kripke Logical Relation for Linear Functions

36

Free theorem: use a logical relation

Page 37: A Kripke Logical Relation for Linear Functions

37

Free theorem: use a logical relation

Page 38: A Kripke Logical Relation for Linear Functions

38

Free theorem: use a logical relation

Page 39: A Kripke Logical Relation for Linear Functions

39

Free theorem: use a logical relation

?

Page 40: A Kripke Logical Relation for Linear Functions

40

Proving

Page 41: A Kripke Logical Relation for Linear Functions

41

Proving

know

Page 42: A Kripke Logical Relation for Linear Functions

42

Proving

know

Page 43: A Kripke Logical Relation for Linear Functions

43

Proving

showknow

Page 44: A Kripke Logical Relation for Linear Functions

44

Proving

know show

Page 45: A Kripke Logical Relation for Linear Functions

45

Proving

know:

showknow

Page 46: A Kripke Logical Relation for Linear Functions

46

Proving

know:

show:

showknow

Page 47: A Kripke Logical Relation for Linear Functions

47

Proving

know:

show:

showknow

Page 48: A Kripke Logical Relation for Linear Functions

48

Proving

Page 49: A Kripke Logical Relation for Linear Functions

49

Proving

know

Page 50: A Kripke Logical Relation for Linear Functions

50

Proving

know

know

Page 51: A Kripke Logical Relation for Linear Functions

51

Proving

show

know

know

Page 52: A Kripke Logical Relation for Linear Functions

52

show

know

Proving

know

behaviour?

Page 53: A Kripke Logical Relation for Linear Functions

53

show

know

know

Proving

Page 54: A Kripke Logical Relation for Linear Functions

54

show

know

Proving

know

Page 55: A Kripke Logical Relation for Linear Functions

55

show

know

Proving

=know

Page 56: A Kripke Logical Relation for Linear Functions

56

Outline

Finding a fully abstract CPS translation w/

Proving full-abstraction

Towards a semantic model for linearly-treated functions

Page 57: A Kripke Logical Relation for Linear Functions

57

?

Function semantics: case 1

Page 58: A Kripke Logical Relation for Linear Functions

58

for all possible inputs

Function semantics: case 1

unrestrictedusage

Page 59: A Kripke Logical Relation for Linear Functions

59

Function semantics: case 2

for all possible inputs &treat inputs linearly

unrestrictedusage

Page 60: A Kripke Logical Relation for Linear Functions

60

for particular inputs

Function semantics: case 3

linearly used

Page 61: A Kripke Logical Relation for Linear Functions

61

Function semantics: case 4

for particular inputs &treat input linearly

linearly used

Page 62: A Kripke Logical Relation for Linear Functions

62

Relating linearly-treated functions

Page 63: A Kripke Logical Relation for Linear Functions

63

Relating linearly-treated functions

Page 64: A Kripke Logical Relation for Linear Functions

64

Relating linearly-treated functions

Page 65: A Kripke Logical Relation for Linear Functions

65

Relating linearly-treated functions

Page 66: A Kripke Logical Relation for Linear Functions

66

Relating linearly-treated functions

where

Page 67: A Kripke Logical Relation for Linear Functions

67

Linearity by default

Page 68: A Kripke Logical Relation for Linear Functions

68

Kripke logical relation for linearity

Page 69: A Kripke Logical Relation for Linear Functions

69

Kripke logical relation for linearity

Page 70: A Kripke Logical Relation for Linear Functions

70

Kripke logical relation for linearity

Page 71: A Kripke Logical Relation for Linear Functions

71

Kripke logical relation for linearity

Page 72: A Kripke Logical Relation for Linear Functions

72

Kripke logical relation for linearity

Page 73: A Kripke Logical Relation for Linear Functions

73

Kripke logical relation for linearity

Page 74: A Kripke Logical Relation for Linear Functions

74

Kripke logical relation for linearity

Page 75: A Kripke Logical Relation for Linear Functions

75

Kripke logical relation for linearity

Page 76: A Kripke Logical Relation for Linear Functions

76

Related Work

Fully abstract CPS for PCF [Laird]

• Uses game semantics proof

Logical relation for linear free theorems [Zhao et. al.]

• Open logical relation to ensure preservation of linear resources

TT logical relation for Lily [Bierman et. al.]

Page 77: A Kripke Logical Relation for Linear Functions

77

Conclusion

Fully abstract CPS in a language with rec. types using operational proof techniques

requires

which requires

Page 78: A Kripke Logical Relation for Linear Functions

78

Conclusion

Fully abstract CPS in a language with rec. types using operational proof techniques

requires

which requires

Kripke logical relation that can distinguishlinearly-treated: unrestricted:

Page 79: A Kripke Logical Relation for Linear Functions

79

Page 80: A Kripke Logical Relation for Linear Functions

80

Why polymorphism:ST boundary semantics