AHigher-OrderDemand-DrivenProgramAnalysis ZacharyPalmer …zpalmer/... · ZacharyPalmer1...

100
DDPA A Higher-Order Demand-Driven Program Analysis Zachary Palmer 1 Scott F. Smith 2 Swarthmore College 1 The Johns Hopkins University 2 July 20th, 2016

Transcript of AHigher-OrderDemand-DrivenProgramAnalysis ZacharyPalmer …zpalmer/... · ZacharyPalmer1...

Page 1: AHigher-OrderDemand-DrivenProgramAnalysis ZacharyPalmer …zpalmer/... · ZacharyPalmer1 ScottF.Smith2 Swarthmore College1 The Johns Hopkins University2 July20th,2016. Some Program

DDPAA Higher-Order Demand-Driven Program Analysis

Zachary Palmer1 Scott F. Smith2

Swarthmore College1

The Johns Hopkins University2

July 20th, 2016

Page 2: AHigher-OrderDemand-DrivenProgramAnalysis ZacharyPalmer …zpalmer/... · ZacharyPalmer1 ScottF.Smith2 Swarthmore College1 The Johns Hopkins University2 July20th,2016. Some Program

Some Program Analyses

first order

higher order

push forward demand-driven

abstract interpretation

data flow analysis

CFL-reachability

reverse data flow analysis

kCFA CFA2

ΓCFAPDCFA

DDPA

POLYFLOWCFL

2/16

Page 3: AHigher-OrderDemand-DrivenProgramAnalysis ZacharyPalmer …zpalmer/... · ZacharyPalmer1 ScottF.Smith2 Swarthmore College1 The Johns Hopkins University2 July20th,2016. Some Program

Some Program Analyses

first order

higher order

push forward demand-driven

abstract interpretation

data flow analysis

CFL-reachability

reverse data flow analysis

kCFA CFA2

ΓCFAPDCFA

DDPA

POLYFLOWCFL

2/16

Page 4: AHigher-OrderDemand-DrivenProgramAnalysis ZacharyPalmer …zpalmer/... · ZacharyPalmer1 ScottF.Smith2 Swarthmore College1 The Johns Hopkins University2 July20th,2016. Some Program

Some Program Analyses

first order

higher order

push forward demand-driven

abstract interpretation

data flow analysis

CFL-reachability

reverse data flow analysis

kCFA CFA2

ΓCFAPDCFA

DDPA

POLYFLOWCFL

2/16

Page 5: AHigher-OrderDemand-DrivenProgramAnalysis ZacharyPalmer …zpalmer/... · ZacharyPalmer1 ScottF.Smith2 Swarthmore College1 The Johns Hopkins University2 July20th,2016. Some Program

Some Program Analyses

first order

higher order

push forward demand-driven

abstract interpretation

data flow analysis

CFL-reachability

reverse data flow analysis

kCFA CFA2

ΓCFAPDCFA

DDPA

POLYFLOWCFL

2/16

Page 6: AHigher-OrderDemand-DrivenProgramAnalysis ZacharyPalmer …zpalmer/... · ZacharyPalmer1 ScottF.Smith2 Swarthmore College1 The Johns Hopkins University2 July20th,2016. Some Program

Some Program Analyses

first order

higher order

push forward demand-driven

abstract interpretation

data flow analysis

CFL-reachability

reverse data flow analysis

kCFA CFA2

ΓCFAPDCFADDPA

POLYFLOWCFL

2/16

Page 7: AHigher-OrderDemand-DrivenProgramAnalysis ZacharyPalmer …zpalmer/... · ZacharyPalmer1 ScottF.Smith2 Swarthmore College1 The Johns Hopkins University2 July20th,2016. Some Program

Some Program Analyses

first order

higher order

push forward demand-driven

abstract interpretation

data flow analysis

CFL-reachability

reverse data flow analysis

kCFA CFA2

ΓCFAPDCFADDPA

POLYFLOWCFL

2/16

Page 8: AHigher-OrderDemand-DrivenProgramAnalysis ZacharyPalmer …zpalmer/... · ZacharyPalmer1 ScottF.Smith2 Swarthmore College1 The Johns Hopkins University2 July20th,2016. Some Program

DDPA By Example

1 let id x = x;;2 let s1 = id 1;;3 let s2 = id 2;;

⇓ A-normalize

1 id = fun x -> (2 ret = x;3 );4 n1 = 1;5 s1 = id n1;6 n2 = 2;7 s2 = id n2;

Initial graph before any calls wired:

St

id n1 s1 n2 s2

End

ret

3/16

Page 9: AHigher-OrderDemand-DrivenProgramAnalysis ZacharyPalmer …zpalmer/... · ZacharyPalmer1 ScottF.Smith2 Swarthmore College1 The Johns Hopkins University2 July20th,2016. Some Program

DDPA By Example

1 let id x = x;;2 let s1 = id 1;;3 let s2 = id 2;;

⇓ A-normalize

1 id = fun x -> (2 ret = x;3 );4 n1 = 1;5 s1 = id n1;6 n2 = 2;7 s2 = id n2;

Initial graph before any calls wired:

St

id n1 s1 n2 s2

End

ret

3/16

Page 10: AHigher-OrderDemand-DrivenProgramAnalysis ZacharyPalmer …zpalmer/... · ZacharyPalmer1 ScottF.Smith2 Swarthmore College1 The Johns Hopkins University2 July20th,2016. Some Program

DDPA By Example

1 let id x = x;;2 let s1 = id 1;;3 let s2 = id 2;;

⇓ A-normalize

1 id = fun x -> (2 ret = x;3 );4 n1 = 1;5 s1 = id n1;6 n2 = 2;7 s2 = id n2;

Initial graph before any calls wired:

St

id n1 s1 n2 s2

End

ret

3/16

Page 11: AHigher-OrderDemand-DrivenProgramAnalysis ZacharyPalmer …zpalmer/... · ZacharyPalmer1 ScottF.Smith2 Swarthmore College1 The Johns Hopkins University2 July20th,2016. Some Program

DDPA By Example

St id n1 s1 n2 s2 End

ret

x=n1 s1=ret

x=n2s2=ret

1 id = fun x -> ( ret = x; );2 n1 = 1;3 s1 = id n1;4 n2 = 2;5 s2 = id n2;

4/16

Page 12: AHigher-OrderDemand-DrivenProgramAnalysis ZacharyPalmer …zpalmer/... · ZacharyPalmer1 ScottF.Smith2 Swarthmore College1 The Johns Hopkins University2 July20th,2016. Some Program

DDPA By ExampleAnalyze call site s1

St id n1 s1 n2 s2 End

ret

x=n1 s1=ret

x=n2s2=ret

1 id = fun x -> ( ret = x; );2 n1 = 1;3 s1 = id n1;4 n2 = 2;5 s2 = id n2;

4/16

Page 13: AHigher-OrderDemand-DrivenProgramAnalysis ZacharyPalmer …zpalmer/... · ZacharyPalmer1 ScottF.Smith2 Swarthmore College1 The Johns Hopkins University2 July20th,2016. Some Program

DDPA By ExampleAnalyze call site s1

Look backward to find function id

St id n1 s1 n2 s2 End

ret

x=n1 s1=ret

x=n2s2=ret

1 id = fun x -> ( ret = x; );2 n1 = 1;3 s1 = id n1;4 n2 = 2;5 s2 = id n2;

4/16

Page 14: AHigher-OrderDemand-DrivenProgramAnalysis ZacharyPalmer …zpalmer/... · ZacharyPalmer1 ScottF.Smith2 Swarthmore College1 The Johns Hopkins University2 July20th,2016. Some Program

DDPA By ExampleAnalyze call site s1

Look backward to find function id

St id n1 s1 n2 s2 End

ret

x=n1 s1=ret

x=n2s2=ret

1 id = fun x -> ( ret = x; );2 n1 = 1;3 s1 = id n1;4 n2 = 2;5 s2 = id n2;

4/16

