Logic-Flow Analysis of Higher-Order Programs Matt Might - - PowerPoint PPT Presentation

logic flow analysis of higher order programs
SMART_READER_LITE
LIVE PREVIEW

Logic-Flow Analysis of Higher-Order Programs Matt Might - - PowerPoint PPT Presentation

Logic-Flow Analysis of Higher-Order Programs Matt Might http://matt.might.net/ POPL 2007 1 Why? Tim Sweeney, POPL 2006 Static array-bounds checking. Example ... a[i] ... Will 0 i < a.length always hold? 2 Why? Tim Sweeney, POPL


slide-1
SLIDE 1

Logic-Flow Analysis of Higher-Order Programs

Matt Might

http://matt.might.net/

POPL 2007

1

slide-2
SLIDE 2

Why?

Tim Sweeney, POPL 2006

Static array-bounds checking.

Example

... a[i] ... Will 0 ≤ i < a.length always hold?

2

slide-3
SLIDE 3

Why?

Tim Sweeney, POPL 2006

Static array-bounds checking.

Example

... a[i] ... Will 0 ≤ i < a.length always hold?

Wait...

Hasn’t this been done already? (Range analysis, etc.)

3

slide-4
SLIDE 4

Why?

Tim Sweeney, POPL 2006

Static array-bounds checking.

Example

... a[i] ... Will 0 ≤ i < a.length always hold?

Wait...

Hasn’t this been done already? (Range analysis, etc.) Yeah, but not for permutation/vertex array code.

4

slide-5
SLIDE 5

Why?

Tim Sweeney, POPL 2006

Static array-bounds checking.

Example

... a[i] ... Will 0 ≤ i < a.length always hold?

Wait...

Hasn’t this been done already? (Range analysis, etc.) Yeah, but not for permutation/vertex array code.

Not the big idea

LFA is not about array-bounds checking.

5

slide-6
SLIDE 6

The Idea

Theorem Proving Flow Analysis

6

slide-7
SLIDE 7

The Idea

Theorem Proving Flow Analysis

7

slide-8
SLIDE 8

The Idea

Theorem Proving Flow Analysis

8

slide-9
SLIDE 9

How?

Abstract interpretation

Mechanical (flow):

  • ς

ς′ ς′′

· · ·

Propositional (logic): Π

Π′ Π′′ · · · 9

slide-10
SLIDE 10

How?

Abstract interpretation

Mechanical (flow):

  • ς
  • ς′
  • ς′′
  • · · ·

Propositional (logic): Π

  • Π′
  • Π′′
  • · · ·

10

slide-11
SLIDE 11

Higher-order flow analysis fails

Example

... a[i] ... Will 0 ≤ i < a.length always hold?

11

slide-12
SLIDE 12

Higher-order flow analysis fails

Example

... a[i] ... Will 0 ≤ i < a.length always hold?

Flow analysis results

◮ a is an array.

12

slide-13
SLIDE 13

Higher-order flow analysis fails

Example

... a[i] ... Will 0 ≤ i < a.length always hold?

Flow analysis results

◮ a is an array from line 10 or line 30.

13

slide-14
SLIDE 14

Higher-order flow analysis fails

Example

... a[i] ... Will 0 ≤ i < a.length always hold?

Flow analysis results

◮ a is an array from line 10 or line 30. ◮ i is an integer.

14

slide-15
SLIDE 15

Higher-order flow analysis fails

Example

... a[i] ... Will 0 ≤ i < a.length always hold?

Flow analysis results

◮ a is an array from line 10 or line 30. ◮ i is a non-negative integer.

15

slide-16
SLIDE 16

Higher-order flow analysis fails

Example

... a[i] ... Will 0 ≤ i < a.length always hold?

Flow analysis results

◮ a is an array from line 10 or line 30. ◮ i is a non-negative integer. ◮ a.length is a positive integer.

16

slide-17
SLIDE 17

Higher-order flow analysis fails

Example

... a[i] ... Will 0 ≤ i < a.length always hold?

