designing precise pushdown higher-order flow analysesdeeglaze.github.io/ibmpl2012-slides.pdf · 2....

97
Designing Precise Pushdown Higher-Order Flow Analyses J. Ian Johnson, David Van Horn and Olin Shivers {ianj,dvanhorn,shivers}@ccs.neu.edu Northeastern University Boston, MA, USA 1

Upload: others

Post on 22-Sep-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Designing Precise Pushdown Higher-Order Flow Analysesdeeglaze.github.io/ibmpl2012-slides.pdf · 2. Flow analysis is indispensible Every language should have one 3. Analysis is great

Designing Precise Pushdown

Higher-Order Flow Analyses

J. Ian Johnson, David Van Horn and Olin Shivers{ianj,dvanhorn,shivers}@ccs.neu.edu

Northeastern UniversityBoston, MA, USA

1

Page 2: Designing Precise Pushdown Higher-Order Flow Analysesdeeglaze.github.io/ibmpl2012-slides.pdf · 2. Flow analysis is indispensible Every language should have one 3. Analysis is great

Flow analysis is indispensible

2

Page 3: Designing Precise Pushdown Higher-Order Flow Analysesdeeglaze.github.io/ibmpl2012-slides.pdf · 2. Flow analysis is indispensible Every language should have one 3. Analysis is great

Flow analysis is indispensible

Every language should have one

3

Page 4: Designing Precise Pushdown Higher-Order Flow Analysesdeeglaze.github.io/ibmpl2012-slides.pdf · 2. Flow analysis is indispensible Every language should have one 3. Analysis is great

Analysis is great

• Compiler optimizations

4

Page 5: Designing Precise Pushdown Higher-Order Flow Analysesdeeglaze.github.io/ibmpl2012-slides.pdf · 2. Flow analysis is indispensible Every language should have one 3. Analysis is great

Analysis is great

• Compiler optimizations

• Type reconstruction

5

Page 6: Designing Precise Pushdown Higher-Order Flow Analysesdeeglaze.github.io/ibmpl2012-slides.pdf · 2. Flow analysis is indispensible Every language should have one 3. Analysis is great

Analysis is great

• Compiler optimizations

• Type reconstruction

• Deadlock detection

6

Page 7: Designing Precise Pushdown Higher-Order Flow Analysesdeeglaze.github.io/ibmpl2012-slides.pdf · 2. Flow analysis is indispensible Every language should have one 3. Analysis is great

Analysis is great

• Compiler optimizations

• Type reconstruction

• Deadlock detection

• Data race detection

7

Page 8: Designing Precise Pushdown Higher-Order Flow Analysesdeeglaze.github.io/ibmpl2012-slides.pdf · 2. Flow analysis is indispensible Every language should have one 3. Analysis is great

Analysis is great

• Compiler optimizations

• Type reconstruction

• Deadlock detection

• Data race detection

• Code quality enforcement

8

Page 9: Designing Precise Pushdown Higher-Order Flow Analysesdeeglaze.github.io/ibmpl2012-slides.pdf · 2. Flow analysis is indispensible Every language should have one 3. Analysis is great

Analysis is great

• Compiler optimizations

• Type reconstruction

• Deadlock detection

• Data race detection

• Code quality enforcement

• Hundreds more

9

Page 10: Designing Precise Pushdown Higher-Order Flow Analysesdeeglaze.github.io/ibmpl2012-slides.pdf · 2. Flow analysis is indispensible Every language should have one 3. Analysis is great

Analysis is terrible

• Annoying false positives

10

Page 11: Designing Precise Pushdown Higher-Order Flow Analysesdeeglaze.github.io/ibmpl2012-slides.pdf · 2. Flow analysis is indispensible Every language should have one 3. Analysis is great

Analysis is terrible

• Annoying false positives

• Takes too long

11

Page 12: Designing Precise Pushdown Higher-Order Flow Analysesdeeglaze.github.io/ibmpl2012-slides.pdf · 2. Flow analysis is indispensible Every language should have one 3. Analysis is great

Analysis is terrible

• Annoying false positives

• Takes too long

• Hard to implement

12

Page 13: Designing Precise Pushdown Higher-Order Flow Analysesdeeglaze.github.io/ibmpl2012-slides.pdf · 2. Flow analysis is indispensible Every language should have one 3. Analysis is great

Analysis is terrible

• Annoying false positives

• Takes too long

• Hard to implement

• Hard to show correct

13

Page 14: Designing Precise Pushdown Higher-Order Flow Analysesdeeglaze.github.io/ibmpl2012-slides.pdf · 2. Flow analysis is indispensible Every language should have one 3. Analysis is great

Analysis is terrible

• Annoying false positives

• Takes too long

• Hard to implement

• Hard to show correct

• The good ones inherently first-order

14

Page 15: Designing Precise Pushdown Higher-Order Flow Analysesdeeglaze.github.io/ibmpl2012-slides.pdf · 2. Flow analysis is indispensible Every language should have one 3. Analysis is great

Analysis is terrible

• Annoying false positives

• Takes too long

• Hard to implement

• Hard to show correct

• The good ones inherently first-order

We can fix this

15

Page 16: Designing Precise Pushdown Higher-Order Flow Analysesdeeglaze.github.io/ibmpl2012-slides.pdf · 2. Flow analysis is indispensible Every language should have one 3. Analysis is great

Analysis is terrible

• Annoying false positives

• Takes too long

• Hard to implement

• Hard to show correct

• The good ones inherently first-order

We can fix thisFirst some history

16

Page 17: Designing Precise Pushdown Higher-Order Flow Analysesdeeglaze.github.io/ibmpl2012-slides.pdf · 2. Flow analysis is indispensible Every language should have one 3. Analysis is great

Flow Graphs vs. Programs

First-order

(Hecht 77) CFG + lattice

Higher-order

17

Page 18: Designing Precise Pushdown Higher-Order Flow Analysesdeeglaze.github.io/ibmpl2012-slides.pdf · 2. Flow analysis is indispensible Every language should have one 3. Analysis is great

Flow Graphs vs. Programs

First-order

(Hecht 77) CFG + lattice

(Sharir & Pnueli 81) CFG + lattice + summaries

Higher-order

(Jones & Muchnick 82) Program + set constraints