Page 15: AHigher-OrderDemand-DrivenProgramAnalysis ZacharyPalmer …zpalmer/... · ZacharyPalmer1 ScottF.Smith2 Swarthmore College1 The Johns Hopkins University2 July20th,2016. Some Program

DDPA By ExampleAnalyze call site s1

Look backward to find function id

St id n1 s1 n2 s2 End

ret

x=n1 s1=ret

x=n2s2=ret

1 id = fun x -> ( ret = x; );2 n1 = 1;3 s1 = id n1;4 n2 = 2;5 s2 = id n2;

4/16

Page 16: AHigher-OrderDemand-DrivenProgramAnalysis ZacharyPalmer …zpalmer/... · ZacharyPalmer1 ScottF.Smith2 Swarthmore College1 The Johns Hopkins University2 July20th,2016. Some Program

DDPA By ExampleAnalyze call site s1

Bind argument n1 to parameter x

St id n1 s1 n2 s2 End

retx=n1

s1=ret

x=n2s2=ret

1 id = fun x -> ( ret = x; );2 n1 = 1;3 s1 = id n1;4 n2 = 2;5 s2 = id n2;

4/16

Page 17: AHigher-OrderDemand-DrivenProgramAnalysis ZacharyPalmer …zpalmer/... · ZacharyPalmer1 ScottF.Smith2 Swarthmore College1 The Johns Hopkins University2 July20th,2016. Some Program

DDPA By ExampleAnalyze call site s1

Assign result ret to call site z1

St id n1 s1 n2 s2 End

retx=n1 s1=ret

x=n2s2=ret

1 id = fun x -> ( ret = x; );2 n1 = 1;3 s1 = id n1;4 n2 = 2;5 s2 = id n2;

4/16

Page 18: AHigher-OrderDemand-DrivenProgramAnalysis ZacharyPalmer …zpalmer/... · ZacharyPalmer1 ScottF.Smith2 Swarthmore College1 The Johns Hopkins University2 July20th,2016. Some Program

DDPA By ExampleAnalyze call site s2

St id n1 s1 n2 s2 End

retx=n1 s1=ret

x=n2s2=ret

1 id = fun x -> ( ret = x; );2 n1 = 1;3 s1 = id n1;4 n2 = 2;5 s2 = id n2;

4/16

Page 19: AHigher-OrderDemand-DrivenProgramAnalysis ZacharyPalmer …zpalmer/... · ZacharyPalmer1 ScottF.Smith2 Swarthmore College1 The Johns Hopkins University2 July20th,2016. Some Program

DDPA By ExampleAnalyze call site s2

Look backward to find function id

St id n1 s1 n2 s2 End

retx=n1 s1=ret

x=n2s2=ret

1 id = fun x -> ( ret = x; );2 n1 = 1;3 s1 = id n1;4 n2 = 2;5 s2 = id n2;

4/16

Page 20: AHigher-OrderDemand-DrivenProgramAnalysis ZacharyPalmer …zpalmer/... · ZacharyPalmer1 ScottF.Smith2 Swarthmore College1 The Johns Hopkins University2 July20th,2016. Some Program

DDPA By ExampleAnalyze call site s2

Look backward to find function id

St id n1 s1 n2 s2 End

retx=n1 s1=ret

x=n2s2=ret

1 id = fun x -> ( ret = x; );2 n1 = 1;3 s1 = id n1;4 n2 = 2;5 s2 = id n2;

4/16

Page 21: AHigher-OrderDemand-DrivenProgramAnalysis ZacharyPalmer …zpalmer/... · ZacharyPalmer1 ScottF.Smith2 Swarthmore College1 The Johns Hopkins University2 July20th,2016. Some Program

DDPA By ExampleAnalyze call site s2

Bind argument n2 to parameter x

St id n1 s1 n2 s2 End

retx=n1 s1=ret

x=n2

s2=ret

1 id = fun x -> ( ret = x; );2 n1 = 1;3 s1 = id n1;4 n2 = 2;5 s2 = id n2;

4/16

Page 22: AHigher-OrderDemand-DrivenProgramAnalysis ZacharyPalmer …zpalmer/... · ZacharyPalmer1 ScottF.Smith2 Swarthmore College1 The Johns Hopkins University2 July20th,2016. Some Program

DDPA By ExampleAnalyze call site s2

Assign result ret to call site z2

St id n1 s1 n2 s2 End

retx=n1 s1=ret

x=n2s2=ret

1 id = fun x -> ( ret = x; );2 n1 = 1;3 s1 = id n1;4 n2 = 2;5 s2 = id n2;

4/16

Page 23: AHigher-OrderDemand-DrivenProgramAnalysis ZacharyPalmer …zpalmer/... · ZacharyPalmer1 ScottF.Smith2 Swarthmore College1 The Johns Hopkins University2 July20th,2016. Some Program

DDPA By ExampleCFG construction complete

St id n1 s1 n2 s2 End

retx=n1 s1=ret

x=n2s2=ret

1 id = fun x -> ( ret = x; );2 n1 = 1;3 s1 = id n1;4 n2 = 2;5 s2 = id n2;

4/16

Page 24: AHigher-OrderDemand-DrivenProgramAnalysis ZacharyPalmer …zpalmer/... · ZacharyPalmer1 ScottF.Smith2 Swarthmore College1 The Johns Hopkins University2 July20th,2016. Some Program

Observe

Incrementally built control-flow graph (CFG)

Function bodies were wired to call sites as discoveredAnalysis focused on variable lookup

“What values might variable x have at program point p?”

Lookup is temporally reversed and on demandHow could this lookup be accurate?

Challenges:Context-sensitivity / polymorphism?Non-local variables?Recursion?Function parameters?State and heap aliases?Path-sensitivity?(Flow-sensitivity comes for free)

5/16

Page 25: AHigher-OrderDemand-DrivenProgramAnalysis ZacharyPalmer …zpalmer/... · ZacharyPalmer1 ScottF.Smith2 Swarthmore College1 The Johns Hopkins University2 July20th,2016. Some Program

Observe

Incrementally built control-flow graph (CFG)Function bodies were wired to call sites as discovered

Analysis focused on variable lookup

“What values might variable x have at program point p?”

Lookup is temporally reversed and on demandHow could this lookup be accurate?

Challenges:Context-sensitivity / polymorphism?Non-local variables?Recursion?Function parameters?State and heap aliases?Path-sensitivity?(Flow-sensitivity comes for free)

5/16

Page 26: AHigher-OrderDemand-DrivenProgramAnalysis ZacharyPalmer …zpalmer/... · ZacharyPalmer1 ScottF.Smith2 Swarthmore College1 The Johns Hopkins University2 July20th,2016. Some Program

Observe

Incrementally built control-flow graph (CFG)Function bodies were wired to call sites as discoveredAnalysis focused on variable lookup

“What values might variable x have at program point p?”

Lookup is temporally reversed and on demandHow could this lookup be accurate?

Challenges:Context-sensitivity / polymorphism?Non-local variables?Recursion?Function parameters?State and heap aliases?Path-sensitivity?(Flow-sensitivity comes for free)

5/16

Page 27: AHigher-OrderDemand-DrivenProgramAnalysis ZacharyPalmer …zpalmer/... · ZacharyPalmer1 ScottF.Smith2 Swarthmore College1 The Johns Hopkins University2 July20th,2016. Some Program

Observe

Incrementally built control-flow graph (CFG)Function bodies were wired to call sites as discoveredAnalysis focused on variable lookup

“What values might variable x have at program point p?”Lookup is temporally reversed and on demand

How could this lookup be accurate?

Challenges:Context-sensitivity / polymorphism?Non-local variables?Recursion?Function parameters?State and heap aliases?Path-sensitivity?(Flow-sensitivity comes for free)

5/16

Page 28: AHigher-OrderDemand-DrivenProgramAnalysis ZacharyPalmer …zpalmer/... · ZacharyPalmer1 ScottF.Smith2 Swarthmore College1 The Johns Hopkins University2 July20th,2016. Some Program

Observe

Incrementally built control-flow graph (CFG)Function bodies were wired to call sites as discoveredAnalysis focused on variable lookup