Flow analysis results

◮ a is an array from line 10 or line 30. ◮ i is a non-negative integer. ◮ a.length is a positive integer.

Insufficiently rich information

Frequently can’t show i < a.length.

17

slide-18
SLIDE 18

First attempt: Enrich flow values with relations

Example

... a[i] ... Will 0 ≤ i < a.length always hold?

18

slide-19
SLIDE 19

First attempt: Enrich flow values with relations

Example

... a[i] ... Will 0 ≤ i < a.length always hold?

Hypothetical results

◮ a is an array from line 10 or line 30. ◮ i is a non-negative integer. ◮ a.length is a positive integer.

19

slide-20
SLIDE 20

First attempt: Enrich flow values with relations

Example

... a[i] ... Will 0 ≤ i < a.length always hold?

Hypothetical results

◮ a is an array from line 10 or line 30. ◮ i is in {x : 0 ≤ x < a.length}. ◮ a.length is a positive integer.

20

slide-21
SLIDE 21

First attempt: Enrich flow values with relations

Example

... a[i] ... Will 0 ≤ i < a.length always hold?

Hypothetical results

◮ a is an array from line 10 or line 30. ◮ i is in {x : 0 ≤ x < a.length}. ◮ a.length is a positive integer.

Problems

  • 1. What does a.length mean where a is out of scope?
  • 2. How did this set get there in the first place?

21

slide-22
SLIDE 22

First attempt: Enrich flow values with relations

Example

... a[i] ... Will 0 ≤ i < a.length always hold?

Hypothetical results

◮ a is an array from line 10 or line 30. ◮ i is in {x : 0 ≤ x < a.length}. ◮ a.length is a positive integer.

Problems

  • 1. What does a.length mean where a is out of scope?
  • 2. How did this set get there in the first place?

22

slide-23
SLIDE 23

Problem 1: Meaning of variables

Ambiguity problem

◮ Need environment-independent identities for values.

23

slide-24
SLIDE 24

Problem 1: Meaning of variables

Ambiguity problem

◮ Need environment-independent identities for values.

Solutions

◮ Constants. E.g. 5 means 5 anywhere.

24

slide-25
SLIDE 25

Problem 1: Meaning of variables

Ambiguity problem

◮ Need environment-independent identities for values.

Solutions

◮ Constants. E.g. 5 means 5 anywhere. ◮ Heap locations. E.g. Heap location 10 offset 3.

25

slide-26
SLIDE 26

Problem 1: Meaning of variables

Ambiguity problem

◮ Need environment-independent identities for values.

Solutions

◮ Constants. E.g. 5 means 5 anywhere. ◮ Heap locations. E.g. Heap location 10 offset 3. ◮ Bindings. [Shivers 1988]

26

slide-27
SLIDE 27

Bindings

Definition

A binding is a variable-time pairing, e.g. (x, 3).

27

slide-28
SLIDE 28

Bindings

Definition

A binding is a variable-time pairing, e.g. (x, 3).

Example (Variable v. binding)

◮ Value of variable x depends on environment. ◮ Value of x bound at time 3: Same in any environment/state.

28

slide-29
SLIDE 29

Bindings

Definition

A binding is a variable-time pairing, e.g. (x, 3).

Example (Variable v. binding)

◮ Value of variable x depends on environment. ◮ Value of x bound at time 3: Same in any environment/state.

Example (Abstract bindings)

◮ 0CFA: All values of x bound at any time. ◮ 1CFA: All values of x bound at a time while calling foo.

29

slide-30
SLIDE 30

Strategy

◮ Build binding-sensitive flow analysis.

30

slide-31
SLIDE 31

Strategy

◮ Build binding-sensitive flow analysis. ◮ Build binding-sensitive logic.

31

slide-32
SLIDE 32

Strategy

◮ Build binding-sensitive flow analysis. ◮ Build binding-sensitive logic. ◮ Build binding-sensitive propositional abstract interpretation.

32

slide-33
SLIDE 33