18

Page 19: Designing Precise Pushdown Higher-Order Flow Analysesdeeglaze.github.io/ibmpl2012-slides.pdf · 2. Flow analysis is indispensible Every language should have one 3. Analysis is great

Flow Graphs vs. Programs

First-order

(Hecht 77) CFG + lattice

(Sharir & Pnueli 81) CFG + lattice + summaries

(Reps 95) PDS + idempotent semiring

Higher-order

(Jones & Muchnick 82) Program + set constraints

(Shivers 91) CPS + set constraints

19

Page 20: Designing Precise Pushdown Higher-Order Flow Analysesdeeglaze.github.io/ibmpl2012-slides.pdf · 2. Flow analysis is indispensible Every language should have one 3. Analysis is great

Flow Graphs vs. Programs

First-order

(Hecht 77) CFG + lattice

(Sharir & Pnueli 81) CFG + lattice + summaries

(Reps 95) PDS + idempotent semiring

Higher-order

(Jones & Muchnick 82) Program + set constraints

(Shivers 91) CPS + set constraints

(Might 07) CPS + abstract small step semantics

20

Page 21: Designing Precise Pushdown Higher-Order Flow Analysesdeeglaze.github.io/ibmpl2012-slides.pdf · 2. Flow analysis is indispensible Every language should have one 3. Analysis is great

Flow Graphs vs. Programs

First-order

(Hecht 77) CFG + lattice

(Sharir & Pnueli 81) CFG + lattice + summaries

(Reps 95) PDS + idempotent semiring

Higher-order

(Jones & Muchnick 82) Program + set constraints

(Shivers 91) CPS + set constraints

(Might 07) CPS + abstract small step semantics

(Might & Van Horn 10) Derived from concrete

21

Page 22: Designing Precise Pushdown Higher-Order Flow Analysesdeeglaze.github.io/ibmpl2012-slides.pdf · 2. Flow analysis is indispensible Every language should have one 3. Analysis is great

Flow Graphs vs. Programs

First-order

(Hecht 77) CFG + lattice

(Sharir & Pnueli 81) CFG + lattice + summaries

(Reps 95) PDS + idempotent semiring

Higher-order

(Jones & Muchnick 82) Program + set constraints

(Shivers 91) CPS + set constraints

(Might 07) CPS + abstract small step semantics

(Might & Van Horn 10) Derived from concrete

(Vardoulakis & Shivers 10) CPS + summaries

(Earl et al. 10) ANF + Dyck state graph

22

Page 23: Designing Precise Pushdown Higher-Order Flow Analysesdeeglaze.github.io/ibmpl2012-slides.pdf · 2. Flow analysis is indispensible Every language should have one 3. Analysis is great

Flow Graphs vs. Programs

First-order

(Hecht 77) CFG + lattice

(Sharir & Pnueli 81) CFG + lattice + summaries

(Reps 95) PDS + idempotent semiring

Higher-order

(Jones & Muchnick 82) Program + set constraints

(Shivers 91) CPS + set constraints

(Might 07) CPS + abstract small step semantics

(Might & Van Horn 10) Derived from concrete

(Vardoulakis & Shivers 10) CPS + summaries

(Earl et al. 10) ANF + Dyck state graph

Graphs are a bad abstraction

23

Page 24: Designing Precise Pushdown Higher-Order Flow Analysesdeeglaze.github.io/ibmpl2012-slides.pdf · 2. Flow analysis is indispensible Every language should have one 3. Analysis is great

Flow Graphs vs. Programs

First-order

(Hecht 77) CFG + lattice

(Sharir & Pnueli 81) CFG + lattice + summaries

(Reps 95) PDS + idempotent semiring

Higher-order

(Jones & Muchnick 82) Program + set constraints

(Shivers 91) CPS + set constraints

(Might 07) CPS + abstract small step semantics

(Might & Van Horn 10) Derived from concrete

(Vardoulakis & Shivers 10) CPS + summaries

(Earl et al. 10) ANF + Dyck state graph

Graphs are a bad abstraction

24

Page 25: Designing Precise Pushdown Higher-Order Flow Analysesdeeglaze.github.io/ibmpl2012-slides.pdf · 2. Flow analysis is indispensible Every language should have one 3. Analysis is great

Flow Graphs vs. Programs

First-order

(Hecht 77) CFG + lattice

(Sharir & Pnueli 81) CFG + lattice + summaries

(Reps 95) PDS + idempotent semiring

Higher-order

(Jones & Muchnick 82) Program + set constraints

(Shivers 91) CPS + set constraints

(Might 07) CPS + abstract small step semantics

(Might & Van Horn 10) Derived from concrete

(Vardoulakis & Shivers 10) CPS + summaries

(Earl et al. 10) ANF + Dyck state graph

25

Page 26: Designing Precise Pushdown Higher-Order Flow Analysesdeeglaze.github.io/ibmpl2012-slides.pdf · 2. Flow analysis is indispensible Every language should have one 3. Analysis is great

Flow Graphs vs. Programs

First-order

(Hecht 77) CFG + lattice

(Sharir & Pnueli 81) CFG + lattice + summaries

(Reps 95) PDS + idempotent semiring

Higher-order

(Jones & Muchnick 82) Program + set constraints

(Shivers 91) CPS + set constraints

(Might 07) CPS + abstract small step semantics

(Might & Van Horn 10) Derived from concrete

(Vardoulakis & Shivers 10) CPS + summaries

(Earl et al. 10) ANF + Dyck state graph

?

26

Page 27: Designing Precise Pushdown Higher-Order Flow Analysesdeeglaze.github.io/ibmpl2012-slides.pdf · 2. Flow analysis is indispensible Every language should have one 3. Analysis is great

Analyses are derivable [Might & Van Horn 2010]

• Start: concrete machine semantics

27

Page 28: Designing Precise Pushdown Higher-Order Flow Analysesdeeglaze.github.io/ibmpl2012-slides.pdf · 2. Flow analysis is indispensible Every language should have one 3. Analysis is great

Analyses are derivable [Might & Van Horn 2010]

• Start: concrete machine semantics

• Simple transforms: put semantics in right form

28