“What values might variable x have at program point p?”Lookup is temporally reversed and on demandHow could this lookup be accurate? Challenges:

Context-sensitivity / polymorphism?Non-local variables?Recursion?Function parameters?State and heap aliases?Path-sensitivity?(Flow-sensitivity comes for free)

5/16

Page 29: AHigher-OrderDemand-DrivenProgramAnalysis ZacharyPalmer …zpalmer/... · ZacharyPalmer1 ScottF.Smith2 Swarthmore College1 The Johns Hopkins University2 July20th,2016. Some Program

Observe

Incrementally built control-flow graph (CFG)Function bodies were wired to call sites as discoveredAnalysis focused on variable lookup

“What values might variable x have at program point p?”Lookup is temporally reversed and on demandHow could this lookup be accurate? Challenges:

Context-sensitivity / polymorphism?Non-local variables?Recursion?Function parameters?State and heap aliases?Path-sensitivity?

(Flow-sensitivity comes for free)

5/16

Page 30: AHigher-OrderDemand-DrivenProgramAnalysis ZacharyPalmer …zpalmer/... · ZacharyPalmer1 ScottF.Smith2 Swarthmore College1 The Johns Hopkins University2 July20th,2016. Some Program

Observe

Incrementally built control-flow graph (CFG)Function bodies were wired to call sites as discoveredAnalysis focused on variable lookup

“What values might variable x have at program point p?”Lookup is temporally reversed and on demandHow could this lookup be accurate? Challenges:

Context-sensitivity / polymorphism?Non-local variables?Recursion?Function parameters?State and heap aliases?Path-sensitivity?

(Flow-sensitivity comes for free)

5/16

Page 31: AHigher-OrderDemand-DrivenProgramAnalysis ZacharyPalmer …zpalmer/... · ZacharyPalmer1 ScottF.Smith2 Swarthmore College1 The Johns Hopkins University2 July20th,2016. Some Program

Observe

Incrementally built control-flow graph (CFG)Function bodies were wired to call sites as discoveredAnalysis focused on variable lookup

“What values might variable x have at program point p?”Lookup is temporally reversed and on demandHow could this lookup be accurate? Challenges:

Context-sensitivity / polymorphism?Non-local variables?Recursion? (brief mention)Function parameters?State and heap aliases?Path-sensitivity?

(Flow-sensitivity comes for free)

5/16

Page 32: AHigher-OrderDemand-DrivenProgramAnalysis ZacharyPalmer …zpalmer/... · ZacharyPalmer1 ScottF.Smith2 Swarthmore College1 The Johns Hopkins University2 July20th,2016. Some Program

Observe

Incrementally built control-flow graph (CFG)Function bodies were wired to call sites as discoveredAnalysis focused on variable lookup

“What values might variable x have at program point p?”Lookup is temporally reversed and on demandHow could this lookup be accurate? Challenges:

Context-sensitivity / polymorphism?Non-local variables?Recursion? (brief mention)Function parameters?State and heap aliases?Path-sensitivity?(Flow-sensitivity comes for free)

5/16

Page 33: AHigher-OrderDemand-DrivenProgramAnalysis ZacharyPalmer …zpalmer/... · ZacharyPalmer1 ScottF.Smith2 Swarthmore College1 The Johns Hopkins University2 July20th,2016. Some Program

Call Stack Alignment for Context-Sensitivity

St id n1 s1 n2 s2 End

retx=n1 s1=ret

x=n2s2=ret

s2?

ret?

x?

n2?

2! ,

x?

n1?

1! /

s2?[]

ret?[s2]

x?[s2]

n2?[]

x?[s2]

1 id = fun x -> ( ret = x; );2 n1 = 1;3 s1 = id n1;4 n2 = 2;5 s2 = id n2;

6/16

Page 34: AHigher-OrderDemand-DrivenProgramAnalysis ZacharyPalmer …zpalmer/... · ZacharyPalmer1 ScottF.Smith2 Swarthmore College1 The Johns Hopkins University2 July20th,2016. Some Program

Call Stack Alignment for Context-SensitivityLook up s2 from end of program

St id n1 s1 n2 s2 End

retx=n1 s1=ret

x=n2s2=ret

s2?

ret?

x?

n2?

2! ,

x?

n1?

1! /

s2?[]

ret?[s2]

x?[s2]

n2?[]

x?[s2]

1 id = fun x -> ( ret = x; );2 n1 = 1;3 s1 = id n1;4 n2 = 2;5 s2 = id n2;

6/16

Page 35: AHigher-OrderDemand-DrivenProgramAnalysis ZacharyPalmer …zpalmer/... · ZacharyPalmer1 ScottF.Smith2 Swarthmore College1 The Johns Hopkins University2 July20th,2016. Some Program

Call Stack Alignment for Context-SensitivityLook up s2 from end of program

St id n1 s1 n2 s2 End

retx=n1 s1=ret

x=n2s2=ret

s2?

ret?

x?

n2?

2! ,

x?

n1?

1! /

s2?[]

ret?[s2]

x?[s2]

n2?[]

x?[s2]

1 id = fun x -> ( ret = x; );2 n1 = 1;3 s1 = id n1;4 n2 = 2;5 s2 = id n2;

6/16

Page 36: AHigher-OrderDemand-DrivenProgramAnalysis ZacharyPalmer …zpalmer/... · ZacharyPalmer1 ScottF.Smith2 Swarthmore College1 The Johns Hopkins University2 July20th,2016. Some Program

Call Stack Alignment for Context-SensitivityLook up s2 from end of program

St id n1 s1 n2 s2 End

retx=n1 s1=ret

x=n2s2=ret

s2?

ret?

x?

n2?

2! ,

x?

n1?

1! /

s2?[]

ret?[s2]

x?[s2]

n2?[]

x?[s2]

1 id = fun x -> ( ret = x; );2 n1 = 1;3 s1 = id n1;4 n2 = 2;5 s2 = id n2;

6/16

Page 37: AHigher-OrderDemand-DrivenProgramAnalysis ZacharyPalmer …zpalmer/... · ZacharyPalmer1 ScottF.Smith2 Swarthmore College1 The Johns Hopkins University2 July20th,2016. Some Program

Call Stack Alignment for Context-SensitivityLook up s2 from end of program

St id n1 s1 n2 s2 End

retx=n1 s1=ret

x=n2s2=ret

s2?

ret?

x?

n2?

2! ,

x?

n1?

1! /

s2?[]

ret?[s2]

x?[s2]

n2?[]

x?[s2]

1 id = fun x -> ( ret = x; );2 n1 = 1;3 s1 = id n1;4 n2 = 2;5 s2 = id n2;

6/16

Page 38: AHigher-OrderDemand-DrivenProgramAnalysis ZacharyPalmer …zpalmer/... · ZacharyPalmer1 ScottF.Smith2 Swarthmore College1 The Johns Hopkins University2 July20th,2016. Some Program

Call Stack Alignment for Context-SensitivityLook up s2 from end of program

St id n1 s1 n2 s2 End

retx=n1 s1=ret

x=n2s2=ret

s2?

ret?

x?

n2?

2! ,

x?

n1?

1! /

s2?[]

ret?[s2]

x?[s2]

n2?[]

x?[s2]

1 id = fun x -> ( ret = x; );2 n1 = 1;3 s1 = id n1;4 n2 = 2;5 s2 = id n2;

6/16

Page 39: AHigher-OrderDemand-DrivenProgramAnalysis ZacharyPalmer …zpalmer/... · ZacharyPalmer1 ScottF.Smith2 Swarthmore College1 The Johns Hopkins University2 July20th,2016. Some Program

Call Stack Alignment for Context-SensitivityLook up s2 from end of program

St id n1 s1 n2 s2 End

retx=n1 s1=ret

x=n2s2=ret

s2?

ret?

x?

n2?

2! ,

x?

n1?

1! /

s2?[]

ret?[s2]

x?[s2]

n2?[]

x?[s2]

1 id = fun x -> ( ret = x; );2 n1 = 1;3 s1 = id n1;4 n2 = 2;5 s2 = id n2;