Strategy

◮ Build binding-sensitive flow analysis. ◮ Build binding-sensitive logic. ◮ Build binding-sensitive propositional abstract interpretation. ◮ Weave.

33

slide-34
SLIDE 34

Tool 1: Continuation-passing style (CPS)

Contract

◮ Calls never return. ◮ Continuations are passed to receive the result.

Example

Direct-style identity function: (define (id x) x)

Example

CPS identity function: (define (id x return) (return x))

34

slide-35
SLIDE 35

CPS simplifies

In CPS, fun call, fun return, conditional branch, sequencing, iteration, exception throw, coroutine switch, continuation invocation...

35

slide-36
SLIDE 36

CPS simplifies

In CPS, fun call, fun return, conditional branch, sequencing, iteration, exception throw, coroutine switch, continuation invocation... ...all become call to λ

36

slide-37
SLIDE 37

CPS simplifies

In CPS, fun call, fun return, conditional branch, sequencing, iteration, exception throw, coroutine switch, continuation invocation... ...all become call to λ

Machine state without CPS

ς ∈ State = CALL × Env × Store × Stack × Time

37

slide-38
SLIDE 38

CPS simplifies

In CPS, fun call, fun return, conditional branch, sequencing, iteration, exception throw, coroutine switch, continuation invocation... ...all become call to λ

Machine state without CPS

ς ∈ State = CALL × Env × Store × Stack × Time

38

slide-39
SLIDE 39

CPS simplifies

In CPS, fun call, fun return, conditional branch, sequencing, iteration, exception throw, coroutine switch, continuation invocation... ...all become call to λ

Machine state with CPS

ς ∈ State = CALL × Env × Store × Time

39

slide-40
SLIDE 40

Tool 2: Machine-based abstract interpretation

Idea

Abstract machine states component-wise.

Machine state

◮ A

call site.

◮ An

environment for variable lookup.

◮ A

heap.

◮ A

time.

More formally

ς ∈ State = CALL × Env × Store × Time

40

slide-41
SLIDE 41

Tool 2: Machine-based abstract interpretation

Idea

Abstract machine states component-wise.

Abstract machine state

◮ An abstract call site. ◮ An abstract environment for variable lookup. ◮ An abstract heap. ◮ An abstract time.

More formally

  • ς ∈

State = CALL × Env × Store × Time

41

slide-42
SLIDE 42

Tool 2: Machine-based abstract interpretation

Idea

Abstract machine states component-wise.

Abstract machine state

◮ An abstract call site. ◮ An abstract environment for variable lookup. ◮ An abstract heap. ◮ An abstract time.

More formally

  • ς ∈

State = CALL × Env × Store × Time

42

slide-43
SLIDE 43

Binding-factored environment

Definition

An environment maps variables to values.

43

slide-44
SLIDE 44

Binding-factored environment

Definition

An environment maps variables to values.

Definition

A binding-factored environment (β, ve) [Shivers 1988] maps:

◮ variables to their binding times. (β) ◮ and then, variables plus times (bindings) to values. (ve)

44

slide-45
SLIDE 45

Tool 3: Restricted first-order logic for states

Features

◮ Propositions are facts about concrete machine states. ◮ Ground terms are identities (bindings, locations, constants).

45

slide-46
SLIDE 46

Tool 3: Restricted first-order logic for states

Features

◮ Propositions are facts about concrete machine states. ◮ Ground terms are identities (bindings, locations, constants).

Restrictions

◮ No existential quantifiers. ◮ Only outer-level universal quantifiers. ◮ Quantifiers range over abstract identities.

46

slide-47
SLIDE 47

Example: Proposition

Example

“Every value of x bound while calling foo is less than the length of every array bound to a.”

47

slide-48
SLIDE 48

Example: Proposition

Example

“Every value of x bound while calling foo is less than the length of every array bound to a.” In longhand: (forall x : (x, tfoo) (forall a : (a, ⊤) (< x (alen a))))

48

