Choice Calculus & Variational Programmingakcheung/pnw16/walkingshaw.pdf · PL Research @ OSU 2 Lots...
Transcript of Choice Calculus & Variational Programmingakcheung/pnw16/walkingshaw.pdf · PL Research @ OSU 2 Lots...
1
Choice Calculus &Variational Programming
PNW PL/SE Meeting 2016
Eric Walkingshaw Oregon State University
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
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
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
• Intro and motivation
• Choice calculus
• Variational type inference + applications
• Brief note on variational data structures
Outline
5
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
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
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:
• Intro and motivation
• Choice calculus
• Variational type inference + applications
• Brief note on variational data structures
Outline
9
Variational type inference
10
Hindley-Milner
confi
gure
confi
gure
variational type
inference
variational lambda calculus
variational type
lambda calculus type
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⌅ }
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⌅ }
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
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⌅⌅ }
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
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
• Intro and motivation
• Choice calculus
• Variational type inference + applications
• Brief note on variational data structures
Outline
17
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)
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 …
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
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