6/16

Page 40: AHigher-OrderDemand-DrivenProgramAnalysis ZacharyPalmer …zpalmer/... · ZacharyPalmer1 ScottF.Smith2 Swarthmore College1 The Johns Hopkins University2 July20th,2016. Some Program

Call Stack Alignment for Context-SensitivityLook up s2 from end of program

St id n1 s1 n2 s2 End

retx=n1 s1=ret

x=n2s2=ret

s2?

ret?

x?

n2?

2! ,

x?

n1?

1! /

s2?[]

ret?[s2]

x?[s2]

n2?[]

x?[s2]

1 id = fun x -> ( ret = x; );2 n1 = 1;3 s1 = id n1;4 n2 = 2;5 s2 = id n2;

6/16

Page 41: AHigher-OrderDemand-DrivenProgramAnalysis ZacharyPalmer …zpalmer/... · ZacharyPalmer1 ScottF.Smith2 Swarthmore College1 The Johns Hopkins University2 July20th,2016. Some Program

Call Stack Alignment for Context-SensitivityLook up s2 from end of program

St id n1 s1 n2 s2 End

retx=n1 s1=ret

x=n2s2=ret

s2?

ret?

x?

n2?

2! ,

x?

n1?

1! /

s2?[]

ret?[s2]

x?[s2]

n2?[]

x?[s2]

1 id = fun x -> ( ret = x; );2 n1 = 1;3 s1 = id n1;4 n2 = 2;5 s2 = id n2;

6/16

Page 42: AHigher-OrderDemand-DrivenProgramAnalysis ZacharyPalmer …zpalmer/... · ZacharyPalmer1 ScottF.Smith2 Swarthmore College1 The Johns Hopkins University2 July20th,2016. Some Program

Call Stack Alignment for Context-SensitivitySolution: Maintain call stack during lookup, use to filter

St id n1 s1 n2 s2 End

retx=n1 s1=ret

x=n2s2=ret

s2?

ret?

x?

n2?

2! ,

x?

n1?

1! /

s2?[]

ret?[s2]

x?[s2]

n2?[]

x?[s2]

1 id = fun x -> ( ret = x; );2 n1 = 1;3 s1 = id n1;4 n2 = 2;5 s2 = id n2;

6/16

Page 43: AHigher-OrderDemand-DrivenProgramAnalysis ZacharyPalmer …zpalmer/... · ZacharyPalmer1 ScottF.Smith2 Swarthmore College1 The Johns Hopkins University2 July20th,2016. Some Program

Call Stack Alignment for Context-SensitivitySolution: Maintain call stack during lookup, use to filter

St id n1 s1 n2 s2 End

retxs1↓= n1 s1s1↑

= ret

xs2↓= n2

s2s2↑= ret

s2?

ret?

x?

n2?

2! ,

x?

n1?

1! /

s2?[]

ret?[s2]

x?[s2]

n2?[]

x?[s2]

1 id = fun x -> ( ret = x; );2 n1 = 1;3 s1 = id n1;4 n2 = 2;5 s2 = id n2;

6/16

Page 44: AHigher-OrderDemand-DrivenProgramAnalysis ZacharyPalmer …zpalmer/... · ZacharyPalmer1 ScottF.Smith2 Swarthmore College1 The Johns Hopkins University2 July20th,2016. Some Program

Call Stack Alignment for Context-SensitivitySolution: Maintain call stack during lookup, use to filter

St id n1 s1 n2 s2 End

retxs1↓= n1 s1s1↑

= ret

xs2↓= n2

s2s2↑= ret

s2?

ret?

x?

n2?

2! ,

x?

n1?

1! /

s2?[]

ret?[s2]

x?[s2]

n2?[]

x?[s2]

1 id = fun x -> ( ret = x; );2 n1 = 1;3 s1 = id n1;4 n2 = 2;5 s2 = id n2;

6/16

Page 45: AHigher-OrderDemand-DrivenProgramAnalysis ZacharyPalmer …zpalmer/... · ZacharyPalmer1 ScottF.Smith2 Swarthmore College1 The Johns Hopkins University2 July20th,2016. Some Program

Call Stack Alignment for Context-SensitivitySolution: Maintain call stack during lookup, use to filter

St id n1 s1 n2 s2 End

retxs1↓= n1 s1s1↑

= ret

xs2↓= n2

s2s2↑= ret

s2?

ret?

x?

n2?

2! ,

x?

n1?

1! /

s2?[]

ret?[s2]

x?[s2]

n2?[]

x?[s2]

1 id = fun x -> ( ret = x; );2 n1 = 1;3 s1 = id n1;4 n2 = 2;5 s2 = id n2;

6/16

Page 46: AHigher-OrderDemand-DrivenProgramAnalysis ZacharyPalmer …zpalmer/... · ZacharyPalmer1 ScottF.Smith2 Swarthmore College1 The Johns Hopkins University2 July20th,2016. Some Program

Call Stack Alignment for Context-SensitivitySolution: Maintain call stack during lookup, use to filter

St id n1 s1 n2 s2 End

retxs1↓= n1 s1s1↑

= ret

xs2↓= n2

s2s2↑= ret

s2?

ret?

x?

n2?

2! ,

x?

n1?

1! /

s2?[]

ret?[s2]

x?[s2]

n2?[]

x?[s2]

1 id = fun x -> ( ret = x; );2 n1 = 1;3 s1 = id n1;4 n2 = 2;5 s2 = id n2;

6/16

Page 47: AHigher-OrderDemand-DrivenProgramAnalysis ZacharyPalmer …zpalmer/... · ZacharyPalmer1 ScottF.Smith2 Swarthmore College1 The Johns Hopkins University2 July20th,2016. Some Program

Call Stack Alignment for Context-SensitivitySolution: Maintain call stack during lookup, use to filter

St id n1 s1 n2 s2 End

retxs1↓= n1 s1s1↑

= ret

xs2↓= n2

s2s2↑= ret

s2?

ret?

x?

n2?

2! ,

x?

n1?

1! /

s2?[]

ret?[s2]

x?[s2]

n2?[]

x?[s2]

1 id = fun x -> ( ret = x; );2 n1 = 1;3 s1 = id n1;4 n2 = 2;5 s2 = id n2;

6/16

Page 48: AHigher-OrderDemand-DrivenProgramAnalysis ZacharyPalmer …zpalmer/... · ZacharyPalmer1 ScottF.Smith2 Swarthmore College1 The Johns Hopkins University2 July20th,2016. Some Program

Call Stack Alignment for Context-SensitivitySolution: Maintain call stack during lookup, use to filter

St id n1 s1 n2 s2 End

retxs1↓= n1 s1s1↑

= ret

xs2↓= n2

s2s2↑= ret

s2?

ret?

x?

n2?

2! ,

x?

n1?

1! /

s2?[]

ret?[s2]

x?[s2]

n2?[]

x?[s2]

1 id = fun x -> ( ret = x; );2 n1 = 1;3 s1 = id n1;4 n2 = 2;5 s2 = id n2;

6/16

Page 49: AHigher-OrderDemand-DrivenProgramAnalysis ZacharyPalmer …zpalmer/... · ZacharyPalmer1 ScottF.Smith2 Swarthmore College1 The Johns Hopkins University2 July20th,2016. Some Program

Implementing stack alignment

CFA2/PDCFA:

Push-Down System (PDS) for aligning calls and returnsDoes not align non-locals; uses context copying for that

POLYFLOWCFL

Uses CFL/PDA for aligning calls and returnsNot flow-sensitive; lesser precision

DDPA:

Also uses PDS: lookup decision ≡ automata reachabilityPDS stack is not call stackWe need the PDS stack for something else...

7/16

Page 50: AHigher-OrderDemand-DrivenProgramAnalysis ZacharyPalmer …zpalmer/... · ZacharyPalmer1 ScottF.Smith2 Swarthmore College1 The Johns Hopkins University2 July20th,2016. Some Program

Implementing stack alignment

CFA2/PDCFA:Push-Down System (PDS) for aligning calls and returns