slide-49
SLIDE 49

Example: Proposition

Example

“Every value of x bound while calling foo is less than the length of every array bound to a.” In longhand: (forall x : (x, tfoo) (forall a : (a, ⊤) (< x (alen a)))) Or, in convenient (but incomplete) shorthand: (< (x, tfoo) (alen (a, ⊤)))

49

slide-50
SLIDE 50

Logic syntax

Features

◮ S-Expressions. ◮ Just or, not. ◮ Relations encoded as functions.

50

slide-51
SLIDE 51

Logic semantics

Question

How do we know when proposition φ is true for state ς?

51

slide-52
SLIDE 52

Logic semantics

Question

How do we know when proposition φ is true for state ς?

Answer

When ς | = φ holds.

52

slide-53
SLIDE 53

Logic semantics

Question

How do we know when proposition φ is true for state ς?

Answer

When ς | = φ holds. Means exactly what you think it means.

53

slide-54
SLIDE 54

Filtered concretization

Set of conrete states (State)

54

slide-55
SLIDE 55

Filtered concretization

  • ς

Set of conrete states (State) {ς : |ς| ⊑ ς }

55

slide-56
SLIDE 56

Filtered concretization

Π

Set of conrete states (State) {ς : ς | = Π}

56

slide-57
SLIDE 57

Filtered concretization

  • ς

Π

  • ς/Π

Set of conrete states (State) {ς : |ς| ⊑ ς and ς | = Π}

57

slide-58
SLIDE 58

Deriving new propositions

Example

If ς | = (= x y) and ς | = (= y z), does ς | = (= x z) hold?

58

slide-59
SLIDE 59

Deriving new propositions

Example

If ς | = (= x y) and ς | = (= y z), does ς | = (= x z) hold?

Answer

Yes, if {(= x y), (= y z)} ⊢ (= x z) holds.

59

slide-60
SLIDE 60

Deriving new propositions

Example

If ς | = (= x y) and ς | = (= y z), does ς | = (= x z) hold?

Answer

Yes, if {(= x y), (= y z)} ⊢ (= x z) holds.

(Assm) ψ ∈ Π Π ⊢ ψ (∨Ant) Π ∪ {φ1} ⊢ φ3 Π ∪ {φ2} ⊢ φ3 Π ∪ {(or φ1 φ2)} ⊢ φ3 (Subst) Π ⊢ (= ι ι′) Π ⊢ ψ[ι/x] Π ⊢ ψ[ι′/x] (Ant) Π ⊢ φ Π ⊆ Π′ Π′ ⊢ φ (Cases) Π ∪ {φ1} ⊢ φ2 Π ∪ {(not φ1)} ⊢ φ2 Π ⊢ φ2 (Contr) Π ∪ {(not φ1)} ⊢ φ2 Π ∪ {(not φ1)} ⊢ (not φ2) Π ⊢ φ1 (Eq) Π ⊢ (= ι ι) (∨Cons) Π ⊢ φ1 Π ⊢ (or φ1 φ2), (or φ2 φ1) (Int) Π ⊢ (forall x : ι φ) {φ} ⊢ φ′ Π ⊢ (forall x : ι (and φ φ′)) (∀Intro) Π ⊢ ψ x ∈ free(ψ) Π ⊢ (forall x : ι ψ) (∀Swap) Π ⊢ (forall x1, x2 : ι1, ι2 ψ) Π ⊢ (forall x2, x1 : ι2, ι1 ψ)

60

slide-61
SLIDE 61

Trusting the theorem prover

Summary

◮ |

= : What a proposition means.

◮ ⊢ : What a proposition implies.

61

slide-62
SLIDE 62

Trusting the theorem prover

Summary

◮ |

= : What a proposition means.

◮ ⊢ : What a proposition implies.

Question

How can we trust an external theorem prover?

62

slide-63
SLIDE 63

Trusting the theorem prover

Summary

◮ |

= : What a proposition means.

◮ ⊢ : What a proposition implies.

Question