Page 29: Designing Precise Pushdown Higher-Order Flow Analysesdeeglaze.github.io/ibmpl2012-slides.pdf · 2. Flow analysis is indispensible Every language should have one 3. Analysis is great

Analyses are derivable [Might & Van Horn 2010]

• Start: concrete machine semantics

• Simple transforms: put semantics in right form

• Analysis: pointwise-abstraction

29

Page 30: Designing Precise Pushdown Higher-Order Flow Analysesdeeglaze.github.io/ibmpl2012-slides.pdf · 2. Flow analysis is indispensible Every language should have one 3. Analysis is great

Functions Without Stack

(define (sqr x) (* x x))

(sqrt (+ (sqr y) (sqr z)))

30

Page 31: Designing Precise Pushdown Higher-Order Flow Analysesdeeglaze.github.io/ibmpl2012-slides.pdf · 2. Flow analysis is indispensible Every language should have one 3. Analysis is great

Functions Without Stack

(define (sqr x) (* x x))

(sqrt (+ (sqr y) (sqr z)))

31

Page 32: Designing Precise Pushdown Higher-Order Flow Analysesdeeglaze.github.io/ibmpl2012-slides.pdf · 2. Flow analysis is indispensible Every language should have one 3. Analysis is great

Functions Without Stack

(define (sqr x) (* x x))

(sqrt (+ (sqr y) (sqr z)))

0CFA: Not even terminating!

32

Page 33: Designing Precise Pushdown Higher-Order Flow Analysesdeeglaze.github.io/ibmpl2012-slides.pdf · 2. Flow analysis is indispensible Every language should have one 3. Analysis is great

Pushdown Higher-Order Flow Analysis

33

Page 34: Designing Precise Pushdown Higher-Order Flow Analysesdeeglaze.github.io/ibmpl2012-slides.pdf · 2. Flow analysis is indispensible Every language should have one 3. Analysis is great

Pushdown Higher-Order Flow Analysis

34

Page 35: Designing Precise Pushdown Higher-Order Flow Analysesdeeglaze.github.io/ibmpl2012-slides.pdf · 2. Flow analysis is indispensible Every language should have one 3. Analysis is great

Pushdown Higher-Order Flow Analysis

35

Page 36: Designing Precise Pushdown Higher-Order Flow Analysesdeeglaze.github.io/ibmpl2012-slides.pdf · 2. Flow analysis is indispensible Every language should have one 3. Analysis is great

Pushdown Higher-Order Flow Analysis

36

Page 37: Designing Precise Pushdown Higher-Order Flow Analysesdeeglaze.github.io/ibmpl2012-slides.pdf · 2. Flow analysis is indispensible Every language should have one 3. Analysis is great

Pushdown Higher-Order Flow Analysis

37

Page 38: Designing Precise Pushdown Higher-Order Flow Analysesdeeglaze.github.io/ibmpl2012-slides.pdf · 2. Flow analysis is indispensible Every language should have one 3. Analysis is great

Pushdown Higher-Order Flow Analysis

38

Page 39: Designing Precise Pushdown Higher-Order Flow Analysesdeeglaze.github.io/ibmpl2012-slides.pdf · 2. Flow analysis is indispensible Every language should have one 3. Analysis is great

Pushdown Higher-Order Flow Analysis

39

Page 40: Designing Precise Pushdown Higher-Order Flow Analysesdeeglaze.github.io/ibmpl2012-slides.pdf · 2. Flow analysis is indispensible Every language should have one 3. Analysis is great

Pushdown Higher-Order Flow Analysis

40

Page 41: Designing Precise Pushdown Higher-Order Flow Analysesdeeglaze.github.io/ibmpl2012-slides.pdf · 2. Flow analysis is indispensible Every language should have one 3. Analysis is great

Pushdown Higher-Order Flow Analysis

41

Page 42: Designing Precise Pushdown Higher-Order Flow Analysesdeeglaze.github.io/ibmpl2012-slides.pdf · 2. Flow analysis is indispensible Every language should have one 3. Analysis is great

Analysis is terrible salvagable

• Annoying false positives

• Takes too long

• Hard to implement

• Hard to show correct

• The good ones inherently first-order

42

Page 43: Designing Precise Pushdown Higher-Order Flow Analysesdeeglaze.github.io/ibmpl2012-slides.pdf · 2. Flow analysis is indispensible Every language should have one 3. Analysis is great

Deriving Pushdown Analyses

• Start: Concrete machine semantics

43

Page 44: Designing Precise Pushdown Higher-Order Flow Analysesdeeglaze.github.io/ibmpl2012-slides.pdf · 2. Flow analysis is indispensible Every language should have one 3. Analysis is great

Deriving Pushdown Analyses

• Start: Concrete machine semantics

• Simple transform: memoize functions

44

Page 45: Designing Precise Pushdown Higher-Order Flow Analysesdeeglaze.github.io/ibmpl2012-slides.pdf · 2. Flow analysis is indispensible Every language should have one 3. Analysis is great

Deriving Pushdown Analyses

• Start: Concrete machine semantics

• Simple transform: memoize functions

• Simple transform: store functions’ calling contexts

45

Page 46: Designing Precise Pushdown Higher-Order Flow Analysesdeeglaze.github.io/ibmpl2012-slides.pdf · 2. Flow analysis is indispensible Every language should have one 3. Analysis is great

Deriving Pushdown Analyses

• Start: Concrete machine semantics

• Simple transform: memoize functions

• Simple transform: store functions’ calling contexts

• Simple transform: heap-allocate data

46

Page 47: Designing Precise Pushdown Higher-Order Flow Analysesdeeglaze.github.io/ibmpl2012-slides.pdf · 2. Flow analysis is indispensible Every language should have one 3. Analysis is great

Deriving Pushdown Analyses

• Start: Concrete machine semantics

• Simple transform: memoize functions

• Simple transform: store functions’ calling contexts

• Simple transform: heap-allocate data

• Analysis: pointwise-abstraction

47

Page 48: Designing Precise Pushdown Higher-Order Flow Analysesdeeglaze.github.io/ibmpl2012-slides.pdf · 2. Flow analysis is indispensible Every language should have one 3. Analysis is great

Deriving Pushdown Analyses

• Start: Concrete machine semantics

• Simple transform: memoize functions

• Simple transform: store functions’ calling contexts