Does not align non-locals; uses context copying for thatPOLYFLOWCFL

Uses CFL/PDA for aligning calls and returnsNot flow-sensitive; lesser precision

DDPA:

Also uses PDS: lookup decision ≡ automata reachabilityPDS stack is not call stackWe need the PDS stack for something else...

7/16

Page 51: AHigher-OrderDemand-DrivenProgramAnalysis ZacharyPalmer …zpalmer/... · ZacharyPalmer1 ScottF.Smith2 Swarthmore College1 The Johns Hopkins University2 July20th,2016. Some Program

Implementing stack alignment

CFA2/PDCFA:Push-Down System (PDS) for aligning calls and returnsDoes not align non-locals; uses context copying for that

POLYFLOWCFL

Uses CFL/PDA for aligning calls and returnsNot flow-sensitive; lesser precision

DDPA:

Also uses PDS: lookup decision ≡ automata reachabilityPDS stack is not call stackWe need the PDS stack for something else...

7/16

Page 52: AHigher-OrderDemand-DrivenProgramAnalysis ZacharyPalmer …zpalmer/... · ZacharyPalmer1 ScottF.Smith2 Swarthmore College1 The Johns Hopkins University2 July20th,2016. Some Program

Implementing stack alignment

CFA2/PDCFA:Push-Down System (PDS) for aligning calls and returnsDoes not align non-locals; uses context copying for that

POLYFLOWCFLUses CFL/PDA for aligning calls and returns

Not flow-sensitive; lesser precisionDDPA:

Also uses PDS: lookup decision ≡ automata reachabilityPDS stack is not call stackWe need the PDS stack for something else...

7/16

Page 53: AHigher-OrderDemand-DrivenProgramAnalysis ZacharyPalmer …zpalmer/... · ZacharyPalmer1 ScottF.Smith2 Swarthmore College1 The Johns Hopkins University2 July20th,2016. Some Program

Implementing stack alignment

CFA2/PDCFA:Push-Down System (PDS) for aligning calls and returnsDoes not align non-locals; uses context copying for that

POLYFLOWCFLUses CFL/PDA for aligning calls and returnsNot flow-sensitive; lesser precision

DDPA:

Also uses PDS: lookup decision ≡ automata reachabilityPDS stack is not call stackWe need the PDS stack for something else...

7/16

Page 54: AHigher-OrderDemand-DrivenProgramAnalysis ZacharyPalmer …zpalmer/... · ZacharyPalmer1 ScottF.Smith2 Swarthmore College1 The Johns Hopkins University2 July20th,2016. Some Program

Implementing stack alignment

CFA2/PDCFA:Push-Down System (PDS) for aligning calls and returnsDoes not align non-locals; uses context copying for that

POLYFLOWCFLUses CFL/PDA for aligning calls and returnsNot flow-sensitive; lesser precision

DDPA:Also uses PDS: lookup decision ≡ automata reachability

PDS stack is not call stackWe need the PDS stack for something else...

7/16

Page 55: AHigher-OrderDemand-DrivenProgramAnalysis ZacharyPalmer …zpalmer/... · ZacharyPalmer1 ScottF.Smith2 Swarthmore College1 The Johns Hopkins University2 July20th,2016. Some Program

Implementing stack alignment

CFA2/PDCFA:Push-Down System (PDS) for aligning calls and returnsDoes not align non-locals; uses context copying for that

POLYFLOWCFLUses CFL/PDA for aligning calls and returnsNot flow-sensitive; lesser precision

DDPA:Also uses PDS: lookup decision ≡ automata reachabilityPDS stack is not call stackWe need the PDS stack for something else...

7/16

Page 56: AHigher-OrderDemand-DrivenProgramAnalysis ZacharyPalmer …zpalmer/... · ZacharyPalmer1 ScottF.Smith2 Swarthmore College1 The Johns Hopkins University2 July20th,2016. Some Program

Handling Non-Local Variables

Non-local example: K-combinator

1 let k v j = v;;2 let f = k 1;;3 let g = k 2;;4 let s = f 0;;

⇓ A-normalization

1 k = fun v -> (k0 = fun j -> (r = v;););2 a = 1; f = k a;3 b = 2; g = k b;4 z = 0; s = f z;

8/16

Page 57: AHigher-OrderDemand-DrivenProgramAnalysis ZacharyPalmer …zpalmer/... · ZacharyPalmer1 ScottF.Smith2 Swarthmore College1 The Johns Hopkins University2 July20th,2016. Some Program

Handling Non-Local Variables

Non-local example: K-combinator

1 let k v j = v;;2 let f = k 1;;3 let g = k 2;;4 let s = f 0;;

⇓ A-normalization

1 k = fun v -> (k0 = fun j -> (r = v;););2 a = 1; f = k a;3 b = 2; g = k b;4 z = 0; s = f z;

8/16

Page 58: AHigher-OrderDemand-DrivenProgramAnalysis ZacharyPalmer …zpalmer/... · ZacharyPalmer1 ScottF.Smith2 Swarthmore College1 The Johns Hopkins University2 July20th,2016. Some Program

Non-Local Variable Lookup

k a f b g z s

St End

k0

vf↓=a ff↑

=k0

vg↓=b gg↑

=k0

r

js↓=z

ss↑=rs?[]

r?[s]

v?[s]

v?[]

v?[]v?[]v?[]v?[]v?[]v?[]

/

v?[]

k0?[f]v?[f]

a?[]

1! ,

1 k = fun v -> (k0 = fun j -> (r = v;););2 a = 1; f = k a;3 b = 2; g = k b;4 z = 0; s = f z;

9/16

Page 59: AHigher-OrderDemand-DrivenProgramAnalysis ZacharyPalmer …zpalmer/... · ZacharyPalmer1 ScottF.Smith2 Swarthmore College1 The Johns Hopkins University2 July20th,2016. Some Program

Non-Local Variable LookupAnalyze call site f.

k a f b g z s

St End

k0vf↓=a ff↑

=k0

vg↓=b gg↑

=k0

r

js↓=z

ss↑=rs?[]

r?[s]

v?[s]

v?[]

v?[]v?[]v?[]v?[]v?[]v?[]

/

v?[]

k0?[f]v?[f]

a?[]

1! ,

1 k = fun v -> (k0 = fun j -> (r = v;););2 a = 1; f = k a;3 b = 2; g = k b;4 z = 0; s = f z;

9/16

Page 60: AHigher-OrderDemand-DrivenProgramAnalysis ZacharyPalmer …zpalmer/... · ZacharyPalmer1 ScottF.Smith2 Swarthmore College1 The Johns Hopkins University2 July20th,2016. Some Program

Non-Local Variable LookupAnalyze call site g.

k a f b g z s

St End

k0vf↓=a ff↑

=k0

vg↓=b gg↑

=k0 r

js↓=z

ss↑=rs?[]

r?[s]

v?[s]

v?[]

v?[]v?[]v?[]v?[]v?[]v?[]

/

v?[]

k0?[f]v?[f]

a?[]

1! ,

1 k = fun v -> (k0 = fun j -> (r = v;););2 a = 1; f = k a;3 b = 2; g = k b;4 z = 0; s = f z;

9/16

Page 61: AHigher-OrderDemand-DrivenProgramAnalysis ZacharyPalmer …zpalmer/... · ZacharyPalmer1 ScottF.Smith2 Swarthmore College1 The Johns Hopkins University2 July20th,2016. Some Program

Non-Local Variable LookupAnalyze call site s.

k a f b g z s

St End

k0vf↓=a ff↑

=k0

vg↓=b gg↑

=k0 r

js↓=z

ss↑=r

s?[]

r?[s]

v?[s]

v?[]

v?[]v?[]v?[]v?[]v?[]v?[]

/

v?[]

k0?[f]v?[f]

a?[]

1! ,

1 k = fun v -> (k0 = fun j -> (r = v;););2 a = 1; f = k a;3 b = 2; g = k b;4 z = 0; s = f z;

9/16