How can we trust an external theorem prover?

Theorem (Syntactic soundness)

If Π ⊢ φ holds, then Π | = φ holds.

63

slide-64
SLIDE 64

All together now

64

slide-65
SLIDE 65

Woven state

Example (Machine, ς)

call site (f x k) local env f → tfoo k → tfoo x → tfoo global env (f, tfoo) → · · · (k, tfoo) → · · · (x, tfoo) → positive (z, tbar) → positive time

  • tf

Example (Assumptions, Π)

(forall x : (x, tfoo) (forall z : (z, tbar) (< x z)))

65

slide-66
SLIDE 66

Woven state

Example (Machine, ς)

call site (f x k) local env f → tfoo k → tfoo x → tfoo global env (f, tfoo) → · · · (k, tfoo) → · · · (x, tfoo) → positive (z, tbar) → positive time

  • tf

Example (Assumptions, Π)

(forall x : (x, tfoo) (forall z : (z, tbar) (< x z)))

66

slide-67
SLIDE 67

Woven transition relation

Old machine state New machine state ( ς, Π) | = > ( ς′, Π′) Old assumption base New assumption base

67

slide-68
SLIDE 68

Example: Transition

Example

call site (f x k) time

  • tf

68

slide-69
SLIDE 69

Example: Transition

Example

call site (f x k) local env f → tfoo time

  • tf

69

slide-70
SLIDE 70

Example: Transition

Example

call site (f x k) local env f → tfoo global env (f, tfoo) → a closure over (λ (a q) ...) time

  • tf

70

slide-71
SLIDE 71

Example: Transition

Example

call site (f x k) local env f → tfoo x → tfoo global env (f, tfoo) → a closure over (λ (a q) ...) time

  • tf

71

slide-72
SLIDE 72

Example: Transition

Example

call site (f x k) local env f → tfoo x → tfoo global env (f, tfoo) → a closure over (λ (a q) ...) time

  • tf

New fact?

(forall x, a : (x, tfoo), (a, tf) (= x a))

72

slide-73
SLIDE 73

It depends.

73

slide-74
SLIDE 74

Chaining equal values

Candidate for Π′

φ = (forall x, a : (x, tfoo), (a, tf) (= x a))

Prerequisites

Can add it if Π ⊢ φ.

Chicken and egg

How can φ be in there already?

74

slide-75
SLIDE 75

ΓCFA: Abstract counting

Idea

Keep count of concrete counterparts to abstract identities.

75

slide-76
SLIDE 76

ΓCFA: Abstract counting

Idea

Keep count of concrete counterparts to abstract identities.

Mechanism

◮ Add counter to every abstract machine state. ◮ Counter maps each binding to times allocated. ◮ Stop counting after 1.

76

slide-77
SLIDE 77

ΓCFA: Abstract counting

Idea

Keep count of concrete counterparts to abstract identities.

Mechanism

◮ Add counter to every abstract machine state. ◮ Counter maps each binding to times allocated. ◮ Stop counting after 1.

Theorem

If {binding1} = {binding2}, then binding1 = binding2.

77

slide-78
SLIDE 78

Chaining equal values

Candidate for Π′

φ = (forall x, a : (x, tfoo), (a, tf) (= x a))

Prerequisites

◮ Can add it if Π ⊢ φ. ◮ Or, if count of (x,

tfoo) is 1 and count of (a, tf) is 0.

78

slide-79
SLIDE 79

ΓCFA: Abstract garbage collection

Idea

Discard unreachable bindings.

79

slide-80
SLIDE 80

ΓCFA: Abstract garbage collection

Idea

Discard unreachable bindings.

Mechanism

◮ Start with bindings touched by current state. ◮ Take transitive closure. ◮ Can reset unreachable bindings’ counts to 0.

80

slide-81
SLIDE 81

Chaining equal values

Candidate for Π′

φ = (forall x, a : (x, tfoo), (a, tf) (= x a))

Prerequisites