• Simple transform: heap-allocate data

• Analysis: pointwise-abstraction

Gives semantic account of summaries

48

Page 49: Designing Precise Pushdown Higher-Order Flow Analysesdeeglaze.github.io/ibmpl2012-slides.pdf · 2. Flow analysis is indispensible Every language should have one 3. Analysis is great

Analysis is terrible salvagable

• Annoying false positives

• Takes too long

• Hard to implement

• Hard to show correct

• The good ones inherently first-order

49

Page 50: Designing Precise Pushdown Higher-Order Flow Analysesdeeglaze.github.io/ibmpl2012-slides.pdf · 2. Flow analysis is indispensible Every language should have one 3. Analysis is great

(app id 1)

Memo

Contexts

Environment:id ...app ...

(let* ([id (λ (x) x)][app (λ (f y) (f y))][n1 (app id 1)][n2 (app id 2)])

(+ n1 n2))

50

Page 51: Designing Precise Pushdown Higher-Order Flow Analysesdeeglaze.github.io/ibmpl2012-slides.pdf · 2. Flow analysis is indispensible Every language should have one 3. Analysis is great

(f y)

Memo

Contexts⟨app id 1⟩ (let* (... [n1 •] ...) ...)

Environment:id ...f idy 1

(let* ([id (λ (x) x)][app (λ (f y) (f y))][n1 (app id 1)][n2 (app id 2)])

(+ n1 n2))

51

Page 52: Designing Precise Pushdown Higher-Order Flow Analysesdeeglaze.github.io/ibmpl2012-slides.pdf · 2. Flow analysis is indispensible Every language should have one 3. Analysis is great

x

Memo

Contexts⟨app id 1⟩ (let* (... [n1 •] ...) ...)

⟨id 1⟩ (let* (... [app (λ (f y) •)] ...) ...)

Environment:x 1

(let* ([id (λ (x) x)][app (λ (f y) (f y))][n1 (app id 1)][n2 (app id 2)])

(+ n1 n2))

52

Page 53: Designing Precise Pushdown Higher-Order Flow Analysesdeeglaze.github.io/ibmpl2012-slides.pdf · 2. Flow analysis is indispensible Every language should have one 3. Analysis is great

x

Memo⟨id 1⟩ 1

Contexts⟨app id 1⟩ (let* (... [n1 •] ...) ...)

⟨id 1⟩ (let* (... [app (λ (f y) •)] ...) ...)

Environment:(let* ([id (λ (x) x)][app (λ (f y) (f y))][n1 (app id 1)][n2 (app id 2)])

(+ n1 n2))

53

Page 54: Designing Precise Pushdown Higher-Order Flow Analysesdeeglaze.github.io/ibmpl2012-slides.pdf · 2. Flow analysis is indispensible Every language should have one 3. Analysis is great

(f y)

Memo⟨id 1⟩ 1

⟨app id 1⟩ 1

Contexts⟨app id 1⟩ (let* (... [n1 •] ...) ...)

⟨id 1⟩ (let* (... [app (λ (f y) •)] ...) ...)

Environment:(let* ([id (λ (x) x)][app (λ (f y) (f y))][n1 (app id 1)][n2 (app id 2)])

(+ n1 n2))

54

Page 55: Designing Precise Pushdown Higher-Order Flow Analysesdeeglaze.github.io/ibmpl2012-slides.pdf · 2. Flow analysis is indispensible Every language should have one 3. Analysis is great

(app id 2)

Memo⟨id 1⟩ 1

⟨app id 1⟩ 1

Contexts⟨app id 1⟩ (let* (... [n1 •] ...) ...)

⟨id 1⟩ (let* (... [app (λ (f y) •)] ...) ...)

Environment:id ...app ...n1 1

(let* ([id (λ (x) x)][app (λ (f y) (f y))][n1 (app id 1)][n2 (app id 2)])

(+ n1 n2))

55

Page 56: Designing Precise Pushdown Higher-Order Flow Analysesdeeglaze.github.io/ibmpl2012-slides.pdf · 2. Flow analysis is indispensible Every language should have one 3. Analysis is great

(f y)

Memo⟨id 1⟩ 1

⟨app id 1⟩ 1

Contexts⟨app id 1⟩ (let* (... [n1 •] ...) ...)

⟨id 1⟩ (let* (... [app (λ (f y) •)] ...) ...)

⟨app id 2⟩ (let* (... [n2 •]) ...)

Environment:id ...f idy 2

(let* ([id (λ (x) x)][app (λ (f y) (f y))][n1 (app id 1)][n2 (app id 2)])

(+ n1 n2))

56

Page 57: Designing Precise Pushdown Higher-Order Flow Analysesdeeglaze.github.io/ibmpl2012-slides.pdf · 2. Flow analysis is indispensible Every language should have one 3. Analysis is great

x

Memo⟨id 1⟩ 1

⟨app id 1⟩ 1

Contexts⟨app id 1⟩ (let* (... [n1 •] ...) ...)

⟨id 1⟩ (let* (... [app (λ (f y) •)] ...) ...)

⟨app id 2⟩ (let* (... [n2 •]) ...)

⟨id 2⟩ (let* (... [app (λ (f y) •)] ...) ...)

Environment:x 2

(let* ([id (λ (x) x)][app (λ (f y) (f y))][n1 (app id 1)][n2 (app id 2)])

(+ n1 n2))

57

Page 58: Designing Precise Pushdown Higher-Order Flow Analysesdeeglaze.github.io/ibmpl2012-slides.pdf · 2. Flow analysis is indispensible Every language should have one 3. Analysis is great

x

Memo⟨id 1⟩ 1

⟨app id 1⟩ 1

⟨id 2⟩ 2

Contexts⟨app id 1⟩ (let* (... [n1 •] ...) ...)

⟨id 1⟩ (let* (... [app (λ (f y) •)] ...) ...)

⟨app id 2⟩ (let* (... [n2 •]) ...)

⟨id 2⟩ (let* (... [app (λ (f y) •)] ...) ...)

Environment:(let* ([id (λ (x) x)][app (λ (f y) (f y))][n1 (app id 1)][n2 (app id 2)])

(+ n1 n2))

58

