choice calculus & variational programmingakcheung/pnw16/walkingshaw.pdf · pl research @ osu 2...

21
1 Choice Calculus & Variational Programming PNW PL/SE Meeting 2016 Eric Walkingshaw Oregon State University

Upload: others

Post on 04-May-2020

4 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Choice Calculus & Variational Programmingakcheung/pnw16/walkingshaw.pdf · PL Research @ OSU 2 Lots of research related to variability: • variational program analyses • variational

1

Choice Calculus &Variational Programming

PNW PL/SE Meeting 2016

Eric Walkingshaw Oregon State University

Page 2: Choice Calculus & Variational Programmingakcheung/pnw16/walkingshaw.pdf · PL Research @ OSU 2 Lots of research related to variability: • variational program analyses • variational

PL Research @ OSU

2

Lots of research related to variability:

• variational program analyses

• variational program execution

• variational data structures

• view-based editing of variational programs

Other active areas:

• language design & domain-specific languages

• functional programming

Page 3: Choice Calculus & Variational Programmingakcheung/pnw16/walkingshaw.pdf · PL Research @ OSU 2 Lots of research related to variability: • variational program analyses • variational

class Buffer { int buff = 0; #ifdef UndoOne int back = 0; #endif #ifdef UndoMany Stack stack = new Stack(); #endif int get() { return buff; } void set(int x) { #ifdef Logging log(buff+"->"+x); #endif #ifdef UndoOne back = buff; #endif #ifdef UndoMany stack.push(buff); #endif buff = x; }

#ifdef UndoOne void undo() { #ifdef Logging log(back+"<-"+bug); #endif buff = back; } #endif #ifdef UndoMany void undo() { #ifdef Logging log(stack.peek() +"<-"+buff); #endif buff = stack.pop(); } #endif }

class Buffer { int buff = 0; int get() { return buff; } void set(int x) { buff = x; } }

class Buffer { int buff = 0; int get() { return buff; } void set(int x) { log(buff+"->"+x); buff = x; } }

class Buffer { int buff = 0; int back = 0; int get() { return buff; } void set(int x) { back = buff; buff = x; } void undo() { buff = back; } }

class Buffer { int buff = 0; int back = 0; int get() { return buff; } void set(int x) { log(buff+"->"+x); back = buff; buff = x; } void undo() { log(back +"<-"+bug); buff = back; } }

class Buffer { int buff = 0; Stack stack = new Stack(); int get() { return buff; } void set(int x) { stack.push(buff); buff = x; } void undo() { buff = stack.pop(); } }

class Buffer { int buff = 0; Stack stack = new Stack(); int get() { return buff; } void set(int x) { log(buff+"->"+x); stack.push(buff); buff = x; } void undo() { log(stack.peek() +"<-"+buff); buff = stack.pop(); } }

software product line

Motivation: a problem from SPLs

3

class Buffer { int buff = 0; int get() { return buff; } void set(int x) { buff = x; } }

✓program analysis

✓✓✓✘✓✓

Goal: apply thisto all of these

configure

Page 4: Choice Calculus & Variational Programmingakcheung/pnw16/walkingshaw.pdf · PL Research @ OSU 2 Lots of research related to variability: • variational program analyses • variational

Solution: analyze variational program

4

class Buffer { int buff = 0; int get() { return buff; } void set(int x) { buff = x; } }

✓program analysis

variational program analysis

class Buffer { int buff = 0; #ifdef UndoOne int back = 0; #endif #ifdef UndoMany Stack stack = new Stack(); #endif int get() { return buff; } void set(int x) { #ifdef Logging log(buff+"->"+x); #endif #ifdef UndoOne back = buff; #endif #ifdef UndoMany stack.push(buff); #endif buff = x; }

#ifdef UndoOne void undo() { #ifdef Logging log(back+"<-"+bug); #endif buff = back; } #endif #ifdef UndoMany void undo() { #ifdef Logging log(stack.peek() +"<-"+buff); #endif buff = stack.pop(); } #endif }

✓✘✓✓✓

confi

gure

confi

gure

implementing these things = research

variational programvariational result

Page 5: Choice Calculus & Variational Programmingakcheung/pnw16/walkingshaw.pdf · PL Research @ OSU 2 Lots of research related to variability: • variational program analyses • variational

• Intro and motivation

• Choice calculus

• Variational type inference + applications

• Brief note on variational data structures

Outline

5

Page 6: Choice Calculus & Variational Programmingakcheung/pnw16/walkingshaw.pdf · PL Research @ OSU 2 Lots of research related to variability: • variational program analyses • variational

Choice calculus

6

e ::= a{e,...,e} | D⟨e,e⟩

A⟨2,3⟩ + B⟨4,A⟨5,6⟩⟩

2 + B⟨4,5⟩ 3 + B⟨4,6⟩

3 + 4 3 + 62 + 4 2 + 5

{A} {¬A}

{A,B} {A,¬B} {¬A,¬B}{¬A,B}

object language AST

choice between two alternatives synchronized by a dimension

A core metalanguage for describing variation

Martin Erwig

Page 7: Choice Calculus & Variational Programmingakcheung/pnw16/walkingshaw.pdf · PL Research @ OSU 2 Lots of research related to variability: • variational program analyses • variational

Equivalence laws

7

D⟨e,e⟩ ≡ e idempotency

D⟨e1,D⟨e2,e3⟩⟩ ≡ D⟨e1,e3⟩ domination

D1⟨D2⟨e1,e2⟩,D2⟨e3,e4⟩⟩ ≡ D2⟨D1⟨e1,e3⟩,D1⟨e2,e4⟩⟩

distribution

D⟨a{e1,e2},a{e3,e4}⟩ ≡ a{D⟨e1,e3⟩,D⟨e2,e4⟩}

factoring

Page 8: Choice Calculus & Variational Programmingakcheung/pnw16/walkingshaw.pdf · PL Research @ OSU 2 Lots of research related to variability: • variational program analyses • variational

Instantiating the choice calculus

8

e ::= c | x | λx.e | e e | D⟨e,e⟩

variational lambda calculus

T ::= κ | a | T -> T | D⟨T,T⟩

variational types

D⟨T1 -> T2, T3 -> T4⟩ ≡ D⟨T1,T3⟩ -> D⟨T2,T4⟩

can instantiate theequivalence laws too:

Page 9: Choice Calculus & Variational Programmingakcheung/pnw16/walkingshaw.pdf · PL Research @ OSU 2 Lots of research related to variability: • variational program analyses • variational

• Intro and motivation

• Choice calculus

• Variational type inference + applications

• Brief note on variational data structures

Outline

9

Page 10: Choice Calculus & Variational Programmingakcheung/pnw16/walkingshaw.pdf · PL Research @ OSU 2 Lots of research related to variability: • variational program analyses • variational

Variational type inference

10

Hindley-Milner

confi

gure

confi

gure

variational type

inference

variational lambda calculus

variational type

lambda calculus type

Page 11: Choice Calculus & Variational Programmingakcheung/pnw16/walkingshaw.pdf · PL Research @ OSU 2 Lots of research related to variability: • variational program analyses • variational

Variational unification

11

Goal: find a mapping so that�= {a ⇥� T } TL�� TR�

AhInt,ai ¥? Aha,Booli

Int¥? a a ¥?Bool

stuck!

decompose byalternatives

�= {a ⇥� A⇤Int,Bool⌅ }

Page 12: Choice Calculus & Variational Programmingakcheung/pnw16/walkingshaw.pdf · PL Research @ OSU 2 Lots of research related to variability: • variational program analyses • variational

Variational unification

12

A�Int,aA⇥ ⇤? A�aA ,Bool⇥

AhInt,ai ¥? Aha,Booli

1. Qualification

aA ¥?BoolInt¥? aA 2. Solve qualified problem

3. Completion

{aA ⇥� Int,aA ⇥� Bool }

{a ⇥� A⇤Int,Bool⌅ }

Page 13: Choice Calculus & Variational Programmingakcheung/pnw16/walkingshaw.pdf · PL Research @ OSU 2 Lots of research related to variability: • variational program analyses • variational

Variational unification

13

AhBhInt,Booli,aAi ¥? BhaB,Booli

AhBhInt,Booli,ai ¥? Bha,Booli

Goal: transformso we candecomposeby alternatives

1. Qualification

BhAhInt,aABi, AhBool,aABii ¥? BhaB,Booliswap

2. Solve qualified problem

C-C-SWAP1D0hDhT1,T2i,T3i ¥ DhD0hT1,T3i,D0hT2,T3ii

Page 14: Choice Calculus & Variational Programmingakcheung/pnw16/walkingshaw.pdf · PL Research @ OSU 2 Lots of research related to variability: • variational program analyses • variational

Variational unification

14

AhBhInt,Booli,aAi ¥? BhaB,Booli

AhBhInt,Booli,ai ¥? Bha,Booli

1. Qualification

BhAhInt,aABi, AhBool,aABii ¥? BhaB,Booliswap

AhInt,aABi ¥? aB

Bool¥?Bool aAB ¥?

Bool

AhBool,aABi ¥?Bool

3. Completion

2. Solve qualified problem

C-IDEMPT1 ¥ T T2 ¥ T

DhT1,T2i ¥ T

{aB ⇥� A⇤Int,aAB⌅, aAB ⇥� Bool }

{a ⇥� B⇤A⇤Int, c⌅, A⇤d,Bool⌅⌅ }

Page 15: Choice Calculus & Variational Programmingakcheung/pnw16/walkingshaw.pdf · PL Research @ OSU 2 Lots of research related to variability: • variational program analyses • variational

Important results

15

O(l2r+ lr2)

Extending Type Inference to Variational ProgramsTOPLAS, 2014

Variational unification is:

• sound, complete, and most general

• polynomially bounded:

Variational type inference is sound, complete, and principal

Page 16: Choice Calculus & Variational Programmingakcheung/pnw16/walkingshaw.pdf · PL Research @ OSU 2 Lots of research related to variability: • variational program analyses • variational

Surprising applications

16

Sheng Chen @ Lafayette• Improving error location in plain Haskell

Counter-Factual Typing for Debugging Type ErrorsPOPL, 2014

• Improving precision of type inference for GADTs

Principal Type Inference for GADTsPOPL, 2016

Page 17: Choice Calculus & Variational Programmingakcheung/pnw16/walkingshaw.pdf · PL Research @ OSU 2 Lots of research related to variability: • variational program analyses • variational

• Intro and motivation

• Choice calculus

• Variational type inference + applications

• Brief note on variational data structures

Outline

17

Page 18: Choice Calculus & Variational Programmingakcheung/pnw16/walkingshaw.pdf · PL Research @ OSU 2 Lots of research related to variability: • variational program analyses • variational

Variational analysis strike force

18

Christian KästnerCarnegie Mellon

Sven ApelPassau

Martin ErwigOregon State

Eric BoddenDarmstadt

Variational . . .• parsing in TypeChef• type checking in TypeChef & FFJPL

• type inference in VLC

• data-flow analysis in SPLLIFT

• execution in a Haskell DSL• test execution in VarEx(J)

Page 19: Choice Calculus & Variational Programmingakcheung/pnw16/walkingshaw.pdf · PL Research @ OSU 2 Lots of research related to variability: • variational program analyses • variational

When implementing variational analyses … the variation gets everywhere!

19

Must manage variation in …

• lists – token streams, TLDs

• trees – ASTs, types

• maps – symbol tables

• graphs – data-flow, control-flow

• and all kinds of intermediate values

so far we’ve dealt with this in an ad hoc way …

Page 20: Choice Calculus & Variational Programmingakcheung/pnw16/walkingshaw.pdf · PL Research @ OSU 2 Lots of research related to variability: • variational program analyses • variational

Variational execution and data structures

20

Needed: foundational work

• deal with variation systematically

• solve problems by considering tradeoffs among well-understood, general-purpose variational data structures

support reuse (libraries) and intentional design decisions

Variational Data Structures: Exploring Tradeoffs in Computing with Variability Onward!, 2014

Page 21: Choice Calculus & Variational Programmingakcheung/pnw16/walkingshaw.pdf · PL Research @ OSU 2 Lots of research related to variability: • variational program analyses • variational

Beyond variational program analyses

21

evaluation w/ multiple privacy policies

Austin et al. (PLAS'13)

encoding lists in symbolic execution Torlak & Bodik (PLDI'14)

Car BikeWalkBus

PDX, Portland, OR

Starting Location(s)

OSU, Corvallis, OR

Ending Location(s)

Fillmore Inn, Corvallis, OR

Silver Falls, Marion, OR

Waypoints

Add alternative...

Add alternative...

Add waypoint...

Avoid Highways Avoid Tolls

route planning software

representationssimilar to oneswe've used