◮ Can add it if Π ⊢ φ. ◮ Or, if count of (x,

tfoo) is 1 and count of (a, tf) is 0.

◮ Or, if count of (x,

tfoo) is 1 and (a, tf) is unreachable.

◮ (More in paper.)

81

slide-82
SLIDE 82

Example: Invertible rebinding

Example

call site (f (+ x 1) k) local env f → tfoo x → tf global env (f, tfoo) → a closure over (λ (x q) ...) time

  • tf

Updating assumption base

Can replace (x, tf) with (- (x, tf) 1) in Π?

82

slide-83
SLIDE 83

Example: Invertible rebinding

Example

call site (f (+ x 1) k) local env f → tfoo x → tf global env (f, tfoo) → a closure over (λ (x q) ...) time

  • tf

Updating assumption base

Can replace (x, tf) with (- (x, tf) 1) in Π? Yes, if (x, tf) is unreachable and its count is 1. (E.g. tail recursion, for loops.) (More on this in the paper.)

83

slide-84
SLIDE 84

Example: Conditional

Example

call site (if (< i (alen a)) ... ...)

84

slide-85
SLIDE 85

Example: Conditional

Example

call site (if (< i (alen a)) ... ...)

Case 1

Π can (dis)prove (< i (alen a)). Branch one way.

  • ςtrue
  • ς
  • ςfalse

85

slide-86
SLIDE 86

Example: Conditional

Example

call site (if (< i (alen a)) ... ...)

Case 2

(< i (alen a)) has one counterpart. Branch both ways & assert.

  • ςtrue
  • ς

(< i (alen a))

  • (not (< i (alen a)))
  • ςfalse

86

slide-87
SLIDE 87

Example: Conditional

Example

call site (if (< i (alen a)) ... ...)

Case 3

None of the above. Branch both ways. Don’t touch Π′.

  • ςtrue
  • ς
  • ςfalse

87

slide-88
SLIDE 88

Walkthrough: Simple for loop

Example

for (i = 0; i < a.length; i++) print(a[i]) ;

Example (CPS)

(letrec ((loop (λ (i) (if (< i (alen a)) (print (aget a i) (λ () (loop (+ i 1)))) ...)))) (loop 0))

Parameters

◮ 0CFA contour set. (Bindings = Variables.)

88

slide-89
SLIDE 89

Walkthrough: Simple for loop

(letrec ((loop (λ (i) (if (< i (alen a)) (print (aget a i) (λ () (loop (+ i 1)))) ...)))) (loop 0))

Assumption base, Π

(< 0 (alen a))

89

slide-90
SLIDE 90

Walkthrough: Simple for loop

(letrec ((loop (λ (i) (if (< i (alen a)) (print (aget a i) (λ () (loop (+ i 1)))) ...)))) (loop 0))

Assumption base, Π

(< 0 (alen a))

90

slide-91
SLIDE 91

Walkthrough: Simple for loop

(letrec ((loop (λ (i) (if (< i (alen a)) (print (aget a i) (λ () (loop (+ i 1)))) ...)))) (loop 0))

Assumption base, Π

(< 0 (alen a)), (= 0 i)

91

slide-92
SLIDE 92

Walkthrough: Simple for loop

(letrec ((loop (λ (i) (if (< i (alen a)) (print (aget a i) (λ () (loop (+ i 1)))) ...)))) (loop 0))

Assumption base, Π

(< 0 (alen a)), (= 0 i)

92

slide-93
SLIDE 93

Walkthrough: Simple for loop

(letrec ((loop (λ (i) (if (< i (alen a)) (print (aget a i) (λ () (loop (+ i 1)))) ...)))) (loop 0))

Assumption base, Π

(< 0 (alen a)), (= 0 i)

Safe

0 ≤ i < (alen a) holds!

93

slide-94
SLIDE 94

Walkthrough: Simple for loop

(letrec ((loop (λ (i) (if (< i (alen a)) (print (aget a i) (λ () (loop (+ i 1)))) ...)))) (loop 0))

Assumption base, Π