Page 62: AHigher-OrderDemand-DrivenProgramAnalysis ZacharyPalmer …zpalmer/... · ZacharyPalmer1 ScottF.Smith2 Swarthmore College1 The Johns Hopkins University2 July20th,2016. Some Program

Non-Local Variable LookupLook up s from end of program.

k a f b g z s

St End

k0vf↓=a ff↑

=k0

vg↓=b gg↑

=k0 r

js↓=z

ss↑=r

s?[]

r?[s]

v?[s]

v?[]

v?[]v?[]v?[]v?[]v?[]v?[]

/

v?[]

k0?[f]v?[f]

a?[]

1! ,

1 k = fun v -> (k0 = fun j -> (r = v;););2 a = 1; f = k a;3 b = 2; g = k b;4 z = 0; s = f z;

9/16

Page 63: AHigher-OrderDemand-DrivenProgramAnalysis ZacharyPalmer …zpalmer/... · ZacharyPalmer1 ScottF.Smith2 Swarthmore College1 The Johns Hopkins University2 July20th,2016. Some Program

Non-Local Variable LookupLook up s from end of program.

k a f b g z s

St End

k0vf↓=a ff↑

=k0

vg↓=b gg↑

=k0 r

js↓=z

ss↑=rs?[]

r?[s]

v?[s]

v?[]

v?[]v?[]v?[]v?[]v?[]v?[]

/

v?[]

k0?[f]v?[f]

a?[]

1! ,

1 k = fun v -> (k0 = fun j -> (r = v;););2 a = 1; f = k a;3 b = 2; g = k b;4 z = 0; s = f z;

9/16

Page 64: AHigher-OrderDemand-DrivenProgramAnalysis ZacharyPalmer …zpalmer/... · ZacharyPalmer1 ScottF.Smith2 Swarthmore College1 The Johns Hopkins University2 July20th,2016. Some Program

Non-Local Variable LookupLook up s from end of program.

k a f b g z s

St End

k0vf↓=a ff↑

=k0

vg↓=b gg↑

=k0 r

js↓=z

ss↑=rs?[]

r?[s]

v?[s]

v?[]

v?[]v?[]v?[]v?[]v?[]v?[]

/

v?[]

k0?[f]v?[f]

a?[]

1! ,

1 k = fun v -> (k0 = fun j -> (r = v;););2 a = 1; f = k a;3 b = 2; g = k b;4 z = 0; s = f z;

9/16

Page 65: AHigher-OrderDemand-DrivenProgramAnalysis ZacharyPalmer …zpalmer/... · ZacharyPalmer1 ScottF.Smith2 Swarthmore College1 The Johns Hopkins University2 July20th,2016. Some Program

Non-Local Variable LookupLook up s from end of program.

k a f b g z s

St End

k0vf↓=a ff↑

=k0

vg↓=b gg↑

=k0 r

js↓=z

ss↑=rs?[]

r?[s]

v?[s]

v?[]

v?[]v?[]v?[]v?[]v?[]v?[]

/

v?[]

k0?[f]v?[f]

a?[]

1! ,

1 k = fun v -> (k0 = fun j -> (r = v;););2 a = 1; f = k a;3 b = 2; g = k b;4 z = 0; s = f z;

9/16

Page 66: AHigher-OrderDemand-DrivenProgramAnalysis ZacharyPalmer …zpalmer/... · ZacharyPalmer1 ScottF.Smith2 Swarthmore College1 The Johns Hopkins University2 July20th,2016. Some Program

Non-Local Variable Lookup

k a f b g z s

St End

k0vf↓=a ff↑

=k0

vg↓=b gg↑

=k0 r

js↓=z

ss↑=rs?[]

r?[s]

v?[s]

v?[]

v?[]v?[]v?[]v?[]v?[]v?[]

/

v?[]

k0?[f]v?[f]

a?[]

1! ,

1 k = fun v -> (k0 = fun j -> (r = v;););2 a = 1; f = k a;3 b = 2; g = k b;4 z = 0; s = f z;

9/16

Page 67: AHigher-OrderDemand-DrivenProgramAnalysis ZacharyPalmer …zpalmer/... · ZacharyPalmer1 ScottF.Smith2 Swarthmore College1 The Johns Hopkins University2 July20th,2016. Some Program

Non-Local Variable Lookup

k a f b g z s

St End

k0vf↓=a ff↑

=k0

vg↓=b gg↑

=k0 r

js↓=z

ss↑=rs?[]

r?[s]

v?[s]

v?[]

v?[]v?[]v?[]v?[]v?[]v?[]

/

f?[]

k0?[f]v?[f]

a?[]

1! ,

1 k = fun v -> (k0 = fun j -> (r = v;););2 a = 1; f = k a;3 b = 2; g = k b;4 z = 0; s = f z;

9/16

Page 68: AHigher-OrderDemand-DrivenProgramAnalysis ZacharyPalmer …zpalmer/... · ZacharyPalmer1 ScottF.Smith2 Swarthmore College1 The Johns Hopkins University2 July20th,2016. Some Program

Non-Local Variable Lookup

k a f b g z s

St End

k0vf↓=a ff↑

=k0

vg↓=b gg↑

=k0 r

js↓=z

ss↑=rs?[]

r?[s]

v?[s]

v?[]

v?[]v?[]v?[]v?[]v?[]v?[]

/

f?[]

k0?[f]v?[f]

a?[]

1! ,

1 k = fun v -> (k0 = fun j -> (r = v;););2 a = 1; f = k a;3 b = 2; g = k b;4 z = 0; s = f z;

9/16

Page 69: AHigher-OrderDemand-DrivenProgramAnalysis ZacharyPalmer …zpalmer/... · ZacharyPalmer1 ScottF.Smith2 Swarthmore College1 The Johns Hopkins University2 July20th,2016. Some Program

Non-Local Variable Lookup

k a f b g z s

St End

k0vf↓=a ff↑

=k0

vg↓=b gg↑

=k0 r

js↓=z

ss↑=rs?[]

r?[s]

v?[s]

v?[]

v?[]v?[]v?[]v?[]v?[]v?[]

/

f?[]

k0?[f]

v?[f]

a?[]

1! ,

1 k = fun v -> (k0 = fun j -> (r = v;););2 a = 1; f = k a;3 b = 2; g = k b;4 z = 0; s = f z;

9/16

Page 70: AHigher-OrderDemand-DrivenProgramAnalysis ZacharyPalmer …zpalmer/... · ZacharyPalmer1 ScottF.Smith2 Swarthmore College1 The Johns Hopkins University2 July20th,2016. Some Program

Non-Local Variable Lookup

k a f b g z s

St End

k0vf↓=a ff↑

=k0

vg↓=b gg↑

=k0 r

js↓=z

ss↑=rs?[]

r?[s]

v?[s]

v?[]

v?[]v?[]v?[]v?[]v?[]v?[]

/

f?[]

k0?[f]v?[f]

a?[]

1! ,

1 k = fun v -> (k0 = fun j -> (r = v;););2 a = 1; f = k a;3 b = 2; g = k b;4 z = 0; s = f z;

9/16

Page 71: AHigher-OrderDemand-DrivenProgramAnalysis ZacharyPalmer …zpalmer/... · ZacharyPalmer1 ScottF.Smith2 Swarthmore College1 The Johns Hopkins University2 July20th,2016. Some Program

Non-Local Variable Lookup

k a f b g z s

St End

k0vf↓=a ff↑

=k0

vg↓=b gg↑

=k0 r

js↓=z

ss↑=rs?[]

r?[s]

v?[s]

v?[]

v?[]v?[]v?[]v?[]v?[]v?[]

/

f?[]

k0?[f]v?[f]

a?[]

1! ,

1 k = fun v -> (k0 = fun j -> (r = v;););2 a = 1; f = k a;3 b = 2; g = k b;4 z = 0; s = f z;

9/16

Page 72: AHigher-OrderDemand-DrivenProgramAnalysis ZacharyPalmer …zpalmer/... · ZacharyPalmer1 ScottF.Smith2 Swarthmore College1 The Johns Hopkins University2 July20th,2016. Some Program

Handling Non-Local Variables