Page 59: Designing Precise Pushdown Higher-Order Flow Analysesdeeglaze.github.io/ibmpl2012-slides.pdf · 2. Flow analysis is indispensible Every language should have one 3. Analysis is great

(f y)

Memo⟨id 1⟩ 1

⟨app id 1⟩ 1

⟨id 2⟩ 2

⟨app id 2⟩ 2

Contexts⟨app id 1⟩ (let* (... [n1 •] ...) ...)

⟨id 1⟩ (let* (... [app (λ (f y) •)] ...) ...)

⟨app id 2⟩ (let* (... [n2 •]) ...)

⟨id 2⟩ (let* (... [app (λ (f y) •)] ...) ...)

Environment:(let* ([id (λ (x) x)][app (λ (f y) (f y))][n1 (app id 1)][n2 (app id 2)])

(+ n1 n2))

59

Page 60: Designing Precise Pushdown Higher-Order Flow Analysesdeeglaze.github.io/ibmpl2012-slides.pdf · 2. Flow analysis is indispensible Every language should have one 3. Analysis is great

(+ n1 n2)

Memo⟨id 1⟩ 1

⟨app id 1⟩ 1

⟨id 2⟩ 2

⟨app id 2⟩ 2

Contexts⟨app id 1⟩ (let* (... [n1 •] ...) ...)

⟨id 1⟩ (let* (... [app (λ (f y) •)] ...) ...)

⟨app id 2⟩ (let* (... [n2 •]) ...)

⟨id 2⟩ (let* (... [app (λ (f y) •)] ...) ...)

Environment:id ...app ...n1 1n2 2

(let* ([id (λ (x) x)][app (λ (f y) (f y))][n1 (app id 1)][n2 (app id 2)])

(+ n1 n2))

60

Page 61: Designing Precise Pushdown Higher-Order Flow Analysesdeeglaze.github.io/ibmpl2012-slides.pdf · 2. Flow analysis is indispensible Every language should have one 3. Analysis is great

(app id 1)

Memo

Contexts

Store: σ₀

Start Store: σ₀

(let* ([id (λ (x) x)][app (λ (f y) (f y))][n1 (app id 1)][n2 (app id 2)])

(+ n1 n2))

61

Page 62: Designing Precise Pushdown Higher-Order Flow Analysesdeeglaze.github.io/ibmpl2012-slides.pdf · 2. Flow analysis is indispensible Every language should have one 3. Analysis is great

(f y)

Memo

Contexts⟨app σ₁ ⟩ ((let* (... [n1 •] ...) ...) σ₀)

Store: σ₁

f id

y 1

Start Store: σ₁

(let* ([id (λ (x) x)][app (λ (f y) (f y))][n1 (app id 1)][n2 (app id 2)])

(+ n1 n2))

62

Page 63: Designing Precise Pushdown Higher-Order Flow Analysesdeeglaze.github.io/ibmpl2012-slides.pdf · 2. Flow analysis is indispensible Every language should have one 3. Analysis is great

x

Memo

Contexts⟨app σ₁ ⟩ ((let* (... [n1 •] ...) ...) σ₀)

⟨id σ₂ ⟩ ((let* (... [app (λ (f y) •)] ...) ...) σ₁)

Store: σ₂

f id

y 1

x 1

Start Store: σ₂

(let* ([id (λ (x) x)][app (λ (f y) (f y))][n1 (app id 1)][n2 (app id 2)])

(+ n1 n2))

63

Page 64: Designing Precise Pushdown Higher-Order Flow Analysesdeeglaze.github.io/ibmpl2012-slides.pdf · 2. Flow analysis is indispensible Every language should have one 3. Analysis is great

x

Memo⟨id σ₂⟩ (1 σ₂)

Contexts⟨app σ₁ ⟩ ((let* (... [n1 •] ...) ...) σ₀)

⟨id σ₂ ⟩ ((let* (... [app (λ (f y) •)] ...) ...) σ₁)

Store: σ₂

f id

y 1

x 1

Start Store: σ₂

(let* ([id (λ (x) x)][app (λ (f y) (f y))][n1 (app id 1)][n2 (app id 2)])

(+ n1 n2))

64

Page 65: Designing Precise Pushdown Higher-Order Flow Analysesdeeglaze.github.io/ibmpl2012-slides.pdf · 2. Flow analysis is indispensible Every language should have one 3. Analysis is great

(f y)

Memo⟨id σ₂⟩ (1 σ₂)

⟨app σ₁⟩ (1 σ₂)

Contexts⟨app σ₁ ⟩ ((let* (... [n1 •] ...) ...) σ₀)

⟨id σ₂ ⟩ ((let* (... [app (λ (f y) •)] ...) ...) σ₁)

Store: σ₂

f id

y 1

x 1

Start Store: σ₁

(let* ([id (λ (x) x)][app (λ (f y) (f y))][n1 (app id 1)][n2 (app id 2)])

(+ n1 n2))

65

Page 66: Designing Precise Pushdown Higher-Order Flow Analysesdeeglaze.github.io/ibmpl2012-slides.pdf · 2. Flow analysis is indispensible Every language should have one 3. Analysis is great

(app id 2)

Memo⟨id σ₂⟩ (1 σ₂)

⟨app σ₁⟩ (1 σ₂)

Contexts⟨app σ₁ ⟩ ((let* (... [n1 •] ...) ...) σ₀)

⟨id σ₂ ⟩ ((let* (... [app (λ (f y) •)] ...) ...) σ₁)

Store: σ₃

f id

y 1

x 1

n1 1

Start Store: σ₀

(let* ([id (λ (x) x)][app (λ (f y) (f y))][n1 (app id 1)][n2 (app id 2)])

(+ n1 n2))

66

Page 67: Designing Precise Pushdown Higher-Order Flow Analysesdeeglaze.github.io/ibmpl2012-slides.pdf · 2. Flow analysis is indispensible Every language should have one 3. Analysis is great

(f y)

Memo⟨id σ₂⟩ (1 σ₂)

⟨app σ₁⟩ (1 σ₂)

Contexts⟨app σ₁ ⟩ ((let* (... [n1 •] ...) ...) σ₀)

⟨id σ₂ ⟩ ((let* (... [app (λ (f y) •)] ...) ...) σ₁)

⟨app σ₄ ⟩ ((let* (... [n2 •]) ...) σ₀)