(< 0 (alen a)), (= 0 i)

94

slide-95
SLIDE 95

Walkthrough: Simple for loop

(letrec ((loop (λ (i) (if (< i (alen a)) (print (aget a i) (λ () (loop (+ i 1)))) ...)))) (loop 0))

Assumption base, Π

(< 0 (alen a)), (= 0 i)

95

slide-96
SLIDE 96

Walkthrough: Simple for loop

(letrec ((loop (λ (i) (if (< i (alen a)) (print (aget a i) (λ () (loop (+ i 1)))) ...)))) (loop 0))

Assumption base, Π

(< 0 (alen a)), (= 0 (- i 1))

96

slide-97
SLIDE 97

Walkthrough: Simple for loop

(letrec ((loop (λ (i) (if (< i (alen a)) (print (aget a i) (λ () (loop (+ i 1)))) ...)))) (loop 0))

Assumption base, Π

(< 0 (alen a)), (≤ 0 i)

97

slide-98
SLIDE 98

Walkthrough: Simple for loop

(letrec ((loop (λ (i) (if (< i (alen a)) (print (aget a i) (λ () (loop (+ i 1)))) ...)))) (loop 0))

Assumption base, Π

(< 0 (alen a)), (≤ 0 i), (< i (alen a))

Safe

0 ≤ i < (alen a) holds!

98

slide-99
SLIDE 99

Walkthrough: Simple for loop

(letrec ((loop (λ (i) (if (< i (alen a)) (print (aget a i) (λ () (loop (+ i 1)))) ...)))) (loop 0))

Assumption base, Π

(< 0 (alen a)), (≤ 0 i), (< i (alen a))

99

slide-100
SLIDE 100

Walkthrough: Simple for loop

(letrec ((loop (λ (i) (if (< i (alen a)) (print (aget a i) (λ () (loop (+ i 1)))) ...)))) (loop 0))

Assumption base, Π

(< 0 (alen a)), (≤ 0 i), (< i (alen a))

100

slide-101
SLIDE 101

Walkthrough: Simple for loop

(letrec ((loop (λ (i) (if (< i (alen a)) (print (aget a i) (λ () (loop (+ i 1)))) ...)))) (loop 0))

Assumption base, Π

(< 0 (alen a)), (≤ 0 (- i 1)), (< (- i 1) (alen a))

101

slide-102
SLIDE 102

Walkthrough: Simple for loop

(letrec ((loop (λ (i) (if (< i (alen a)) (print (aget a i) (λ () (loop (+ i 1)))) ...)))) (loop 0))

Assumption base, Π

(< 0 (alen a)), (≤ 0 i), (< (- i 1) (alen a)), (< i (alen a))

Safe

0 ≤ i < (alen a) holds!

102

slide-103
SLIDE 103

Walkthrough: Simple for loop

(letrec ((loop (λ (i) (if (< i (alen a)) (print (aget a i) (λ () (loop (+ i 1)))) ...)))) (loop 0))

Assumption base, Π

(< 0 (alen a)), (≤ 0 i), (< i (alen a))

Finished

State already visited.

103

slide-104
SLIDE 104

More in the paper

◮ Formal treatment. ◮ Flow analysis as oracle inference rules. ◮ More rules for assumption base management. ◮ Rules for handling arrays. ◮ Three-page worked example for vertex arrays.

104

slide-105
SLIDE 105

Related & inspiring work

◮ Cousot & Cousot. (Abstract interpretation)

105

slide-106
SLIDE 106

Related & inspiring work

◮ Cousot & Cousot. (Abstract interpretation) ◮ Cousot & Cousot. (Invariant synthesis)

106

slide-107
SLIDE 107

Related & inspiring work

◮ Cousot & Cousot. (Abstract interpretation) ◮ Cousot & Cousot. (Invariant synthesis) ◮ Cousot & Cousot. (Widening & narrowing)

107

slide-108
SLIDE 108

Related & inspiring work