Search for defining closure; then, resume looking for variable

General case: continuation stack needed for non-local lookupsCan’t have a 2-stack PDS!

Solution: finitize call stack in PDS nodes; keep full lookupstack.kDDPA: maximum call stack depth kLookup still translates to PDS reachability decision problem

10/16

Page 73: AHigher-OrderDemand-DrivenProgramAnalysis ZacharyPalmer …zpalmer/... · ZacharyPalmer1 ScottF.Smith2 Swarthmore College1 The Johns Hopkins University2 July20th,2016. Some Program

Handling Non-Local Variables

Search for defining closure; then, resume looking for variableGeneral case: continuation stack needed for non-local lookups

Can’t have a 2-stack PDS!

Solution: finitize call stack in PDS nodes; keep full lookupstack.kDDPA: maximum call stack depth kLookup still translates to PDS reachability decision problem

10/16

Page 74: AHigher-OrderDemand-DrivenProgramAnalysis ZacharyPalmer …zpalmer/... · ZacharyPalmer1 ScottF.Smith2 Swarthmore College1 The Johns Hopkins University2 July20th,2016. Some Program

Handling Non-Local Variables

Search for defining closure; then, resume looking for variableGeneral case: continuation stack needed for non-local lookupsCan’t have a 2-stack PDS!

Solution: finitize call stack in PDS nodes; keep full lookupstack.kDDPA: maximum call stack depth kLookup still translates to PDS reachability decision problem

10/16

Page 75: AHigher-OrderDemand-DrivenProgramAnalysis ZacharyPalmer …zpalmer/... · ZacharyPalmer1 ScottF.Smith2 Swarthmore College1 The Johns Hopkins University2 July20th,2016. Some Program

Handling Non-Local Variables

Search for defining closure; then, resume looking for variableGeneral case: continuation stack needed for non-local lookupsCan’t have a 2-stack PDS!

Solution: finitize call stack in PDS nodes; keep full lookupstack.

kDDPA: maximum call stack depth kLookup still translates to PDS reachability decision problem

10/16

Page 76: AHigher-OrderDemand-DrivenProgramAnalysis ZacharyPalmer …zpalmer/... · ZacharyPalmer1 ScottF.Smith2 Swarthmore College1 The Johns Hopkins University2 July20th,2016. Some Program

Handling Non-Local Variables

Search for defining closure; then, resume looking for variableGeneral case: continuation stack needed for non-local lookupsCan’t have a 2-stack PDS!

Solution: finitize call stack in PDS nodes; keep full lookupstack.kDDPA: maximum call stack depth k

Lookup still translates to PDS reachability decision problem

10/16

Page 77: AHigher-OrderDemand-DrivenProgramAnalysis ZacharyPalmer …zpalmer/... · ZacharyPalmer1 ScottF.Smith2 Swarthmore College1 The Johns Hopkins University2 July20th,2016. Some Program

Handling Non-Local Variables

Search for defining closure; then, resume looking for variableGeneral case: continuation stack needed for non-local lookupsCan’t have a 2-stack PDS!

Solution: finitize call stack in PDS nodes; keep full lookupstack.kDDPA: maximum call stack depth kLookup still translates to PDS reachability decision problem

10/16

Page 78: AHigher-OrderDemand-DrivenProgramAnalysis ZacharyPalmer …zpalmer/... · ZacharyPalmer1 ScottF.Smith2 Swarthmore College1 The Johns Hopkins University2 July20th,2016. Some Program

Properties

Recursion: handled by PDS lookup; cycles are fine in a PDS

Theorem: kDDPA (for fixed k) has polynomial time boundLemma: both CFG and PDS are monotonically increasing overanalysis

Allows for analysis to be purely additive – efficient sharingObserve we have reduced program analysis to incremental(PDS) model checking - fast!

11/16

Page 79: AHigher-OrderDemand-DrivenProgramAnalysis ZacharyPalmer …zpalmer/... · ZacharyPalmer1 ScottF.Smith2 Swarthmore College1 The Johns Hopkins University2 July20th,2016. Some Program

Properties

Recursion: handled by PDS lookup; cycles are fine in a PDSTheorem: kDDPA (for fixed k) has polynomial time bound

Lemma: both CFG and PDS are monotonically increasing overanalysis

Allows for analysis to be purely additive – efficient sharingObserve we have reduced program analysis to incremental(PDS) model checking - fast!

11/16

Page 80: AHigher-OrderDemand-DrivenProgramAnalysis ZacharyPalmer …zpalmer/... · ZacharyPalmer1 ScottF.Smith2 Swarthmore College1 The Johns Hopkins University2 July20th,2016. Some Program

Properties

Recursion: handled by PDS lookup; cycles are fine in a PDSTheorem: kDDPA (for fixed k) has polynomial time boundLemma: both CFG and PDS are monotonically increasing overanalysis

Allows for analysis to be purely additive – efficient sharingObserve we have reduced program analysis to incremental(PDS) model checking - fast!

11/16

Page 81: AHigher-OrderDemand-DrivenProgramAnalysis ZacharyPalmer …zpalmer/... · ZacharyPalmer1 ScottF.Smith2 Swarthmore College1 The Johns Hopkins University2 July20th,2016. Some Program

Properties

Recursion: handled by PDS lookup; cycles are fine in a PDSTheorem: kDDPA (for fixed k) has polynomial time boundLemma: both CFG and PDS are monotonically increasing overanalysis

Allows for analysis to be purely additive – efficient sharing

Observe we have reduced program analysis to incremental(PDS) model checking - fast!

11/16

Page 82: AHigher-OrderDemand-DrivenProgramAnalysis ZacharyPalmer …zpalmer/... · ZacharyPalmer1 ScottF.Smith2 Swarthmore College1 The Johns Hopkins University2 July20th,2016. Some Program

Properties

Recursion: handled by PDS lookup; cycles are fine in a PDSTheorem: kDDPA (for fixed k) has polynomial time boundLemma: both CFG and PDS are monotonically increasing overanalysis

Allows for analysis to be purely additive – efficient sharingObserve we have reduced program analysis to incremental(PDS) model checking - fast!

11/16

Page 83: AHigher-OrderDemand-DrivenProgramAnalysis ZacharyPalmer …zpalmer/... · ZacharyPalmer1 ScottF.Smith2 Swarthmore College1 The Johns Hopkins University2 July20th,2016. Some Program

Source / CFG / PDS - the whole analysis

1 x = {};2 f = fun i -> ( r = i );3 z = f x; Start x f z End

iz↓=x zz↑

=rr

context ε

context [z] iz↓=x r zz↑

=r

x f z End z?

nopnop

nopnop

nop ↑f↓f

↑x↓x

↑fnop

↑x↓x↑xnop

↑z

↓r

↑r↓i↑i↓x

↑x

↓x↓z

Build both CFG and PDS incrementally; above is final result

12/16

Page 84: AHigher-OrderDemand-DrivenProgramAnalysis ZacharyPalmer …zpalmer/... · ZacharyPalmer1 ScottF.Smith2 Swarthmore College1 The Johns Hopkins University2 July20th,2016. Some Program

Forward and reverse analyses compared

Forward analyses are more natural to derive from operationalsemantics

DDPA is demand-driven and model-checking: potentiallymore efficient than forward analysesk in kDDPA not directly comparable to kCFA, etc.

k of kDDPA also needs to be bigger for handling non-localsWhich makes sense: for fixed k, kCFA is EXPTIME butkDDPA is polynomial

Practically speaking, expressiveness appears similar

13/16

Page 85: AHigher-OrderDemand-DrivenProgramAnalysis ZacharyPalmer …zpalmer/... · ZacharyPalmer1 ScottF.Smith2 Swarthmore College1 The Johns Hopkins University2 July20th,2016. Some Program

Forward and reverse analyses compared

Forward analyses are more natural to derive from operationalsemanticsDDPA is demand-driven and model-checking: potentiallymore efficient than forward analyses

k in kDDPA not directly comparable to kCFA, etc.

k of kDDPA also needs to be bigger for handling non-localsWhich makes sense: for fixed k, kCFA is EXPTIME butkDDPA is polynomial