Store: σ₄

f id

y (1 2)

x 1

n1 1

Start Store: σ₄

(let* ([id (λ (x) x)][app (λ (f y) (f y))][n1 (app id 1)][n2 (app id 2)])

(+ n1 n2))

67

Page 68: Designing Precise Pushdown Higher-Order Flow Analysesdeeglaze.github.io/ibmpl2012-slides.pdf · 2. Flow analysis is indispensible Every language should have one 3. Analysis is great

x

Memo⟨id σ₂⟩ (1 σ₂)

⟨app σ₁⟩ (1 σ₂)

Contexts⟨app σ₁ ⟩ ((let* (... [n1 •] ...) ...) σ₀)

⟨id σ₂ ⟩ ((let* (... [app (λ (f y) •)] ...) ...) σ₁)

⟨app σ₄ ⟩ ((let* (... [n2 •]) ...) σ₀)

⟨id σ₅ ⟩ ((let* (... [app (λ (f y) •)] ...) ...) σ₄)

Store: σ₅

f id

y (1 2)

x (1 2)

n1 1

Start Store: σ₅

(let* ([id (λ (x) x)][app (λ (f y) (f y))][n1 (app id 1)][n2 (app id 2)])

(+ n1 n2))

68

Page 69: Designing Precise Pushdown Higher-Order Flow Analysesdeeglaze.github.io/ibmpl2012-slides.pdf · 2. Flow analysis is indispensible Every language should have one 3. Analysis is great

x

Memo⟨id σ₂⟩ (1 σ₂)

⟨app σ₁⟩ (1 σ₂)

⟨id σ₅⟩ (2 σ₅)

Contexts⟨app σ₁ ⟩ ((let* (... [n1 •] ...) ...) σ₀)

⟨id σ₂ ⟩ ((let* (... [app (λ (f y) •)] ...) ...) σ₁)

⟨app σ₄ ⟩ ((let* (... [n2 •]) ...) σ₀)

⟨id σ₅ ⟩ ((let* (... [app (λ (f y) •)] ...) ...) σ₄)

Store: σ₅

f id

y (1 2)

x (1 2)

n1 1

Start Store: σ₅

(let* ([id (λ (x) x)][app (λ (f y) (f y))][n1 (app id 1)][n2 (app id 2)])

(+ n1 n2))

69

Page 70: Designing Precise Pushdown Higher-Order Flow Analysesdeeglaze.github.io/ibmpl2012-slides.pdf · 2. Flow analysis is indispensible Every language should have one 3. Analysis is great

(f y)

Memo⟨id σ₂⟩ (1 σ₂)

⟨app σ₁⟩ (1 σ₂)

⟨id σ₅⟩ (2 σ₅)

⟨app σ₄⟩ (2 σ₅)

Contexts⟨app σ₁ ⟩ ((let* (... [n1 •] ...) ...) σ₀)

⟨id σ₂ ⟩ ((let* (... [app (λ (f y) •)] ...) ...) σ₁)

⟨app σ₄ ⟩ ((let* (... [n2 •]) ...) σ₀)

⟨id σ₅ ⟩ ((let* (... [app (λ (f y) •)] ...) ...) σ₄)

Store: σ₅

f id

y (1 2)

x (1 2)

n1 1

Start Store: σ₄

(let* ([id (λ (x) x)][app (λ (f y) (f y))][n1 (app id 1)][n2 (app id 2)])

(+ n1 n2))

70

Page 71: Designing Precise Pushdown Higher-Order Flow Analysesdeeglaze.github.io/ibmpl2012-slides.pdf · 2. Flow analysis is indispensible Every language should have one 3. Analysis is great

(+ n1 n2)

Memo⟨id σ₂⟩ (1 σ₂)

⟨app σ₁⟩ (1 σ₂)

⟨id σ₅⟩ (2 σ₅)

⟨app σ₄⟩ (2 σ₅)

Contexts⟨app σ₁ ⟩ ((let* (... [n1 •] ...) ...) σ₀)

⟨id σ₂ ⟩ ((let* (... [app (λ (f y) •)] ...) ...) σ₁)

⟨app σ₄ ⟩ ((let* (... [n2 •]) ...) σ₀)

⟨id σ₅ ⟩ ((let* (... [app (λ (f y) •)] ...) ...) σ₄)

Store: σ₆

f id

y (1 2)

x (1 2)

n1 1

n2 (1 2)

Start Store: σ₀

(let* ([id (λ (x) x)][app (λ (f y) (f y))][n1 (app id 1)][n2 (app id 2)])

(+ n1 n2))

71

Page 72: Designing Precise Pushdown Higher-Order Flow Analysesdeeglaze.github.io/ibmpl2012-slides.pdf · 2. Flow analysis is indispensible Every language should have one 3. Analysis is great

Heaps are imprecise

(+ n1 n2)

Memo⟨id σ₂⟩ (1 σ₂)

⟨app σ₁⟩ (1 σ₂)

⟨id σ₅⟩ (2 σ₅)

⟨app σ₄⟩ (2 σ₅)

Contexts⟨app σ₁ ⟩ ((let* (... [n1 •] ...) ...) σ₀)

⟨id σ₂ ⟩ ((let* (... [app (λ (f y) •)] ...) ...) σ₁)

⟨app σ₄ ⟩ ((let* (... [n2 •]) ...) σ₀)

⟨id σ₅ ⟩ ((let* (... [app (λ (f y) •)] ...) ...) σ₄)

Store: σ₆

f id

y (1 2)

x (1 2)

n1 1

n2 (1 2)

Start Store: σ₀

(let* ([id (λ (x) x)][app (λ (f y) (f y))][n1 (app id 1)][n2 (app id 2)])

(+ n1 n2))

72

Page 73: Designing Precise Pushdown Higher-Order Flow Analysesdeeglaze.github.io/ibmpl2012-slides.pdf · 2. Flow analysis is indispensible Every language should have one 3. Analysis is great

Fixed[Vardoulakis & Shivers 10]

Local storage (stack frames)

73

Page 74: Designing Precise Pushdown Higher-Order Flow Analysesdeeglaze.github.io/ibmpl2012-slides.pdf · 2. Flow analysis is indispensible Every language should have one 3. Analysis is great