◮ Cousot & Cousot. (Abstract interpretation) ◮ Cousot & Cousot. (Invariant synthesis) ◮ Cousot & Cousot. (Widening & narrowing) ◮ Cousot & Cousot. (Relational abstract domains)

108

slide-109
SLIDE 109

Related & inspiring work

◮ Cousot & Cousot. (Abstract interpretation) ◮ Cousot & Cousot. (Invariant synthesis) ◮ Cousot & Cousot. (Widening & narrowing) ◮ Cousot & Cousot. (Relational abstract domains) ◮ Shivers. (Control-flow analysis w/ factored environment)

109

slide-110
SLIDE 110

Related & inspiring work

◮ Cousot & Cousot. (Abstract interpretation) ◮ Cousot & Cousot. (Invariant synthesis) ◮ Cousot & Cousot. (Widening & narrowing) ◮ Cousot & Cousot. (Relational abstract domains) ◮ Shivers. (Control-flow analysis w/ factored environment) ◮ Hudak. (Abstract reference counting)

110

slide-111
SLIDE 111

Related & inspiring work

◮ Cousot & Cousot. (Abstract interpretation) ◮ Cousot & Cousot. (Invariant synthesis) ◮ Cousot & Cousot. (Widening & narrowing) ◮ Cousot & Cousot. (Relational abstract domains) ◮ Shivers. (Control-flow analysis w/ factored environment) ◮ Hudak. (Abstract reference counting) ◮ Nanevski & Morrisett. (Soundness of theorem prover interaction)

111

slide-112
SLIDE 112

Related & inspiring work

◮ Cousot & Cousot. (Abstract interpretation) ◮ Cousot & Cousot. (Invariant synthesis) ◮ Cousot & Cousot. (Widening & narrowing) ◮ Cousot & Cousot. (Relational abstract domains) ◮ Shivers. (Control-flow analysis w/ factored environment) ◮ Hudak. (Abstract reference counting) ◮ Nanevski & Morrisett. (Soundness of theorem prover interaction) ◮ Ball. (Predicate abstraction)

112

slide-113
SLIDE 113

Related & inspiring work

◮ Cousot & Cousot. (Abstract interpretation) ◮ Cousot & Cousot. (Invariant synthesis) ◮ Cousot & Cousot. (Widening & narrowing) ◮ Cousot & Cousot. (Relational abstract domains) ◮ Shivers. (Control-flow analysis w/ factored environment) ◮ Hudak. (Abstract reference counting) ◮ Nanevski & Morrisett. (Soundness of theorem prover interaction) ◮ Ball. (Predicate abstraction) ◮ ...

113

slide-114
SLIDE 114

Related & future work

∆CFA

  • LFA

ΓCFA

  • 114
slide-115
SLIDE 115

Related & future work

∆CFA

  • LFA

ΓCFA

  • 115
slide-116
SLIDE 116

Related & future work

∆CFA

  • LFA

ΓCFA

  • ΘCFA
  • 116
slide-117
SLIDE 117

Conclusion

HOFA + FOL = LFA

117

slide-118
SLIDE 118

Conclusion

HOFA + FOL = LFA Merci

118

slide-119
SLIDE 119

Question

What are some other applications of LFA?

Answer

◮ Improving flow precision. ◮ Static checks of assert statements. ◮ Pre- and post-condition checks.

119

slide-120
SLIDE 120

Question

Do you have an implementation?

Answer

Half of one:

◮ Modified ACL/2 for theorem prover. ◮ Modified ΓCFA.

Goal: Meet in the middle.

120

slide-121
SLIDE 121

Question

Does a backward version exist?

Answer

◮ Not yet. ◮ Start by widening into constraint-solving form.

121

slide-122
SLIDE 122

Question

What is the complexity of LFA?

Answer

Exponential in theory. Usually much friendlier in pratice. It depends on... ...the contour set. ...the degree of widening to assumption base & abstract heap.

122

slide-123
SLIDE 123

Question

Do you support floats?

Answer

Patrick, not yet.

123