Practically speaking, expressiveness appears similar

13/16

Page 86: AHigher-OrderDemand-DrivenProgramAnalysis ZacharyPalmer …zpalmer/... · ZacharyPalmer1 ScottF.Smith2 Swarthmore College1 The Johns Hopkins University2 July20th,2016. Some Program

Forward and reverse analyses compared

Forward analyses are more natural to derive from operationalsemanticsDDPA is demand-driven and model-checking: potentiallymore efficient than forward analysesk in kDDPA not directly comparable to kCFA, etc.

k of kDDPA also needs to be bigger for handling non-localsWhich makes sense: for fixed k, kCFA is EXPTIME butkDDPA is polynomial

Practically speaking, expressiveness appears similar

13/16

Page 87: AHigher-OrderDemand-DrivenProgramAnalysis ZacharyPalmer …zpalmer/... · ZacharyPalmer1 ScottF.Smith2 Swarthmore College1 The Johns Hopkins University2 July20th,2016. Some Program

Forward and reverse analyses compared

Forward analyses are more natural to derive from operationalsemanticsDDPA is demand-driven and model-checking: potentiallymore efficient than forward analysesk in kDDPA not directly comparable to kCFA, etc.

k of kDDPA also needs to be bigger for handling non-locals

Which makes sense: for fixed k, kCFA is EXPTIME butkDDPA is polynomial

Practically speaking, expressiveness appears similar

13/16

Page 88: AHigher-OrderDemand-DrivenProgramAnalysis ZacharyPalmer …zpalmer/... · ZacharyPalmer1 ScottF.Smith2 Swarthmore College1 The Johns Hopkins University2 July20th,2016. Some Program

Forward and reverse analyses compared

Forward analyses are more natural to derive from operationalsemanticsDDPA is demand-driven and model-checking: potentiallymore efficient than forward analysesk in kDDPA not directly comparable to kCFA, etc.

k of kDDPA also needs to be bigger for handling non-localsWhich makes sense: for fixed k, kCFA is EXPTIME butkDDPA is polynomial

Practically speaking, expressiveness appears similar

13/16

Page 89: AHigher-OrderDemand-DrivenProgramAnalysis ZacharyPalmer …zpalmer/... · ZacharyPalmer1 ScottF.Smith2 Swarthmore College1 The Johns Hopkins University2 July20th,2016. Some Program

Forward and reverse analyses compared

Forward analyses are more natural to derive from operationalsemanticsDDPA is demand-driven and model-checking: potentiallymore efficient than forward analysesk in kDDPA not directly comparable to kCFA, etc.

k of kDDPA also needs to be bigger for handling non-localsWhich makes sense: for fixed k, kCFA is EXPTIME butkDDPA is polynomial

Practically speaking, expressiveness appears similar

13/16

Page 90: AHigher-OrderDemand-DrivenProgramAnalysis ZacharyPalmer …zpalmer/... · ZacharyPalmer1 ScottF.Smith2 Swarthmore College1 The Johns Hopkins University2 July20th,2016. Some Program

Implementation

Paper artifact: inefficient proof-of-concept

Now: efficient implementation with additional features

RecordsPath-sensitivity – paths validated by PDSHeap-sensitive state including may/must alias information

Lazily constructs PDS according to regular definitionLooks to be reasonabily efficient

14/16

Page 91: AHigher-OrderDemand-DrivenProgramAnalysis ZacharyPalmer …zpalmer/... · ZacharyPalmer1 ScottF.Smith2 Swarthmore College1 The Johns Hopkins University2 July20th,2016. Some Program

Implementation

Paper artifact: inefficient proof-of-conceptNow: efficient implementation with additional features

RecordsPath-sensitivity – paths validated by PDSHeap-sensitive state including may/must alias information

Lazily constructs PDS according to regular definitionLooks to be reasonabily efficient

14/16

Page 92: AHigher-OrderDemand-DrivenProgramAnalysis ZacharyPalmer …zpalmer/... · ZacharyPalmer1 ScottF.Smith2 Swarthmore College1 The Johns Hopkins University2 July20th,2016. Some Program

Implementation

Paper artifact: inefficient proof-of-conceptNow: efficient implementation with additional features

Records

Path-sensitivity – paths validated by PDSHeap-sensitive state including may/must alias information

Lazily constructs PDS according to regular definitionLooks to be reasonabily efficient

14/16

Page 93: AHigher-OrderDemand-DrivenProgramAnalysis ZacharyPalmer …zpalmer/... · ZacharyPalmer1 ScottF.Smith2 Swarthmore College1 The Johns Hopkins University2 July20th,2016. Some Program

Implementation

Paper artifact: inefficient proof-of-conceptNow: efficient implementation with additional features

RecordsPath-sensitivity – paths validated by PDS

Heap-sensitive state including may/must alias informationLazily constructs PDS according to regular definitionLooks to be reasonabily efficient

14/16

Page 94: AHigher-OrderDemand-DrivenProgramAnalysis ZacharyPalmer …zpalmer/... · ZacharyPalmer1 ScottF.Smith2 Swarthmore College1 The Johns Hopkins University2 July20th,2016. Some Program

Implementation

Paper artifact: inefficient proof-of-conceptNow: efficient implementation with additional features

RecordsPath-sensitivity – paths validated by PDSHeap-sensitive state including may/must alias information

Lazily constructs PDS according to regular definitionLooks to be reasonabily efficient

14/16

Page 95: AHigher-OrderDemand-DrivenProgramAnalysis ZacharyPalmer …zpalmer/... · ZacharyPalmer1 ScottF.Smith2 Swarthmore College1 The Johns Hopkins University2 July20th,2016. Some Program

Implementation

Paper artifact: inefficient proof-of-conceptNow: efficient implementation with additional features

RecordsPath-sensitivity – paths validated by PDSHeap-sensitive state including may/must alias information

Lazily constructs PDS according to regular definition

Looks to be reasonabily efficient

14/16

Page 96: AHigher-OrderDemand-DrivenProgramAnalysis ZacharyPalmer …zpalmer/... · ZacharyPalmer1 ScottF.Smith2 Swarthmore College1 The Johns Hopkins University2 July20th,2016. Some Program

Implementation

Paper artifact: inefficient proof-of-conceptNow: efficient implementation with additional features

RecordsPath-sensitivity – paths validated by PDSHeap-sensitive state including may/must alias information

Lazily constructs PDS according to regular definitionLooks to be reasonabily efficient

14/16

Page 97: AHigher-OrderDemand-DrivenProgramAnalysis ZacharyPalmer …zpalmer/... · ZacharyPalmer1 ScottF.Smith2 Swarthmore College1 The Johns Hopkins University2 July20th,2016. Some Program

Future Work

Variable alignment for precision

Better call stack model for performanceApplication to existing languages

15/16

Page 98: AHigher-OrderDemand-DrivenProgramAnalysis ZacharyPalmer …zpalmer/... · ZacharyPalmer1 ScottF.Smith2 Swarthmore College1 The Johns Hopkins University2 July20th,2016. Some Program

Future Work

Variable alignment for precisionBetter call stack model for performance

Application to existing languages

15/16

Page 99: AHigher-OrderDemand-DrivenProgramAnalysis ZacharyPalmer …zpalmer/... · ZacharyPalmer1 ScottF.Smith2 Swarthmore College1 The Johns Hopkins University2 July20th,2016. Some Program

Future Work

Variable alignment for precisionBetter call stack model for performanceApplication to existing languages

15/16

Page 100: AHigher-OrderDemand-DrivenProgramAnalysis ZacharyPalmer …zpalmer/... · ZacharyPalmer1 ScottF.Smith2 Swarthmore College1 The Johns Hopkins University2 July20th,2016. Some Program

Conclusions

DDPA: first flow-sensitive, demand-driven, higher-orderprogram analysisProgram analysis based on incremental model checking

Promising for efficiencyAppears comparable in expressiveness with state-of-the-artforward analysesCode: https://github.com/JHU-PL-Lab/odefa

16/16