(define (foldr f b lst) (letrec

([loop(λ (lst)(cond [(empty? lst) b]

[else (cons (f (car lst))(loop (cdr lst)))]))])

(loop lst)))

74

Page 75: Designing Precise Pushdown Higher-Order Flow Analysesdeeglaze.github.io/ibmpl2012-slides.pdf · 2. Flow analysis is indispensible Every language should have one 3. Analysis is great

(define (foldr f b lst) (letrec

([loop(λ (lst)(cond [(empty? lst) b]

[else (cons (f (car lst))(loop (cdr lst)))]))])

(loop lst)))

75

Page 76: Designing Precise Pushdown Higher-Order Flow Analysesdeeglaze.github.io/ibmpl2012-slides.pdf · 2. Flow analysis is indispensible Every language should have one 3. Analysis is great

(define (foldr f b lst) (letrec

([loop(λ (lst)(cond [(empty? lst) b]

[else (cons (f (car lst))(loop (cdr lst)))]))])

(loop lst)))

76

Page 77: Designing Precise Pushdown Higher-Order Flow Analysesdeeglaze.github.io/ibmpl2012-slides.pdf · 2. Flow analysis is indispensible Every language should have one 3. Analysis is great

Fixed

Instrument your escape analysis

77

Page 78: Designing Precise Pushdown Higher-Order Flow Analysesdeeglaze.github.io/ibmpl2012-slides.pdf · 2. Flow analysis is indispensible Every language should have one 3. Analysis is great

Escape Analysis

Which addresses outlive their creator’s context?

78

Page 79: Designing Precise Pushdown Higher-Order Flow Analysesdeeglaze.github.io/ibmpl2012-slides.pdf · 2. Flow analysis is indispensible Every language should have one 3. Analysis is great

Escape Analysis

Which addresses outlive their creator’s context?

We introduce three components:

• Escaped addresses  ℰ

• Addresses owned by current function  𝒪

• The random access stack Ξ

79

Page 80: Designing Precise Pushdown Higher-Order Flow Analysesdeeglaze.github.io/ibmpl2012-slides.pdf · 2. Flow analysis is indispensible Every language should have one 3. Analysis is great

Escape Analysis

Which addresses outlive their creator’s context?

We introduce three components:

• Escaped addresses  ℰ

• Addresses owned by current function  𝒪

• The random access stack Ξ

Lookup is now defined with

ℒ(a,σ,Ξ,ℰ) = a ∈ ℰ → σ(a), Ξ(a)

80

Page 81: Designing Precise Pushdown Higher-Order Flow Analysesdeeglaze.github.io/ibmpl2012-slides.pdf · 2. Flow analysis is indispensible Every language should have one 3. Analysis is great

⟨(x ,ρ),σ,Ξ,κ⟩ ⟼ ⟨v,σ,Ξ,κ⟩

   where v ∈ ℒ(ρ(x) ,σ ,Ξ ,ℰ)

81

Page 82: Designing Precise Pushdown Higher-Order Flow Analysesdeeglaze.github.io/ibmpl2012-slides.pdf · 2. Flow analysis is indispensible Every language should have one 3. Analysis is great

⟨(x ,ρ),σ,Ξ,κ⟩ ⟼ ⟨v,σ,Ξ,κ⟩

   where v ∈ ℒ(ρ(x) ,σ ,Ξ ,ℰ)

⟨v,σ,Ξ,fn((λ x.e ,ρ),κ)⟩ ⟼ ⟨c,σnext,Ξ[a ↦ v],[]c⟩

where c = (e ,ρ[x ↦ a])

   σnext  =  σ[a ↦ v]

ℰ' = ℰ∩ ℛ(𝒯(c) ,σnext)

82

Page 83: Designing Precise Pushdown Higher-Order Flow Analysesdeeglaze.github.io/ibmpl2012-slides.pdf · 2. Flow analysis is indispensible Every language should have one 3. Analysis is great

⟨(x ,ρ),σ,Ξ,κ⟩ ⟼ ⟨v,σ,Ξ,κ⟩

   where v ∈ ℒ(ρ(x) ,σ ,Ξ ,ℰ)

⟨v,σ,Ξ,fn((λ x.e ,ρ),κ)⟩ ⟼ ⟨c,σnext,Ξ[a ↦ v],[]c⟩

where c = (e ,ρ[x ↦ a])

   σnext  =  σ[a ↦ v]

ℰ' = ℰ∩ ℛ(𝒯(c) ,σnext)

   𝒪 ' =  {a}

83

Page 84: Designing Precise Pushdown Higher-Order Flow Analysesdeeglaze.github.io/ibmpl2012-slides.pdf · 2. Flow analysis is indispensible Every language should have one 3. Analysis is great

⟨(x ,ρ),σ,Ξ,κ⟩ ⟼ ⟨v,σ,Ξ,κ⟩

   where v ∈ ℒ(ρ(x) ,σ ,Ξ ,ℰ)

⟨v,σ,Ξ,fn((λ x.e ,ρ),κ)⟩ ⟼ ⟨c,σnext,Ξ[a ↦ v],[]c⟩

where c = (e ,ρ[x ↦ a])

   σnext  =  σ[a ↦ v]

ℰ' = ℰ∩ ℛ(𝒯(c) ,σnext)

   𝒪 ' =  {a}

   L'  =  L⊔[(c ,σnext) ↦ (κ ,σcur ,Ξ ,ℰ ,𝒪)]

84

Page 85: Designing Precise Pushdown Higher-Order Flow Analysesdeeglaze.github.io/ibmpl2012-slides.pdf · 2. Flow analysis is indispensible Every language should have one 3. Analysis is great

⟨v,σ,Ξ,[]c⟩ ⟼ ⟨v,σ,Ξ',κ⟩

  if  (κ ,σnext ,Ξ' ,ℰ' ,𝒪) ' ∈  L(c ,σcur)

   M'  =  M[(c ,σcur) ↦ (v ,σ)]

ℰ'' = ℰ' ∪ ((ℰ ∪ 𝒪) ∩ ℛ(𝒯(v),σ))

85

Page 86: Designing Precise Pushdown Higher-Order Flow Analysesdeeglaze.github.io/ibmpl2012-slides.pdf · 2. Flow analysis is indispensible Every language should have one 3. Analysis is great

Analysis is terrible salvagable

• Annoying false positives

• Takes too long

• Hard to implement

• Hard to show correct

• The good ones inherently first-order

86

Page 87: Designing Precise Pushdown Higher-Order Flow Analysesdeeglaze.github.io/ibmpl2012-slides.pdf · 2. Flow analysis is indispensible Every language should have one 3. Analysis is great

We're not done yet

87

Page 88: Designing Precise Pushdown Higher-Order Flow Analysesdeeglaze.github.io/ibmpl2012-slides.pdf · 2. Flow analysis is indispensible Every language should have one 3. Analysis is great

Too context-sensitive

Memo⟨id σ₂⟩ (1 σ₂)

⟨app σ₁⟩ (1 σ₂)

⟨id σ₅⟩ (2 σ₅)

⟨app σ₄⟩ (2 σ₅)

Contexts⟨app σ₁ ⟩ ((let* (... [n1 •] ...) ...) σ₀)

⟨id σ₂ ⟩ ((let* (... [app (λ (f y) •)] ...) ...) σ₁)

⟨app σ₄ ⟩ ((let* (... [n2 •]) ...) σ₀)

⟨id σ₅ ⟩ ((let* (... [app (λ (f y) •)] ...) ...) σ₄)

Store: σ₆

f id

y (1 2)

x (1 2)

n1 1

n2 (1 2)

Start Store: σ₀

(let* ([id (λ (x) x)][app (λ (f y) (f y))][n1 (app id 1)][n2 (app id 2)])

(+ n1 n2))

88

Page 89: Designing Precise Pushdown Higher-Order Flow Analysesdeeglaze.github.io/ibmpl2012-slides.pdf · 2. Flow analysis is indispensible Every language should have one 3. Analysis is great

First-Order Influence

First-order

(Hecht 77) CFG + lattice

(Sharir & Pnueli 81) CFG + lattice + summaries

(Reps 95) PDS + idempotent semiring

Higher-order

(Jones & Muchnick 82) Program + set constraints

(Shivers 91) CPS + set constraints

(Might 07) CPS + abstract small step semantics

(Might & Van Horn 10) Derived from concrete

(Vardoulakis & Shivers 10) CPS + summaries

(Earl et al. 10) ANF + Dyck state graph

Today's talk

?

89

Page 90: Designing Precise Pushdown Higher-Order Flow Analysesdeeglaze.github.io/ibmpl2012-slides.pdf · 2. Flow analysis is indispensible Every language should have one 3. Analysis is great

First-Order Influence

First-order

(Hecht 77) CFG + lattice

(Sharir & Pnueli 81) CFG + lattice + summaries

(Reps 95) PDS + idempotent semiring

(Oh et al. 12) CFG + lattice + bypassing

Higher-order

(Jones & Muchnick 82) Program + set constraints

(Shivers 91) CPS + set constraints

(Might 07) CPS + abstract small step semantics

(Might & Van Horn 10) Derived from concrete

(Vardoulakis & Shivers 10) CPS + summaries

(Earl et al. 10) ANF + Dyck state graph

Today's talk

?

90

Page 91: Designing Precise Pushdown Higher-Order Flow Analysesdeeglaze.github.io/ibmpl2012-slides.pdf · 2. Flow analysis is indispensible Every language should have one 3. Analysis is great

First-order

(Hecht 77) CFG + lattice

(Sharir & Pnueli 81) CFG + lattice + summaries

(Reps 95) PDS + idempotent semiring

(Oh et al. 12) CFG + lattice + bypassing

Higher-order

(Jones & Muchnick 82) Program + set constraints

(Shivers 91) CPS + set constraints

(Might 07) CPS + abstract small step semantics

(Might & Van Horn 10) Derived from concrete

(Vardoulakis & Shivers 10) CPS + summaries

(Earl et al. 10) ANF + Dyck state graph

Today's talk

?

91

Page 92: Designing Precise Pushdown Higher-Order Flow Analysesdeeglaze.github.io/ibmpl2012-slides.pdf · 2. Flow analysis is indispensible Every language should have one 3. Analysis is great

To Conclude

• Design: Model abstract mechanisms concretely

92

Page 93: Designing Precise Pushdown Higher-Order Flow Analysesdeeglaze.github.io/ibmpl2012-slides.pdf · 2. Flow analysis is indispensible Every language should have one 3. Analysis is great

To Conclude

• Design: Model abstract mechanisms concretely

• Pushdown: Memo and local continuation tables

93

Page 94: Designing Precise Pushdown Higher-Order Flow Analysesdeeglaze.github.io/ibmpl2012-slides.pdf · 2. Flow analysis is indispensible Every language should have one 3. Analysis is great

To Conclude

• Design: Model abstract mechanisms concretely

• Pushdown: Memo and local continuation tables

• Precise analyses: Stack allocation ⟹ precision

94

Page 95: Designing Precise Pushdown Higher-Order Flow Analysesdeeglaze.github.io/ibmpl2012-slides.pdf · 2. Flow analysis is indispensible Every language should have one 3. Analysis is great

To Conclude

• Design: Model abstract mechanisms concretely

• Pushdown: Memo and local continuation tables

• Precise analyses: Stack allocation ⟹ precision

• (Not shown) works for control operators / GC

95

Page 96: Designing Precise Pushdown Higher-Order Flow Analysesdeeglaze.github.io/ibmpl2012-slides.pdf · 2. Flow analysis is indispensible Every language should have one 3. Analysis is great

To Conclude

• Design: Model abstract mechanisms concretely

• Pushdown: Memo and local continuation tables

• Precise analyses: Stack allocation ⟹ precision

• (Not shown) works for control operators / GC

• Future work: sparse analysis via time travel

96

Page 97: Designing Precise Pushdown Higher-Order Flow Analysesdeeglaze.github.io/ibmpl2012-slides.pdf · 2. Flow analysis is indispensible Every language should have one 3. Analysis is great

To Conclude

• Design: Model abstract mechanisms concretely

• Pushdown: Memo and local continuation tables

• Precise analyses: Stack allocation ⟹ precision

• (Not shown) works for control operators / GC

• Future work: sparse analysis via time travel

Thank you

97